diff options
author | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-09-11 19:59:44 +0000 |
---|---|---|
committer | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-09-11 19:59:44 +0000 |
commit | 68f49002ee2b89bbbb78240b0e6f66147e00866c (patch) | |
tree | eb0be73d7db72a56b46da11207c2bb29096e4836 | |
parent | more docu in gpgwin.cpp and set slots in gpgwin from public to private (diff) | |
download | gpg4usb-68f49002ee2b89bbbb78240b0e6f66147e00866c.tar.gz gpg4usb-68f49002ee2b89bbbb78240b0e6f66147e00866c.zip |
show details in different colours in verfiy detail dialog, further commenting and added fillTextEditWithText to textedit
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@530 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | gpgwin.cpp | 83 | ||||
-rw-r--r-- | textedit.cpp | 8 | ||||
-rw-r--r-- | textedit.h | 175 | ||||
-rw-r--r-- | verifynotification.cpp | 45 | ||||
-rw-r--r-- | verifynotification.h | 50 |
5 files changed, 134 insertions, 227 deletions
@@ -124,7 +124,7 @@ void GpgWin::saveSettings() void GpgWin::createActions() { - /** Main Menu + /* Main Menu */ newTabAct = new QAction(tr("&New"), this); QList<QKeySequence> newTabActShortcutList; @@ -170,7 +170,7 @@ void GpgWin::createActions() quitAct->setToolTip(tr("Quit Program")); connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); - /** Edit Menu + /* Edit Menu */ undoAct = new QAction(tr("&Undo"), this); undoAct->setShortcut(QKeySequence::Undo); @@ -224,7 +224,7 @@ void GpgWin::createActions() openSettingsAct->setShortcut(QKeySequence::Preferences); connect(openSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog())); - /** Crypt Menu + /* Crypt Menu */ encryptAct = new QAction(tr("&Encrypt"), this); encryptAct->setIcon(QIcon(iconPath + "encrypted.png")); @@ -255,7 +255,7 @@ void GpgWin::createActions() verifyAct->setToolTip(tr("Verify Message")); connect(verifyAct, SIGNAL(triggered()), this, SLOT(verify())); - /** Key Menu + /* Key Menu */ importKeyFromFileAct = new QAction(tr("&File"), this); importKeyFromFileAct->setIcon(QIcon(iconPath + "misc_doc.png")); @@ -286,7 +286,7 @@ void GpgWin::createActions() importKeyDialogAct->setToolTip(tr("Open Import New Key Dialog")); connect(importKeyDialogAct, SIGNAL(triggered()), this, SLOT(importKeyDialog())); - /** About Menu + /* About Menu */ aboutAct = new QAction(tr("&About"), this); aboutAct->setIcon(QIcon(iconPath + "help.png")); @@ -302,7 +302,7 @@ void GpgWin::createActions() openTranslateAct->setToolTip(tr("Translate gpg4usb yourself")); connect(openTranslateAct, SIGNAL(triggered()), this, SLOT(openTranslate())); - /** Popup-Menu-Action for KeyList + /* Popup-Menu-Action for KeyList */ appendSelectedKeysAct = new QAction(tr("Append Selected Key(s) To Text"), this); appendSelectedKeysAct->setToolTip(tr("Append The Selected Keys To Text in Editor")); @@ -317,7 +317,7 @@ void GpgWin::createActions() showKeyDetailsAct->setToolTip(tr("Show Details for this Key")); connect(showKeyDetailsAct, SIGNAL(triggered()), this, SLOT(showKeyDetails())); - /** Key-Shortcuts for Tab-Switchung-Action + /* Key-Shortcuts for Tab-Switchung-Action */ switchTabUpAct = new QAction(this); switchTabUpAct->setShortcut(QKeySequence::NextChild); @@ -427,7 +427,7 @@ void GpgWin::createStatusBar() void GpgWin::createDockWindows() { - /** KeyList-Dockwindow + /* KeyList-Dockwindow */ dock = new QDockWidget(tr("Encrypt for:"), this); dock->setObjectName("EncryptDock"); @@ -436,7 +436,7 @@ void GpgWin::createDockWindows() dock->setWidget(mKeyList); viewMenu->addAction(dock->toggleViewAction()); - /** Attachments-Dockwindow + /* Attachments-Dockwindow */ aDock = new QDockWidget(tr("Attached files:"), this); aDock->setObjectName("AttachmentDock"); @@ -450,7 +450,7 @@ void GpgWin::createDockWindows() void GpgWin::closeEvent(QCloseEvent *event) { - /** + /* * ask to save changes, if there are * modified documents in any tab */ @@ -513,7 +513,7 @@ void GpgWin::openTutorial() { QDesktopServices::openUrl(QUrl("http://gpg4usb.cpunk.de/docu.html")); } -/** +/* * if this is mime, split text and attachments... * message contains only text afterwards */ @@ -574,7 +574,7 @@ void GpgWin::checkAttachmentFolder() { } } -/** +/* * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace, * GPGME doesn't recognise the Message as encrypted. This function adds '\n' * before the PGP-Begin-Block, if missing. @@ -641,13 +641,7 @@ void GpgWin::encrypt() QByteArray *tmp = new QByteArray(); if (mCtx->encrypt(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()); - cursor.beginEditBlock(); - edit->curTextPage()->selectAll(); - edit->curTextPage()->insertPlainText(*tmp2); - cursor.endEditBlock(); + edit->fillTextEditWithText(*tmp2); } } @@ -659,13 +653,7 @@ void GpgWin::sign() // TODO: toUtf8() here? if (mCtx->sign(uidList, edit->curTextPage()->toPlainText().toAscii(), tmp)) { QString *tmp2 = new QString(*tmp); - - // beginEditBlock and endEditBlock() let operation look like single undo/redo operation - QTextCursor cursor(edit->curTextPage()->document()); - cursor.beginEditBlock(); - edit->curTextPage()->selectAll(); - edit->curTextPage()->insertPlainText(*tmp2); - cursor.endEditBlock(); + edit->fillTextEditWithText(*tmp2); } } @@ -680,7 +668,7 @@ void GpgWin::decrypt() return; } - /** + /* * 1) is it mime (content-type:) * 2) parse header * 2) choose action depending on content-type @@ -701,12 +689,7 @@ void GpgWin::decrypt() } } } - // beginEditBlock and endEditBlock() let operation look like single undo/redo operation - QTextCursor cursor(edit->curTextPage()->document()); - cursor.beginEditBlock(); - edit->curTextPage()->selectAll(); - edit->curTextPage()->insertPlainText(QString::fromUtf8(*decrypted)); - cursor.endEditBlock(); + edit->fillTextEditWithText(QString::fromUtf8(*decrypted)); } /* @@ -731,7 +714,6 @@ void GpgWin::verify() verify_label_status verifyStatus=VERIFY_ERROR_OK; QByteArray text = edit->curTextPage()->toPlainText().toAscii(); // TODO: toUtf8() here? preventNoDataErr(&text); - QString verifyDetailText; int textIsSigned = isSigned(text); gpgme_signature_t sign = mCtx->verify(text); @@ -755,31 +737,28 @@ void GpgWin::verify() verifyStatus=VERIFY_ERROR_WARN; verifyLabelText.append(tr("Key not present with Fingerprint: ")+QString(sign->fpr)); *vn->keysNotInList << sign->fpr; - vn->setProperty("keyNotFound", true); unknownKeyFound=true; - verifyDetailText.append(tr("Key not present in keylist: ")+QString(sign->fpr)+"\n\n"); + vn->addVerifyDetailLabel(tr("Key not present in keylist: ")+QString(sign->fpr),VERIFY_ERROR_WARN, false); break; } case GPG_ERR_NO_ERROR: { - qDebug() << "GPG_ERR_NO_ERR"; QString name = mKeyList->getKeyNameByFpr(sign->fpr); QString email =mKeyList->getKeyEmailByFpr(sign->fpr); - verifyDetailText.append(tr("Name: ")+name+"\n"+tr("EMail: ")+email+"\n"); - verifyDetailText.append(tr("Fingerprint: ")+QString(sign->fpr)+"\n\n"); verifyLabelText.append(name); if (!email.isEmpty()) { verifyLabelText.append("<"+email+">"); } - vn->setProperty("keyFound", true); + vn->addVerifyDetailLabel(tr("Name: ")+name+"\n"+tr("EMail: ")+email+"\n"+tr("Fingerprint: ")+QString(sign->fpr),VERIFY_ERROR_OK, false); break; } default: { - qDebug() << "switch default"; - verifyDetailText.append(tr("Key with Fingerprint: ")+QString(sign->fpr)+"\n"); - verifyDetailText.append(tr("Signature status: ")+gpg_strerror(sign->status)+"\n"); - verifyDetailText.append(tr("Signature validity reason: ")+QString(gpgme_strerror(sign->validity_reason))+"\n"); + verifyStatus=VERIFY_ERROR_WARN; + vn->addVerifyDetailLabel(tr("Key with Fingerprint: ")+ + QString(sign->fpr)+"\n"+tr("Signature status: ")+gpg_strerror(sign->status)+"\n" + +tr("Signature validity reason: ")+QString(gpgme_strerror(sign->validity_reason)), + VERIFY_ERROR_WARN, false); verifyLabelText.append(tr("Error for key with fingerprint ")+QString(sign->fpr)); break; } @@ -789,7 +768,6 @@ void GpgWin::verify() 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); - qDebug() << "timestamp: " << sign->timestamp; sign = sign->next; } @@ -798,13 +776,13 @@ void GpgWin::verify() case 2: { verifyLabelText.prepend(tr("Text is completly signed by: ")); - verifyDetailText.prepend(tr("Text was completly signed on %1 by:\n\n").arg(timestamp.toString(Qt::SystemLocaleShortDate))); + vn->addVerifyDetailLabel(tr("Text was completly signed on %1 by:\n").arg(timestamp.toString(Qt::SystemLocaleShortDate)),VERIFY_ERROR_NEUTRAL, true); break; } case 1: { verifyLabelText.prepend(tr("Text is partially signed by: ")); - verifyDetailText.prepend(tr("Text was partially signed on %1 by:\n\n").arg(timestamp.toString(Qt::SystemLocaleShortDate))); + vn->addVerifyDetailLabel(tr("Text was partially signed on %1 by:\n").arg(timestamp.toString(Qt::SystemLocaleShortDate)),VERIFY_ERROR_NEUTRAL, true); break; } } @@ -814,10 +792,8 @@ void GpgWin::verify() // Remove the last linebreak verifyLabelText.remove(verifyLabelText.length()-1,1); - verifyDetailText.remove(verifyDetailText.length()-1,1); vn->setVerifyLabel(verifyLabelText,verifyStatus); - vn->setVerifyDetailText(verifyDetailText); edit->curPage()->showNotificationWidget(vn, "verifyNotification"); } @@ -861,7 +837,7 @@ void GpgWin::importKeyDialog() } } -/** +/* * Append the selected (not checked!) Key(s) To Textedit */ void GpgWin::appendSelectedKeys() @@ -909,10 +885,5 @@ void GpgWin::openSettingsDialog() void GpgWin::cleanDoubleLinebreaks() { QString content = edit->curTextPage()->toPlainText(); content.replace("\n\n", "\n"); - QTextCursor cursor(edit->curTextPage()->document()); - // TODO: own utils method for following: - cursor.beginEditBlock(); - edit->curTextPage()->selectAll(); - edit->curTextPage()->insertPlainText(content); - cursor.endEditBlock(); + edit->fillTextEditWithText(content); } diff --git a/textedit.cpp b/textedit.cpp index d7d4ad6..c7939e3 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -320,6 +320,14 @@ void TextEdit::quote() cursor.endEditBlock(); } +void TextEdit::fillTextEditWithText(QString text) { + QTextCursor cursor(curTextPage()->document()); + cursor.beginEditBlock(); + this->curTextPage()->selectAll(); + this->curTextPage()->insertPlainText(text); + cursor.endEditBlock(); +} + void TextEdit::loadFile(const QString &fileName) { QFile file(fileName); @@ -54,7 +54,7 @@ public: TextEdit(QString iconPath); /** - * @brief Load the content of file into the current textpage + * @details Load the content of file into the current textpage * * @param fileName QString containing the filename to load * @return nothing @@ -77,88 +77,48 @@ public: QPlainTextEdit* curTextPage(); /** - * @details List of currently unsaved tabs - * @returns QHash<int, QString> Hash of tabindexes and title of unsaved tabs + * @details List of currently unsaved tabs. + * @returns QHash<int, QString> Hash of tabindexes and title of unsaved tabs. */ QHash<int, QString> unsavedDocuments(); public slots: - /**************************************************************************************** - * Name: quote - * Description: Insert a ">" at the begining of every line of current textedit - * Parameters: none - * Return Values: none - * Change on members: - */ /** - * @brief - * + * @details Insert a ">" at the begining of every line of current textedit. */ void quote(); - /**************************************************************************************** - * Name: save - * Description: Saves the content of the current tab, if it has a filepath - * otherwise it calls saveAs for the current tab - * Parameters: none - * Return Values: none - * Change on members: - */ /** - * @brief - * + * @details replace the text of currently active textedit with given text. + * @param text to fill on. + */ + void fillTextEditWithText(QString text); + + /** + * @details Saves the content of the current tab, if it has a filepath + * otherwise it calls saveAs for the current tab */ void save(); - /**************************************************************************************** - * Name: SaveAs - * Description: Opens a savefiledialog and calls saveFile with the choosen filename - * Parameters: none - * Return Values: just returns the return value of the saveFile method - * Change on members: none - */ /** - * @brief + * @details Opens a savefiledialog and calls saveFile with the choosen filename. * + * @return Return the return value of the savefile method */ bool saveAs(); - /**************************************************************************************** - * Name: open - * Description: shows an OpenFileDoalog and opens the file in a new tab - * shows an error dialog, if the open fails - * sets the focus to the tab of the opened file - * Parameters: none - * Return Values: none - * Change on members: none - */ /** - * @brief - * + * @details Show an OpenFileDoalog and open the file in a new tab. + * Shows an error dialog, if the open fails. + * Set the focus to the tab of the opened file. */ void open(); - /**************************************************************************************** - * Name: print - * Description: opens print dialog for the current tab - * Parameters: none - * Return Values: none - * Change on members: none - */ /** - * @brief - * + * @details Open a print-dialog for the current tab */ void print(); - /**************************************************************************************** - * Name: newTab() - * Description: Adds a new tab with the title "untitled"+countpage+".txt" - * Sets the focus to the new tab - * Parameters: none - * Return Values: none - * Change on members: increases countPage per 1 - */ /** * @details Adds a new tab with the title "untitled"+countpage+".txt" * Sets the focus to the new tab. Increase Tab-Count by one @@ -175,62 +135,40 @@ public slots: * */ void closeTab(); - /**************************************************************************************** - * Name: switchTabUp - * Description: switch to next tab - * Parameters: none - * Return Values: none - * Change on members: increase tabWidget->count() per 1 - */ + /** - * @brief + * @details Switch to the next tab. * */ void switchTabUp(); - /**************************************************************************************** - * Name: switchTabDown - * Description: switch to next tab - * Parameters: none - * Return Values: none - * Change on members: decrease tabWidget->count() per 1 - */ + /** - * @brief + * @details Switch to the previous tab. * */ void switchTabDown(); - /**************************************************************************************** - * Name: curPage - * Description: return pointer to the currently activated tabpage - * Parameters: none - * Return Values: pointer to the currently activated tabpage - * Change on members: none - */ + /** - * @brief + * @details Return pointer to the currently activated tabpage. * */ EditorPage *curPage(); private: - /**************************************************************************************** - * Name: strippedName - * Description: return just filename - * Parameters: a filename path - * Return Values: QStirng containig the filename - * Change on members: none - */ /** - * @brief + * @details return just a filename stripped of a whole path * - * @param fullFileName + * @param a filename path + * @return QString containing the filename */ QString strippedName(const QString &fullFileName); + /** * @brief * */ bool maybeSaveFile(); + /** * @brief * @@ -238,78 +176,39 @@ private: */ bool maybeSaveCurrentTab(bool askToSave); - QString mIconPath; /* TODO */ + QString mIconPath; /** Path to the apps icons */ /**************************************************************************************** * Name: countPage * Description: int cotaining the number of added tabs */ int countPage; /* TODO */ - QTabWidget *tabWidget; /* TODO */ + QTabWidget *tabWidget; /** Widget containing the tabs of the editor */ private slots: - /**************************************************************************************** - * Name: removeTab - * Description: Removes the tab on index - * Parameters: int index, shows the index of the tab to remove - * Return Values: none - * Change on members: none - */ /** - * @brief + * @details Remove the tab with given index * - * @param index + * @param index Tab-number to remove */ void removeTab(int index); - /**************************************************************************************** - * Name: cut - * Description: cut selected text in current textpage - * Parameters: none - * Return Values: none - * Change on members: none - */ /** - * @brief - * + * @details Cut selected text in current textpage. */ void cut(); - /**************************************************************************************** - * Name: copy - * Description: copy selected text of current textpage to clipboard - * Parameters: none - * Return Values: none - * Change on members: none - */ /** - * @brief - * + * @details Copy selected text of current textpage to clipboard. */ void copy(); - /**************************************************************************************** - * Name: paste - * Description: paste text from clipboard to current textpage - * Parameters: none - * Return Values: none - * Change on members: none - */ /** - * @brief - * + * @details Paste text from clipboard to current textpage. */ void paste(); - /**************************************************************************************** - * Name: undo - * Description: undo last change in current textpage - * Parameters: none - * Return Values: none - * Change on members: none - */ - /** - * @brief + * @details Undo last change in current textpage. * */ void undo(); diff --git a/verifynotification.cpp b/verifynotification.cpp index c177497..a13bcc8 100644 --- a/verifynotification.cpp +++ b/verifynotification.cpp @@ -26,7 +26,6 @@ VerifyNotification::VerifyNotification(GpgME::Context *ctx, QWidget *parent ) : { mCtx = ctx; verifyLabel = new QLabel(this); - verifyDetailText = new QString(); importFromKeyserverAct = new QAction(tr("Import missing key from Keyserver"), this); connect(importFromKeyserverAct, SIGNAL(triggered()), this, SLOT(importFromKeyserver())); @@ -47,15 +46,19 @@ VerifyNotification::VerifyNotification(GpgME::Context *ctx, QWidget *parent ) : notificationWidgetLayout->setContentsMargins(0,0,0,0); notificationWidgetLayout->addWidget(verifyLabel,2); notificationWidgetLayout->addWidget(detailsButton); - this->setLayout(notificationWidgetLayout); + verifyDetailListLayout = new QVBoxLayout(); } -void VerifyNotification::setVerifyDetailText (QString text) +void VerifyNotification::addVerifyDetailLabel(QString text,verify_label_status status,bool prepend) { - verifyDetailText->clear(); - verifyDetailText->append(text); - return; + if (prepend) { + verifyDetailStringVector.prepend(text); + verifyDetailStatusVector.prepend(status); + } else { + verifyDetailStringVector.append(text); + verifyDetailStatusVector.append(status); + } } void VerifyNotification::importFromKeyserver() @@ -90,6 +93,34 @@ void VerifyNotification::showImportAction(bool visible) void VerifyNotification::showVerifyDetails() { - QMessageBox::information(this,tr("Details"),QString(*verifyDetailText), QMessageBox::Ok); + QDialog *verifyDetailsDialog = new QDialog(this); + // QLabel *label = new QLabel(*verifyDetailText); + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); + connect(buttonBox, SIGNAL(rejected()), verifyDetailsDialog, SLOT(close())); + for (int i=0;i<verifyDetailStringVector.size();i++) { + QLabel *label = new QLabel(verifyDetailStringVector[i]); + verifyDetailListLayout->addWidget(label); + switch (verifyDetailStatusVector[i]) { + case VERIFY_ERROR_OK: label->setObjectName("ok"); + break; + case VERIFY_ERROR_WARN: label->setObjectName("warning"); + break; + case VERIFY_ERROR_CRITICAL: label->setObjectName("critical"); + break; + default: + break; + } + } + +// verifyDetailStatusVector.append(status); + +// verifyDetailListLayout->addWidget(label); + + verifyDetailListLayout->addWidget(buttonBox); + + verifyDetailsDialog->setLayout(verifyDetailListLayout); + verifyDetailsDialog->show(); + + //QMessageBox::information(this,tr("Details"),QString(*verifyDetailText), QMessageBox::Ok); return; } diff --git a/verifynotification.h b/verifynotification.h index c8cdd4c..f641b05 100644 --- a/verifynotification.h +++ b/verifynotification.h @@ -41,6 +41,7 @@ typedef enum VERIFY_ERROR_OK = 0, VERIFY_ERROR_WARN = 1, VERIFY_ERROR_CRITICAL = 2, + VERIFY_ERROR_NEUTRAL =3, } verify_label_status; /** @@ -72,43 +73,40 @@ public: */ void showImportAction(bool visible); - /** - * @details Set the text of verify-detail dialog. - * - * @param text The text to be set. - */ - void setVerifyDetailText(QString text); - - /**************************************************************************************** - * Name: keysNotInList - * Description: List holding the keys in signature, which are not in the keylist - */ - QStringList *keysNotInList; + QStringList *keysNotInList; /** List with keys, which are in signature but not in keylist */ -signals: + /** + * @details add text to the verifyDetailStringVector and associated status to the + * verifyDetailStatusVector + * @param text The text to be added + * @param status The status to be set + * @param prepend If prepend is true, prepend to the vectors, + * otherwise append to the vectors + */ + void addVerifyDetailLabel(QString text, verify_label_status status, bool prepend); public slots: - // import missing key from keyserver /** - * @brief + * @details Import the keys contained in keysNotInList from keyserver * */ void importFromKeyserver(); - // show verify details + /** - * @brief - * + * @details Show a dialog with signing details. */ void showVerifyDetails(); private: - QMenu *detailMenu; // Menu for te Button in verfiyNotification /**< TODO */ - QAction *importFromKeyserverAct; /**< TODO */ - QAction *showVerifyDetailsAct; /**< TODO */ - QString *verifyDetailText; // Text showed in VerifiyNotification /**< TODO */ - QPushButton *detailsButton; // Button shown in verifynotification /**< TODO */ - QLabel *verifyLabel; // Label holding the text shown in verifyNotification /**< TODO */ - GpgME::Context *mCtx; /**< TODO */ - QHBoxLayout *notificationWidgetLayout; /**< TODO */ + QMenu *detailMenu; /** Menu for te Button in verfiyNotification */ + QAction *importFromKeyserverAct; /** Action for importing keys from keyserver which are notin keylist */ + QAction *showVerifyDetailsAct; /** Action for showing verify detail dialog */ + QPushButton *detailsButton; /** Button shown in verifynotification */ + QLabel *verifyLabel; /** Label holding the text shown in verifyNotification */ + GpgME::Context *mCtx; /** GpgME Context */ + QHBoxLayout *notificationWidgetLayout; /** Layout for verify-notification */ + QVBoxLayout *verifyDetailListLayout; /** Layout for verify-detail-dialog */ + QVector<QString> verifyDetailStringVector; /** Vector containing the text for labels in verifydetaildialog */ + QVector<verify_label_status> verifyDetailStatusVector; /** Vector containing the status for labels in verifydetaildialog */ }; #endif // VERIFYNOTIFICATION_H |