diff options
Diffstat (limited to 'src')
25 files changed, 1645 insertions, 1129 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c695d58c..9a640c1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,6 +61,7 @@ if(MINGW) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/imageformats DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/printsupport DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/platforms DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) + file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/openssl/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) endif() set(RESOURCE_FILES ${CMAKE_SOURCE_DIR}/gpgfrontend.qrc ${APP_ICON_RESOURCE_WINDOWS} ${QON_QM_FILES}) @@ -84,11 +85,19 @@ if(${CMAKE_BUILD_TYPE} STREQUAL "Release") add_custom_command(TARGET gpgfrontend POST_BUILD COMMAND /bin/rm -rf ./gpgfrontend.app/Contents/Resources WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Resource INTO App Bundle Resource") + COMMENT "Deleting Resources IN App Bundle") add_custom_command(TARGET gpgfrontend POST_BUILD COMMAND /bin/mv -n ./Resources ./gpgfrontend.app/Contents/ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Resource INTO App Bundle Resource") + COMMENT "Copying Resources INTO App Bundle Resource") + add_custom_command(TARGET gpgfrontend POST_BUILD + COMMAND /bin/rm -rf ./GpgFrontend.app + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Deleting Old Final App Bundle") + add_custom_command(TARGET gpgfrontend POST_BUILD + COMMAND /bin/mv -n ./gpgfrontend.app ./GpgFrontend.app + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Rename Build App Bundle to Final App Bundle") endif() else() add_executable(gpgfrontend ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e2e610a2..6fa77e5a 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -133,7 +133,7 @@ void MainWindow::restoreSettings() { settings.setValue("keyserver/keyServerList", keyServerList); // set default keyserver, if it's not set - QString defaultKeyServer = settings.value("keyserver/defaultKeyServer", QString("http://keys.gnupg.net")).toString(); + QString defaultKeyServer = settings.value("keyserver/defaultKeyServer", QString("https://keyserver.ubuntu.com")).toString(); settings.setValue("keyserver/defaultKeyServer", defaultKeyServer); // Iconstyle @@ -169,474 +169,6 @@ void MainWindow::saveSettings() { } } -void MainWindow::createActions() { - /* Main Menu - */ - newTabAct = new QAction(tr("&New"), this); - newTabAct->setIcon(QIcon(":misc_doc.png")); - QList<QKeySequence> newTabActShortcutList; - newTabActShortcutList.append(QKeySequence(Qt::CTRL + Qt::Key_N)); - newTabActShortcutList.append(QKeySequence(Qt::CTRL + Qt::Key_T)); - newTabAct->setShortcuts(newTabActShortcutList); - newTabAct->setToolTip(tr("Open a new file")); - connect(newTabAct, SIGNAL(triggered()), edit, SLOT(slotNewTab())); - - openAct = new QAction(tr("&Open..."), this); - openAct->setIcon(QIcon(":fileopen.png")); - openAct->setShortcut(QKeySequence::Open); - openAct->setToolTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), edit, SLOT(slotOpen())); - - saveAct = new QAction(tr("&Save"), this); - saveAct->setIcon(QIcon(":filesave.png")); - saveAct->setShortcut(QKeySequence::Save); - saveAct->setToolTip(tr("Save the current File")); - connect(saveAct, SIGNAL(triggered()), edit, SLOT(slotSave())); - - saveAsAct = new QAction(tr("Save &As") + "...", this); - saveAsAct->setIcon(QIcon(":filesaveas.png")); - saveAsAct->setShortcut(QKeySequence::SaveAs); - saveAsAct->setToolTip(tr("Save the current File as...")); - connect(saveAsAct, SIGNAL(triggered()), edit, SLOT(slotSaveAs())); - - printAct = new QAction(tr("&Print"), this); - printAct->setIcon(QIcon(":fileprint.png")); - printAct->setShortcut(QKeySequence::Print); - printAct->setToolTip(tr("Print Document")); - connect(printAct, SIGNAL(triggered()), edit, SLOT(slotPrint())); - - closeTabAct = new QAction(tr("&Close"), this); - closeTabAct->setShortcut(QKeySequence::Close); - closeTabAct->setToolTip(tr("Close file")); - connect(closeTabAct, SIGNAL(triggered()), edit, SLOT(slotCloseTab())); - - quitAct = new QAction(tr("&Quit"), this); - quitAct->setShortcut(QKeySequence::Quit); - quitAct->setIcon(QIcon(":exit.png")); - quitAct->setToolTip(tr("Quit Program")); - connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); - - /* Edit Menu - */ - undoAct = new QAction(tr("&Undo"), this); - undoAct->setShortcut(QKeySequence::Undo); - undoAct->setToolTip(tr("Undo Last Edit Action")); - connect(undoAct, SIGNAL(triggered()), edit, SLOT(slotUndo())); - - redoAct = new QAction(tr("&Redo"), this); - redoAct->setShortcut(QKeySequence::Redo); - redoAct->setToolTip(tr("Redo Last Edit Action")); - connect(redoAct, SIGNAL(triggered()), edit, SLOT(slotRedo())); - - zoomInAct = new QAction(tr("Zoom In"), this); - zoomInAct->setShortcut(QKeySequence::ZoomIn); - connect(zoomInAct, SIGNAL(triggered()), edit, SLOT(slotZoomIn())); - - zoomOutAct = new QAction(tr("Zoom Out"), this); - zoomOutAct->setShortcut(QKeySequence::ZoomOut); - connect(zoomOutAct, SIGNAL(triggered()), edit, SLOT(slotZoomOut())); - - pasteAct = new QAction(tr("&Paste"), this); - pasteAct->setIcon(QIcon(":button_paste.png")); - pasteAct->setShortcut(QKeySequence::Paste); - pasteAct->setToolTip(tr("Paste Text From Clipboard")); - connect(pasteAct, SIGNAL(triggered()), edit, SLOT(slotPaste())); - - cutAct = new QAction(tr("Cu&t"), this); - cutAct->setIcon(QIcon(":button_cut.png")); - cutAct->setShortcut(QKeySequence::Cut); - cutAct->setToolTip(tr("Cut the current selection's contents to the " - "clipboard")); - connect(cutAct, SIGNAL(triggered()), edit, SLOT(slotCut())); - - copyAct = new QAction(tr("&Copy"), this); - copyAct->setIcon(QIcon(":button_copy.png")); - copyAct->setShortcut(QKeySequence::Copy); - copyAct->setToolTip(tr("Copy the current selection's contents to the " - "clipboard")); - connect(copyAct, SIGNAL(triggered()), edit, SLOT(slotCopy())); - - quoteAct = new QAction(tr("&Quote"), this); - quoteAct->setIcon(QIcon(":quote.png")); - quoteAct->setToolTip(tr("Quote whole text")); - connect(quoteAct, SIGNAL(triggered()), edit, SLOT(slotQuote())); - - selectallAct = new QAction(tr("Select &All"), this); - selectallAct->setIcon(QIcon(":edit.png")); - selectallAct->setShortcut(QKeySequence::SelectAll); - selectallAct->setToolTip(tr("Select the whole text")); - connect(selectallAct, SIGNAL(triggered()), edit, SLOT(slotSelectAll())); - - findAct = new QAction(tr("&Find"), this); - findAct->setShortcut(QKeySequence::Find); - findAct->setToolTip(tr("Find a word")); - connect(findAct, SIGNAL(triggered()), this, SLOT(slotFind())); - - cleanDoubleLinebreaksAct = new QAction(tr("Remove &spacing"), this); - cleanDoubleLinebreaksAct->setIcon(QIcon(":format-line-spacing-triple.png")); - //cleanDoubleLineBreaksAct->setShortcut(QKeySequence::SelectAll); - cleanDoubleLinebreaksAct->setToolTip(tr("Remove double linebreaks, e.g. in pasted text from webmailer")); - connect(cleanDoubleLinebreaksAct, SIGNAL(triggered()), this, SLOT(slotCleanDoubleLinebreaks())); - - openSettingsAct = new QAction(tr("Se&ttings"), this); - openSettingsAct->setToolTip(tr("Open settings dialog")); - openSettingsAct->setShortcut(QKeySequence::Preferences); - connect(openSettingsAct, SIGNAL(triggered()), this, SLOT(slotOpenSettingsDialog())); - - /* Crypt Menu - */ - encryptAct = new QAction(tr("&Encrypt"), this); - encryptAct->setIcon(QIcon(":encrypted.png")); - encryptAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E)); - encryptAct->setToolTip(tr("Encrypt Message")); - connect(encryptAct, SIGNAL(triggered()), this, SLOT(slotEncrypt())); - - encryptSignAct = new QAction(tr("&Encrypt &Sign"), this); - encryptSignAct->setIcon(QIcon(":encrypted_signed.png")); - encryptSignAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_E)); - encryptSignAct->setToolTip(tr("Encrypt and Sign Message")); - connect(encryptSignAct, SIGNAL(triggered()), this, SLOT(slotEncryptSign())); - - decryptAct = new QAction(tr("&Decrypt"), this); - decryptAct->setIcon(QIcon(":decrypted.png")); - decryptAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - decryptAct->setToolTip(tr("Decrypt Message")); - connect(decryptAct, SIGNAL(triggered()), this, SLOT(slotDecrypt())); - - decryptVerifyAct = new QAction(tr("&Decrypt &Verify"), this); - decryptVerifyAct->setIcon(QIcon(":decrypted_verified.png")); - decryptVerifyAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D)); - decryptVerifyAct->setToolTip(tr("Decrypt and Verify Message")); - connect(decryptVerifyAct, SIGNAL(triggered()), this, SLOT(slotDecryptVerify())); - - /* - * File encryption submenu - */ - fileEncryptAct = new QAction(tr("&Encrypt File"), this); - fileEncryptAct->setToolTip(tr("Encrypt File")); - connect(fileEncryptAct, SIGNAL(triggered()), this, SLOT(slotFileEncrypt())); - - fileDecryptAct = new QAction(tr("&Decrypt File"), this); - fileDecryptAct->setToolTip(tr("Decrypt File")); - connect(fileDecryptAct, SIGNAL(triggered()), this, SLOT(slotFileDecrypt())); - - fileSignAct = new QAction(tr("&Sign File"), this); - fileSignAct->setToolTip(tr("Sign File")); - connect(fileSignAct, SIGNAL(triggered()), this, SLOT(slotFileSign())); - - fileVerifyAct = new QAction(tr("&Verify File"), this); - fileVerifyAct->setToolTip(tr("Verify File")); - connect(fileVerifyAct, SIGNAL(triggered()), this, SLOT(slotFileVerify())); - - - signAct = new QAction(tr("&Sign"), this); - signAct->setIcon(QIcon(":signature.png")); - signAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I)); - signAct->setToolTip(tr("Sign Message")); - connect(signAct, SIGNAL(triggered()), this, SLOT(slotSign())); - - verifyAct = new QAction(tr("&Verify"), this); - verifyAct->setIcon(QIcon(":verify.png")); - verifyAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V)); - verifyAct->setToolTip(tr("Verify Message")); - connect(verifyAct, SIGNAL(triggered()), this, SLOT(slotVerify())); - - /* Key Menu - */ - - importKeyFromEditAct = new QAction(tr("&Editor"), this); - importKeyFromEditAct->setIcon(QIcon(":txt.png")); - importKeyFromEditAct->setToolTip(tr("Import New Key From Editor")); - connect(importKeyFromEditAct, SIGNAL(triggered()), this, SLOT(slotImportKeyFromEdit())); - - openKeyManagementAct = new QAction(tr("Manage &keys"), this); - openKeyManagementAct->setIcon(QIcon(":keymgmt.png")); - openKeyManagementAct->setToolTip(tr("Open Keymanagement")); - connect(openKeyManagementAct, SIGNAL(triggered()), this, SLOT(slotOpenKeyManagement())); - - /* About Menu - */ - aboutAct = new QAction(tr("&About"), this); - aboutAct->setIcon(QIcon(":help.png")); - aboutAct->setToolTip(tr("Show the application's About box")); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(slotAbout())); - - startWizardAct = new QAction(tr("Open &Wizard"), this); - startWizardAct->setToolTip(tr("Open the wizard")); - connect(startWizardAct, SIGNAL(triggered()), this, SLOT(slotStartWizard())); - - /* 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")); - connect(appendSelectedKeysAct, SIGNAL(triggered()), this, SLOT(slotAppendSelectedKeys())); - - copyMailAddressToClipboardAct = new QAction(tr("Copy EMail-address"), this); - copyMailAddressToClipboardAct->setToolTip(tr("Copy selected EMailaddress to clipboard")); - connect(copyMailAddressToClipboardAct, SIGNAL(triggered()), this, SLOT(slotCopyMailAddressToClipboard())); - - // TODO: find central place for shared actions, to avoid code-duplication with keymgmt.cpp - showKeyDetailsAct = new QAction(tr("Show Keydetails"), this); - showKeyDetailsAct->setToolTip(tr("Show Details for this Key")); - connect(showKeyDetailsAct, SIGNAL(triggered()), this, SLOT(slotShowKeyDetails())); - - refreshKeysFromKeyserverAct = new QAction(tr("Refresh key from keyserver"), this); - refreshKeysFromKeyserverAct->setToolTip(tr("Refresh key from default keyserver")); - connect(refreshKeysFromKeyserverAct, SIGNAL(triggered()), this, SLOT(refreshKeysFromKeyserver())); - - uploadKeyToServerAct = new QAction(tr("Upload Key(s) To Server"), this); - uploadKeyToServerAct->setToolTip(tr("Upload The Selected Keys To Server")); - connect(uploadKeyToServerAct, SIGNAL(triggered()), this, SLOT(uploadKeyToServer())); - /* Key-Shortcuts for Tab-Switchung-Action - */ - switchTabUpAct = new QAction(this); - switchTabUpAct->setShortcut(QKeySequence::NextChild); - connect(switchTabUpAct, SIGNAL(triggered()), edit, SLOT(slotSwitchTabUp())); - this->addAction(switchTabUpAct); - - switchTabDownAct = new QAction(this); - switchTabDownAct->setShortcut(QKeySequence::PreviousChild); - connect(switchTabDownAct, SIGNAL(triggered()), edit, SLOT(slotSwitchTabDown())); - this->addAction(switchTabDownAct); - - cutPgpHeaderAct = new QAction(tr("Remove PGP Header"), this); - connect(cutPgpHeaderAct, SIGNAL(triggered()), this, SLOT(slotCutPgpHeader())); - - addPgpHeaderAct = new QAction(tr("Add PGP Header"), this); - connect(addPgpHeaderAct, SIGNAL(triggered()), this, SLOT(slotAddPgpHeader())); -} - -void MainWindow::slotDisableTabActions(int number) { - bool disable; - - if (number == -1) { - disable = true; - } else { - disable = false; - } - printAct->setDisabled(disable); - saveAct->setDisabled(disable); - saveAsAct->setDisabled(disable); - quoteAct->setDisabled(disable); - cutAct->setDisabled(disable); - copyAct->setDisabled(disable); - pasteAct->setDisabled(disable); - closeTabAct->setDisabled(disable); - selectallAct->setDisabled(disable); - findAct->setDisabled(disable); - verifyAct->setDisabled(disable); - signAct->setDisabled(disable); - encryptAct->setDisabled(disable); - decryptAct->setDisabled(disable); - - redoAct->setDisabled(disable); - undoAct->setDisabled(disable); - zoomOutAct->setDisabled(disable); - zoomInAct->setDisabled(disable); - cleanDoubleLinebreaksAct->setDisabled(disable); - quoteAct->setDisabled(disable); - appendSelectedKeysAct->setDisabled(disable); - importKeyFromEditAct->setDisabled(disable); - - cutPgpHeaderAct->setDisabled(disable); - addPgpHeaderAct->setDisabled(disable); -} - -void MainWindow::createMenus() { - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(newTabAct); - fileMenu->addAction(openAct); - fileMenu->addSeparator(); - fileMenu->addAction(saveAct); - fileMenu->addAction(saveAsAct); - fileMenu->addSeparator(); - fileMenu->addAction(printAct); - fileMenu->addSeparator(); - fileMenu->addAction(closeTabAct); - fileMenu->addAction(quitAct); - - editMenu = menuBar()->addMenu(tr("&Edit")); - editMenu->addAction(undoAct); - editMenu->addAction(redoAct); - editMenu->addSeparator(); - editMenu->addAction(zoomInAct); - editMenu->addAction(zoomOutAct); - editMenu->addSeparator(); - editMenu->addAction(copyAct); - editMenu->addAction(cutAct); - editMenu->addAction(pasteAct); - editMenu->addAction(selectallAct); - editMenu->addAction(findAct); - editMenu->addSeparator(); - editMenu->addAction(quoteAct); - editMenu->addAction(cleanDoubleLinebreaksAct); - editMenu->addSeparator(); - editMenu->addAction(openSettingsAct); - - fileEncMenu = new QMenu(tr("&File...")); - fileEncMenu->addAction(fileEncryptAct); - fileEncMenu->addAction(fileDecryptAct); - fileEncMenu->addAction(fileSignAct); - fileEncMenu->addAction(fileVerifyAct); - - cryptMenu = menuBar()->addMenu(tr("&Crypt")); - cryptMenu->addAction(encryptAct); - cryptMenu->addAction(encryptSignAct); - cryptMenu->addAction(decryptAct); - cryptMenu->addAction(decryptVerifyAct); - cryptMenu->addSeparator(); - cryptMenu->addAction(signAct); - cryptMenu->addAction(verifyAct); - cryptMenu->addSeparator(); - cryptMenu->addMenu(fileEncMenu); - - keyMenu = menuBar()->addMenu(tr("&Keys")); - importKeyMenu = keyMenu->addMenu(tr("&Import Key")); - importKeyMenu->setIcon(QIcon(":key_import.png")); - importKeyMenu->addAction(keyMgmt->importKeyFromFileAct); - importKeyMenu->addAction(importKeyFromEditAct); - importKeyMenu->addAction(keyMgmt->importKeyFromClipboardAct); - importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct); - importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct); - keyMenu->addAction(openKeyManagementAct); - - steganoMenu = menuBar()->addMenu(tr("&Steganography")); - steganoMenu->addAction(cutPgpHeaderAct); - steganoMenu->addAction(addPgpHeaderAct); - - // Hide menu, when steganography menu is disabled in settings - if (!settings.value("advanced/steganography").toBool()) { - this->menuBar()->removeAction(steganoMenu->menuAction()); - } - - viewMenu = menuBar()->addMenu(tr("&View")); - - helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(startWizardAct); - helpMenu->addSeparator(); - helpMenu->addAction(aboutAct); - -} - -void MainWindow::createToolBars() { - fileToolBar = addToolBar(tr("File")); - fileToolBar->setObjectName("fileToolBar"); - fileToolBar->addAction(newTabAct); - fileToolBar->addAction(openAct); - fileToolBar->addAction(saveAct); - fileToolBar->hide(); - viewMenu->addAction(fileToolBar->toggleViewAction()); - - cryptToolBar = addToolBar(tr("Crypt")); - cryptToolBar->setObjectName("cryptToolBar"); - cryptToolBar->addAction(encryptAct); - cryptToolBar->addAction(encryptSignAct); - cryptToolBar->addAction(decryptAct); - cryptToolBar->addAction(decryptVerifyAct); - cryptToolBar->addAction(signAct); - cryptToolBar->addAction(verifyAct); - viewMenu->addAction(cryptToolBar->toggleViewAction()); - - keyToolBar = addToolBar(tr("Key")); - keyToolBar->setObjectName("keyToolBar"); - keyToolBar->addAction(openKeyManagementAct); - viewMenu->addAction(keyToolBar->toggleViewAction()); - - editToolBar = addToolBar(tr("Edit")); - editToolBar->setObjectName("editToolBar"); - editToolBar->addAction(copyAct); - editToolBar->addAction(pasteAct); - editToolBar->addAction(selectallAct); - viewMenu->addAction(editToolBar->toggleViewAction()); - - specialEditToolBar = addToolBar(tr("Special Edit")); - specialEditToolBar->setObjectName("specialEditToolBar"); - specialEditToolBar->addAction(quoteAct); - specialEditToolBar->addAction(cleanDoubleLinebreaksAct); - specialEditToolBar->hide(); - viewMenu->addAction(specialEditToolBar->toggleViewAction()); - - // Add dropdown menu for key import to keytoolbar - importButton = new QToolButton(); - importButton->setMenu(importKeyMenu); - importButton->setPopupMode(QToolButton::InstantPopup); - importButton->setIcon(QIcon(":key_import.png")); - importButton->setToolTip(tr("Import key from...")); - importButton->setText(tr("Import key")); - keyToolBar->addWidget(importButton); - - // Add dropdown menu for file encryption/decryption to crypttoolbar - fileEncButton = new QToolButton(); - fileEncButton->setMenu(fileEncMenu); - fileEncButton->setPopupMode(QToolButton::InstantPopup); - fileEncButton->setIcon(QIcon(":fileencryption.png")); - fileEncButton->setToolTip(tr("Encrypt or decrypt File")); - fileEncButton->setText(tr("File..")); - fileEncButton->hide(); - - cryptToolBar->addWidget(fileEncButton); - -} - -void MainWindow::createStatusBar() { - auto *statusBarBox = new QWidget(); - auto *statusBarBoxLayout = new QHBoxLayout(); - QPixmap *pixmap; - - // icon which should be shown if there are files in attachments-folder - pixmap = new QPixmap(":statusbar_icon.png"); - statusBarIcon = new QLabel(); - statusBar()->addWidget(statusBarIcon); - - statusBarIcon->setPixmap(*pixmap); - statusBar()->insertPermanentWidget(0, statusBarIcon, 0); - statusBarIcon->hide(); - statusBar()->showMessage(tr("Ready"), 2000); - statusBarBox->setLayout(statusBarBoxLayout); -} - -void MainWindow::createDockWindows() { - /* KeyList-Dockwindow - */ - keylistDock = new QDockWidget(tr("Key ToolBox"), this); - keylistDock->setObjectName("EncryptDock"); - keylistDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - keylistDock->setMinimumWidth(460); - addDockWidget(Qt::RightDockWidgetArea, keylistDock); - keylistDock->setWidget(mKeyList); - viewMenu->addAction(keylistDock->toggleViewAction()); - - infoBoardDock = new QDockWidget(tr("Information Board"), this); - infoBoardDock->setObjectName("Information Board"); - infoBoardDock->setAllowedAreas(Qt::BottomDockWidgetArea); - addDockWidget(Qt::BottomDockWidgetArea, infoBoardDock); - infoBoardDock->setWidget(infoBoard); - infoBoardDock->widget()->layout()->setContentsMargins(0, 0, 0, 0); - viewMenu->addAction(infoBoardDock->toggleViewAction()); - - /* Attachments-Dockwindow - */ - if (settings.value("mime/parseMime").toBool()) { - createAttachmentDock(); - } -} - -void MainWindow::createAttachmentDock() { - if (attachmentDockCreated) { - return; - } - mAttachments = new Attachments(); - attachmentDock = new QDockWidget(tr("Attached files:"), this); - attachmentDock->setObjectName("AttachmentDock"); - attachmentDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); - addDockWidget(Qt::LeftDockWidgetArea, attachmentDock); - attachmentDock->setWidget(mAttachments); - // hide till attachment is decrypted - viewMenu->addAction(attachmentDock->toggleViewAction()); - attachmentDock->hide(); - attachmentDockCreated = true; -} - void MainWindow::closeAttachmentDock() { if (!attachmentDockCreated) { return; @@ -662,494 +194,3 @@ void MainWindow::closeEvent(QCloseEvent *event) { mCtx->clearPasswordCache(); } -void MainWindow::slotAbout() { - new AboutDialog(this); -} - -void MainWindow::slotSetStatusBarText(const QString &text) { - statusBar()->showMessage(text, 20000); -} - -void MainWindow::slotStartWizard() { - auto *wizard = new Wizard(mCtx, keyMgmt, this); - wizard->show(); - wizard->setModal(true); -} - - -void MainWindow::slotCheckAttachmentFolder() { - // TODO: always check? - if (!settings.value("mime/parseMime").toBool()) { - return; - } - - QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; - // filenum minus . and .. - uint filenum = QDir(attachmentDir).count() - 2; - if (filenum > 0) { - QString statusText; - if (filenum == 1) { - statusText = tr("There is one unencrypted file in attachment folder"); - } else { - statusText = tr("There are ") + QString::number(filenum) + tr(" unencrypted files in attachment folder"); - } - statusBarIcon->setStatusTip(statusText); - statusBarIcon->show(); - } else { - statusBarIcon->hide(); - } -} - -void MainWindow::slotImportKeyFromEdit() { - if (edit->tabCount() == 0 || edit->slotCurPage() == 0) { - return; - } - - keyMgmt->slotImportKeys(edit->curTextPage()->toPlainText().toUtf8()); -} - -void MainWindow::slotOpenKeyManagement() { - keyMgmt->show(); - keyMgmt->raise(); - keyMgmt->activateWindow(); -} - -void MainWindow::slotEncrypt() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QVector<GpgKey> keys; - mKeyList->getCheckedKeys(keys); - - if (keys.count() == 0) { - QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); - return; - } - - for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { - QMessageBox::information(nullptr, - tr("Invalid Operation"), - tr("The selected key contains a key that does not actually have a encrypt function.<br/>") - + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); - return; - - } - } - - auto *tmp = new QByteArray(); - - gpgme_encrypt_result_t result = nullptr; - auto error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &result); - - auto resultAnalyse = new EncryptResultAnalyse(error, result); - auto &reportText = resultAnalyse->getResultReport(); - - auto *tmp2 = new QString(*tmp); - edit->slotFillTextEditWithText(*tmp2); - infoBoard->associateTextEdit(edit->curTextPage()); - - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyse; -} - -void MainWindow::slotSign() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QVector<GpgKey> keys; - - mKeyList->getPrivateCheckedKeys(keys); - - if (keys.isEmpty()) { - QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); - return; - } - - for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanSign(key)) { - QMessageBox::information(nullptr, - tr("Invalid Operation"), - tr("The selected key contains a key that does not actually have a signature function.<br/>") - + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); - return; - } - } - - auto *tmp = new QByteArray(); - - gpgme_sign_result_t result = nullptr; - - auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result); - infoBoard->associateTextEdit(edit->curTextPage()); - edit->slotFillTextEditWithText(QString::fromUtf8(*tmp)); - - auto resultAnalyse = new SignResultAnalyse(error, result); - - auto &reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyse; -} - -void MainWindow::slotDecrypt() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - auto *decrypted = new QByteArray(); - QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); - - gpgme_decrypt_result_t result = nullptr; - // try decrypt, if fail do nothing, especially don't replace text - auto error = mCtx->decrypt(text, decrypted, &result); - infoBoard->associateTextEdit(edit->curTextPage()); - - if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) - edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); - - auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); - - auto &reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyse; -} - -void MainWindow::slotFind() { - if (edit->tabCount() == 0 || edit->curTextPage() == nullptr) { - return; - } - - // At first close verifynotification, if existing - edit->slotCurPage()->closeNoteByClass("findwidget"); - - auto *fw = new FindWidget(this, edit->curTextPage()); - edit->slotCurPage()->showNotificationWidget(fw, "findWidget"); - -} - -void MainWindow::slotVerify() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - // If an unknown key is found, enable the importfromkeyserveraction - - QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); - - - gpgme_verify_result_t result; - - auto error = mCtx->verify(&text, nullptr, &result); - - auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); - infoBoard->associateTextEdit(edit->curTextPage()); - - auto &reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - if (resultAnalyse->getStatus() >= 0) { - infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction("Show Verify Details", [this, error, result]() { - VerifyDetailsDialog(this, mCtx, mKeyList, error, result); - }); - } - - delete resultAnalyse; -} - -/* - * Append the selected (not checked!) Key(s) To Textedit - */ -void MainWindow::slotAppendSelectedKeys() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - auto *keyArray = new QByteArray(); - mCtx->exportKeys(mKeyList->getSelected(), keyArray); - edit->curTextPage()->append(*keyArray); -} - -void MainWindow::slotCopyMailAddressToClipboard() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } - auto &key = mCtx->getKeyById(mKeyList->getSelected()->first()); - QClipboard *cb = QApplication::clipboard(); - QString mail = key.email; - cb->setText(mail); -} - -void MainWindow::slotShowKeyDetails() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } - auto &key = mCtx->getKeyById(mKeyList->getSelected()->first()); - if (key.good) { - new KeyDetailsDialog(mCtx, key, this); - } -} - -void MainWindow::refreshKeysFromKeyserver() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } - - auto *ksid = new KeyServerImportDialog(mCtx, mKeyList, this); - ksid->slotImport(*mKeyList->getSelected()); - -} - -void MainWindow::uploadKeyToServer() { - auto *keyArray = new QByteArray(); - mCtx->exportKeys(mKeyList->getSelected(), keyArray); - - mKeyList->uploadKeyToServer(keyArray); -} - -void MainWindow::slotFileEncrypt() { - QStringList *keyList; - keyList = mKeyList->getChecked(); - new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Encrypt, this); -} - -void MainWindow::slotFileDecrypt() { - QStringList *keyList; - keyList = mKeyList->getChecked(); - new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Decrypt, this); -} - -void MainWindow::slotFileSign() { - QStringList *keyList; - keyList = mKeyList->getChecked(); - new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Sign, this); -} - -void MainWindow::slotFileVerify() { - QStringList *keyList; - keyList = mKeyList->getChecked(); - new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Verify, this); -} - -void MainWindow::slotOpenSettingsDialog() { - - QString preLang = settings.value("int/lang").toString(); - QString preKeydbPath = settings.value("gpgpaths/keydbpath").toString(); - - auto dialog = new SettingsDialog(mCtx, this); - - connect(dialog, &SettingsDialog::finished, this, [&] () -> void { - - qDebug() << "Setting Dialog Finished"; - - // Iconsize - QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize(); - this->setIconSize(iconSize); - importButton->setIconSize(iconSize); - fileEncButton->setIconSize(iconSize); - - // Iconstyle - Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(settings.value("toolbar/iconstyle", - Qt::ToolButtonTextUnderIcon).toUInt()); - this->setToolButtonStyle(buttonStyle); - importButton->setToolButtonStyle(buttonStyle); - fileEncButton->setToolButtonStyle(buttonStyle); - - // Mime-settings - if (settings.value("mime/parseMime").toBool()) { - createAttachmentDock(); - } else if (attachmentDockCreated) { - closeAttachmentDock(); - } - - // restart mainwindow if necessary - if (getRestartNeeded()) { - if (edit->maybeSaveAnyTab()) { - saveSettings(); - qApp->exit(RESTART_CODE); - } - } - - // steganography hide/show - if (!settings.value("advanced/steganography").toBool()) { - this->menuBar()->removeAction(steganoMenu->menuAction()); - } else { - this->menuBar()->insertAction(viewMenu->menuAction(), steganoMenu->menuAction()); - } - }); - -} - -void MainWindow::slotCleanDoubleLinebreaks() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QString content = edit->curTextPage()->toPlainText(); - content.replace("\n\n", "\n"); - edit->slotFillTextEditWithText(content); -} - -void MainWindow::slotAddPgpHeader() { - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QString content = edit->curTextPage()->toPlainText().trimmed(); - - content.prepend("\n\n").prepend(GpgConstants::PGP_CRYPT_BEGIN); - content.append("\n").append(GpgConstants::PGP_CRYPT_END); - - edit->slotFillTextEditWithText(content); -} - -void MainWindow::slotCutPgpHeader() { - - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QString content = edit->curTextPage()->toPlainText(); - int start = content.indexOf(GpgConstants::PGP_CRYPT_BEGIN); - int end = content.indexOf(GpgConstants::PGP_CRYPT_END); - - if (start < 0 || end < 0) { - return; - } - - // remove head - int headEnd = content.indexOf("\n\n", start) + 2; - content.remove(start, headEnd - start); - - // remove tail - end = content.indexOf(GpgConstants::PGP_CRYPT_END); - content.remove(end, QString(GpgConstants::PGP_CRYPT_END).size()); - - edit->slotFillTextEditWithText(content.trimmed()); -} - -void MainWindow::slotSetRestartNeeded(bool needed) { - this->restartNeeded = needed; -} - -bool MainWindow::getRestartNeeded() const { - return this->restartNeeded; -} - -void MainWindow::slotEncryptSign() { - - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - QVector<GpgKey> keys; - mKeyList->getCheckedKeys(keys); - - if (keys.empty()) { - QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); - return; - } - - for (const auto &key : keys) { - if (!GpgME::GpgContext::checkIfKeyCanSign(key) || !GpgME::GpgContext::checkIfKeyCanEncr(key)) { - QMessageBox::information(nullptr, - tr("Invalid Operation"), - tr("The selected key cannot be used for signing and encryption at the same time.<br/>") - + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); - return; - } - } - - auto *tmp = new QByteArray(); - gpgme_encrypt_result_t encr_result = nullptr; - gpgme_sign_result_t sign_result = nullptr; - - auto error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result, &sign_result); - auto *tmp2 = new QString(*tmp); - edit->slotFillTextEditWithText(*tmp2); - - auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result); - auto resultAnalyseSign = new SignResultAnalyse(error, sign_result); - int status = std::min(resultAnalyseEncr->getStatus(), resultAnalyseSign->getStatus()); - auto reportText = resultAnalyseEncr->getResultReport() + resultAnalyseSign->getResultReport(); - - infoBoard->associateTextEdit(edit->curTextPage()); - - if (status < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (status > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyseEncr; - delete resultAnalyseSign; -} - -void MainWindow::slotDecryptVerify() { - - if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { - return; - } - - auto *decrypted = new QByteArray(); - QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgME::GpgContext::preventNoDataErr(&text); - - gpgme_decrypt_result_t d_result = nullptr; - gpgme_verify_result_t v_result = nullptr; - // try decrypt, if fail do nothing, especially don't replace text - auto error = mCtx->decryptVerify(text, decrypted, &d_result, &v_result); - infoBoard->associateTextEdit(edit->curTextPage()); - - if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) - edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); - - auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result); - auto resultAnalyseVerify = new VerifyResultAnalyse(mCtx, error, v_result); - - int status = std::min(resultAnalyseDecrypt->getStatus(), resultAnalyseVerify->getStatus()); - auto &reportText = resultAnalyseDecrypt->getResultReport() + resultAnalyseVerify->getResultReport(); - if (status < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (status > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - if (resultAnalyseVerify->getStatus() >= 0) { - infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction("Show Verify Details", [this, error, v_result]() { - VerifyDetailsDialog(this, mCtx, mKeyList, error, v_result); - }); - } - delete resultAnalyseDecrypt; - delete resultAnalyseVerify; -} diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 62d7a246..603ad90b 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -1215,4 +1215,30 @@ namespace GpgME { return err; } + + bool GpgContext::exportKeys(const QVector<GpgKey> &keys, QByteArray &outBuffer) { + size_t read_bytes; + gpgme_data_t dataOut = nullptr; + outBuffer.resize(0); + + if (keys.count() == 0) { + QMessageBox::critical(nullptr, "Export Keys Error", "No Keys Selected"); + return false; + } + + for (const auto& key : keys) { + err = gpgme_data_new(&dataOut); + checkErr(err); + + err = gpgme_op_export(mCtx,key.id.toUtf8().constData(), 0, dataOut); + checkErr(err); + + read_bytes = gpgme_data_seek(dataOut, 0, SEEK_END); + + err = readToBuffer(dataOut, &outBuffer); + checkErr(err); + gpgme_data_release(dataOut); + } + return true; + } }
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7d6a71a3..db11ee6f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,6 +81,8 @@ int main(int argc, char *argv[]) { qDebug() << "Translator2" << translator2.filePath(); QApplication::installTranslator(&translator2); + QApplication::setQuitOnLastWindowClosed(true); + MainWindow window; return_from_event_loop_code = QApplication::exec(); diff --git a/src/ui/AboutDialog.cpp b/src/ui/AboutDialog.cpp index 652bb956..e51f225d 100644 --- a/src/ui/AboutDialog.cpp +++ b/src/ui/AboutDialog.cpp @@ -50,21 +50,19 @@ InfoTab::InfoTab(QWidget *parent) : QWidget(parent) { auto *pixmap = new QPixmap(":gpgfrontend-logo.png"); auto *text = new QString("<center><h2>" + qApp->applicationName() + "</h2></center>" - + "<center><b>" + qApp->applicationVersion() + "</b></center>" - + "<center>" + GIT_VERSION + "</center>" - + tr("<br><center>GPGFrontend is a modern, easy-to-use, compact, <br>" - "cross-platform, and installation-free gpg front-end tool.<br>" - "It visualizes most of the common operations of gpg commands.<br>" - "It's licensed under the GPL v3<br><br>" - "<b>Developer:</b><br>" - "Saturneric<br><br>" - "If you have any questions or suggestions have a look<br/>" - "at my <a href=\"https://bktus.com/%e8%81%94%e7%b3%bb%e4%b8%8e%e9%aa%8c%e8%af%81\">" - "contact page</a> or send a mail to my<br/> mailing list at" - " <a href=\"mailto:[email protected]\">[email protected]</a>.") + - tr("<br><br> Built with Qt ") + qVersion() - + tr(" and GPGME ") + GpgME::GpgContext::getGpgmeVersion() + - tr("<br>Built at ") + BUILD_TIMESTAMP + "</center>"); + + "<center><b>" + qApp->applicationVersion() + "</b></center>" + + "<center>" + GIT_VERSION + "</center>" + + tr("<br><center>GPGFrontend is an easy-to-use, compact, <br>" + "cross-platform, and installation-free gpg front-end tool.<br>" + "It visualizes most of the common operations of gpg commands.<br>" + "It's licensed under the GPL v3<br><br>" + "<b>Developer:</b><br>" + "Saturneric<br><br>" + "If you have any questions or suggestions, raise an issue<br/>" + "at <a href=\"https://github.com/saturneric/GpgFrontend\">GitHub</a> or send a mail to my mailing list at <a href=\"mailto:[email protected]\">[email protected]</a>.") + + tr("<br><br> Built with Qt ") + qVersion() + + tr(" and GPGME ") + GpgME::GpgContext::getGpgmeVersion() + + tr("<br>Built at ") + BUILD_TIMESTAMP + "</center>"); auto *layout = new QGridLayout(); auto *pixmapLabel = new QLabel(); @@ -83,7 +81,7 @@ InfoTab::InfoTab(QWidget *parent) TranslatorsTab::TranslatorsTab(QWidget *parent) : QWidget(parent) { QFile translatorsFile; - translatorsFile.setFileName(qApp->applicationDirPath() + "/TRANSLATORS"); + translatorsFile.setFileName(qApp->applicationDirPath() + "/About"); translatorsFile.open(QIODevice::ReadOnly); QByteArray inBuffer = translatorsFile.readAll(); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index d92a63ed..68f57b81 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -2,6 +2,7 @@ aux_source_directory(. UI_SOURCE) aux_source_directory(./keypair_details UI_SOURCE) aux_source_directory(./widgets UI_SOURCE) aux_source_directory(./keygen UI_SOURCE) +aux_source_directory(./main_window UI_SOURCE) add_library(gpgfrontend-ui STATIC ${UI_SOURCE}) diff --git a/src/ui/KeyImportDetailDialog.cpp b/src/ui/KeyImportDetailDialog.cpp index 4c60ad0f..3d8d1cdc 100644 --- a/src/ui/KeyImportDetailDialog.cpp +++ b/src/ui/KeyImportDetailDialog.cpp @@ -24,13 +24,17 @@ #include <ui/KeyImportDetailDialog.h> -KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportInformation result, QWidget *parent) +KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportInformation result, bool automatic, + QWidget *parent) : QDialog(parent) { mCtx = ctx; mResult = std::move(result); // If no key for import found, just show a message if (mResult.considered == 0) { - QMessageBox::information(nullptr, tr("Key import details"), tr("No keys found to import")); + if(automatic) + QMessageBox::information(nullptr, tr("Key Update Details"), tr("No keys found")); + else + QMessageBox::information(nullptr, tr("Key Import Details"), tr("No keys found to import")); return; } @@ -46,7 +50,11 @@ KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportIn mvbox->addWidget(buttonBox); this->setLayout(mvbox); - this->setWindowTitle(tr("Key import details")); + if(automatic) + this->setWindowTitle(tr("Key Update Details")); + else + this->setWindowTitle(tr("Key Import Details")); + this->resize(QSize(600, 300)); this->setModal(true); this->exec(); @@ -54,7 +62,7 @@ KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportIn void KeyImportDetailDialog::createGeneralInfoBox() { // GridBox for general import information - generalInfoBox = new QGroupBox(tr("Genral key import info")); + generalInfoBox = new QGroupBox(tr("General key info")); auto *generalInfoBoxLayout = new QGridLayout(generalInfoBox); generalInfoBoxLayout->addWidget(new QLabel(tr("Considered:")), 1, 0); diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 326c20b2..6f9c64a2 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -142,7 +142,7 @@ void KeyMgmt::createActions() deleteCheckedKeysAct->setIcon(QIcon(":button_delete.png")); connect(deleteCheckedKeysAct, SIGNAL(triggered()), this, SLOT(slotDeleteCheckedKeys())); - showKeyDetailsAct = new QAction(tr("Show Keydetails"), this); + showKeyDetailsAct = new QAction(tr("Show Key Details"), this); showKeyDetailsAct->setToolTip(tr("Show Details for this Key")); connect(showKeyDetailsAct, SIGNAL(triggered()), this, SLOT(slotShowKeyDetails())); } @@ -204,7 +204,7 @@ void KeyMgmt::createToolBars() void KeyMgmt::slotImportKeys(QByteArray inBuffer) { GpgImportInformation result = mCtx->importKey(std::move(inBuffer)); - new KeyImportDetailDialog(mCtx, result, this); + new KeyImportDetailDialog(mCtx, result, false, this); } @@ -226,7 +226,7 @@ void KeyMgmt::slotImportKeyFromFile() void KeyMgmt::slotImportKeyFromKeyServer() { - importDialog = new KeyServerImportDialog(mCtx, mKeyList, this); + importDialog = new KeyServerImportDialog(mCtx, mKeyList, false, this); importDialog->show(); } @@ -328,12 +328,6 @@ void KeyMgmt::slotGenerateKeyDialog() void KeyMgmt::closeEvent(QCloseEvent *event) { - QSettings settings; - //settings.setValue("geometry", saveGeometry()); - settings.setValue("keymgmt/windowState", saveState()); - settings.setValue("keymgmt/pos", pos()); - settings.setValue("keymgmt/size", size()); - QMainWindow::closeEvent(event); } diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index 88ec1c11..bfa53cce 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -26,52 +26,103 @@ #include <utility> -KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *keyList, QWidget *parent) +KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *keyList, bool automatic, + QWidget *parent) : QDialog(parent), appPath(qApp->applicationDirPath()), - settings(appPath + "/conf/gpgfrontend.ini", QSettings::IniFormat), mCtx(ctx), mKeyList(keyList) { + settings(appPath + "/conf/gpgfrontend.ini", QSettings::IniFormat), + mCtx(ctx), mKeyList(keyList), mAutomatic(automatic) { + + if(automatic) { + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); + } + // Buttons closeButton = createButton(tr("&Close"), SLOT(close())); - importButton = createButton(tr("&Import"), SLOT(slotImport())); + importButton = createButton(tr("&Import ALL"), SLOT(slotImport())); searchButton = createButton(tr("&Search"), SLOT(slotSearch())); // Line edit for search string - searchLabel = new QLabel(tr("Search string:")); + searchLabel = new QLabel(tr("Search String:")); searchLineEdit = new QLineEdit(); // combobox for keyserverlist - keyServerLabel = new QLabel(tr("Keyserver:")); + keyServerLabel = new QLabel(tr("Key Server:")); keyServerComboBox = createComboBox(); // table containing the keys found createKeysTable(); message = new QLabel; + message->setFixedHeight(24); icon = new QLabel; + icon->setFixedHeight(24); + + // Network Waiting + waitingBar = new QProgressBar(); + waitingBar->setVisible(false); + waitingBar->setRange(0, 0); + waitingBar->setFixedHeight(24); + waitingBar->setFixedWidth(200); // Layout for messagebox auto *messageLayout = new QHBoxLayout; messageLayout->addWidget(icon); messageLayout->addWidget(message); + messageLayout->addWidget(waitingBar); messageLayout->addStretch(); // Layout for import and close button auto *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(); - buttonsLayout->addWidget(importButton); + if(!automatic) + buttonsLayout->addWidget(importButton); buttonsLayout->addWidget(closeButton); auto *mainLayout = new QGridLayout; - mainLayout->addWidget(searchLabel, 1, 0); - mainLayout->addWidget(searchLineEdit, 1, 1); - mainLayout->addWidget(searchButton, 1, 2); - mainLayout->addWidget(keyServerLabel, 2, 0); - mainLayout->addWidget(keyServerComboBox, 2, 1); - mainLayout->addWidget(keysTable, 3, 0, 1, 3); - mainLayout->addLayout(messageLayout, 4, 0, 1, 3); - mainLayout->addLayout(buttonsLayout, 5, 0, 1, 3); + + // 自动化调用界面布局 + if(automatic) { + mainLayout->addLayout(messageLayout, 0, 0, 1, 3); + } else { + mainLayout->addWidget(searchLabel, 1, 0); + mainLayout->addWidget(searchLineEdit, 1, 1); + mainLayout->addWidget(searchButton, 1, 2); + mainLayout->addWidget(keyServerLabel, 2, 0); + mainLayout->addWidget(keyServerComboBox, 2, 1); + mainLayout->addWidget(keysTable, 3, 0, 1, 3); + mainLayout->addLayout(messageLayout, 4, 0, 1, 3); + mainLayout->addLayout(buttonsLayout, 6, 0, 1, 3); + } this->setLayout(mainLayout); - this->setWindowTitle(tr("Import Keys from Keyserver")); - this->resize(700, 300); + if(automatic) + this->setWindowTitle(tr("Update Keys from Keyserver")); + else + this->setWindowTitle(tr("Import Keys from Keyserver")); + + if(automatic) { + this->setFixedSize(200, 42); + } else { + // Restore window size & location + if (this->settings.value("ImportKeyFromServer/setWindowSize").toBool()) { + QPoint pos = settings.value("ImportKeyFromServer/pos", QPoint(150, 150)).toPoint(); + QSize size = settings.value("ImportKeyFromServer/size", QSize(500, 300)).toSize(); + qDebug() << "Settings size" << size << "pos" << pos; + this->setMinimumSize(size); + this->move(pos); + } else { + qDebug() << "Use default min windows size and pos"; + QPoint defaultPoint(150, 150); + QSize defaultMinSize(500, 300); + this->setMinimumSize(defaultMinSize); + this->move(defaultPoint); + this->settings.setValue("ImportKeyFromServer/pos", defaultPoint); + this->settings.setValue("ImportKeyFromServer/size", defaultMinSize); + this->settings.setValue("ImportKeyFromServer/setWindowSize", true); + } + } + + + this->setModal(true); } @@ -119,23 +170,35 @@ void KeyServerImportDialog::createKeysTable() { void KeyServerImportDialog::setMessage(const QString &text, bool error) { message->setText(text); if (error) { - QIcon undoicon = QIcon::fromTheme("dialog-error"); - QPixmap pixmap = undoicon.pixmap(QSize(32, 32), QIcon::Normal, QIcon::On); - icon->setPixmap(pixmap); + icon->setPixmap(QPixmap(":error.png").scaled(QSize(24, 24), Qt::KeepAspectRatio)); } else { - QIcon undoicon = QIcon::fromTheme("dialog-information"); - QPixmap pixmap = undoicon.pixmap(QSize(32, 32), QIcon::Normal, QIcon::On); - icon->setPixmap(pixmap); + icon->setPixmap(QPixmap(":info.png").scaled(QSize(24, 24), Qt::KeepAspectRatio)); } } void KeyServerImportDialog::slotSearch() { + + if (searchLineEdit->text().isEmpty()) { + setMessage(tr("<h4>Text is empty.</h4>"), false); + return; + } + QUrl urlFromRemote = keyServerComboBox->currentText() + "/pks/lookup?search=" + searchLineEdit->text() + "&op=index&options=mr"; qnam = new QNetworkAccessManager(this); QNetworkReply *reply = qnam->get(QNetworkRequest(urlFromRemote)); + connect(reply, SIGNAL(finished()), this, SLOT(slotSearchFinished())); + + setLoading(true); + + while (reply->isRunning()) { + QApplication::processEvents(); + } + + setLoading(false); + } void KeyServerImportDialog::slotSearchFinished() { @@ -145,31 +208,49 @@ void KeyServerImportDialog::slotSearchFinished() { keysTable->setRowCount(0); QString firstLine = QString(reply->readLine(1024)); - QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (reply->error()) { - setMessage(tr("Couldn't contact keyserver!"), true); - //setMessage(reply->error()); - qDebug() << reply->error(); + auto error = reply->error(); + if (error != QNetworkReply::NoError) { + qDebug() << "Error From Reply" << reply->errorString(); + switch (error) { + case QNetworkReply::ContentNotFoundError : + setMessage(tr("Not Key Found"), true); + break; + case QNetworkReply::TimeoutError : + setMessage(tr("Timeout"), true); + break; + case QNetworkReply::HostNotFoundError : + setMessage(tr("Key Server Not Found"), true); + break; + default: + setMessage(tr("Connection Error"), true); + } + return; } + if (firstLine.contains("Error")) { QString text = QString(reply->readLine(1024)); if (text.contains("Too many responses")) { - setMessage(tr("Too many responses from keyserver!"), true); + setMessage(tr("<h4>CToo many responses from keyserver!</h4>"), true); + return; } else if (text.contains("No keys found")) { // if string looks like hex string, search again with 0x prepended QRegExp rx("[0-9A-Fa-f]*"); QString query = searchLineEdit->text(); if (rx.exactMatch(query)) { - setMessage(tr("No keys found, input may be kexId, retrying search with 0x."), true); + setMessage(tr("<h4>No keys found, input may be kexId, retrying search with 0x.</h4>"), true); searchLineEdit->setText(query.prepend("0x")); this->slotSearch(); + return; } else { - setMessage(tr("No keys found containing the search string!"), true); + setMessage(tr("<h4>No keys found containing the search string!</h4>"), true); + return; } } else if (text.contains("Insufficiently specific words")) { - setMessage(tr("Insufficiently specific search string!"), true); + setMessage(tr("<h4>Insufficiently specific search string!</h4>"), true); + return; } else { setMessage(text, true); + return; } } else { int row = 0; @@ -236,7 +317,7 @@ void KeyServerImportDialog::slotSearchFinished() { } } } - setMessage(tr("%1 keys found. Doubleclick a key to import it.").arg(row), false); + setMessage(tr("<h4>%1 keys found. Double click a key to import it.</h4>").arg(row), false); } keysTable->resizeColumnsToContents(); } @@ -250,23 +331,44 @@ void KeyServerImportDialog::slotImport() { } } -void KeyServerImportDialog::slotImport(QStringList keyIds) { - QString keyserver = settings.value("keyserver/defaultKeyServer").toString();; - slotImport(std::move(keyIds), QUrl(keyserver)); +void KeyServerImportDialog::slotImport(const QStringList& keyIds) { + QString keyserver = settings.value("keyserver/defaultKeyServer").toString(); + qDebug() << "Select Key Server" << keyserver; + slotImport(keyIds, QUrl(keyserver)); } +void KeyServerImportDialog::slotImportKey(const QVector<GpgKey>& keys) { + QString keyserver = settings.value("keyserver/defaultKeyServer").toString(); + qDebug() << "Select Key Server" << keyserver; + auto keyIds = QStringList(); + for(const auto &key : keys) { + keyIds.append(key.id); + } + slotImport(keyIds, QUrl(keyserver)); +} + + +void KeyServerImportDialog::slotImport(const QStringList& keyIds, const QUrl &keyServerUrl) { + for (const auto &keyId : keyIds) { + QUrl reqUrl( + keyServerUrl.scheme() + "://" + keyServerUrl.host() + "/pks/lookup?op=get&search=0x" + keyId + + "&options=mr"); + qDebug() << "slotImport reqUrl" << reqUrl; + auto pManager = new QNetworkAccessManager(this); -void KeyServerImportDialog::slotImport(QStringList keyIds, const QUrl &keyServerUrl) { - foreach(QString keyId, keyIds) { - QUrl reqUrl( - keyServerUrl.scheme() + "://" + keyServerUrl.host() + ":11371/pks/lookup?op=get&search=0x" + keyId + - "&options=mr"); - //qDebug() << "req to " << reqUrl; - qnam = new QNetworkAccessManager(this); - QNetworkReply *reply = qnam->get(QNetworkRequest(reqUrl)); - connect(reply, SIGNAL(finished()), - this, SLOT(slotImportFinished())); + QNetworkReply *reply = pManager->get(QNetworkRequest(reqUrl)); + + connect(reply, SIGNAL(finished()), + this, SLOT(slotImportFinished())); + + setLoading(true); + + while(reply->isRunning()) { + QApplication::processEvents(); } + + setLoading(false); + } } void KeyServerImportDialog::slotImportFinished() { @@ -275,12 +377,28 @@ void KeyServerImportDialog::slotImportFinished() { QByteArray key = reply->readAll(); QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (reply->error()) { - setMessage(tr("Error while contacting keyserver!"), true); + + auto error = reply->error(); + if (error != QNetworkReply::NoError) { + qDebug() << "Error From Reply" << reply->errorString(); + switch (error) { + case QNetworkReply::ContentNotFoundError : + setMessage(tr("Key Not Found"), true); + break; + case QNetworkReply::TimeoutError : + setMessage(tr("Timeout"), true); + break; + case QNetworkReply::HostNotFoundError : + setMessage(tr("Key Server Not Found"), true); + break; + default: + setMessage(tr("Connection Error"), true); + } + if(mAutomatic) { + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); + } return; } - this->importKeys(key.constData()); - setMessage(tr("Key imported"), false); // Add keyserver to list in config-file, if it isn't contained QStringList keyServerList = settings.value("keyserver/keyServerList").toStringList(); @@ -289,10 +407,73 @@ void KeyServerImportDialog::slotImportFinished() { settings.setValue("keyserver/keyServerList", keyServerList); } reply->deleteLater(); - reply = nullptr; + + this->importKeys(key.constData()); + if(mAutomatic) { + setMessage(tr("<h4>Key Updated</h4>"), false); + } else { + setMessage(tr("<h4>Key Imported</h4>"), false); + } + + } void KeyServerImportDialog::importKeys(QByteArray inBuffer) { GpgImportInformation result = mCtx->importKey(std::move(inBuffer)); - new KeyImportDetailDialog(mCtx, result, this); + if(mAutomatic) { + new KeyImportDetailDialog(mCtx, result, false, this); + this->accept(); + } else { + new KeyImportDetailDialog(mCtx, result, false, this); + } +} + +void KeyServerImportDialog::setLoading(bool status) { + if (status) { + waitingBar->setVisible(true); + icon->setVisible(false); + message->setVisible(false); + } else { + waitingBar->setVisible(false); + icon->setVisible(true); + message->setVisible(true); + } +} + +KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, QWidget *parent) + : QDialog(parent), appPath(qApp->applicationDirPath()), + settings(appPath + "/conf/gpgfrontend.ini", QSettings::IniFormat), + mCtx(ctx), mAutomatic(true) { + + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); + + message = new QLabel; + message->setFixedHeight(24); + icon = new QLabel; + icon->setFixedHeight(24); + + // Network Waiting + waitingBar = new QProgressBar(); + waitingBar->setVisible(false); + waitingBar->setRange(0, 0); + waitingBar->setFixedHeight(24); + waitingBar->setFixedWidth(200); + + // Layout for messagebox + auto *messageLayout = new QHBoxLayout; + messageLayout->addWidget(icon); + messageLayout->addWidget(message); + messageLayout->addWidget(waitingBar); + messageLayout->addStretch(); + + keyServerComboBox = createComboBox(); + + auto *mainLayout = new QGridLayout; + + mainLayout->addLayout(messageLayout, 0, 0, 1, 3); + + this->setLayout(mainLayout); + this->setWindowTitle(tr("Upload Keys from Keyserver")); + this->setFixedSize(200, 42); + this->setModal(true); } diff --git a/src/ui/KeyUploadDialog.cpp b/src/ui/KeyUploadDialog.cpp new file mode 100644 index 00000000..a81ed7a4 --- /dev/null +++ b/src/ui/KeyUploadDialog.cpp @@ -0,0 +1,125 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "ui/KeyUploadDialog.h" + +#include <utility> + +KeyUploadDialog::KeyUploadDialog(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent) +: appPath(qApp->applicationDirPath()), +settings(appPath + "/conf/gpgfrontend.ini", QSettings::IniFormat), +QDialog(parent) { + ctx->exportKeys(keys, mKeyData); + uploadKeyToServer(mKeyData); +} + +void KeyUploadDialog::uploadKeyToServer(QByteArray &keys) { + + // set default keyserver + QString keyserver = settings.value("keyserver/defaultKeyServer").toString(); + + QUrl reqUrl(keyserver + "/pks/add"); + auto qnam = new QNetworkAccessManager(this); + + // Building Post Data + QByteArray postData; + + keys.replace("\n", "%0A") + .replace("\r", "%0D") + .replace("(", "%28") + .replace(")", "%29") + .replace("/", "%2F") + .replace(":", "%3A") + .replace("+", "%2B") + .replace('=', "%3D") + .replace(' ', '+'); + + QNetworkRequest request(reqUrl); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + postData.append("keytext").append("=").append(keys); + + // Send Post Data + QNetworkReply *reply = qnam->post(request, postData); + connect(reply, SIGNAL(finished()), + this, SLOT(slotUploadFinished())); + + + // A Waiting Dialog + auto *dialog = new QDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint); + dialog->setModal(true); + dialog->setWindowTitle(tr("Uploading Public Key")); + dialog->setFixedSize(200, 42); + + auto *pb = new QProgressBar(); + pb->setRange(0, 0); + pb->setFixedSize(200, 24); + + auto *layout = new QVBoxLayout(dialog); + layout->addWidget(pb); + dialog->setLayout(layout); + + dialog->show(); + + // Keep Waiting + while(reply->isRunning()) { + QApplication::processEvents(); + } + + // Done + dialog->hide(); + dialog->close(); +} + +void KeyUploadDialog::slotUploadFinished() { + auto *reply = qobject_cast<QNetworkReply *>(sender()); + + QByteArray response = reply->readAll(); + qDebug() << "Response: " << response.data(); + + auto error = reply->error(); + if (error != QNetworkReply::NoError) { + qDebug() << "Error From Reply" << reply->errorString(); + QString message; + switch (error) { + case QNetworkReply::ContentNotFoundError : + message = tr("Key Not Found"); + break; + case QNetworkReply::TimeoutError : + message = tr("Timeout"); + break; + case QNetworkReply::HostNotFoundError : + message = tr("Key Server Not Found"); + break; + default: + message = tr("Connection Error"); + } + QMessageBox::critical(this, "Upload Failed", message); + return; + } else { + QMessageBox::information(this, "Upload Success", "Upload Public Key Successfully"); + qDebug() << "Success while contacting keyserver!"; + } + reply->deleteLater(); +} diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index 97b9cf87..c72a7685 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -135,9 +135,19 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q vboxPK->addWidget(exportButton); connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey())); - auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime")); - vboxPK->addWidget(editExpiresButton); - connect(editExpiresButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime())); + if(mKey.has_master_key) { + auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime")); + vboxPK->addWidget(editExpiresButton); + connect(editExpiresButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime())); + + auto *keyServerOperaButton = new QPushButton(tr("Key Server Operation")); + vboxPK->addWidget(keyServerOperaButton); + connect(keyServerOperaButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime())); + + // Set Menu + createKeyServerOperaMenu(); + keyServerOperaButton->setMenu(keyServerOperaMenu); + } privKeyBox->setLayout(vboxPK); mvbox->addWidget(privKeyBox); @@ -147,19 +157,18 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q if ((mKey.expired) || (mKey.revoked)) { auto *expBox = new QHBoxLayout(); - QIcon icon = QIcon::fromTheme("dialog-warning"); - QPixmap pixmap = icon.pixmap(QSize(32, 32), QIcon::Normal, QIcon::On); + QPixmap pixmap(":warning.png"); auto *expLabel = new QLabel(); auto *iconLabel = new QLabel(); if (mKey.expired) { - expLabel->setText(tr("Warning: The master key of the key pair has expired.")); + expLabel->setText(tr("Warning: The Master Key has expired.")); } if (mKey.revoked) { - expLabel->setText(tr("Warning: The master key of the key pair has been revoked")); + expLabel->setText(tr("Warning: The Master Key has been revoked")); } - iconLabel->setPixmap(pixmap); + iconLabel->setPixmap(pixmap.scaled(24,24,Qt::KeepAspectRatio)); QFont font = expLabel->font(); font.setBold(true); expLabel->setFont(font); @@ -180,10 +189,9 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q void KeyPairDetailTab::slotExportPrivateKey() { // Show a information box with explanation about private key int ret = QMessageBox::information(this, tr("Exporting private Key"), - tr("You are about to export your private key.\n" - "This is NOT your public key, so don't give it away.\n" - "Make sure you keep it save." - "Do you really want to export your private key?"), + tr("<h3>You are about to export your <font color=\"red\">PRIVATE KEY</font>!</h3>\n" + "This is NOT your Public Key, so DON'T give it away.<br />" + "Do you REALLY want to export your PRIVATE KEY?"), QMessageBox::Cancel | QMessageBox::Ok); // export key, if ok was clicked @@ -192,12 +200,12 @@ void KeyPairDetailTab::slotExportPrivateKey() { mCtx->exportSecretKey(*keyid, keyArray); auto &key = mCtx->getKeyById(*keyid); QString fileString = key.name + " " +key.email + "(" + - key.id + ")_pub_sec.asc"; + key.id + ")_secret.asc"; QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QMessageBox::critical(nullptr, tr("Export error"), tr("Couldn't open %1 for writing").arg(fileName)); + QMessageBox::critical(nullptr, tr("Export Error"), tr("Couldn't open %1 for writing").arg(fileName)); return; } QTextStream stream(&file); @@ -284,3 +292,30 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { } +void KeyPairDetailTab::createKeyServerOperaMenu() { + keyServerOperaMenu = new QMenu(this); + + auto *uploadKeyPair = new QAction(tr("Upload Key Pair"), this); + connect(uploadKeyPair, SIGNAL(triggered()), this, SLOT(slotUploadKeyToServer())); + auto *updateKeyPair = new QAction(tr("Update Key Pair"), this); + connect(updateKeyPair, SIGNAL(triggered()), this, SLOT(slotUpdateKeyToServer())); + + keyServerOperaMenu->addAction(uploadKeyPair); + // TODO Solve Refresh Problem +// keyServerOperaMenu->addAction(updateKeyPair); +} + +void KeyPairDetailTab::slotUploadKeyToServer() { + QVector<GpgKey> keys; + keys.append(mKey); + auto *dialog = new KeyUploadDialog(mCtx, keys); +} + +void KeyPairDetailTab::slotUpdateKeyToServer() { + QVector<GpgKey> keys; + keys.append(mKey); + auto *dialog = new KeyServerImportDialog(mCtx, this); + dialog->show(); + dialog->slotImportKey(keys); +} + diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 84042323..c5647553 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -35,7 +35,7 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QW auto uidButtonsLayout = new QGridLayout(); auto addSubkeyButton = new QPushButton(tr("Generate A New Subkey")); - if(!mKey.is_private_key) { + if(!mKey.is_private_key || !mKey.has_master_key) { addSubkeyButton->setDisabled(true); setHidden(addSubkeyButton); } diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 1a6c769d..51f188bd 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -39,7 +39,11 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget auto addUIDButton = new QPushButton(tr("New UID")); auto manageUIDButton = new QPushButton(tr("UID Management")); - manageUIDButton->setMenu(manageSelectedUIDMenu); + if(mKey.has_master_key) { + manageUIDButton->setMenu(manageSelectedUIDMenu); + } else { + manageUIDButton->setDisabled(true); + } uidButtonsLayout->addWidget(addUIDButton, 0, 1); uidButtonsLayout->addWidget(manageUIDButton, 0, 2); @@ -258,8 +262,10 @@ void KeyPairUIDTab::createManageUIDMenu() { auto *delUIDAct = new QAction(tr("Delete Selected UID(s)"), this); connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUID())); - manageSelectedUIDMenu->addAction(signUIDAct); - manageSelectedUIDMenu->addAction(delUIDAct); + if(mKey.has_master_key) { + manageSelectedUIDMenu->addAction(signUIDAct); + manageSelectedUIDMenu->addAction(delUIDAct); + } } void KeyPairUIDTab::slotAddUID() { @@ -390,9 +396,11 @@ void KeyPairUIDTab::createUIDPopupMenu() { auto *delUIDAct = new QAction(tr("Delete UID"), this); connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUIDSingle())); - uidPopupMenu->addAction(serPrimaryUIDAct); - uidPopupMenu->addAction(signUIDAct); - uidPopupMenu->addAction(delUIDAct); + if(mKey.has_master_key) { + uidPopupMenu->addAction(serPrimaryUIDAct); + uidPopupMenu->addAction(signUIDAct); + uidPopupMenu->addAction(delUIDAct); + } } void KeyPairUIDTab::contextMenuEvent(QContextMenuEvent *event) { diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp index 67238685..f76fa3ab 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp @@ -37,9 +37,9 @@ QDialog(parent), mKey(key), mSubkey(subkey), mCtx(ctx) { auto *gridLayout = new QGridLayout(); gridLayout->addWidget(dateTimeEdit, 0, 0, 1, 2); - gridLayout->addWidget(nonExpiredCheck, 1, 0, 1, 1, Qt::AlignRight); - gridLayout->addWidget(new QLabel(tr("Never Expire"))); - gridLayout->addWidget(confirmButton, 2, 0); + gridLayout->addWidget(nonExpiredCheck, 0, 2, 1, 1, Qt::AlignRight); + gridLayout->addWidget(new QLabel(tr("Never Expire")), 0, 3); + gridLayout->addWidget(confirmButton, 1, 3); connect(nonExpiredCheck, SIGNAL(stateChanged(int)), this, SLOT(slotNonExpiredChecked(int))); connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(slotConfirm())); diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp new file mode 100644 index 00000000..60c33d83 --- /dev/null +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -0,0 +1,360 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "MainWindow.h" + +void MainWindow::slotEncrypt() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QVector<GpgKey> keys; + mKeyList->getCheckedKeys(keys); + + if (keys.count() == 0) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; + } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { + QMessageBox::information(nullptr, + tr("Invalid Operation"), + tr("The selected key contains a key that does not actually have a encrypt function.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + return; + + } + } + + auto *tmp = new QByteArray(); + + gpgme_encrypt_result_t result = nullptr; + auto error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &result); + + auto resultAnalyse = new EncryptResultAnalyse(error, result); + auto &reportText = resultAnalyse->getResultReport(); + + auto *tmp2 = new QString(*tmp); + edit->slotFillTextEditWithText(*tmp2); + infoBoard->associateTextEdit(edit->curTextPage()); + + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; +} + +void MainWindow::slotSign() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QVector<GpgKey> keys; + + mKeyList->getPrivateCheckedKeys(keys); + + if (keys.isEmpty()) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; + } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanSign(key)) { + QMessageBox::information(nullptr, + tr("Invalid Operation"), + tr("The selected key contains a key that does not actually have a signature function.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + return; + } + } + + auto *tmp = new QByteArray(); + + gpgme_sign_result_t result = nullptr; + + auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result); + infoBoard->associateTextEdit(edit->curTextPage()); + edit->slotFillTextEditWithText(QString::fromUtf8(*tmp)); + + auto resultAnalyse = new SignResultAnalyse(error, result); + + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; +} + +void MainWindow::slotDecrypt() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + auto *decrypted = new QByteArray(); + QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); + GpgME::GpgContext::preventNoDataErr(&text); + + gpgme_decrypt_result_t result = nullptr; + // try decrypt, if fail do nothing, especially don't replace text + auto error = mCtx->decrypt(text, decrypted, &result); + infoBoard->associateTextEdit(edit->curTextPage()); + + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) + edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); + + auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); + + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; +} + +void MainWindow::slotFind() { + if (edit->tabCount() == 0 || edit->curTextPage() == nullptr) { + return; + } + + // At first close verifynotification, if existing + edit->slotCurPage()->closeNoteByClass("findwidget"); + + auto *fw = new FindWidget(this, edit->curTextPage()); + edit->slotCurPage()->showNotificationWidget(fw, "findWidget"); + +} + +void MainWindow::slotVerify() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + // If an unknown key is found, enable the importfromkeyserveraction + + QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); + GpgME::GpgContext::preventNoDataErr(&text); + + + gpgme_verify_result_t result; + + auto error = mCtx->verify(&text, nullptr, &result); + + auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); + infoBoard->associateTextEdit(edit->curTextPage()); + + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + if (resultAnalyse->getStatus() >= 0) { + infoBoard->resetOptionActionsMenu(); + infoBoard->addOptionalAction("Show Verify Details", [this, error, result]() { + VerifyDetailsDialog(this, mCtx, mKeyList, error, result); + }); + } + + delete resultAnalyse; +} + +/* + * Append the selected (not checked!) Key(s) To Textedit + */ +void MainWindow::slotAppendSelectedKeys() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + auto *keyArray = new QByteArray(); + mCtx->exportKeys(mKeyList->getSelected(), keyArray); + edit->curTextPage()->append(*keyArray); +} + +void MainWindow::slotCopyMailAddressToClipboard() { + if (mKeyList->getSelected()->isEmpty()) { + return; + } + auto &key = mCtx->getKeyById(mKeyList->getSelected()->first()); + QClipboard *cb = QApplication::clipboard(); + QString mail = key.email; + cb->setText(mail); +} + +void MainWindow::slotShowKeyDetails() { + if (mKeyList->getSelected()->isEmpty()) { + return; + } + auto &key = mCtx->getKeyById(mKeyList->getSelected()->first()); + if (key.good) { + new KeyDetailsDialog(mCtx, key, this); + } +} + +void MainWindow::refreshKeysFromKeyserver() { + if (mKeyList->getSelected()->isEmpty()) { + return; + } + + auto *dialog = new KeyServerImportDialog(mCtx, mKeyList, true, this); + dialog->show(); + dialog->slotImport(*mKeyList->getSelected()); + +} + +void MainWindow::uploadKeyToServer() { + QVector<GpgKey> keys; + keys.append(mKeyList->getSelectedKey()); + auto *dialog = new KeyUploadDialog(mCtx, keys); +} + +void MainWindow::slotFileEncrypt() { + QStringList *keyList; + keyList = mKeyList->getChecked(); + new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Encrypt, this); +} + +void MainWindow::slotFileDecrypt() { + QStringList *keyList; + keyList = mKeyList->getChecked(); + new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Decrypt, this); +} + +void MainWindow::slotFileSign() { + QStringList *keyList; + keyList = mKeyList->getChecked(); + new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Sign, this); +} + +void MainWindow::slotFileVerify() { + QStringList *keyList; + keyList = mKeyList->getChecked(); + new FileEncryptionDialog(mCtx, *keyList, FileEncryptionDialog::Verify, this); +} + +void MainWindow::slotEncryptSign() { + + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QVector<GpgKey> keys; + mKeyList->getCheckedKeys(keys); + + if (keys.empty()) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; + } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanSign(key) || !GpgME::GpgContext::checkIfKeyCanEncr(key)) { + QMessageBox::information(nullptr, + tr("Invalid Operation"), + tr("The selected key cannot be used for signing and encryption at the same time.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + return; + } + } + + auto *tmp = new QByteArray(); + gpgme_encrypt_result_t encr_result = nullptr; + gpgme_sign_result_t sign_result = nullptr; + + auto error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result, &sign_result); + auto *tmp2 = new QString(*tmp); + edit->slotFillTextEditWithText(*tmp2); + + auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result); + auto resultAnalyseSign = new SignResultAnalyse(error, sign_result); + int status = std::min(resultAnalyseEncr->getStatus(), resultAnalyseSign->getStatus()); + auto reportText = resultAnalyseEncr->getResultReport() + resultAnalyseSign->getResultReport(); + + infoBoard->associateTextEdit(edit->curTextPage()); + + if (status < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (status > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyseEncr; + delete resultAnalyseSign; +} + +void MainWindow::slotDecryptVerify() { + + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + auto *decrypted = new QByteArray(); + QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); + GpgME::GpgContext::preventNoDataErr(&text); + + gpgme_decrypt_result_t d_result = nullptr; + gpgme_verify_result_t v_result = nullptr; + // try decrypt, if fail do nothing, especially don't replace text + auto error = mCtx->decryptVerify(text, decrypted, &d_result, &v_result); + infoBoard->associateTextEdit(edit->curTextPage()); + + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) + edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); + + auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result); + auto resultAnalyseVerify = new VerifyResultAnalyse(mCtx, error, v_result); + + int status = std::min(resultAnalyseDecrypt->getStatus(), resultAnalyseVerify->getStatus()); + auto &reportText = resultAnalyseDecrypt->getResultReport() + resultAnalyseVerify->getResultReport(); + if (status < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (status > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + if (resultAnalyseVerify->getStatus() >= 0) { + infoBoard->resetOptionActionsMenu(); + infoBoard->addOptionalAction("Show Verify Details", [this, error, v_result]() { + VerifyDetailsDialog(this, mCtx, mKeyList, error, v_result); + }); + } + delete resultAnalyseDecrypt; + delete resultAnalyseVerify; +} diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp new file mode 100644 index 00000000..8ee09f64 --- /dev/null +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -0,0 +1,219 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "MainWindow.h" + +void MainWindow::slotAbout() { + new AboutDialog(this); +} + +void MainWindow::slotSetStatusBarText(const QString &text) { + statusBar()->showMessage(text, 20000); +} + +void MainWindow::slotStartWizard() { + auto *wizard = new Wizard(mCtx, keyMgmt, this); + wizard->show(); + wizard->setModal(true); +} + + +void MainWindow::slotCheckAttachmentFolder() { + // TODO: always check? + if (!settings.value("mime/parseMime").toBool()) { + return; + } + + QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; + // filenum minus . and .. + uint filenum = QDir(attachmentDir).count() - 2; + if (filenum > 0) { + QString statusText; + if (filenum == 1) { + statusText = tr("There is one unencrypted file in attachment folder"); + } else { + statusText = tr("There are ") + QString::number(filenum) + tr(" unencrypted files in attachment folder"); + } + statusBarIcon->setStatusTip(statusText); + statusBarIcon->show(); + } else { + statusBarIcon->hide(); + } +} + +void MainWindow::slotImportKeyFromEdit() { + if (edit->tabCount() == 0 || edit->slotCurPage() == 0) { + return; + } + + keyMgmt->slotImportKeys(edit->curTextPage()->toPlainText().toUtf8()); +} + +void MainWindow::slotOpenKeyManagement() { + keyMgmt->show(); + keyMgmt->raise(); + keyMgmt->activateWindow(); +} + +void MainWindow::slotOpenFileTab() { + edit->slotNewFileTab(); +} + +void MainWindow::slotDisableTabActions(int number) { + bool disable; + + if (number == -1) + disable = true; + else + disable = false; + + printAct->setDisabled(disable); + saveAct->setDisabled(disable); + saveAsAct->setDisabled(disable); + quoteAct->setDisabled(disable); + cutAct->setDisabled(disable); + copyAct->setDisabled(disable); + pasteAct->setDisabled(disable); + closeTabAct->setDisabled(disable); + selectAllAct->setDisabled(disable); + findAct->setDisabled(disable); + verifyAct->setDisabled(disable); + signAct->setDisabled(disable); + encryptAct->setDisabled(disable); + decryptAct->setDisabled(disable); + + redoAct->setDisabled(disable); + undoAct->setDisabled(disable); + zoomOutAct->setDisabled(disable); + zoomInAct->setDisabled(disable); + cleanDoubleLinebreaksAct->setDisabled(disable); + quoteAct->setDisabled(disable); + appendSelectedKeysAct->setDisabled(disable); + importKeyFromEditAct->setDisabled(disable); + + cutPgpHeaderAct->setDisabled(disable); + addPgpHeaderAct->setDisabled(disable); +} + +void MainWindow::slotOpenSettingsDialog() { + + auto dialog = new SettingsDialog(mCtx, this); + + connect(dialog, &SettingsDialog::finished, this, [&] () -> void { + + qDebug() << "Setting Dialog Finished"; + + // Iconsize + QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize(); + this->setIconSize(iconSize); + importButton->setIconSize(iconSize); + fileEncButton->setIconSize(iconSize); + + // Iconstyle + Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(settings.value("toolbar/iconstyle", + Qt::ToolButtonTextUnderIcon).toUInt()); + this->setToolButtonStyle(buttonStyle); + importButton->setToolButtonStyle(buttonStyle); + fileEncButton->setToolButtonStyle(buttonStyle); + + // Mime-settings + if (settings.value("mime/parseMime").toBool()) { + createAttachmentDock(); + } else if (attachmentDockCreated) { + closeAttachmentDock(); + } + + // restart mainwindow if necessary + if (getRestartNeeded()) { + if (edit->maybeSaveAnyTab()) { + saveSettings(); + qApp->exit(RESTART_CODE); + } + } + + // steganography hide/show + if (!settings.value("advanced/steganography").toBool()) { + this->menuBar()->removeAction(steganoMenu->menuAction()); + } else { + this->menuBar()->insertAction(viewMenu->menuAction(), steganoMenu->menuAction()); + } + }); + +} + +void MainWindow::slotCleanDoubleLinebreaks() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QString content = edit->curTextPage()->toPlainText(); + content.replace("\n\n", "\n"); + edit->slotFillTextEditWithText(content); +} + +void MainWindow::slotAddPgpHeader() { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QString content = edit->curTextPage()->toPlainText().trimmed(); + + content.prepend("\n\n").prepend(GpgConstants::PGP_CRYPT_BEGIN); + content.append("\n").append(GpgConstants::PGP_CRYPT_END); + + edit->slotFillTextEditWithText(content); +} + +void MainWindow::slotCutPgpHeader() { + + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + QString content = edit->curTextPage()->toPlainText(); + int start = content.indexOf(GpgConstants::PGP_CRYPT_BEGIN); + int end = content.indexOf(GpgConstants::PGP_CRYPT_END); + + if (start < 0 || end < 0) { + return; + } + + // remove head + int headEnd = content.indexOf("\n\n", start) + 2; + content.remove(start, headEnd - start); + + // remove tail + end = content.indexOf(GpgConstants::PGP_CRYPT_END); + content.remove(end, QString(GpgConstants::PGP_CRYPT_END).size()); + + edit->slotFillTextEditWithText(content.trimmed()); +} + +void MainWindow::slotSetRestartNeeded(bool needed) { + this->restartNeeded = needed; +} + +bool MainWindow::getRestartNeeded() const { + return this->restartNeeded; +} diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp new file mode 100644 index 00000000..fba2fe62 --- /dev/null +++ b/src/ui/main_window/MainWindowUI.cpp @@ -0,0 +1,456 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "MainWindow.h" + +void MainWindow::createActions() { + /* Main Menu + */ + newTabAct = new QAction(tr("&New"), this); + newTabAct->setIcon(QIcon(":misc_doc.png")); + QList<QKeySequence> newTabActShortcutList; + newTabActShortcutList.append(QKeySequence(Qt::CTRL + Qt::Key_N)); + newTabActShortcutList.append(QKeySequence(Qt::CTRL + Qt::Key_T)); + newTabAct->setShortcuts(newTabActShortcutList); + newTabAct->setToolTip(tr("Open a new file")); + connect(newTabAct, SIGNAL(triggered()), edit, SLOT(slotNewTab())); + + openAct = new QAction(tr("&Open..."), this); + openAct->setIcon(QIcon(":fileopen.png")); + openAct->setShortcut(QKeySequence::Open); + openAct->setToolTip(tr("Open an existing file")); + connect(openAct, SIGNAL(triggered()), edit, SLOT(slotOpen())); + + saveAct = new QAction(tr("&Save"), this); + saveAct->setIcon(QIcon(":filesave.png")); + saveAct->setShortcut(QKeySequence::Save); + saveAct->setToolTip(tr("Save the current File")); + connect(saveAct, SIGNAL(triggered()), edit, SLOT(slotSave())); + + saveAsAct = new QAction(tr("Save &As") + "...", this); + saveAsAct->setIcon(QIcon(":filesaveas.png")); + saveAsAct->setShortcut(QKeySequence::SaveAs); + saveAsAct->setToolTip(tr("Save the current File as...")); + connect(saveAsAct, SIGNAL(triggered()), edit, SLOT(slotSaveAs())); + + printAct = new QAction(tr("&Print"), this); + printAct->setIcon(QIcon(":fileprint.png")); + printAct->setShortcut(QKeySequence::Print); + printAct->setToolTip(tr("Print Document")); + connect(printAct, SIGNAL(triggered()), edit, SLOT(slotPrint())); + + closeTabAct = new QAction(tr("&Close"), this); + closeTabAct->setShortcut(QKeySequence::Close); + closeTabAct->setToolTip(tr("Close file")); + connect(closeTabAct, SIGNAL(triggered()), edit, SLOT(slotCloseTab())); + + quitAct = new QAction(tr("&Quit"), this); + quitAct->setShortcut(QKeySequence::Quit); + quitAct->setIcon(QIcon(":exit.png")); + quitAct->setToolTip(tr("Quit Program")); + connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); + + /* Edit Menu + */ + undoAct = new QAction(tr("&Undo"), this); + undoAct->setShortcut(QKeySequence::Undo); + undoAct->setToolTip(tr("Undo Last Edit Action")); + connect(undoAct, SIGNAL(triggered()), edit, SLOT(slotUndo())); + + redoAct = new QAction(tr("&Redo"), this); + redoAct->setShortcut(QKeySequence::Redo); + redoAct->setToolTip(tr("Redo Last Edit Action")); + connect(redoAct, SIGNAL(triggered()), edit, SLOT(slotRedo())); + + zoomInAct = new QAction(tr("Zoom In"), this); + zoomInAct->setShortcut(QKeySequence::ZoomIn); + connect(zoomInAct, SIGNAL(triggered()), edit, SLOT(slotZoomIn())); + + zoomOutAct = new QAction(tr("Zoom Out"), this); + zoomOutAct->setShortcut(QKeySequence::ZoomOut); + connect(zoomOutAct, SIGNAL(triggered()), edit, SLOT(slotZoomOut())); + + pasteAct = new QAction(tr("&Paste"), this); + pasteAct->setIcon(QIcon(":button_paste.png")); + pasteAct->setShortcut(QKeySequence::Paste); + pasteAct->setToolTip(tr("Paste Text From Clipboard")); + connect(pasteAct, SIGNAL(triggered()), edit, SLOT(slotPaste())); + + cutAct = new QAction(tr("Cu&t"), this); + cutAct->setIcon(QIcon(":button_cut.png")); + cutAct->setShortcut(QKeySequence::Cut); + cutAct->setToolTip(tr("Cut the current selection's contents to the " + "clipboard")); + connect(cutAct, SIGNAL(triggered()), edit, SLOT(slotCut())); + + copyAct = new QAction(tr("&Copy"), this); + copyAct->setIcon(QIcon(":button_copy.png")); + copyAct->setShortcut(QKeySequence::Copy); + copyAct->setToolTip(tr("Copy the current selection's contents to the " + "clipboard")); + connect(copyAct, SIGNAL(triggered()), edit, SLOT(slotCopy())); + + quoteAct = new QAction(tr("&Quote"), this); + quoteAct->setIcon(QIcon(":quote.png")); + quoteAct->setToolTip(tr("Quote whole text")); + connect(quoteAct, SIGNAL(triggered()), edit, SLOT(slotQuote())); + + selectAllAct = new QAction(tr("Select &All"), this); + selectAllAct->setIcon(QIcon(":edit.png")); + selectAllAct->setShortcut(QKeySequence::SelectAll); + selectAllAct->setToolTip(tr("Select the whole text")); + connect(selectAllAct, SIGNAL(triggered()), edit, SLOT(slotSelectAll())); + + findAct = new QAction(tr("&Find"), this); + findAct->setShortcut(QKeySequence::Find); + findAct->setToolTip(tr("Find a word")); + connect(findAct, SIGNAL(triggered()), this, SLOT(slotFind())); + + cleanDoubleLinebreaksAct = new QAction(tr("Remove &spacing"), this); + cleanDoubleLinebreaksAct->setIcon(QIcon(":format-line-spacing-triple.png")); + //cleanDoubleLineBreaksAct->setShortcut(QKeySequence::SelectAll); + cleanDoubleLinebreaksAct->setToolTip(tr("Remove double linebreaks, e.g. in pasted text from webmailer")); + connect(cleanDoubleLinebreaksAct, SIGNAL(triggered()), this, SLOT(slotCleanDoubleLinebreaks())); + + openSettingsAct = new QAction(tr("Se&ttings"), this); + openSettingsAct->setToolTip(tr("Open settings dialog")); + openSettingsAct->setShortcut(QKeySequence::Preferences); + connect(openSettingsAct, SIGNAL(triggered()), this, SLOT(slotOpenSettingsDialog())); + + /* Crypt Menu + */ + encryptAct = new QAction(tr("&Encrypt"), this); + encryptAct->setIcon(QIcon(":encrypted.png")); + encryptAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E)); + encryptAct->setToolTip(tr("Encrypt Message")); + connect(encryptAct, SIGNAL(triggered()), this, SLOT(slotEncrypt())); + + encryptSignAct = new QAction(tr("&Encrypt &Sign"), this); + encryptSignAct->setIcon(QIcon(":encrypted_signed.png")); + encryptSignAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_E)); + encryptSignAct->setToolTip(tr("Encrypt and Sign Message")); + connect(encryptSignAct, SIGNAL(triggered()), this, SLOT(slotEncryptSign())); + + decryptAct = new QAction(tr("&Decrypt"), this); + decryptAct->setIcon(QIcon(":decrypted.png")); + decryptAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + decryptAct->setToolTip(tr("Decrypt Message")); + connect(decryptAct, SIGNAL(triggered()), this, SLOT(slotDecrypt())); + + decryptVerifyAct = new QAction(tr("&Decrypt &Verify"), this); + decryptVerifyAct->setIcon(QIcon(":decrypted_verified.png")); + decryptVerifyAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D)); + decryptVerifyAct->setToolTip(tr("Decrypt and Verify Message")); + connect(decryptVerifyAct, SIGNAL(triggered()), this, SLOT(slotDecryptVerify())); + + /* + * File encryption submenu + */ + fileEncryptAct = new QAction(tr("&Encrypt File"), this); + fileEncryptAct->setToolTip(tr("Encrypt File")); + connect(fileEncryptAct, SIGNAL(triggered()), this, SLOT(slotFileEncrypt())); + + fileDecryptAct = new QAction(tr("&Decrypt File"), this); + fileDecryptAct->setToolTip(tr("Decrypt File")); + connect(fileDecryptAct, SIGNAL(triggered()), this, SLOT(slotFileDecrypt())); + + fileSignAct = new QAction(tr("&Sign File"), this); + fileSignAct->setToolTip(tr("Sign File")); + connect(fileSignAct, SIGNAL(triggered()), this, SLOT(slotFileSign())); + + fileVerifyAct = new QAction(tr("&Verify File"), this); + fileVerifyAct->setToolTip(tr("Verify File")); + connect(fileVerifyAct, SIGNAL(triggered()), this, SLOT(slotFileVerify())); + + + signAct = new QAction(tr("&Sign"), this); + signAct->setIcon(QIcon(":signature.png")); + signAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I)); + signAct->setToolTip(tr("Sign Message")); + connect(signAct, SIGNAL(triggered()), this, SLOT(slotSign())); + + verifyAct = new QAction(tr("&Verify"), this); + verifyAct->setIcon(QIcon(":verify.png")); + verifyAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V)); + verifyAct->setToolTip(tr("Verify Message")); + connect(verifyAct, SIGNAL(triggered()), this, SLOT(slotVerify())); + + /* Key Menu + */ + + importKeyFromEditAct = new QAction(tr("&Editor"), this); + importKeyFromEditAct->setIcon(QIcon(":txt.png")); + importKeyFromEditAct->setToolTip(tr("Import New Key From Editor")); + connect(importKeyFromEditAct, SIGNAL(triggered()), this, SLOT(slotImportKeyFromEdit())); + + openKeyManagementAct = new QAction(tr("Manage &keys"), this); + openKeyManagementAct->setIcon(QIcon(":keymgmt.png")); + openKeyManagementAct->setToolTip(tr("Open Keymanagement")); + connect(openKeyManagementAct, SIGNAL(triggered()), this, SLOT(slotOpenKeyManagement())); + + /* About Menu + */ + aboutAct = new QAction(tr("&About"), this); + aboutAct->setIcon(QIcon(":help.png")); + aboutAct->setToolTip(tr("Show the application's About box")); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(slotAbout())); + + startWizardAct = new QAction(tr("Open &Wizard"), this); + startWizardAct->setToolTip(tr("Open the wizard")); + connect(startWizardAct, SIGNAL(triggered()), this, SLOT(slotStartWizard())); + + /* 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")); + connect(appendSelectedKeysAct, SIGNAL(triggered()), this, SLOT(slotAppendSelectedKeys())); + + copyMailAddressToClipboardAct = new QAction(tr("Copy EMail-address"), this); + copyMailAddressToClipboardAct->setToolTip(tr("Copy selected EMailaddress to clipboard")); + connect(copyMailAddressToClipboardAct, SIGNAL(triggered()), this, SLOT(slotCopyMailAddressToClipboard())); + + // TODO: find central place for shared actions, to avoid code-duplication with keymgmt.cpp + showKeyDetailsAct = new QAction(tr("Show Key Details"), this); + showKeyDetailsAct->setToolTip(tr("Show Details for this Key")); + connect(showKeyDetailsAct, SIGNAL(triggered()), this, SLOT(slotShowKeyDetails())); + + refreshKeysFromKeyserverAct = new QAction(tr("Refresh Key From Key Server"), this); + refreshKeysFromKeyserverAct->setToolTip(tr("Refresh key from default key server")); + connect(refreshKeysFromKeyserverAct, SIGNAL(triggered()), this, SLOT(refreshKeysFromKeyserver())); + + uploadKeyToServerAct = new QAction(tr("Upload Public Key(s) To Server"), this); + uploadKeyToServerAct->setToolTip(tr("Upload The Selected Public Keys To Server")); + connect(uploadKeyToServerAct, SIGNAL(triggered()), this, SLOT(uploadKeyToServer())); + /* Key-Shortcuts for Tab-Switchung-Action + */ + switchTabUpAct = new QAction(this); + switchTabUpAct->setShortcut(QKeySequence::NextChild); + connect(switchTabUpAct, SIGNAL(triggered()), edit, SLOT(slotSwitchTabUp())); + this->addAction(switchTabUpAct); + + switchTabDownAct = new QAction(this); + switchTabDownAct->setShortcut(QKeySequence::PreviousChild); + connect(switchTabDownAct, SIGNAL(triggered()), edit, SLOT(slotSwitchTabDown())); + this->addAction(switchTabDownAct); + + cutPgpHeaderAct = new QAction(tr("Remove PGP Header"), this); + connect(cutPgpHeaderAct, SIGNAL(triggered()), this, SLOT(slotCutPgpHeader())); + + addPgpHeaderAct = new QAction(tr("Add PGP Header"), this); + connect(addPgpHeaderAct, SIGNAL(triggered()), this, SLOT(slotAddPgpHeader())); +} + +void MainWindow::createMenus() { + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(newTabAct); + fileMenu->addAction(openAct); + fileMenu->addSeparator(); + fileMenu->addAction(saveAct); + fileMenu->addAction(saveAsAct); + fileMenu->addSeparator(); + fileMenu->addAction(printAct); + fileMenu->addSeparator(); + fileMenu->addAction(closeTabAct); + fileMenu->addAction(quitAct); + + editMenu = menuBar()->addMenu(tr("&Edit")); + editMenu->addAction(undoAct); + editMenu->addAction(redoAct); + editMenu->addSeparator(); + editMenu->addAction(zoomInAct); + editMenu->addAction(zoomOutAct); + editMenu->addSeparator(); + editMenu->addAction(copyAct); + editMenu->addAction(cutAct); + editMenu->addAction(pasteAct); + editMenu->addAction(selectAllAct); + editMenu->addAction(findAct); + editMenu->addSeparator(); + editMenu->addAction(quoteAct); + editMenu->addAction(cleanDoubleLinebreaksAct); + editMenu->addSeparator(); + editMenu->addAction(openSettingsAct); + + fileEncMenu = new QMenu(tr("&File...")); + fileEncMenu->addAction(fileEncryptAct); + fileEncMenu->addAction(fileDecryptAct); + fileEncMenu->addAction(fileSignAct); + fileEncMenu->addAction(fileVerifyAct); + + cryptMenu = menuBar()->addMenu(tr("&Crypt")); + cryptMenu->addAction(encryptAct); + cryptMenu->addAction(encryptSignAct); + cryptMenu->addAction(decryptAct); + cryptMenu->addAction(decryptVerifyAct); + cryptMenu->addSeparator(); + cryptMenu->addAction(signAct); + cryptMenu->addAction(verifyAct); + cryptMenu->addSeparator(); + cryptMenu->addMenu(fileEncMenu); + + keyMenu = menuBar()->addMenu(tr("&Keys")); + importKeyMenu = keyMenu->addMenu(tr("&Import Key")); + importKeyMenu->setIcon(QIcon(":key_import.png")); + importKeyMenu->addAction(keyMgmt->importKeyFromFileAct); + importKeyMenu->addAction(importKeyFromEditAct); + importKeyMenu->addAction(keyMgmt->importKeyFromClipboardAct); + importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct); + importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct); + keyMenu->addAction(openKeyManagementAct); + + steganoMenu = menuBar()->addMenu(tr("&Steganography")); + steganoMenu->addAction(cutPgpHeaderAct); + steganoMenu->addAction(addPgpHeaderAct); + + // Hide menu, when steganography menu is disabled in settings + if (!settings.value("advanced/steganography").toBool()) { + this->menuBar()->removeAction(steganoMenu->menuAction()); + } + + viewMenu = menuBar()->addMenu(tr("&View")); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(startWizardAct); + helpMenu->addSeparator(); + helpMenu->addAction(aboutAct); + +} + +void MainWindow::createToolBars() { + fileToolBar = addToolBar(tr("File")); + fileToolBar->setObjectName("fileToolBar"); + fileToolBar->addAction(newTabAct); + fileToolBar->addAction(openAct); + fileToolBar->addAction(saveAct); + fileToolBar->hide(); + viewMenu->addAction(fileToolBar->toggleViewAction()); + + cryptToolBar = addToolBar(tr("Crypt")); + cryptToolBar->setObjectName("cryptToolBar"); + cryptToolBar->addAction(encryptAct); + cryptToolBar->addAction(encryptSignAct); + cryptToolBar->addAction(decryptAct); + cryptToolBar->addAction(decryptVerifyAct); + cryptToolBar->addAction(signAct); + cryptToolBar->addAction(verifyAct); + viewMenu->addAction(cryptToolBar->toggleViewAction()); + + keyToolBar = addToolBar(tr("Key")); + keyToolBar->setObjectName("keyToolBar"); + keyToolBar->addAction(openKeyManagementAct); + viewMenu->addAction(keyToolBar->toggleViewAction()); + + editToolBar = addToolBar(tr("Edit")); + editToolBar->setObjectName("editToolBar"); + editToolBar->addAction(copyAct); + editToolBar->addAction(pasteAct); + editToolBar->addAction(selectAllAct); + viewMenu->addAction(editToolBar->toggleViewAction()); + + specialEditToolBar = addToolBar(tr("Special Edit")); + specialEditToolBar->setObjectName("specialEditToolBar"); + specialEditToolBar->addAction(quoteAct); + specialEditToolBar->addAction(cleanDoubleLinebreaksAct); + specialEditToolBar->hide(); + viewMenu->addAction(specialEditToolBar->toggleViewAction()); + + // Add dropdown menu for key import to keytoolbar + importButton = new QToolButton(); + importButton->setMenu(importKeyMenu); + importButton->setPopupMode(QToolButton::InstantPopup); + importButton->setIcon(QIcon(":key_import.png")); + importButton->setToolTip(tr("Import key from...")); + importButton->setText(tr("Import key")); + keyToolBar->addWidget(importButton); + + // Add dropdown menu for file encryption/decryption to crypttoolbar + fileEncButton = new QToolButton(); + // fileEncButton->setMenu(fileEncMenu); + connect(fileEncButton, SIGNAL(clicked(bool)), this, SLOT(slotOpenFileTab())); + fileEncButton->setPopupMode(QToolButton::InstantPopup); + fileEncButton->setIcon(QIcon(":fileencryption.png")); + fileEncButton->setToolTip(tr("Opera File")); + fileEncButton->setText(tr("File Crypto")); + cryptToolBar->addWidget(fileEncButton); + +} + +void MainWindow::createStatusBar() { + auto *statusBarBox = new QWidget(); + auto *statusBarBoxLayout = new QHBoxLayout(); + QPixmap *pixmap; + + // icon which should be shown if there are files in attachments-folder + pixmap = new QPixmap(":statusbar_icon.png"); + statusBarIcon = new QLabel(); + statusBar()->addWidget(statusBarIcon); + + statusBarIcon->setPixmap(*pixmap); + statusBar()->insertPermanentWidget(0, statusBarIcon, 0); + statusBarIcon->hide(); + statusBar()->showMessage(tr("Ready"), 2000); + statusBarBox->setLayout(statusBarBoxLayout); +} + +void MainWindow::createDockWindows() { + /* KeyList-Dockwindow + */ + keyListDock = new QDockWidget(tr("Key ToolBox"), this); + keyListDock->setObjectName("EncryptDock"); + keyListDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + keyListDock->setMinimumWidth(460); + addDockWidget(Qt::RightDockWidgetArea, keyListDock); + keyListDock->setWidget(mKeyList); + viewMenu->addAction(keyListDock->toggleViewAction()); + + infoBoardDock = new QDockWidget(tr("Information Board"), this); + infoBoardDock->setObjectName("Information Board"); + infoBoardDock->setAllowedAreas(Qt::BottomDockWidgetArea); + addDockWidget(Qt::BottomDockWidgetArea, infoBoardDock); + infoBoardDock->setWidget(infoBoard); + infoBoardDock->widget()->layout()->setContentsMargins(0, 0, 0, 0); + viewMenu->addAction(infoBoardDock->toggleViewAction()); + + /* Attachments-Dockwindow + */ + if (settings.value("mime/parseMime").toBool()) { + createAttachmentDock(); + } +} + +void MainWindow::createAttachmentDock() { + if (attachmentDockCreated) { + return; + } + mAttachments = new Attachments(); + attachmentDock = new QDockWidget(tr("Attached files:"), this); + attachmentDock->setObjectName("AttachmentDock"); + attachmentDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); + addDockWidget(Qt::LeftDockWidgetArea, attachmentDock); + attachmentDock->setWidget(mAttachments); + // hide till attachment is decrypted + viewMenu->addAction(attachmentDock->toggleViewAction()); + attachmentDock->hide(); + attachmentDockCreated = true; +} diff --git a/src/ui/Attachments.cpp b/src/ui/widgets/Attachments.cpp index 87b42fa5..8f741f66 100644 --- a/src/ui/Attachments.cpp +++ b/src/ui/widgets/Attachments.cpp @@ -37,7 +37,7 @@ */ -#include "ui/Attachments.h" +#include "ui/widgets/Attachments.h" Attachments::Attachments(QWidget *parent) : QWidget(parent) { diff --git a/src/ui/EditorPage.cpp b/src/ui/widgets/EditorPage.cpp index b09b7460..cb4ca5ef 100644 --- a/src/ui/EditorPage.cpp +++ b/src/ui/widgets/EditorPage.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/EditorPage.h" +#include "ui/widgets/EditorPage.h" #include <utility> diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp new file mode 100644 index 00000000..e3d73670 --- /dev/null +++ b/src/ui/widgets/FilePage.cpp @@ -0,0 +1,88 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "ui/widgets/FilePage.h" + +FilePage::FilePage(QWidget *parent) : QWidget(parent) { + qDebug() << "New File Page"; + + dirModel = new QFileSystemModel(); + + dirModel->setRootPath(QDir::currentPath()); + + dirTreeView = new QTreeView(); + dirTreeView->setModel(dirModel); + dirTreeView->setAnimated(true); + dirTreeView->setIndentation(20); + dirTreeView->setSortingEnabled(true); + dirTreeView->setRootIndex(dirModel->index(QDir::currentPath())); + + upLevelButton = new QPushButton("UP Level"); + connect(upLevelButton, SIGNAL(clicked(bool)), this, SLOT(slotUpLevel())); + + auto *menuLayout = new QHBoxLayout(); + menuLayout->addWidget(upLevelButton); + menuLayout->addStretch(0); + + auto *layout = new QVBoxLayout(); + layout->addLayout(menuLayout); + layout->addWidget(dirTreeView); + + this->setLayout(layout); + + connect(dirTreeView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(fileTreeViewItemClicked(const QModelIndex &))); + connect(dirTreeView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(fileTreeViewItemDoubleClicked(const QModelIndex &))); + +} + +void FilePage::fileTreeViewItemClicked(const QModelIndex &index) { + mPath = dirModel->fileInfo(index).absoluteFilePath(); + qDebug() << "mPath" << mPath; +} + +void FilePage::slotUpLevel() { + QModelIndex currentRoot = dirTreeView->rootIndex(); + mPath = dirModel->fileInfo(currentRoot).absoluteFilePath(); + auto fileInfo = QFileInfo(mPath); + if(fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { + dirTreeView->setRootIndex(currentRoot.parent()); + } + qDebug() << "Current Root mPath" << mPath; +} + +void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex &index) { + mPath = dirModel->fileInfo(index).absoluteFilePath(); + auto fileInfo = QFileInfo(mPath); + if(fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { + dirTreeView->setRootIndex(index); + } + qDebug() << "Index mPath" << mPath; +} + +void FilePage::getSelected(QString &path) { + QModelIndex index = dirTreeView->currentIndex(); + QVariant data = dirTreeView->model()->data(index); + path = data.toString(); + qDebug() << "Target Path" << mPath; +} diff --git a/src/ui/HelpPage.cpp b/src/ui/widgets/HelpPage.cpp index f2f0da48..e018da81 100644 --- a/src/ui/HelpPage.cpp +++ b/src/ui/widgets/HelpPage.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/HelpPage.h" +#include "ui/widgets/HelpPage.h" #include <utility> @@ -35,8 +35,6 @@ HelpPage::HelpPage(const QString &path, QWidget *parent) : mainLayout->addWidget(browser); mainLayout->setContentsMargins(0, 0, 0, 0); setLayout(mainLayout); - //setAttribute(Qt::WA_DeleteOnClose); - //browser->setSource(QUrl::fromLocalFile(path)); connect(browser, SIGNAL(anchorClicked(QUrl)), this, SLOT(slotOpenUrl(QUrl))); browser->setOpenLinks(false); diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index bfd0c643..76f82505 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -60,7 +60,7 @@ InfoBoardWidget::InfoBoardWidget(QWidget *parent, GpgME::GpgContext *ctx, KeyLis } void InfoBoardWidget::slotImportFromKeyserver() { - auto *importDialog = new KeyServerImportDialog(mCtx, mKeyList, this); + auto *importDialog = new KeyServerImportDialog(mCtx, mKeyList, false, this); importDialog->slotImport(*keysNotInList); } diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index dccf1a56..6982c3a2 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -30,7 +30,8 @@ KeyList::KeyList(GpgME::GpgContext *ctx, KeyListRow::KeyType selectType, KeyListColumn::InfoType infoType, QWidget *parent) - : QWidget(parent), mSelectType(selectType), mInfoType(infoType) + : QWidget(parent), mSelectType(selectType), mInfoType(infoType), appPath(qApp->applicationDirPath()), + settings(appPath + "/conf/gpgfrontend.ini", QSettings::IniFormat) { mCtx = ctx; @@ -304,14 +305,12 @@ void KeyList::addMenuAction(QAction *act) void KeyList::dropEvent(QDropEvent* event) { -// importKeyDialog(); - QSettings settings; auto *dialog = new QDialog(); dialog->setWindowTitle(tr("Import Keys")); QLabel *label; - label = new QLabel(tr("You've dropped something on the keylist.\n gpg4usb will now try to import key(s).")+"\n"); + label = new QLabel(tr("You've dropped something on the table.\n GpgFrontend will now try to import key(s).")+"\n"); // "always import keys"-CheckBox auto *checkBox = new QCheckBox(tr("Always import without bothering.")); @@ -345,7 +344,7 @@ void KeyList::dropEvent(QDropEvent* event) if (event->mimeData()->hasUrls()) { - foreach (QUrl tmp, event->mimeData()->urls()) + for (const QUrl& tmp : event->mimeData()->urls()) { QFile file; file.setFileName(tmp.toLocalFile()); @@ -380,56 +379,7 @@ void KeyList::dragEnterEvent(QDragEnterEvent *event) void KeyList::importKeys(QByteArray inBuffer) { GpgImportInformation result = mCtx->importKey(std::move(inBuffer)); - new KeyImportDetailDialog(mCtx, result, this); -} - -void KeyList::uploadKeyToServer(QByteArray *keys) -{ - QUrl reqUrl("http://localhost:11371/pks/add"); - qnam = new QNetworkAccessManager(this); - - QUrl params; - keys->replace("\n", "%0D%0A") - .replace("(", "%28") - .replace(")", "%29") - .replace("/", "%2F") - .replace(":", "%3A") - .replace("+","%2B") - .replace(' ', '+'); - - QUrlQuery q; - - q.addQueryItem("keytext", *keys); - - params = q.query(QUrl::FullyEncoded).toUtf8(); - - QNetworkRequest req(reqUrl); - - req.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded"); - - QNetworkReply *reply = qnam->post(req,params.toEncoded()); - connect(reply, SIGNAL(finished()), - this, SLOT(uploadFinished())); - qDebug() << "REQURL: " << reqUrl; - qDebug() << "PARAMS.ENCODED: " << params.toEncoded(); -} - -void KeyList::uploadFinished() -{ - auto *reply = qobject_cast<QNetworkReply *>(sender()); - - QByteArray response = reply->readAll(); - qDebug() << "RESPNOSE: " << response.data(); - //reply->readAll(); - qDebug() << "ERROR: " << reply->error(); - if (reply->error()) { - qDebug() << "Error while contacting keyserver!"; - return; - } else { - qDebug() << "Success while contacting keyserver!"; - } - - reply->deleteLater(); + new KeyImportDetailDialog(mCtx, result, false, this); } void KeyList::getCheckedKeys(QVector<GpgKey> &keys) { @@ -472,3 +422,12 @@ void KeyList::getPrivateCheckedKeys(QVector<GpgKey> &keys) { } } } + +GpgKey KeyList::getSelectedKey() { + for (int i = 0; i < mKeyList->rowCount(); i++) { + if (mKeyList->item(i, 0)->isSelected() == 1) { + return buffered_keys[i]; + } + } + return GpgKey(); +} diff --git a/src/ui/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 5a9206ca..49049baa 100644 --- a/src/ui/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/TextEdit.h" +#include "ui/widgets/TextEdit.h" TextEdit::TextEdit() { countPage = 0; @@ -64,6 +64,14 @@ void TextEdit::slotNewHelpTab(const QString &title, const QString &path) const { } +void TextEdit::slotNewFileTab() const { + + auto *page = new FilePage(); + tabWidget->addTab(page, "File"); + tabWidget->setCurrentIndex(tabWidget->count() - 1); + +} + void TextEdit::slotOpen() { QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open file"), QDir::currentPath()); diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp index 3091d672..3a0695b8 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.cpp +++ b/src/ui/widgets/VerifyKeyDetailBox.cpp @@ -141,7 +141,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget *parent, GpgME::GpgContext *ctx, } void VerifyKeyDetailBox::slotImportFormKeyserver() { - auto *importDialog = new KeyServerImportDialog(mCtx, mKeyList, this); + auto *importDialog = new KeyServerImportDialog(mCtx, mKeyList, false, this); importDialog->slotImport(QStringList(fpr)); } |