[Pkg-owncloud-commits] [qtkeychain] 33/115: kwallet: make read and write work

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Mar 15 19:25:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository qtkeychain.

commit 55b1fc88636c08d4a5c38ad63ff6ad409a5bd876
Author: Frank Osterfeld <frank.osterfeld at kdab.com>
Date:   Tue May 8 10:47:38 2012 +0200

    kwallet: make read and write work
---
 keychain_dbus.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 keychain_p.h      | 18 ++++++++++++++++-
 2 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/keychain_dbus.cpp b/keychain_dbus.cpp
index 63e7b44..03f1ad3 100644
--- a/keychain_dbus.cpp
+++ b/keychain_dbus.cpp
@@ -13,7 +13,63 @@
 using namespace QKeychain;
 
 void ReadPasswordJob::Private::doStart() {
-    q->emitFinishedWithError( NotImplemented, QString() );
+    iface = new org::kde::KWallet( QLatin1String("org.kde.kwalletd"), QLatin1String("/modules/kwalletd"), QDBusConnection::sessionBus(), this );
+    const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
+    QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
+    connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
+}
+
+void ReadPasswordJob::Private::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
+    watcher->deleteLater();
+    const QDBusPendingReply<int> reply = *watcher;
+    if ( reply.isError() ) {
+        const QDBusError err = reply.error();
+        q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+        return;
+    }
+
+    walletHandle = reply.value();
+
+    const QDBusPendingReply<int> nextReply = iface->entryType( walletHandle, q->service(), key, q->service() );
+    QDBusPendingCallWatcher* nextWatcher = new QDBusPendingCallWatcher( nextReply, this );
+    connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletEntryTypeFinished(QDBusPendingCallWatcher*)) );
+}
+
+void ReadPasswordJob::Private::kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher ) {
+    watcher->deleteLater();
+    if ( watcher->isError() ) {
+        const QDBusError err = watcher->error();
+        q->emitFinishedWithError( OtherError, tr("Could not determine data type: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+        return;
+    }
+
+    const QDBusPendingReply<int> reply = *watcher;
+
+    dataType = reply.value() == 1/*Password*/ ? Text : Binary;
+
+    const QDBusPendingCall nextReply = dataType == Text
+        ? QDBusPendingCall( iface->readPassword( walletHandle, q->service(), key, q->service() ) )
+        : QDBusPendingCall( iface->readEntry( walletHandle, q->service(), key, q->service() ) );
+    QDBusPendingCallWatcher* nextWatcher = new QDBusPendingCallWatcher( nextReply, this );
+    connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletReadFinished(QDBusPendingCallWatcher*)) );
+}
+
+void ReadPasswordJob::Private::kwalletReadFinished( QDBusPendingCallWatcher* watcher ) {
+    watcher->deleteLater();
+    if ( watcher->isError() ) {
+        const QDBusError err = watcher->error();
+        q->emitFinishedWithError( OtherError, tr("Could not read password: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+        return;
+    }
+
+    if ( dataType == Binary ) {
+        QDBusPendingReply<QByteArray> reply = *watcher;
+        data = reply.value();
+    } else {
+        QDBusPendingReply<QString> reply = *watcher;
+        data = reply.value().toUtf8();
+    }
+    q->emitFinished();
 }
 
 void WritePasswordJob::Private::doStart() {
@@ -21,7 +77,6 @@ void WritePasswordJob::Private::doStart() {
     const QDBusPendingReply<int> reply = iface->open( QLatin1String("kdewallet"), 0, q->service() );
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
     connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletOpenFinished(QDBusPendingCallWatcher*)) );
-    //q->emitFinishedWithError( NotImplemented, QString() );
 }
 
 void WritePasswordJob::Private::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
diff --git a/keychain_p.h b/keychain_p.h
index 7b0ad0b..be6bdf2 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -43,11 +43,27 @@ public:
 class ReadPasswordJob::Private : public QObject {
     Q_OBJECT
 public:
-    explicit Private( ReadPasswordJob* qq ) : q( qq ) {}
+    explicit Private( ReadPasswordJob* qq ) : q( qq ), walletHandle( 0 ), dataType( Text ) {}
     void doStart();
     ReadPasswordJob* const q;
     QByteArray data;
     QString key;
+    int walletHandle;
+    enum DataType {
+        Binary,
+        Text
+    };
+    DataType dataType;
+
+#if defined (Q_OS_UNIX) && (!defined(Q_WS_DARWIN))
+    org::kde::KWallet* iface;
+
+private Q_SLOTS:
+    void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
+    void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
+    void kwalletReadFinished( QDBusPendingCallWatcher* watcher );
+#endif
+
 };
 
 class WritePasswordJob::Private : public QObject {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/qtkeychain.git



More information about the Pkg-owncloud-commits mailing list