[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:51 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=93fbd62

The following commit has been merged in the master branch:
commit 93fbd621a44bfff18dc72fc1482157ce3313a2e9
Author: Martin Klapetek <mklapetek at kde.org>
Date:   Tue Jun 2 14:34:32 2015 +0200

    Implement migration from KAccounts1 accounts
    
    This migrates both the account and the logs too.
    
    So far successfully tested on various combinations using ICQ account.
---
 kaccounts/kaccounts-ktp-plugin.cpp | 159 ++++++++++++++++++++++++++++++++++++-
 kaccounts/kaccounts-ktp-plugin.h   |   2 +
 2 files changed, 160 insertions(+), 1 deletion(-)

diff --git a/kaccounts/kaccounts-ktp-plugin.cpp b/kaccounts/kaccounts-ktp-plugin.cpp
index 627baa0..96a14f8 100644
--- a/kaccounts/kaccounts-ktp-plugin.cpp
+++ b/kaccounts/kaccounts-ktp-plugin.cpp
@@ -24,18 +24,25 @@
 #include <TelepathyQt/PendingOperation>
 #include <TelepathyQt/PendingAccount>
 #include <TelepathyQt/PendingReady>
+#include <TelepathyQt/PendingVariant>
 #include <TelepathyQt/AccountSet>
+#include <TelepathyQt/AccountInterfaceStorageInterface>
+#include <TelepathyQt/Utils>
+#include <TelepathyQt/PendingVariantMap>
 
 #include <KSharedConfig>
 #include <KConfigGroup>
 
 #include <QTimer>
+#include <QStandardPaths>
+#include <QDir>
 
 #include <KTp/Logger/log-manager.h>
 
 #include <Accounts/Service>
 #include <Accounts/Manager>
 #include <Accounts/Account>
+#include <Accounts/AccountService>
 
 #include <KAccounts/getcredentialsjob.h>
 #include <KAccounts/core.h>
@@ -52,11 +59,13 @@ public:
     Private(KAccountsKTpPlugin *qq) { q = qq; };
     Tp::AccountPtr tpAccountForAccountId(const Accounts::AccountId accountId);
     void migrateTelepathyAccounts();
+    void migrateLogs(const QString &tpAccountId, const Accounts::AccountId accountId);
 
     Tp::AccountManagerPtr accountManager;
     Tp::ConnectionManagerPtr connectionManager;
     Tp::ProfilePtr profile;
     KSharedConfigPtr kaccountsConfig;
+    QString logsBasePath;
     KAccountsKTpPlugin *q;
 };
 
