[Pkg-owncloud-commits] [qtkeychain] 61/115: Fallback earlier if D-Bus is not available

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Mar 15 19:25:46 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 4556eb0e4f7e8a254143eb4ec5e39b0440c9f6c4
Author: Uwe L. Korn <uwelk at xhochy.com>
Date:   Thu Jun 6 14:25:07 2013 +0200

    Fallback earlier if D-Bus is not available
---
 keychain_dbus.cpp | 141 ++++++++++++++++++++++++++++++++++--------------------
 keychain_p.h      |   5 +-
 2 files changed, 93 insertions(+), 53 deletions(-)

diff --git a/keychain_dbus.cpp b/keychain_dbus.cpp
index f0ca244..3c735fa 100644
--- a/keychain_dbus.cpp
+++ b/keychain_dbus.cpp
@@ -15,49 +15,70 @@
 using namespace QKeychain;
 
 void ReadPasswordJobPrivate::scheduledStart() {
-    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*)) );
+    if ( QDBusConnection::sessionBus().isConnected() )
+    {
+        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*)) );
+    }
+    else
+    {
+        // D-Bus is not reachable so none can tell us something about KWalletd
+        QDBusError err( QDBusError::NoServer, "D-Bus is not running" );
+        fallbackOnError( err );
+    }
 }
 
-void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
-    watcher->deleteLater();
-    const QDBusPendingReply<int> reply = *watcher;
-
+void ReadPasswordJobPrivate::fallbackOnError(const QDBusError& err )
+{
     std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
     QSettings* actual = q->settings() ? q->settings() : local.get();
     WritePasswordJobPrivate::Mode mode;
 
-    const QString typeKey = QString( "%1/type" ).arg( key );
-    const QString dataKey = QString( "%1/data" ).arg( key );
-    if ( reply.isError() ) {
-        const QDBusError err = reply.error();
+    if ( q->insecureFallback() && actual->contains( dataKey() ) ) {
+
+        mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey() ).toInt();
+        data = actual->value( dataKey() ).toByteArray();
 
-        if ( q->insecureFallback() && actual->contains( dataKey ) ) {
+        q->emitFinished();
+    } else {
+        if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
+            q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
+        else
+            q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+    }
+}
 
-            mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
-            data = actual->value( dataKey ).toByteArray();
+const QString ReadPasswordJobPrivate::typeKey()
+{
+    return QString( "%1/type" ).arg( key );
+}
 
-            q->emitFinished();
+const QString ReadPasswordJobPrivate::dataKey()
+{
+    return QString( "%1/data" ).arg( key );
+}
 
-            return;
-        } else {
-            if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
-                q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
-            else
-                q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
+    watcher->deleteLater();
+    const QDBusPendingReply<int> reply = *watcher;
 
-            return;
-        }
+    std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
+    QSettings* actual = q->settings() ? q->settings() : local.get();
+    WritePasswordJobPrivate::Mode mode;
+
+    if ( reply.isError() ) {
+        fallbackOnError( reply.error() );
+        return;
     }
 
-    if ( actual->contains( dataKey ) ) {
+    if ( actual->contains( dataKey() ) ) {
         // We previously stored data in the insecure QSettings, but now have KWallet available.
         // Do the migration
 
-        data = actual->value( dataKey ).toByteArray();
-        mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
+        data = actual->value( dataKey() ).toByteArray();
+        mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey() ).toInt();
         actual->remove( key );
 
         q->emitFinished();
@@ -129,10 +150,46 @@ void ReadPasswordJobPrivate::kwalletReadFinished( QDBusPendingCallWatcher* watch
 }
 
 void WritePasswordJobPrivate::scheduledStart() {
-    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*)) );
+    if ( QDBusConnection::sessionBus().isConnected() )
+    {
+        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*)) );
+    }
+    else
+    {
+        // D-Bus is not reachable so none can tell us something about KWalletd
+        QDBusError err( QDBusError::NoServer, "D-Bus is not running" );
+        fallbackOnError( err );
+    }
+}
+
+void WritePasswordJobPrivate::fallbackOnError(const QDBusError &err)
+{
+    std::auto_ptr<QSettings> local( !q->settings() ? new QSettings(  q->service() ) : 0 );
+    QSettings* actual = q->settings() ? q->settings() : local.get();
+
+    if ( q->insecureFallback() ) {
+        if ( mode == Delete ) {
+            actual->remove( key );
+            actual->sync();
+
+            q->emitFinished();
+            return;
+        }
+
+        actual->setValue( QString( "%1/type" ).arg( key ), (int)mode );
+        if ( mode == Text )
+            actual->setValue( QString( "%1/data" ).arg( key ), textData.toUtf8() );
+        else if ( mode == Binary )
+            actual->setValue( QString( "%1/data" ).arg( key ), binaryData );
+        actual->sync();
+
+        q->emitFinished();
+    } else {
+        q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
+    }
 }
 
 void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
@@ -143,27 +200,7 @@ void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watc
     QSettings* actual = q->settings() ? q->settings() : local.get();
 
     if ( reply.isError() ) {
-        if ( q->insecureFallback() ) {
-            if ( mode == Delete ) {
-                actual->remove( key );
-                actual->sync();
-
-                q->emitFinished();
-                return;
-            }
-
-            actual->setValue( QString( "%1/type" ).arg( key ), (int)mode );
-            if ( mode == Text )
-                actual->setValue( QString( "%1/data" ).arg( key ), textData.toUtf8() );
-            else if ( mode == Binary )
-                actual->setValue( QString( "%1/data" ).arg( key ), binaryData );
-            actual->sync();
-
-            q->emitFinished();
-        } else {
-            const QDBusError err = reply.error();
-            q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
-        }
+        fallbackOnError( reply.error() );
         return;
     }
 
diff --git a/keychain_p.h b/keychain_p.h
index 9b87d08..a0f3296 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -68,7 +68,10 @@ public:
 #if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
     org::kde::KWallet* iface;
     friend class QKeychain::JobExecutor;
+    void fallbackOnError(const QDBusError& err);
 
+    const QString typeKey();
+    const QString dataKey();
 private Q_SLOTS:
     void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
     void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
@@ -102,7 +105,7 @@ public:
 #if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
     org::kde::KWallet* iface;
     friend class QKeychain::JobExecutor;
-
+    void fallbackOnError(const QDBusError& err);
 
 private Q_SLOTS:
     void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );

-- 
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