[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:05:26 UTC 2016


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

The following commit has been merged in the master branch:
commit cf95564fcea10708d17a7e93314f46841d935d18
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Tue Aug 7 00:35:04 2012 +0100

    Open KWallet asynchronously
    
    REVIEW: 105566
---
 KTp/CMakeLists.txt       |   3 +-
 KTp/pending-wallet.cpp   |  51 +++++++++++++++++++++
 KTp/pending-wallet.h     |  45 ++++++++++++++++++
 KTp/wallet-interface.cpp | 116 ++++++++++++++++++++++++++++-------------------
 KTp/wallet-interface.h   |  36 ++++++++++-----
 5 files changed, 192 insertions(+), 59 deletions(-)

diff --git a/KTp/CMakeLists.txt b/KTp/CMakeLists.txt
index 61da66d..f0f1d5f 100644
--- a/KTp/CMakeLists.txt
+++ b/KTp/CMakeLists.txt
@@ -10,6 +10,7 @@ set (ktp_common_internals_private_SRCS
      service-availability-checker.cpp
      telepathy-handler-application.cpp
      text-parser.cpp
+     pending-wallet.cpp
      wallet-interface.cpp
 )
 
@@ -22,8 +23,8 @@ set (ktp_common_internals_private_HDRS
      service-availability-checker.h
      telepathy-handler-application.h
      text-parser.h
+     pending-wallet.h
      wallet-interface.h
-
      ktp-export.h
 )
 
diff --git a/KTp/pending-wallet.cpp b/KTp/pending-wallet.cpp
new file mode 100644
index 0000000..c8680b9
--- /dev/null
+++ b/KTp/pending-wallet.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "pending-wallet.h"
+
+#include "wallet-interface.h"
+
+namespace KTp {
+class PendingWalletPrivate {
+public:
+    KTp::WalletInterface *walletInterface;
+};
+}
+
+KTp::PendingWallet::PendingWallet(KTp::WalletInterface* walletInterface)
+    :Tp::PendingOperation(Tp::SharedPtr<Tp::RefCounted>(0)),
+      d( new KTp::PendingWalletPrivate())
+{
+    d->walletInterface = walletInterface;
+    if (walletInterface->isOpen()) {
+        setFinished();
+    } else {
+        connect(walletInterface->wallet(), SIGNAL(walletOpened(bool)), SLOT(setFinished()));
+    }
+}
+
+KTp::PendingWallet::~PendingWallet()
+{
+    delete d;
+}
+
+KTp::WalletInterface *KTp::PendingWallet::walletInterface() const
+{
+    return d->walletInterface;
+}
+
diff --git a/KTp/pending-wallet.h b/KTp/pending-wallet.h
new file mode 100644
index 0000000..9ef86d7
--- /dev/null
+++ b/KTp/pending-wallet.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#ifndef PENDINGWALLETOPERATION_H
+#define PENDINGWALLETOPERATION_H
+
+#include <TelepathyQt/PendingOperation>
+
+#include "wallet-interface.h"
+#include <KTp/ktp-export.h>
+
+namespace KTp
+{
+class PendingWalletPrivate;
+
+class KTP_EXPORT PendingWallet : public Tp::PendingOperation
+{
+    Q_OBJECT
+public:
+    friend class WalletInterface;
+    KTp::WalletInterface *walletInterface() const;
+private:
+    PendingWallet(KTp::WalletInterface *wallet);
+    virtual ~PendingWallet();
+    KTp::PendingWalletPrivate *d;
+};
+
+}
+#endif // PENDINGWALLETOPERATION_H
diff --git a/KTp/wallet-interface.cpp b/KTp/wallet-interface.cpp
index d2dc2cb..89e83d7 100644
--- a/KTp/wallet-interface.cpp
+++ b/KTp/wallet-interface.cpp
@@ -19,6 +19,7 @@
  */
 
 #include "wallet-interface.h"
+#include "pending-wallet.h"
 
 #include <KDebug>
 #include <KGlobal>
@@ -39,33 +40,49 @@ using KTp::WalletInterfacePrivate;
 const QLatin1String WalletInterfacePrivate::folderName = QLatin1String("telepathy-kde");
 const QLatin1String WalletInterfacePrivate::mapsPrefix = QLatin1String("maps/");
 
-K_GLOBAL_STATIC(KTp::WalletInterfacePrivate, instance)
 
 WalletInterfacePrivate::WalletInterfacePrivate() :
-    wallet(KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0))
+    wallet(KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous))
 {
 }
 