@@ -71,7 +80,155 @@ Tp::AccountPtr KAccountsKTpPlugin::Private::tpAccountForAccountId(const Accounts
 
 void KAccountsKTpPlugin::Private::migrateTelepathyAccounts()
 {
-    // some new migration will be needed
+    Q_FOREACH (const Tp::AccountPtr &account, accountManager->validAccounts()->accounts()) {
+        KConfigGroup kaccountsKtpGroup = kaccountsConfig->group(QStringLiteral("ktp-kaccounts"));
+        const Accounts::AccountId kaccountsId = kaccountsKtpGroup.readEntry(account->objectPath(), 0);
+
+        qDebug() << "Looking at" << account->objectPath();
+        qDebug() << " KAccounts id" << kaccountsId;
+
+        if (kaccountsId != 0) {
+            migrateLogs(account->objectPath(), kaccountsId);
+
+            Accounts::Account *kaccount = KAccounts::accountsManager()->account(kaccountsId);
+            auto services = kaccount->services(QStringLiteral("IM"));
+
+            if (services.size() > 0) {
+                qDebug() << "Writing service data:" << account->cmName() << account->protocolName() << account->serviceName();
+                Accounts::Service imService = services.at(0);
+                Accounts::AccountService accountService(kaccount, imService);
+                accountService.setValue("telepathy/manager", account->cmName());
+                accountService.setValue("telepathy/protocol", account->protocolName());
+                kaccount->sync();
+            }
+
+            kaccountsKtpGroup.deleteEntry(account->objectPath());
+            KConfigGroup ktpKaccountsGroup = kaccountsConfig->group(QStringLiteral("kaccounts-ktp"));
+            ktpKaccountsGroup.deleteEntry(QString::number(kaccountsId));
+
+            kaccount->deleteLater();
+            account->remove();
+        } else {
+            // Get account storage interface
+
+            Tp::Client::AccountInterfaceStorageInterface storageInterface(account.data());
+            Tp::PendingVariant *data = storageInterface.requestPropertyStorageProvider();
+            data->setProperty("accountObjectPath", account->objectPath());
+            QObject::connect(data, &Tp::PendingOperation::finished, q, &KAccountsKTpPlugin::onStorageProviderRetrieved);
+        }
+    }
+}
+
+void KAccountsKTpPlugin::onStorageProviderRetrieved(Tp::PendingOperation *op)
+{
+    const QString storageProvider = qobject_cast<Tp::PendingVariant*>(op)->result().toString();
+    if (storageProvider == QLatin1String("im.telepathy.Account.Storage.AccountsSSO")) {
+        qDebug() << "Found Tp Account with AccountsSSO provider, skipping...";
+        return;
+    }
+
+    qDebug() << "No KAccounts id, creating new account";
+    Accounts::Account *kaccount;
+
+    Tp::AccountPtr account = d->accountManager->accountForObjectPath(op->property("accountObjectPath").toString());
+
+    if (account.isNull() || !account->isValid()) {
+        qDebug() << "An invalid Tp Account retrieved, aborting...";
+        return;
+    }
+
+    QString providerName = QStringLiteral("ktp-");
+
+    if (s_knownProviders.contains(account->serviceName())) {
+        providerName.append(account->serviceName());
+    } else {
+        providerName.append(QStringLiteral("generic"));
+    }
+
+    qDebug() << "Creating account with providerName" << providerName;
+
+    kaccount = KAccounts::accountsManager()->createAccount(providerName);
+    kaccount->setDisplayName(account->displayName());
+    kaccount->setValue(QStringLiteral("uid"), account->objectPath());
+    kaccount->setValue(QStringLiteral("username"), account->nickname());
+    kaccount->setValue(QStringLiteral("auth/mechanism"), QStringLiteral("password"));
+    kaccount->setValue(QStringLiteral("auth/method"), QStringLiteral("password"));
+
+    kaccount->setEnabled(true);
+
+    Accounts::ServiceList services = kaccount->services();
+    Q_FOREACH(const Accounts::Service &service, services) {
+        kaccount->selectService(service);
+        kaccount->setEnabled(account->isEnabled());
+
+        if (service.serviceType() == QLatin1String("IM")) {
+            Accounts::AccountService accountService(kaccount, service);
+            accountService.setValue("telepathy/manager", account->cmName());
+            accountService.setValue("telepathy/protocol", account->protocolName());
+        }
+    }
+
+    qDebug() << account->nickname() << kaccount->id();
+
+    kaccount->sync();
+    QObject::connect(kaccount, &Accounts::Account::synced, this, &KAccountsKTpPlugin::onAccountSynced);
+}
+
+void KAccountsKTpPlugin::onAccountSynced()
+{
+    Accounts::Account *account = qobject_cast<Accounts::Account*>(sender());
+    if (!account) {
+        return;
+    }
+
+    const QString tpAccountId = account->value(QStringLiteral("uid")).toString();
+    d->migrateLogs(tpAccountId, account->id());
+    Tp::AccountPtr tpAccount = d->accountManager->accountForObjectPath(tpAccountId);
+    tpAccount->remove();
+}
+
+void KAccountsKTpPlugin::Private::migrateLogs(const QString &tpAccountId, const Accounts::AccountId accountId)
+{
+    if (tpAccountId.isEmpty() || accountId == 0) {
+        qWarning() << "Cannot finish migration because of empty data received: TP account id:" << tpAccountId << "KAccounts ID:" << accountId;
+        return;
+    }
+
+    if (logsBasePath.isEmpty()) {
+        logsBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/TpLogger/logs");
+    }
+
+    Tp::AccountPtr tpAccount = accountManager->accountForObjectPath(tpAccountId);
+
+    if (tpAccount.isNull() || tpAccount->isValid()) {
+        return;
+    }
+
+    QString newLogsDir = tpAccount->cmName() + QStringLiteral("_")
+                           + tpAccount->protocolName() + QStringLiteral("_")
+                           + Tp::escapeAsIdentifier(QStringLiteral("ktp-") + tpAccount->serviceName())
+                           + QStringLiteral("_") + QString::number(accountId);
+
+    QString accountLogsDir = tpAccount->uniqueIdentifier();
+
+    /* Escape '/' in tpAccountId as '_' */
+    if (accountLogsDir.contains(QLatin1Char('/'))) {
+        accountLogsDir.replace(QLatin1Char('/'), QLatin1String("_"));
+    }
+
+    QDir logsDir(logsBasePath);
+
+    qDebug() << "Migrating logs for" << accountLogsDir << "into" << newLogsDir;
+
+    bool renamed = false;
+
+    if (logsDir.exists()) {
+        renamed = logsDir.rename(accountLogsDir, newLogsDir);
+    }
+
+    if (!renamed) {
+        qWarning() << "Could not rename the directory!";
+    }
 }
 
 //---------------------------------------------------------------------------------------
diff --git a/kaccounts/kaccounts-ktp-plugin.h b/kaccounts/kaccounts-ktp-plugin.h
index 11d730d..1156255 100644
--- a/kaccounts/kaccounts-ktp-plugin.h
+++ b/kaccounts/kaccounts-ktp-plugin.h
@@ -47,6 +47,8 @@ public Q_SLOTS:
 
 private Q_SLOTS:
     void onAccountManagerReady(Tp::PendingOperation *op);
+    void onAccountSynced();
+    void onStorageProviderRetrieved(Tp::PendingOperation *op);
 
 private:
     class Private;

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list