aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2011-10-12 21:08:32 +0000
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2011-10-12 21:08:32 +0000
commita21359c80a4ca2a2c6082faf68054f9538f7c4a8 (patch)
treeac4a8e173468a8f006160454f4f1fcd30f95df27
parentmoved textissigned to context (diff)
downloadgpg4usb-a21359c80a4ca2a2c6082faf68054f9538f7c4a8.tar.gz
gpg4usb-a21359c80a4ca2a2c6082faf68054f9538f7c4a8.zip
verifynotification and verifydetailsdialog is refreshed on keylist-change, bt keydetailsdialog is doubled on keylist-change
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@546 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to '')
-rw-r--r--context.cpp9
-rw-r--r--context.h1
-rw-r--r--gpgwin.cpp78
-rw-r--r--verifydetailsdialog.cpp58
-rw-r--r--verifydetailsdialog.h4
-rw-r--r--verifynotification.cpp79
-rw-r--r--verifynotification.h12
7 files changed, 143 insertions, 98 deletions
diff --git a/context.cpp b/context.cpp
index d7a17a1..7ba5fb9 100644
--- a/context.cpp
+++ b/context.cpp
@@ -649,6 +649,15 @@ int Context::textIsSigned(const QByteArray &text) {
return 0;
}
+QString Context::beautifyFingerprint(QString fingerprint)
+{
+ uint len = fingerprint.length();
+ if ((len > 0) && (len % 4 == 0))
+ for (uint n = 0; 4 *(n + 1) < len; ++n)
+ fingerprint.insert(5 * n + 4, ' ');
+ return fingerprint;
+}
+
}
diff --git a/context.h b/context.h
index 375758c..6c58455 100644
--- a/context.h
+++ b/context.h
@@ -107,6 +107,7 @@ public:
* \li 0, if the text is not signed at all.
*/
int textIsSigned(const QByteArray &text);
+ QString beautifyFingerprint(QString fingerprint);
signals:
void keyDBChanged();
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 66b0220..95a73a4 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -636,80 +636,18 @@ void GpgWin::decrypt()
void GpgWin::verify()
{
- QDateTime timestamp;
- verify_label_status verifyStatus=VERIFY_ERROR_OK;
- QByteArray text = edit->curTextPage()->toPlainText().toAscii(); // TODO: toUtf8() here?
- mCtx->preventNoDataErr(&text);
- int textIsSigned = mCtx->textIsSigned(text);
-
- gpgme_signature_t sign = mCtx->verify(text);
+ // At first close verifynotification, if existing
edit->curPage()->closeNoteByClass("verifyNotification");
- if (sign == NULL) {
- return;
- }
+ // create new verfiy notification
+ VerifyNotification *vn = new VerifyNotification(this, mCtx, mKeyList, edit->curTextPage());
- VerifyNotification *vn = new VerifyNotification(this, mCtx, mKeyList, sign);
- //vn->keysNotInList->clear();
- QString verifyLabelText;
- bool unknownKeyFound=false;
-
- while (sign) {
- timestamp.setTime_t(sign->timestamp);
- switch (gpg_err_code(sign->status))
- {
- case GPG_ERR_NO_PUBKEY:
- {
- verifyStatus=VERIFY_ERROR_WARN;
- verifyLabelText.append(tr("Key not present with Fingerprint: ")+KeyDetailsDialog::beautifyFingerprint(QString(sign->fpr)));
- *vn->keysNotInList << sign->fpr;
- unknownKeyFound=true;
- break;
- }
- case GPG_ERR_NO_ERROR:
- {
- QString name = mKeyList->getKeyNameByFpr(sign->fpr);
- QString email =mKeyList->getKeyEmailByFpr(sign->fpr);
- verifyLabelText.append(name);
- if (!email.isEmpty()) {
- verifyLabelText.append("<"+email+">");
- }
- break;
- }
- default:
- {
- verifyStatus=VERIFY_ERROR_WARN;
- verifyLabelText.append(tr("Error for key with fingerprint ")+KeyDetailsDialog::beautifyFingerprint(QString(sign->fpr)));
- break;
- }
- }
- verifyLabelText.append("\n");
- sign = sign->next;
- }
-
- switch (textIsSigned)
- {
- case 2:
- {
- verifyLabelText.prepend(tr("Text is completly signed by: "));
- break;
- }
- case 1:
- {
- verifyLabelText.prepend(tr("Text is partially signed by: "));
- break;
- }
+ // if signing information is found, show the notification, otherwise close it
+ if (vn->refresh()) {
+ edit->curPage()->showNotificationWidget(vn, "verifyNotification");
+ } else {
+ vn->close();
}
-
- // If an unknown key is found, enable the importfromkeyserveraction
- vn->showImportAction(unknownKeyFound);
-
- // Remove the last linebreak
- verifyLabelText.remove(verifyLabelText.length()-1,1);
-
- vn->setVerifyLabel(verifyLabelText,verifyStatus);
-
- edit->curPage()->showNotificationWidget(vn, "verifyNotification");
}
void GpgWin::importKeyDialog()
diff --git a/verifydetailsdialog.cpp b/verifydetailsdialog.cpp
index 9a18090..aec1f73 100644
--- a/verifydetailsdialog.cpp
+++ b/verifydetailsdialog.cpp
@@ -21,27 +21,59 @@
#include "verifydetailsdialog.h"
-VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::Context* ctx, KeyList* keyList, gpgme_signature_t signature) :
+VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::Context* ctx, KeyList* keyList, QPlainTextEdit *edit) :
QDialog(parent)
{
mCtx = ctx;
mKeyList = keyList;
+ mTextpage = edit;
+ this->setWindowTitle(tr("Signaturedetails"));
connect(mCtx, SIGNAL(keyDBChanged()), this, SLOT(refresh()));
mVbox = new QVBoxLayout();
+ this->setLayout(mVbox);
+ refresh();
+
+ this->exec();
+}
- // Timestamp of creation of the signature
+void VerifyDetailsDialog::refresh()
+{
+ // At first claer all children widgets
+ QList<QLabel *> allChildren = mVbox->findChildren<QLabel *>();
+ foreach (QLabel *label,allChildren) {
+ label->close();
+ }
+
+ // Get signature information of current text
+ QByteArray text = mTextpage->toPlainText().toAscii(); // TODO: toUtf8() here?
+ mCtx->preventNoDataErr(&text);
+ gpgme_signature_t sign = mCtx->verify(text);
+
+ // Get timestamp of signature of current text
QDateTime timestamp;
- timestamp.setTime_t(signature->timestamp);
+ timestamp.setTime_t(sign->timestamp);
- // Information for general verify information
- mVbox->addWidget(new QLabel(tr("Text was completly signed on %1 by:\n").arg(timestamp.toString(Qt::SystemLocaleShortDate))));
+ // Set the title widget depending on sign status
+ switch (mCtx->textIsSigned(text))
+ {
+ case 2:
+ {
+ mVbox->addWidget(new QLabel(tr("Text was completly signed on %1 by:\n").arg(timestamp.toString(Qt::SystemLocaleShortDate))));
+ break;
+ }
+ case 1:
+ {
+ mVbox->addWidget(new QLabel(tr("Text was partially signed on %1 by:\n").arg(timestamp.toString(Qt::SystemLocaleShortDate))));
+ break;
+ }
+ }
// Add informationbox for every single key
- while (signature) {
- VerifyKeyDetailBox *sbox = new VerifyKeyDetailBox(this,mCtx,mKeyList,signature);
- signature = signature->next;
+ while (sign) {
+ VerifyKeyDetailBox *sbox = new VerifyKeyDetailBox(this,mCtx,mKeyList,sign);
+ sign = sign->next;
mVbox->addWidget(sbox);
}
@@ -49,14 +81,4 @@ VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::Context* ctx, K
buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
mVbox->addWidget(buttonBox);
-
- this->setLayout(mVbox);
- this->setWindowTitle(tr("Signaturedetails"));
- this->show();
- this->exec();
-}
-
-void VerifyDetailsDialog::refresh()
-{
- qDebug() << "refresh detail dialog";
}
diff --git a/verifydetailsdialog.h b/verifydetailsdialog.h
index 8e24455..afcdfe0 100644
--- a/verifydetailsdialog.h
+++ b/verifydetailsdialog.h
@@ -22,6 +22,7 @@
#ifndef __VERIFYDETAILSDIALOG_H__
#define __VERIFYDETAILSDIALOG_H__
+#include "editorpage.h"
#include "verifykeydetailbox.h"
#include <QDialog>
@@ -29,7 +30,7 @@ class VerifyDetailsDialog : public QDialog
{
Q_OBJECT
public:
- explicit VerifyDetailsDialog(QWidget *parent, GpgME::Context* ctx, KeyList* mKeyList, gpgme_signature_t signature);
+ explicit VerifyDetailsDialog(QWidget *parent, GpgME::Context* ctx, KeyList* mKeyList, QPlainTextEdit *edit);
private slots:
void refresh();
@@ -38,6 +39,7 @@ private:
GpgME::Context* mCtx;
KeyList* mKeyList;
QVBoxLayout* mVbox;
+ QPlainTextEdit *mTextpage; /** Textedit associated to the notification */
QDialogButtonBox* buttonBox;
};
diff --git a/verifynotification.cpp b/verifynotification.cpp
index 0068638..c0614bb 100644
--- a/verifynotification.cpp
+++ b/verifynotification.cpp
@@ -21,12 +21,12 @@
#include "verifynotification.h"
-VerifyNotification::VerifyNotification(QWidget *parent, GpgME::Context *ctx, KeyList *keyList, gpgme_signature_t sign ) :
+VerifyNotification::VerifyNotification(QWidget *parent, GpgME::Context *ctx, KeyList *keyList,QPlainTextEdit *edit) :
QWidget(parent)
{
mCtx = ctx;
mKeyList = keyList;
- mSignature = sign;
+ mTextpage = edit;
verifyLabel = new QLabel(this);
connect(mCtx, SIGNAL(keyDBChanged()), this, SLOT(refresh()));
@@ -84,10 +84,79 @@ void VerifyNotification::showImportAction(bool visible)
void VerifyNotification::showVerifyDetails()
{
- new VerifyDetailsDialog(this, mCtx, mKeyList, mSignature);
+ new VerifyDetailsDialog(this, mCtx, mKeyList, mTextpage);
}
-void VerifyNotification::refresh()
+bool VerifyNotification::refresh()
{
- qDebug() << "refresh signal called";
+ verify_label_status verifyStatus=VERIFY_ERROR_OK;
+
+ QByteArray text = mTextpage->toPlainText().toAscii(); // TODO: toUtf8() here?
+ mCtx->preventNoDataErr(&text);
+ int textIsSigned = mCtx->textIsSigned(text);
+
+ gpgme_signature_t sign = mCtx->verify(text);
+
+ if (sign == NULL) {
+ return false;
+ }
+
+ QString verifyLabelText;
+ bool unknownKeyFound=false;
+
+ while (sign) {
+ switch (gpg_err_code(sign->status))
+ {
+ case GPG_ERR_NO_PUBKEY:
+ {
+ verifyStatus=VERIFY_ERROR_WARN;
+ verifyLabelText.append(tr("Key not present with Fingerprint: ")+mCtx->beautifyFingerprint(QString(sign->fpr)));
+ this->keysNotInList->append(sign->fpr);
+ unknownKeyFound=true;
+ break;
+ }
+ case GPG_ERR_NO_ERROR:
+ {
+ QString name = mKeyList->getKeyNameByFpr(sign->fpr);
+ QString email =mKeyList->getKeyEmailByFpr(sign->fpr);
+ verifyLabelText.append(name);
+ if (!email.isEmpty()) {
+ verifyLabelText.append("<"+email+">");
+ }
+ break;
+ }
+ default:
+ {
+ verifyStatus=VERIFY_ERROR_WARN;
+ verifyLabelText.append(tr("Error for key with fingerprint ")+mCtx->beautifyFingerprint(QString(sign->fpr)));
+ break;
+ }
+ }
+ verifyLabelText.append("\n");
+ sign = sign->next;
+ }
+
+ switch (textIsSigned)
+ {
+ case 2:
+ {
+ verifyLabelText.prepend(tr("Text is completly signed by: "));
+ break;
+ }
+ case 1:
+ {
+ verifyLabelText.prepend(tr("Text is partially signed by: "));
+ break;
+ }
+ }
+
+ // If an unknown key is found, enable the importfromkeyserveraction
+ this->showImportAction(unknownKeyFound);
+
+ // Remove the last linebreak
+ verifyLabelText.remove(verifyLabelText.length()-1,1);
+
+ this->setVerifyLabel(verifyLabelText,verifyStatus);
+
+ return true;
}
diff --git a/verifynotification.h b/verifynotification.h
index 495593b..bc43571 100644
--- a/verifynotification.h
+++ b/verifynotification.h
@@ -22,6 +22,7 @@
#ifndef __VERIFYNOTIFICATION_H__
#define __VERIFYNOTIFICATION_H__
+#include "editorpage.h"
#include "verifydetailsdialog.h"
#include <gpgme.h>
#include <QWidget>
@@ -57,7 +58,7 @@ public:
* @param ctx The GPGme-Context
* @param parent The parent widget
*/
- explicit VerifyNotification(QWidget *parent, GpgME::Context *ctx, KeyList *keyList, gpgme_signature_t sign);
+ explicit VerifyNotification(QWidget *parent, GpgME::Context *ctx, KeyList *keyList,QPlainTextEdit *edit);
/**
* @details Set the text and background-color of verify notification.
*
@@ -87,6 +88,11 @@ public slots:
*/
void showVerifyDetails();
+ /**
+ * @details Refresh the contents of dialog.
+ */
+ bool refresh();
+
private:
QMenu *detailMenu; /** Menu for te Button in verfiyNotification */
QAction *importFromKeyserverAct; /** Action for importing keys from keyserver which are notin keylist */
@@ -95,12 +101,10 @@ private:
QLabel *verifyLabel; /** Label holding the text shown in verifyNotification */
GpgME::Context *mCtx; /** GpgME Context */
KeyList *mKeyList; /** Table holding the keys */
- gpgme_signature_t mSignature; /** List holding the signatures of text */
+ QPlainTextEdit *mTextpage; /** Textedit associated to the notification */
QHBoxLayout *notificationWidgetLayout; /** Layout for verify-notification */
QVector<QString> verifyDetailStringVector; /** Vector containing the text for labels in verifydetaildialog */
QVector<verify_label_status> verifyDetailStatusVector; /** Vector containing the status for labels in verifydetaildialog */
-private slots:
- void refresh();
};
#endif // __VERIFYNOTIFICATION_H__