no point in having two KDirWatches when we can have one
also fix the signatures of the slots in the private class
This commit is contained in:
parent
9f4124973f
commit
fc754ec380
@ -78,26 +78,18 @@ SigningPrivate::SigningPrivate(Signing *auth, const QString &path)
|
|||||||
|
|
||||||
m_keystoreDir = new KDirWatch();
|
m_keystoreDir = new KDirWatch();
|
||||||
m_keystoreDir->addDir(m_keystorePath);
|
m_keystoreDir->addDir(m_keystorePath);
|
||||||
|
m_keystoreDir->addDir(ultimateKeyStoragePath());
|
||||||
m_keystoreDir->startScan(true);
|
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
|
// 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(created(const QString &)), q, SLOT(processKeystore()));
|
||||||
// q->connect(m_keystoreDir, SIGNAL(dirty(const QString &)), q, SLOT(slotKDEKeyRemoved(const QString &)));
|
q->connect(m_keystoreDir, SIGNAL(dirty(const QString &)), q, SLOT(keyAdded(const QString &)));
|
||||||
q->connect(m_keystoreDir, SIGNAL(deleted(const QString &)), q, SLOT(slotKDEKeyRemoved(const QString &)));
|
q->connect(m_keystoreDir, SIGNAL(deleted(const QString &)), q, SLOT(keyRemoved(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 &)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SigningPrivate::~SigningPrivate()
|
SigningPrivate::~SigningPrivate()
|
||||||
{
|
{
|
||||||
delete m_keystoreDir;
|
delete m_keystoreDir;
|
||||||
delete m_KdeKeysDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SigningPrivate::ultimateKeyStoragePath() const
|
QString SigningPrivate::ultimateKeyStoragePath() const
|
||||||
@ -108,24 +100,25 @@ QString SigningPrivate::ultimateKeyStoragePath() const
|
|||||||
void SigningPrivate::registerUltimateTrustKeys()
|
void SigningPrivate::registerUltimateTrustKeys()
|
||||||
{
|
{
|
||||||
QList< QByteArray > tmp;
|
QList< QByteArray > tmp;
|
||||||
|
keys[UltimatelyTrusted] = tmp;
|
||||||
|
|
||||||
if (!m_gpgContext) {
|
if (!m_gpgContext) {
|
||||||
kDebug() << "GPGME context not valid: please re-initialize the library.";
|
kDebug() << "GPGME context not valid: please re-initialize the library.";
|
||||||
keys.insert(UltimatelyTrusted, tmp);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = ultimateKeyStoragePath();
|
QString path = ultimateKeyStoragePath();
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
if (!dir.exists() || path.isEmpty()) {
|
if (!dir.exists() || path.isEmpty()) {
|
||||||
kDebug() << "Directory with KDE keys not found: aborting";
|
kDebug() << "Directory with KDE keys not found: aborting";
|
||||||
keys[UltimatelyTrusted] = tmp;
|
|
||||||
return;
|
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.
|
// Foreach file found, open it and import the key into the gpg keyring.
|
||||||
// First avoid firing multiple entryWritten() signals
|
// First avoid firing multiple entryWritten() signals
|
||||||
m_keystoreDir->stopScan();
|
m_keystoreDir->stopScan();
|
||||||
m_KdeKeysDir->stopScan();
|
|
||||||
|
|
||||||
foreach (QString keyFile, keyFiles) {
|
foreach (QString keyFile, keyFiles) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -145,7 +138,6 @@ void SigningPrivate::registerUltimateTrustKeys()
|
|||||||
|
|
||||||
// Restore scanning folders
|
// Restore scanning folders
|
||||||
m_keystoreDir->startScan(true, true);
|
m_keystoreDir->startScan(true, true);
|
||||||
m_KdeKeysDir->startScan(true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigningPrivate::splitKeysByTrustLevel()
|
void SigningPrivate::splitKeysByTrustLevel()
|
||||||
@ -397,26 +389,30 @@ QString SigningPrivate::descriptiveString(const QString &keyID) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigningPrivate::slotProcessKeystore()
|
void SigningPrivate::processKeystore(const QString &path)
|
||||||
{
|
{
|
||||||
QMap<TrustLevel, QList<QByteArray> > tmpMap = keys;
|
if (path != m_keystorePath) {
|
||||||
splitKeysByTrustLevel();
|
registerUltimateTrustKeys();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QByteArray> oldValues;
|
QList<QByteArray> oldValues;
|
||||||
oldValues << tmpMap[UnverifiableTrust]
|
oldValues << keys[UnverifiableTrust]
|
||||||
<< tmpMap[CompletelyUntrusted]
|
<< keys[CompletelyUntrusted]
|
||||||
<< tmpMap[UnknownTrusted]
|
<< keys[UnknownTrusted]
|
||||||
<< tmpMap[SelfTrusted]
|
<< keys[SelfTrusted]
|
||||||
<< tmpMap[FullyTrused]
|
<< keys[FullyTrused]
|
||||||
<< tmpMap[UltimatelyTrusted];
|
<< keys[UltimatelyTrusted];
|
||||||
|
|
||||||
|
splitKeysByTrustLevel();
|
||||||
|
|
||||||
QList<QByteArray> newValues;
|
QList<QByteArray> newValues;
|
||||||
newValues << keys[UnverifiableTrust]
|
newValues << keys[UnverifiableTrust]
|
||||||
<< keys[CompletelyUntrusted]
|
<< keys[CompletelyUntrusted]
|
||||||
<< keys[UnknownTrusted]
|
<< keys[UnknownTrusted]
|
||||||
<< keys[SelfTrusted]
|
<< keys[SelfTrusted]
|
||||||
<< keys[FullyTrused]
|
<< keys[FullyTrused]
|
||||||
<< keys[UltimatelyTrusted];
|
<< keys[UltimatelyTrusted];
|
||||||
|
|
||||||
QString result;
|
QString result;
|
||||||
bool keystoreIncreased = (newValues.size() >= oldValues.size());
|
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
|
// Avoid firing multiple signals by kdirwatch instances
|
||||||
m_KdeKeysDir->stopScan();
|
|
||||||
m_keystoreDir->stopScan();
|
m_keystoreDir->stopScan();
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -468,21 +469,23 @@ void SigningPrivate::slotKDEKeyAdded(const QString path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore scanning folders
|
// Restore scanning folders
|
||||||
m_KdeKeysDir->startScan(true, true);
|
|
||||||
m_keystoreDir->startScan(true, true);
|
m_keystoreDir->startScan(true, true);
|
||||||
|
|
||||||
QString result(iRes.import(0).fingerprint());
|
QString result(iRes.import(0).fingerprint());
|
||||||
emit(q->keyAdded(result));
|
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
|
// Avoid firing multiple signals by kdirwatch instances
|
||||||
m_KdeKeysDir->stopScan();
|
|
||||||
m_keystoreDir->stopScan();
|
m_keystoreDir->stopScan();
|
||||||
|
|
||||||
|
if (path == m_keystorePath) {
|
||||||
|
// Restore scanning folders
|
||||||
|
m_keystoreDir->startScan(true, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QByteArray> oldKeys = keys[UltimatelyTrusted];
|
QList<QByteArray> oldKeys = keys[UltimatelyTrusted];
|
||||||
registerUltimateTrustKeys();
|
registerUltimateTrustKeys();
|
||||||
QList<QByteArray> newkeys = keys[UltimatelyTrusted];
|
QList<QByteArray> newkeys = keys[UltimatelyTrusted];
|
||||||
@ -523,11 +526,9 @@ void SigningPrivate::slotKDEKeyRemoved(const QString path)
|
|||||||
splitKeysByTrustLevel();
|
splitKeysByTrustLevel();
|
||||||
|
|
||||||
// Restore scanning folders
|
// Restore scanning folders
|
||||||
m_KdeKeysDir->startScan(true, true);
|
|
||||||
m_keystoreDir->startScan(true, true);
|
m_keystoreDir->startScan(true, true);
|
||||||
|
|
||||||
emit(q->keyRemoved(result));
|
emit(q->keyRemoved(result));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SigningPrivate::signersOf(const QString id) const
|
QStringList SigningPrivate::signersOf(const QString id) const
|
||||||
|
@ -174,9 +174,9 @@ Q_SIGNALS:
|
|||||||
void keyRemoved(const QString &keyId);
|
void keyRemoved(const QString &keyId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_PRIVATE_SLOT(d, void slotProcessKeystore());
|
Q_PRIVATE_SLOT(d, void processKeystore(const QString &path));
|
||||||
Q_PRIVATE_SLOT(d, void slotKDEKeyAdded(QString path));
|
Q_PRIVATE_SLOT(d, void keyAdded(const QString &path));
|
||||||
Q_PRIVATE_SLOT(d, void slotKDEKeyRemoved(QString path));
|
Q_PRIVATE_SLOT(d, void keyRemoved(const QString &path));
|
||||||
SigningPrivate * const d;
|
SigningPrivate * const d;
|
||||||
friend class SigningPrivate;
|
friend class SigningPrivate;
|
||||||
};
|
};
|
||||||
|
@ -55,14 +55,13 @@ public:
|
|||||||
QString signerOf(const QString &messagePath, const QString &signaturePath) const;
|
QString signerOf(const QString &messagePath, const QString &signaturePath) const;
|
||||||
QString descriptiveString(const QString &keyID) const;
|
QString descriptiveString(const QString &keyID) const;
|
||||||
|
|
||||||
void slotProcessKeystore();
|
void processKeystore(const QString &path);
|
||||||
void slotKDEKeyAdded(const QString path);
|
void keyAdded(const QString &path);
|
||||||
void slotKDEKeyRemoved(const QString path);
|
void keyRemoved(const QString &path);
|
||||||
|
|
||||||
QStringList signersOf(const QString id) const;
|
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 folders
|
||||||
KDirWatch *m_keystoreDir; // used to be notified for changes in the gnupg folder
|
|
||||||
GpgME::Context *m_gpgContext;
|
GpgME::Context *m_gpgContext;
|
||||||
QString m_keystorePath;
|
QString m_keystorePath;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user