From fc754ec38092f3a1835be06b8fcd16eed19a69d8 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Tue, 24 May 2011 11:52:11 +0200 Subject: [PATCH] no point in having two KDirWatches when we can have one also fix the signatures of the slots in the private class --- remote/signing.cpp | 81 +++++++++++++++++++++++----------------------- remote/signing.h | 6 ++-- remote/signing_p.h | 9 +++--- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/remote/signing.cpp b/remote/signing.cpp index 2ef9ef88a..e66d400f8 100644 --- a/remote/signing.cpp +++ b/remote/signing.cpp @@ -78,26 +78,18 @@ SigningPrivate::SigningPrivate(Signing *auth, const QString &path) m_keystoreDir = new KDirWatch(); m_keystoreDir->addDir(m_keystorePath); + m_keystoreDir->addDir(ultimateKeyStoragePath()); m_keystoreDir->startScan(true); - m_KdeKeysDir = new KDirWatch(); - m_KdeKeysDir->addDir(ultimateKeyStoragePath()); - m_KdeKeysDir->startScan(true); - // Start watching the keystore and the dir with the kde keys, and notify for changed - q->connect(m_keystoreDir, SIGNAL(created(const QString &)), q, SLOT(slotProcessKeystore())); -// q->connect(m_keystoreDir, SIGNAL(dirty(const QString &)), q, SLOT(slotKDEKeyRemoved(const QString &))); - q->connect(m_keystoreDir, SIGNAL(deleted(const QString &)), q, SLOT(slotKDEKeyRemoved(const QString &))); - - q->connect(m_KdeKeysDir, SIGNAL(created(const QString &)), q, SLOT(slotKDEKeyAdded(const QString &))); - q->connect(m_KdeKeysDir, SIGNAL(dirty(const QString &)), q, SLOT(slotKDEKeyAdded(const QString &))); - q->connect(m_KdeKeysDir, SIGNAL(deleted(const QString &)), q, SLOT(slotKDEKeyRemoved(const QString &))); + q->connect(m_keystoreDir, SIGNAL(created(const QString &)), q, SLOT(processKeystore())); + q->connect(m_keystoreDir, SIGNAL(dirty(const QString &)), q, SLOT(keyAdded(const QString &))); + q->connect(m_keystoreDir, SIGNAL(deleted(const QString &)), q, SLOT(keyRemoved(const QString &))); } SigningPrivate::~SigningPrivate() { delete m_keystoreDir; - delete m_KdeKeysDir; } QString SigningPrivate::ultimateKeyStoragePath() const @@ -108,24 +100,25 @@ QString SigningPrivate::ultimateKeyStoragePath() const void SigningPrivate::registerUltimateTrustKeys() { QList< QByteArray > tmp; + keys[UltimatelyTrusted] = tmp; + if (!m_gpgContext) { kDebug() << "GPGME context not valid: please re-initialize the library."; - keys.insert(UltimatelyTrusted, tmp); return; } + QString path = ultimateKeyStoragePath(); QDir dir(path); if (!dir.exists() || path.isEmpty()) { kDebug() << "Directory with KDE keys not found: aborting"; - keys[UltimatelyTrusted] = tmp; return; } - QStringList keyFiles = dir.entryList(QDir::Files); // QDir::Files is rendundant in this stage + + const QStringList keyFiles = dir.entryList(QDir::Files); // QDir::Files is rendundant in this stage // Foreach file found, open it and import the key into the gpg keyring. // First avoid firing multiple entryWritten() signals m_keystoreDir->stopScan(); - m_KdeKeysDir->stopScan(); foreach (QString keyFile, keyFiles) { FILE *fp; @@ -145,7 +138,6 @@ void SigningPrivate::registerUltimateTrustKeys() // Restore scanning folders m_keystoreDir->startScan(true, true); - m_KdeKeysDir->startScan(true, true); } void SigningPrivate::splitKeysByTrustLevel() @@ -397,26 +389,30 @@ QString SigningPrivate::descriptiveString(const QString &keyID) const return result; } -void SigningPrivate::slotProcessKeystore() +void SigningPrivate::processKeystore(const QString &path) { - QMap > tmpMap = keys; - splitKeysByTrustLevel(); + if (path != m_keystorePath) { + registerUltimateTrustKeys(); + return; + } QList oldValues; - oldValues << tmpMap[UnverifiableTrust] - << tmpMap[CompletelyUntrusted] - << tmpMap[UnknownTrusted] - << tmpMap[SelfTrusted] - << tmpMap[FullyTrused] - << tmpMap[UltimatelyTrusted]; + oldValues << keys[UnverifiableTrust] + << keys[CompletelyUntrusted] + << keys[UnknownTrusted] + << keys[SelfTrusted] + << keys[FullyTrused] + << keys[UltimatelyTrusted]; + + splitKeysByTrustLevel(); QList newValues; newValues << keys[UnverifiableTrust] - << keys[CompletelyUntrusted] - << keys[UnknownTrusted] - << keys[SelfTrusted] - << keys[FullyTrused] - << keys[UltimatelyTrusted]; + << keys[CompletelyUntrusted] + << keys[UnknownTrusted] + << keys[SelfTrusted] + << keys[FullyTrused] + << keys[UltimatelyTrusted]; QString result; bool keystoreIncreased = (newValues.size() >= oldValues.size()); @@ -441,10 +437,15 @@ void SigningPrivate::slotProcessKeystore() } } -void SigningPrivate::slotKDEKeyAdded(const QString path) +void SigningPrivate::keyAdded(const QString &path) { + if (path == m_keystorePath) { + // we don't worry about keys added to the key store path, + // just the ultimate store dir + return; + } + // Avoid firing multiple signals by kdirwatch instances - m_KdeKeysDir->stopScan(); m_keystoreDir->stopScan(); FILE *fp; @@ -468,21 +469,23 @@ void SigningPrivate::slotKDEKeyAdded(const QString path) } // Restore scanning folders - m_KdeKeysDir->startScan(true, true); m_keystoreDir->startScan(true, true); QString result(iRes.import(0).fingerprint()); emit(q->keyAdded(result)); } -void SigningPrivate::slotKDEKeyRemoved(const QString path) +void SigningPrivate::keyRemoved(const QString &path) { - Q_UNUSED(path) - // Avoid firing multiple signals by kdirwatch instances - m_KdeKeysDir->stopScan(); m_keystoreDir->stopScan(); + if (path == m_keystorePath) { + // Restore scanning folders + m_keystoreDir->startScan(true, true); + return; + } + QList oldKeys = keys[UltimatelyTrusted]; registerUltimateTrustKeys(); QList newkeys = keys[UltimatelyTrusted]; @@ -523,11 +526,9 @@ void SigningPrivate::slotKDEKeyRemoved(const QString path) splitKeysByTrustLevel(); // Restore scanning folders - m_KdeKeysDir->startScan(true, true); m_keystoreDir->startScan(true, true); emit(q->keyRemoved(result)); - } QStringList SigningPrivate::signersOf(const QString id) const diff --git a/remote/signing.h b/remote/signing.h index 2fb09a3d0..acea58348 100644 --- a/remote/signing.h +++ b/remote/signing.h @@ -174,9 +174,9 @@ Q_SIGNALS: void keyRemoved(const QString &keyId); private: - Q_PRIVATE_SLOT(d, void slotProcessKeystore()); - Q_PRIVATE_SLOT(d, void slotKDEKeyAdded(QString path)); - Q_PRIVATE_SLOT(d, void slotKDEKeyRemoved(QString path)); + Q_PRIVATE_SLOT(d, void processKeystore(const QString &path)); + Q_PRIVATE_SLOT(d, void keyAdded(const QString &path)); + Q_PRIVATE_SLOT(d, void keyRemoved(const QString &path)); SigningPrivate * const d; friend class SigningPrivate; }; diff --git a/remote/signing_p.h b/remote/signing_p.h index f89fe90bf..452ce5c76 100644 --- a/remote/signing_p.h +++ b/remote/signing_p.h @@ -55,14 +55,13 @@ public: QString signerOf(const QString &messagePath, const QString &signaturePath) const; QString descriptiveString(const QString &keyID) const; - void slotProcessKeystore(); - void slotKDEKeyAdded(const QString path); - void slotKDEKeyRemoved(const QString path); + void processKeystore(const QString &path); + void keyAdded(const QString &path); + void keyRemoved(const QString &path); QStringList signersOf(const QString id) const; - KDirWatch *m_KdeKeysDir; // used to be notified for changes in the folder with KDE keys - KDirWatch *m_keystoreDir; // used to be notified for changes in the gnupg folder + KDirWatch *m_keystoreDir; // used to be notified for changes in the gnupg folders GpgME::Context *m_gpgContext; QString m_keystorePath; };