diff options
-rw-r--r-- | context.cpp | 1 | ||||
-rw-r--r-- | context.h | 1 | ||||
-rw-r--r-- | gpgwin.cpp | 54 | ||||
-rw-r--r-- | keylist.cpp | 33 | ||||
-rw-r--r-- | keylist.h | 3 | ||||
-rwxr-xr-x | keymgmt.cpp | 3 | ||||
-rw-r--r-- | keyserverimportdialog.cpp | 9 | ||||
-rw-r--r-- | keyserverimportdialog.h | 2 | ||||
-rw-r--r-- | verifynotification.cpp | 28 | ||||
-rw-r--r-- | verifynotification.h | 12 |
10 files changed, 115 insertions, 31 deletions
diff --git a/context.cpp b/context.cpp index f8ca426..903ddd0 100644 --- a/context.cpp +++ b/context.cpp @@ -190,6 +190,7 @@ GpgKeyList Context::listKeys() if (key->uids) { gpgkey.name = key->uids->name; gpgkey.email = key->uids->email; + gpgkey.fpr = key->subkeys->fpr; } keys.append(gpgkey); gpgme_key_unref(key); @@ -44,6 +44,7 @@ public: QString name; QString email; bool privkey; + QString fpr; }; typedef QLinkedList< GpgKey > GpgKeyList; @@ -44,7 +44,7 @@ GpgWin::GpgWin() /* List of binary Attachments */ mAttachments = new Attachments(iconPath); - + /* test attachmentdir for files alll 15s */ QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(checkAttachmentFolder())); @@ -416,7 +416,7 @@ void GpgWin::createStatusBar() statusBarIcon = new QLabel(statusBar()); statusBarIcon->setPixmap(*pixmap); statusBar()->insertPermanentWidget(0,statusBarIcon,0); - statusBarIcon->hide(); + statusBarIcon->hide(); statusBar()->showMessage(tr("Ready"),2000); statusBarBox->setLayout(statusBarBoxLayout); } @@ -610,7 +610,7 @@ void GpgWin::checkAttachmentFolder() { if(!settings.value("mime/parseMime").toBool()) { return; } - + QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; // filenum minus . and .. int filenum = QDir(attachmentDir).count() - 2 ; @@ -698,7 +698,7 @@ void GpgWin::sign() QStringList *uidList = mKeyList->getChecked(); QByteArray *tmp = new QByteArray(); - if (mCtx->sign(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) { + if (mCtx->sign(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) { QString *tmp2 = new QString(*tmp); // beginEditBlock and endEditBlock() let operation look like single undo/redo operation QTextCursor cursor(edit->curTextPage()->document()); @@ -726,34 +726,56 @@ int GpgWin::isSigned(const QByteArray &text) { void GpgWin::verify() { - bool verified=false; QByteArray text = edit->curTextPage()->toPlainText().toAscii(); // TODO: toUtf8() here? preventNoDataErr(&text); - isSigned(text); + int textIsSigned = isSigned(text); gpgme_signature_t sign = mCtx->verify(text); if (sign == NULL) { return; - } else { - // TODO: should get verifynotification get the whole signature for analysizing - VerifyNotification *vn = new VerifyNotification(); - vn->setVerifyLabel(QString("Verified")); - edit->curPage()->showNotificationWidget(vn); } + VerifyNotification *vn = new VerifyNotification(mCtx,this); + QString verifyLabelText; + switch (textIsSigned) + { + case 2: verifyLabelText="Message is completly signed by: "; + break; + case 1: verifyLabelText="Message is partially signed by: "; + break; + } while (sign) { + if (gpg_err_code(sign->status) == 9) { + verifyLabelText.append("Key with keyid "); + verifyLabelText.append(sign->fpr); + qDebug() << "sign->fpr:" << sign->fpr; + verifyLabelText.append(" not present."); + *vn->keysNotInList << sign->fpr; + } else { + QString name = mKeyList->getKeyNameByFpr(sign->fpr); + QString email = "<"+mKeyList->getKeyEmailByFpr(sign->fpr)+">"; + if ( email == "<>" ) { + email=""; + } + verifyLabelText.append(name); + verifyLabelText.append(email); + verifyLabelText.append(gpg_strerror(sign->status)); + } + verifyLabelText.append(".\n"); qDebug() << "sig summary: " << sign->summary; qDebug() << "sig fingerprint: " << sign->fpr; qDebug() << "sig status: " << sign->status << " - " << gpg_err_code(sign->status) << " - " << gpg_strerror(sign->status); qDebug() << "sig validity: " << sign->validity; qDebug() << "sig validity reason: " << sign->validity_reason << " - " << gpg_err_code(sign->validity_reason) << " - " << gpgme_strerror(sign->validity_reason); - if (gpg_err_code(sign->status) == 9) { - qDebug() << "kein passender Schlüssel gefunden. Vom Schlüsselserver importieren?"; - } sign = sign->next; } + // Remove the last linebreak + verifyLabelText.remove(verifyLabelText.length()-1,1); + + vn->setVerifyLabel(verifyLabelText); + edit->curPage()->showNotificationWidget(vn); } void GpgWin::importKeyDialog() @@ -816,8 +838,8 @@ void GpgWin::showKeyDetails() void GpgWin::fileEncryption() { - QStringList *keyList; - keyList = mKeyList->getChecked(); + QStringList *keyList; + keyList = mKeyList->getChecked(); new FileEncryptionDialog(mCtx, iconPath, *keyList, this); } diff --git a/keylist.cpp b/keylist.cpp index bb2eac6..f14f967 100644 --- a/keylist.cpp +++ b/keylist.cpp @@ -29,15 +29,17 @@ KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent) this->iconPath = iconpath; mKeyList = new QTableWidget(this); - mKeyList->setColumnCount(5); + mKeyList->setColumnCount(6); mKeyList->verticalHeader()->hide(); mKeyList->setShowGrid(false); mKeyList->setColumnWidth(0, 24); mKeyList->setColumnWidth(1, 20); mKeyList->sortByColumn(2, Qt::AscendingOrder); mKeyList->setSelectionBehavior(QAbstractItemView::SelectRows); - // id of key + // hide id and fingerprint of key mKeyList->setColumnHidden(4, true); + mKeyList->setColumnHidden(5, true); + // tableitems not editable mKeyList->setEditTriggers(QAbstractItemView::NoEditTriggers); // no focus (rectangle around tableitems) @@ -47,7 +49,7 @@ KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent) mKeyList->setAlternatingRowColors(true); QStringList labels; - labels << "" << "" << tr("Name") << tr("EMail") << "id"; + labels << "" << "" << tr("Name") << tr("EMail") << "id" << "fpr"; mKeyList->setHorizontalHeaderLabels(labels); mKeyList->horizontalHeader()->setStretchLastSection(true); @@ -95,6 +97,8 @@ void KeyList::refresh() mKeyList->setItem(row, 3, tmp3); QTableWidgetItem *tmp4 = new QTableWidgetItem(it->id); mKeyList->setItem(row, 4, tmp4); + QTableWidgetItem *tmp5 = new QTableWidgetItem(it->fpr); + mKeyList->setItem(row, 5, tmp5); it++; ++row; } @@ -102,6 +106,27 @@ void KeyList::refresh() setChecked(keyList); } +QString KeyList::getKeyNameByFpr(QString fpr) +{ + QString id; + for (int i = 0; i < mKeyList->rowCount(); i++) { + if (mKeyList->item(i, 5)->text() == fpr) { + id=mKeyList->item(i,2)->text(); + } + } + return id; +} + +QString KeyList::getKeyEmailByFpr(QString fpr) +{ + QString id; + for (int i = 0; i < mKeyList->rowCount(); i++) { + if (mKeyList->item(i, 5)->text() == fpr) { + id=mKeyList->item(i,3)->text(); + } + } + return id; +} QStringList *KeyList::getChecked() { @@ -162,6 +187,7 @@ void KeyList::addMenuAction(QAction *act) { popupMenu->addAction(act); } + void KeyList::dropEvent(QDropEvent* event) { // importKeyDialog(); @@ -203,7 +229,6 @@ void KeyList::dropEvent(QDropEvent* event) } } - if (event->mimeData()->hasUrls()) { foreach (QUrl tmp, event->mimeData()->urls()) @@ -41,6 +41,9 @@ public: QStringList *getChecked(); QStringList *getPrivateChecked(); + QString getKeyNameByFpr(QString fpr); + QString getKeyEmailByFpr(QString fpr); + void setChecked(QStringList *keyIds); //QStringList *getPrivateChecked(); QStringList *getSelected(); diff --git a/keymgmt.cpp b/keymgmt.cpp index c3ed7bf..ff7d4fc 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -180,6 +180,9 @@ void KeyMgmt::deleteKeysWithWarning(QStringList *uidList) * more than one selected... compare to seahorse "delete-dialog" */ + if (uidList->isEmpty()) { + return; + } QString keynames; foreach (QString uid, *uidList) { keynames.append(mCtx->getKeyDetails(uid)->uids->name); diff --git a/keyserverimportdialog.cpp b/keyserverimportdialog.cpp index 80469e6..3917817 100644 --- a/keyserverimportdialog.cpp +++ b/keyserverimportdialog.cpp @@ -218,6 +218,15 @@ void KeyServerImportDialog::import() } } +void KeyServerImportDialog::import(QString keyId) +{ + qDebug() << keyId; + QUrl url = "http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x"+keyId+"&options=mr"; + importreply = qnam.get(QNetworkRequest(url)); + connect(importreply, SIGNAL(finished()), + this, SLOT(importFinished())); +} + void KeyServerImportDialog::importFinished() { QByteArray *key = new QByteArray(); diff --git a/keyserverimportdialog.h b/keyserverimportdialog.h index a5a77c5..18aa913 100644 --- a/keyserverimportdialog.h +++ b/keyserverimportdialog.h @@ -49,9 +49,11 @@ class KeyServerImportDialog : public QDialog public: KeyServerImportDialog(GpgME::Context *ctx, QWidget *parent = 0); + void import(QString keyId); private slots: void import(); + void searchFinished(); void importFinished(); void search(); diff --git a/verifynotification.cpp b/verifynotification.cpp index 2de1a2a..2c5cd56 100644 --- a/verifynotification.cpp +++ b/verifynotification.cpp @@ -1,32 +1,40 @@ + #include "verifynotification.h" -VerifyNotification::VerifyNotification(QWidget *parent) : +VerifyNotification::VerifyNotification(GpgME::Context *ctx, QWidget *parent ) : QWidget(parent) { + mCtx = ctx; verifyLabel = new QLabel("Verified"); QHBoxLayout *notificationWidgetLayout = new QHBoxLayout(); notificationWidgetLayout->setContentsMargins(0,0,0,0); - notificationWidgetLayout->addWidget(verifyLabel); + notificationWidgetLayout->addWidget(verifyLabel,2); // notificationWidget = new QWidget(this); this->setStyleSheet("background-color: #CBFDCB;"); this->setLayout(notificationWidgetLayout); - QAction *openAct = new QAction(tr("&Open..."), this); - openAct->setShortcut(QKeySequence::Open); - openAct->setToolTip(tr("Open an existing file")); - - QMenu *verifyMenu = new QMenu(); - verifyMenu->addAction(openAct); + QAction *importFromKeyserverAct = new QAction(tr("Import missing key from Keyserver"), this); + connect(importFromKeyserverAct, SIGNAL(triggered()), this, SLOT(importFromKeyserver())); + QMenu *detailMenu = new QMenu(); + detailMenu->addAction(importFromKeyserverAct); + keysNotInList = new QStringList(); QPushButton *verifyButton = new QPushButton("Details"); - verifyButton->setMenu(verifyMenu); - notificationWidgetLayout->addStretch(1); + verifyButton->setMenu(detailMenu); + // notificationWidgetLayout->addStretch(1); notificationWidgetLayout->addWidget(verifyButton); } +void VerifyNotification::importFromKeyserver(){ + KeyServerImportDialog *importDialog =new KeyServerImportDialog(mCtx,this); + foreach (QString keyid, *keysNotInList) { + importDialog->import(keyid); + } +} + void VerifyNotification::setVerifyLabel(QString text) { verifyLabel->setText(text); diff --git a/verifynotification.h b/verifynotification.h index 539504f..5f5cd99 100644 --- a/verifynotification.h +++ b/verifynotification.h @@ -8,18 +8,28 @@ #include <QWidget> +#include "keyserverimportdialog.h" +#include "context.h" +#include <gpgme.h> + + class VerifyNotification : public QWidget { Q_OBJECT public: - explicit VerifyNotification(QWidget *parent = 0); + explicit VerifyNotification(GpgME::Context *ctx,QWidget *parent = 0 ); void setVerifyLabel(QString text); + QStringList *keysNotInList; + signals: public slots: + void importFromKeyserver(); private: QLabel *verifyLabel; + GpgME::Context *mCtx; + }; #endif // VERIFYNOTIFICATION_H |