diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2012-08-03 23:33:00 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2012-08-03 23:33:00 +0000 |
commit | 851baee42cde8ceb7fcd9d9844b6ff0764843960 (patch) | |
tree | 025bcecce7fc89c5be6a24598b0851abc6f68108 | |
parent | import from textedit works (diff) | |
download | gpg4usb-851baee42cde8ceb7fcd9d9844b6ff0764843960.tar.gz gpg4usb-851baee42cde8ceb7fcd9d9844b6ff0764843960.zip |
deleting keys works
git-svn-id: http://cpunk.de/svn/src/gpg4usb/branches/0.3.2-mac@938 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | gpg4usb.pro | 6 | ||||
-rwxr-xr-x | keymgmt.cpp | 20 | ||||
-rwxr-xr-x | keymgmt.h | 2 | ||||
-rw-r--r-- | kgpg/transactions/kgpgdelkey.cpp | 94 | ||||
-rw-r--r-- | kgpg/transactions/kgpgdelkey.h | 55 | ||||
-rw-r--r-- | mainwindow.cpp | 12 | ||||
-rw-r--r-- | mainwindow.h | 7 |
7 files changed, 190 insertions, 6 deletions
diff --git a/gpg4usb.pro b/gpg4usb.pro index 826df2a..21d89e5 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -68,7 +68,8 @@ HEADERS += attachments.h \ kgpg/transactions/kgpgencrypt.h \ kgpg/transactions/kgpgdecrypt.h \ kgpg/transactions/kgpgexport.h \ - kgpg/transactions/kgpgimport.h + kgpg/transactions/kgpgimport.h \ + kgpg/transactions/kgpgdelkey.h SOURCES += attachments.cpp \ @@ -120,7 +121,8 @@ SOURCES += attachments.cpp \ kgpg/transactions/kgpgencrypt.cpp \ kgpg/transactions/kgpgdecrypt.cpp \ kgpg/transactions/kgpgexport.cpp \ - kgpg/transactions/kgpgimport.cpp + kgpg/transactions/kgpgimport.cpp \ + kgpg/transactions/kgpgdelkey.cpp RC_FILE = gpg4usb.rc diff --git a/keymgmt.cpp b/keymgmt.cpp index 5330479..30dc0be 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -224,10 +224,28 @@ void KeyMgmt::deleteKeysWithWarning(QStringList *uidList) QMessageBox::No | QMessageBox::Yes); if (ret == QMessageBox::Yes) { - mCtx->deleteKeys(uidList); + //mCtx->deleteKeys(uidList); + KGpgDelKey *delkey = new KGpgDelKey(this, *uidList); + connect(delkey, SIGNAL(done(int)), SLOT(slotKeyDeleted(int))); + delkey->start(); } } +void KeyMgmt::slotKeyDeleted(int retcode) +{ + KGpgDelKey *delkey = qobject_cast<KGpgDelKey *>(sender()); + + /*KGpgKeyNode *delkey = m_delkey->keys().first(); + if (retcode == 0) { + KMessageBox::information(this, i18n("Key <b>%1</b> deleted.", delkey->getBeautifiedFingerprint()), i18n("Delete key")); + imodel->delNode(delkey); + } else { + KMessageBox::error(this, i18n("Deleting key <b>%1</b> failed.", delkey->getBeautifiedFingerprint()), i18n("Delete key")); + }*/ + mCtx->emitKeyDBChanged(); + delkey->deleteLater(); +} + void KeyMgmt::showKeyDetails() { if (mKeyList->getSelected()->isEmpty()) { @@ -28,6 +28,7 @@ #include "keyimportdetaildialog.h" #include "keyserverimportdialog.h" #include "keygendialog.h" +#include "kgpg/transactions/kgpgdelkey.h" #include <QtGui> QT_BEGIN_NAMESPACE @@ -60,6 +61,7 @@ public slots: void deleteCheckedKeys(); void generateKeyDialog(); void showKeyDetails(); + void slotKeyDeleted(int retcode); signals: void statusBarChanged(QString); diff --git a/kgpg/transactions/kgpgdelkey.cpp b/kgpg/transactions/kgpgdelkey.cpp new file mode 100644 index 0000000..ac09610 --- /dev/null +++ b/kgpg/transactions/kgpgdelkey.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2008,2009,2012 Rolf Eike Beer <[email protected]> + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kgpgdelkey.h" + +#include "../gpgproc.h" + +#include <QString> +#include <QStringList> + +/*KGpgDelKey::KGpgDelKey(QObject *parent, KGpgKeyNode *key) + : KGpgTransaction(parent) +{ + m_keys << key; + setCmdLine(); +}*/ + +KGpgDelKey::KGpgDelKey(QObject *parent, const QStringList &uids) + : KGpgTransaction(parent), + m_uids(uids) +{ + setCmdLine(); +} + +KGpgDelKey::~KGpgDelKey() +{ +} + +QStringList +KGpgDelKey::keys() const +{ + return m_uids; +} + +bool +KGpgDelKey::nextLine(const QString &line) +{ + if (!line.startsWith(QLatin1String("[GNUPG:] GOT_IT"))) + setSuccess(KGpgTransaction::TS_MSG_SEQUENCE); + + return false; +} + +KGpgTransaction::ts_boolanswer +KGpgDelKey::boolQuestion(const QString &line) +{ + if (line.startsWith(QLatin1String("delete_key.okay"))) + return KGpgTransaction::BA_YES; + + if (line.startsWith(QLatin1String("delete_key.secret.okay"))) + return KGpgTransaction::BA_YES; + + return KGpgTransaction::boolQuestion(line); +} + +bool +KGpgDelKey::preStart() +{ + GPGProc *proc = getProcess(); + QStringList args = proc->program(); + + /*foreach (const KGpgKeyNode *key, m_keys) + args << key->getFingerprint();*/ + foreach (const QString uid, m_uids) + args << uid; + + proc->setProgram(args); + + setSuccess(KGpgTransaction::TS_OK); + + return true; +} + +void +KGpgDelKey::setCmdLine() +{ + addArgument(QLatin1String( "--status-fd=1" )); + addArgument(QLatin1String( "--command-fd=0" )); + addArgument(QLatin1String( "--delete-secret-and-public-key" )); + + m_argscount = getProcess()->program().count(); +} + +//#include "kgpgdelkey.moc" diff --git a/kgpg/transactions/kgpgdelkey.h b/kgpg/transactions/kgpgdelkey.h new file mode 100644 index 0000000..c7a35ae --- /dev/null +++ b/kgpg/transactions/kgpgdelkey.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008,2009 Rolf Eike Beer <[email protected]> + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KGPGDELKEY_H +#define KGPGDELKEY_H + +#include "kgpgtransaction.h" + +#include "../core/KGpgKeyNode.h" + +#include <QObject> + +/** + * @brief delete a public key + */ +class KGpgDelKey: public KGpgTransaction { + Q_OBJECT + + Q_DISABLE_COPY(KGpgDelKey) + KGpgDelKey(); // = delete C++0x +public: + //KGpgDelKey(QObject *parent, KGpgKeyNode *key); + KGpgDelKey(QObject *parent, const QStringList &uids); + virtual ~KGpgDelKey(); + + /** + * @brief the keys that were requested to be removed + * @return the list of key nodes + */ + QStringList keys() const; + +protected: + virtual bool nextLine(const QString &line); + virtual ts_boolanswer boolQuestion(const QString &line); + virtual bool preStart(); + +private: + //KGpgKeyNode::List m_keys; + QStringList m_uids; + int m_argscount; + + void setCmdLine(); +}; + +#endif // KGPGDELKEY_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 1b00289..393b9f0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -783,7 +783,7 @@ void MainWindow::importKeyFromEdit() void MainWindow::startImport(KGpgImport *import) { qDebug() << "start import"; - //changeMessage(i18n("Importing..."), true); + changeMessage(tr("Importing..."), true); connect(import, SIGNAL(done(int)), SLOT(slotImportDone(int))); import->start(); } @@ -792,8 +792,6 @@ void MainWindow::slotImportDone(int result) { KGpgImport *import = qobject_cast<KGpgImport *>(sender()); - qDebug() << "import Done"; - Q_ASSERT(import != NULL); const QStringList rawmsgs(import->getMessages()); @@ -820,10 +818,18 @@ void MainWindow::slotImportDone(int result) changeMessage(i18nc("Application ready for user input", "Ready")); } */ + changeMessage(tr("Application ready for user input", "Ready")); mCtx->emitKeyDBChanged(); import->deleteLater(); } +void MainWindow::changeMessage(const QString &msg, const bool keep) +{ + int timeout = keep ? 0 : 10000; + + statusBar()->showMessage(msg, timeout); +} + void MainWindow::openKeyManagement() { keyMgmt->show(); diff --git a/mainwindow.h b/mainwindow.h index ea047e4..7108237 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -266,6 +266,13 @@ private: */ void parseMime(QByteArray *message); + /** + * @brief show a message in the status bar + * @param msg the text to show + * @param keep if the text should stay visible or may be hidden after a while + */ + void changeMessage(const QString &msg, const bool keep = false); + TextEdit *edit; /** Tabwidget holding the edit-windows */ QMenu *fileMenu; /** Submenu for file-operations*/ QMenu *editMenu; /** Submenu for text-operations*/ |