+KTp::PendingWallet* WalletInterface::openWallet()
+{
+    K_GLOBAL_STATIC(KTp::WalletInterface, s_instance);
+    return new PendingWallet(s_instance);
+}
+
+
+WalletInterface::WalletInterface():
+    d (new WalletInterfacePrivate)
+{
+}
+
+WalletInterface::~WalletInterface()
+{
+    delete d;
+}
+
 bool WalletInterface::hasPassword(const Tp::AccountPtr &account)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return false;
     }
 
-    instance->wallet->setFolder(instance->folderName);
-    return instance->wallet->hasEntry(account->uniqueIdentifier());
+    d->wallet->setFolder(d->folderName);
+    return d->wallet->hasEntry(account->uniqueIdentifier());
 }
 
 QString WalletInterface::password(const Tp::AccountPtr &account)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return QString();
     }
 
-    instance->wallet->setFolder(instance->folderName);
+    d->wallet->setFolder(d->folderName);
     QString password;
-    if (instance->wallet->hasEntry(account->uniqueIdentifier())) {
-        int rc = instance->wallet->readPassword(account->uniqueIdentifier(), password);
+    if (d->wallet->hasEntry(account->uniqueIdentifier())) {
+        int rc = d->wallet->readPassword(account->uniqueIdentifier(), password);
         if (rc != 0) {
             password.clear();
             kWarning() << "failed to read password from KWallet";
@@ -76,41 +93,41 @@ QString WalletInterface::password(const Tp::AccountPtr &account)
 
 void WalletInterface::setPassword(const Tp::AccountPtr &account, const QString &password)
 {
-    if (instance->wallet.isNull()) {
+    if (d->wallet.isNull()) {
         return;
     }
 
-    if (!instance->wallet->hasFolder(instance->folderName)) {
-        instance->wallet->createFolder(instance->folderName);
+    if (!d->wallet->hasFolder(d->folderName)) {
+        d->wallet->createFolder(d->folderName);
     }
 
-    instance->wallet->setFolder(instance->folderName);
-    instance->wallet->writePassword(account->uniqueIdentifier(), password);
+    d->wallet->setFolder(d->folderName);
+    d->wallet->writePassword(account->uniqueIdentifier(), password);
     //sync normally happens on close, but in this case we need it to happen /now/ as it needs to be synced before the auth-client starts
-    instance->wallet->sync();
+    d->wallet->sync();
 }
 
 void WalletInterface::removePassword(const Tp::AccountPtr &account)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return;
     }
 
-    instance->wallet->setFolder(instance->folderName);
-    instance->wallet->removeEntry(account->uniqueIdentifier());
-    instance->wallet->sync();
+    d->wallet->setFolder(d->folderName);
+    d->wallet->removeEntry(account->uniqueIdentifier());
+    d->wallet->sync();
 }
 
 bool WalletInterface::hasEntry(const Tp::AccountPtr &account, const QString &key)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return false;
     }
 
-    instance->wallet->setFolder(instance->folderName);
+    d->wallet->setFolder(d->folderName);
     QMap< QString, QString > map;
-    if (instance->wallet->hasEntry(instance->mapsPrefix + account->uniqueIdentifier())) {
-        int rc = instance->wallet->readMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+    if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
+        int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
         if (rc != 0) {
             kWarning() << "failed to read map from KWallet (probably it is not a map)";
             return false;
@@ -121,15 +138,15 @@ bool WalletInterface::hasEntry(const Tp::AccountPtr &account, const QString &key
 
 QString WalletInterface::entry(const Tp::AccountPtr &account, const QString &key)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return QString();
     }
 
-    instance->wallet->setFolder(instance->folderName);
+    d->wallet->setFolder(d->folderName);
     QString value;
     QMap< QString, QString > map;
-    if (instance->wallet->hasEntry(instance->mapsPrefix + account->uniqueIdentifier())) {
-        int rc = instance->wallet->readMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+    if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
+        int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
         if (rc != 0) {
             kWarning() << "failed to read map from KWallet (probably it is not a map)";
             return QString();
@@ -140,18 +157,18 @@ QString WalletInterface::entry(const Tp::AccountPtr &account, const QString &key
 
 void WalletInterface::setEntry(const Tp::AccountPtr &account, const QString &key, const QString &value)
 {
-    if (instance->wallet.isNull()) {
+    if (d->wallet.isNull()) {
         return;
     }
 
-    if (! instance->wallet->hasFolder(instance->folderName)) {
-        instance->wallet->createFolder(instance->folderName);
+    if (! d->wallet->hasFolder(d->folderName)) {
+        d->wallet->createFolder(d->folderName);
     }
 
-    instance->wallet->setFolder(instance->folderName);
+    d->wallet->setFolder(d->folderName);
     QMap< QString, QString > map;
-    if (instance->wallet->hasEntry(instance->mapsPrefix + account->uniqueIdentifier())) {
-        int rc = instance->wallet->readMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+    if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
+        int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
         if (rc != 0) {
             kWarning() << "failed to read map from KWallet (probably it is not a map)";
             return;
@@ -159,21 +176,21 @@ void WalletInterface::setEntry(const Tp::AccountPtr &account, const QString &key
     }
     map[key] = value;
 
-    instance->wallet->writeMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+    d->wallet->writeMap(d->mapsPrefix + account->uniqueIdentifier(), map);
     //sync normally happens on close, but in this case we need it to happen /now/ as it needs to be synced before the auth-client starts
-    instance->wallet->sync();
+    d->wallet->sync();
 }
 
 void WalletInterface::removeEntry(const Tp::AccountPtr &account, const QString &key)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return;
     }
 
-    instance->wallet->setFolder(instance->folderName);
+    d->wallet->setFolder(d->folderName);
     QMap< QString, QString > map;
-    if (instance->wallet->hasEntry(instance->mapsPrefix + account->uniqueIdentifier())) {
-        int rc = instance->wallet->readMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+    if (d->wallet->hasEntry(d->mapsPrefix + account->uniqueIdentifier())) {
+        int rc = d->wallet->readMap(d->mapsPrefix + account->uniqueIdentifier(), map);
         if (rc != 0) {
             kWarning() << "failed to read map from KWallet (probably it is not a map)";
             return;
@@ -182,22 +199,22 @@ void WalletInterface::removeEntry(const Tp::AccountPtr &account, const QString &
     map.remove(key);
 
     if (!map.empty()) {
-        instance->wallet->writeMap(instance->mapsPrefix + account->uniqueIdentifier(), map);
+        d->wallet->writeMap(d->mapsPrefix + account->uniqueIdentifier(), map);
     } else {
-        instance->wallet->removeEntry(instance->mapsPrefix + account->uniqueIdentifier());
+        d->wallet->removeEntry(d->mapsPrefix + account->uniqueIdentifier());
     }
     //sync normally happens on close, but in this case we need it to happen /now/ as it needs to be synced before the auth-client starts
-    instance->wallet->sync();
+    d->wallet->sync();
 }
 
 void WalletInterface::removeAllEntries(const Tp::AccountPtr& account)
 {
-    if (instance->wallet.isNull() || !instance->wallet->hasFolder(instance->folderName)) {
+    if (d->wallet.isNull() || !d->wallet->hasFolder(d->folderName)) {
         return;
     }
 
-    instance->wallet->setFolder(instance->folderName);
-    instance->wallet->removeEntry(instance->mapsPrefix + account->uniqueIdentifier());
+    d->wallet->setFolder(d->folderName);
+    d->wallet->removeEntry(d->mapsPrefix + account->uniqueIdentifier());
 }
 
 void WalletInterface::removeAccount(const Tp::AccountPtr& account)
@@ -208,5 +225,12 @@ void WalletInterface::removeAccount(const Tp::AccountPtr& account)
 
 bool WalletInterface::isOpen()
 {
-    return (!instance->wallet.isNull() && instance->wallet->isOpen());
+    return (!d->wallet.isNull() && d->wallet->isOpen());
 }
+
+KWallet::Wallet *WalletInterface::wallet() const
+{
+    return d->wallet.data();
+}
+
+
diff --git a/KTp/wallet-interface.h b/KTp/wallet-interface.h
index c43fb38..c6281a6 100644
--- a/KTp/wallet-interface.h
+++ b/KTp/wallet-interface.h
@@ -22,6 +22,7 @@
 #define WALLETINTERFACE_H
 
 #include <TelepathyQt/Account>
+#include <TelepathyQt/PendingOperation>
 
 #include <KWallet/Wallet>
 
@@ -33,50 +34,61 @@ namespace KTp
 {
 
 class WalletInterfacePrivate;
+class PendingWallet;
 
 
+/** Class wraps interface around KWallet. A singleton is used to make sure that the wallet is only even opened once if multiple instances of
+    this class are used throughout the application*/
+
 class KTP_EXPORT WalletInterface
 {
     friend class WalletInterfacePrivate;
 public:
-//    static WalletInterface* instance();
+
+    /** Tries to open the wallet. Op contains a pointer to the wallet operation interface*/
+    static KTp::PendingWallet *openWallet();
 
     /** Returns true if a password is stored for the given account */
-    static bool hasPassword(const Tp::AccountPtr &account);
+    bool hasPassword(const Tp::AccountPtr &account);
 
     /** Returns the stored password for the given account */
-    static QString password(const Tp::AccountPtr &account);
+    QString password(const Tp::AccountPtr &account);
 
     /** Set the password for the given account to a new password */
-    static void setPassword(const Tp::AccountPtr &account, const QString &password);
+    void setPassword(const Tp::AccountPtr &account, const QString &password);
 
     /** Remove the password for the given account from kwallet */
-    static void removePassword(const Tp::AccountPtr &account);
+    void removePassword(const Tp::AccountPtr &account);
 
     /** Returns true if a given entry is stored for the given account */
-    static bool hasEntry(const Tp::AccountPtr &account, const QString &key);
+    bool hasEntry(const Tp::AccountPtr &account, const QString &key);
 
     /** Returns the stored entry for the given account */
-    static QString entry(const Tp::AccountPtr &account, const QString &key);
+    QString entry(const Tp::AccountPtr &account, const QString &key);
 
     /** Set an entry for the given account to a new value */
-    static void setEntry(const Tp::AccountPtr &account, const QString &key, const QString &value);
+    void setEntry(const Tp::AccountPtr &account, const QString &key, const QString &value);
 
     /** Remove the entry for the given account from kwallet */
-    static void removeEntry(const Tp::AccountPtr &account, const QString &key);
+    void removeEntry(const Tp::AccountPtr &account, const QString &key);
 
     /** Remove all the entries for the given account from kwallet */
-    static void removeAllEntries(const Tp::AccountPtr &account);
+    void removeAllEntries(const Tp::AccountPtr &account);
 
     /** Remove entries and password for the account from kwallet */
-    static void removeAccount(const Tp::AccountPtr &account);
+    void removeAccount(const Tp::AccountPtr &account);
 
     /** Determine if the wallet is open, and is a valid wallet handle */
-    static bool isOpen();
+    bool isOpen();
+
+    /** Raw access to the underlying wallet. Should not be used.*/
+    KWallet::Wallet* wallet() const;
 
 private:
+    Q_DISABLE_COPY(WalletInterface)
     WalletInterface();
     virtual ~WalletInterface();
+    WalletInterfacePrivate *d;
 };
 
 } // namespace KTp

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list