diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40de08f1b..23f784a58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,321 +1,322 @@ add_subdirectory(icons) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) if (NOT DISABLE_KWATCHGNUPG) add_subdirectory(kwatchgnupg) endif() add_subdirectory(libkleopatraclient) add_subdirectory(conf) add_subdirectory(kconf_update) if(WIN32) set(_kleopatra_extra_uiserver_SRCS uiserver/uiserver_win.cpp) set(_kleopatra_extra_SRCS utils/gnupg-registry.c selftest/registrycheck.cpp) else() set(_kleopatra_extra_uiserver_SRCS uiserver/uiserver_unix.cpp) set(_kleopatra_extra_SRCS) endif() set(_kleopatra_uiserver_SRCS uiserver/sessiondata.cpp uiserver/uiserver.cpp ${_kleopatra_extra_uiserver_SRCS} uiserver/assuanserverconnection.cpp uiserver/echocommand.cpp uiserver/decryptverifycommandemailbase.cpp uiserver/decryptverifycommandfilesbase.cpp uiserver/signcommand.cpp uiserver/signencryptfilescommand.cpp uiserver/prepencryptcommand.cpp uiserver/prepsigncommand.cpp uiserver/encryptcommand.cpp uiserver/selectcertificatecommand.cpp uiserver/importfilescommand.cpp uiserver/createchecksumscommand.cpp uiserver/verifychecksumscommand.cpp selftest/uiservercheck.cpp ) if(ASSUAN2_FOUND) include_directories(${ASSUAN2_INCLUDES}) set(_kleopatra_uiserver_extra_libs ${ASSUAN2_LIBRARIES}) else() include_directories(${ASSUAN_INCLUDES}) if(WIN32) set(_kleopatra_uiserver_extra_libs ${ASSUAN_VANILLA_LIBRARIES}) else() set(_kleopatra_uiserver_extra_libs ${ASSUAN_PTHREAD_LIBRARIES}) endif() endif() if(HAVE_GPG_ERR_SOURCE_KLEO) add_definitions(-DGPG_ERR_SOURCE_DEFAULT=GPG_ERR_SOURCE_KLEO) else() add_definitions(-DGPG_ERR_SOURCE_DEFAULT=GPG_ERR_SOURCE_USER_1) endif() ki18n_wrap_ui(_kleopatra_uiserver_SRCS crypto/gui/signingcertificateselectionwidget.ui) set(_kleopatra_SRCS utils/gnupg-helper.cpp utils/gui-helper.cpp utils/filedialog.cpp utils/kdpipeiodevice.cpp utils/headerview.cpp utils/scrollarea.cpp utils/dragqueen.cpp utils/multivalidator.cpp utils/systemtrayicon.cpp utils/hex.cpp utils/path-helper.cpp utils/input.cpp utils/output.cpp utils/validation.cpp utils/wsastarter.cpp utils/iodevicelogger.cpp utils/log.cpp utils/action_data.cpp utils/types.cpp utils/archivedefinition.cpp utils/auditlog.cpp utils/clipboardmenu.cpp utils/kuniqueservice.cpp selftest/selftest.cpp selftest/enginecheck.cpp selftest/gpgconfcheck.cpp selftest/gpgagentcheck.cpp selftest/libkleopatrarccheck.cpp ${_kleopatra_extra_SRCS} view/keylistcontroller.cpp view/keytreeview.cpp view/searchbar.cpp view/smartcardwidget.cpp + view/padwidget.cpp view/pgpcardwidget.cpp view/netkeywidget.cpp view/nullpinwidget.cpp view/tabwidget.cpp view/keycacheoverlay.cpp view/waitwidget.cpp view/welcomewidget.cpp dialogs/certificateselectiondialog.cpp dialogs/expirydialog.cpp dialogs/lookupcertificatesdialog.cpp dialogs/ownertrustdialog.cpp dialogs/selftestdialog.cpp dialogs/certifycertificatedialog.cpp dialogs/exportsecretkeydialog.cpp dialogs/adduseriddialog.cpp dialogs/exportcertificatesdialog.cpp dialogs/deletecertificatesdialog.cpp dialogs/setinitialpindialog.cpp dialogs/certificatedetailswidget.cpp dialogs/trustchainwidget.cpp dialogs/weboftrustwidget.cpp dialogs/weboftrustdialog.cpp dialogs/exportdialog.cpp dialogs/subkeyswidget.cpp dialogs/gencardkeydialog.cpp dialogs/updatenotification.cpp crypto/controller.cpp crypto/certificateresolver.cpp crypto/sender.cpp crypto/recipient.cpp crypto/task.cpp crypto/taskcollection.cpp crypto/decryptverifytask.cpp crypto/decryptverifyemailcontroller.cpp crypto/decryptverifyfilescontroller.cpp crypto/autodecryptverifyfilescontroller.cpp crypto/encryptemailtask.cpp crypto/encryptemailcontroller.cpp crypto/newsignencryptemailcontroller.cpp crypto/signencryptfilestask.cpp crypto/signencryptfilescontroller.cpp crypto/signemailtask.cpp crypto/signemailcontroller.cpp crypto/createchecksumscontroller.cpp crypto/verifychecksumscontroller.cpp crypto/gui/wizard.cpp crypto/gui/wizardpage.cpp crypto/gui/certificateselectionline.cpp crypto/gui/certificatelineedit.cpp crypto/gui/signingcertificateselectionwidget.cpp crypto/gui/signingcertificateselectiondialog.cpp crypto/gui/resultitemwidget.cpp crypto/gui/resultlistwidget.cpp crypto/gui/resultpage.cpp crypto/gui/newresultpage.cpp crypto/gui/signencryptfileswizard.cpp crypto/gui/signencryptemailconflictdialog.cpp crypto/gui/decryptverifyoperationwidget.cpp crypto/gui/decryptverifyfileswizard.cpp crypto/gui/decryptverifyfilesdialog.cpp crypto/gui/objectspage.cpp crypto/gui/resolverecipientspage.cpp crypto/gui/signerresolvepage.cpp crypto/gui/encryptemailwizard.cpp crypto/gui/signemailwizard.cpp crypto/gui/signencryptwidget.cpp crypto/gui/signencryptwizard.cpp crypto/gui/verifychecksumsdialog.cpp commands/command.cpp commands/gnupgprocesscommand.cpp commands/detailscommand.cpp commands/exportcertificatecommand.cpp commands/importcertificatescommand.cpp commands/importcertificatefromfilecommand.cpp commands/importcertificatefromclipboardcommand.cpp commands/lookupcertificatescommand.cpp commands/reloadkeyscommand.cpp commands/refreshx509certscommand.cpp commands/refreshopenpgpcertscommand.cpp commands/deletecertificatescommand.cpp commands/decryptverifyfilescommand.cpp commands/signencryptfilescommand.cpp commands/signencryptfoldercommand.cpp commands/encryptclipboardcommand.cpp commands/signclipboardcommand.cpp commands/decryptverifyclipboardcommand.cpp commands/clearcrlcachecommand.cpp commands/dumpcrlcachecommand.cpp commands/dumpcertificatecommand.cpp commands/importcrlcommand.cpp commands/changeexpirycommand.cpp commands/changeownertrustcommand.cpp commands/changeroottrustcommand.cpp commands/changepassphrasecommand.cpp commands/certifycertificatecommand.cpp commands/selftestcommand.cpp commands/exportsecretkeycommand.cpp commands/exportopenpgpcertstoservercommand.cpp commands/adduseridcommand.cpp commands/newcertificatecommand.cpp commands/setinitialpincommand.cpp commands/learncardkeyscommand.cpp commands/checksumcreatefilescommand.cpp commands/checksumverifyfilescommand.cpp commands/exportpaperkeycommand.cpp commands/importpaperkeycommand.cpp commands/genrevokecommand.cpp commands/keytocardcommand.cpp ${_kleopatra_uiserver_files} conf/configuredialog.cpp newcertificatewizard/listwidget.cpp newcertificatewizard/newcertificatewizard.cpp smartcard/readerstatus.cpp smartcard/card.cpp smartcard/openpgpcard.cpp smartcard/netkeycard.cpp aboutdata.cpp systrayicon.cpp kleopatraapplication.cpp mainwindow.cpp main.cpp ) if(HAVE_KCMUTILS) set (_kleopatra_extra_libs KF5::KCMUtils) else() set (_kleopatra_SRCS conf/kleopageconfigdialog.cpp ${_kleopatra_SRCS}) endif() ecm_qt_declare_logging_category(_kleopatra_SRCS HEADER kleopatra_debug.h IDENTIFIER KLEOPATRA_LOG CATEGORY_NAME org.kde.pim.kleopatra) if(KLEO_MODEL_TEST) add_definitions(-DKLEO_MODEL_TEST) set(_kleopatra_SRCS ${_kleopatra_SRCS} models/modeltest.cpp) endif() ki18n_wrap_ui(_kleopatra_SRCS dialogs/certificationoptionswidget.ui dialogs/expirydialog.ui dialogs/lookupcertificatesdialog.ui dialogs/ownertrustdialog.ui dialogs/selectchecklevelwidget.ui dialogs/selftestdialog.ui dialogs/exportsecretkeydialog.ui dialogs/adduseriddialog.ui dialogs/setinitialpindialog.ui dialogs/certificatedetailswidget.ui dialogs/trustchainwidget.ui dialogs/subkeyswidget.ui newcertificatewizard/listwidget.ui newcertificatewizard/chooseprotocolpage.ui newcertificatewizard/enterdetailspage.ui newcertificatewizard/overviewpage.ui newcertificatewizard/keycreationpage.ui newcertificatewizard/resultpage.ui newcertificatewizard/advancedsettingsdialog.ui ) kconfig_add_kcfg_files(_kleopatra_SRCS kcfg/tooltippreferences.kcfgc kcfg/emailoperationspreferences.kcfgc kcfg/fileoperationspreferences.kcfgc kcfg/smimevalidationpreferences.kcfgc ) file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/*-apps-kleopatra.png") ecm_add_app_icon(_kleopatra_SRCS ICONS ${ICONS_SRCS}) qt5_add_resources(_kleopatra_SRCS kleopatra.qrc) add_executable(kleopatra_bin ${_kleopatra_SRCS} ${_kleopatra_uiserver_SRCS}) set_target_properties(kleopatra_bin PROPERTIES OUTPUT_NAME kleopatra) target_link_libraries(kleopatra_bin Gpgmepp QGpgme ${_kleopatra_extra_libs} KF5::Libkleo KF5::Mime KF5::I18n KF5::XmlGui KF5::IconThemes KF5::WindowSystem KF5::CoreAddons KF5::ItemModels Qt5::Network Qt5::PrintSupport # Printing secret keys ${_kleopatra_uiserver_extra_libs} ${_kleopatra_dbusaddons_libs} kleopatraclientcore ) install(TARGETS kleopatra_bin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install( PROGRAMS data/org.kde.kleopatra.desktop data/kleopatra_import.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) install(FILES data/org.kde.kleopatra.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install( FILES data/kleopatra_signencryptfiles.desktop data/kleopatra_signencryptfolders.desktop data/kleopatra_decryptverifyfiles.desktop data/kleopatra_decryptverifyfolders.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) diff --git a/src/kleopatra.rc b/src/kleopatra.rc index aabe39765..914642c3a 100644 --- a/src/kleopatra.rc +++ b/src/kleopatra.rc @@ -1,124 +1,129 @@ - + &File &View + + &Certificates &Tools + + &Settings &Window &Help Main Toolbar - + + &Certificates diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 06af2efb8..86c12e98b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,669 +1,695 @@ /* -*- mode: c++; c-basic-offset:4 -*- mainwindow.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2007 Klarälvdalens Datakonsult AB Kleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kleopatra 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include "mainwindow.h" #include "aboutdata.h" +#include "view/padwidget.h" #include "view/searchbar.h" #include "view/tabwidget.h" #include "view/keylistcontroller.h" #include "view/keycacheoverlay.h" #include "view/smartcardwidget.h" #include "view/welcomewidget.h" #include "commands/selftestcommand.h" #include "commands/importcrlcommand.h" #include "commands/importcertificatefromfilecommand.h" #include "commands/decryptverifyfilescommand.h" #include "commands/signencryptfilescommand.h" #include "utils/detail_p.h" #include "utils/gnupg-helper.h" #include "utils/action_data.h" #include "utils/filedialog.h" #include "utils/clipboardmenu.h" #include "dialogs/updatenotification.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kleopatra_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Commands; using namespace GpgME; static KGuiItem KStandardGuiItem_quit() { static const QString app = KAboutData::applicationData().componentName(); KGuiItem item = KStandardGuiItem::quit(); item.setText(i18nc("Quit [ApplicationName]", "&Quit %1", app)); return item; } static KGuiItem KStandardGuiItem_close() { KGuiItem item = KStandardGuiItem::close(); item.setText(i18n("Only &Close Window")); return item; } static bool isQuitting = false; class MainWindow::Private { friend class ::MainWindow; MainWindow *const q; public: explicit Private(MainWindow *qq); ~Private(); template void createAndStart() { (new T(this->currentView(), &this->controller))->start(); } template void createAndStart(QAbstractItemView *view) { (new T(view, &this->controller))->start(); } template void createAndStart(const QStringList &a) { (new T(a, this->currentView(), &this->controller))->start(); } template void createAndStart(const QStringList &a, QAbstractItemView *view) { (new T(a, view, &this->controller))->start(); } void closeAndQuit() { const QString app = KAboutData::applicationData().componentName(); const int rc = KMessageBox::questionYesNoCancel(q, i18n("%1 may be used by other applications as a service.\n" "You may instead want to close this window without exiting %1.", app), i18n("Really Quit?"), KStandardGuiItem_close(), KStandardGuiItem_quit(), KStandardGuiItem::cancel(), QLatin1String("really-quit-") + app.toLower()); if (rc == KMessageBox::Cancel) { return; } isQuitting = true; if (!q->close()) { return; } // WARNING: 'this' might be deleted at this point! if (rc == KMessageBox::No) { qApp->quit(); } } void configureToolbars() { KEditToolBar dlg(q->factory()); dlg.exec(); } void editKeybindings() { KShortcutsDialog::configure(q->actionCollection(), KShortcutsEditor::LetterShortcutsAllowed); updateSearchBarClickMessage(); } void updateSearchBarClickMessage() { const QString shortcutStr = focusToClickSearchAction->shortcut().toString(); ui.searchBar->updateClickMessage(shortcutStr); } void updateStatusBar() { const auto complianceMode = Formatting::complianceMode(); if (!complianceMode.isEmpty()) { auto statusBar = new QStatusBar; q->setStatusBar(statusBar); auto statusLbl = new QLabel(i18nc("Compliance means that GnuPG is running in a more restricted mode e.g. to handle restricted documents.", // The germans want some extra sausage "Compliance: %1", complianceMode == QStringLiteral("de-vs") ? QStringLiteral ("VS-NfD") : complianceMode)); statusBar->insertPermanentWidget(0, statusLbl); } else { q->setStatusBar(nullptr); } } void selfTest() { createAndStart(); } void configureBackend(); void showHandbook(); void gnupgLogViewer() { if (!QProcess::startDetached(QStringLiteral("kwatchgnupg"))) KMessageBox::error(q, i18n("Could not start the GnuPG Log Viewer (kwatchgnupg). " "Please check your installation."), i18n("Error Starting KWatchGnuPG")); } void forceUpdateCheck() { UpdateNotification::forceUpdateCheck(q); } void openCompendium() { QDir datadir(QCoreApplication::applicationDirPath() + QStringLiteral("/../share/gpg4win")); const auto path = datadir.filePath(i18nc("The Gpg4win compendium is only available" "at this point (24.7.2017) in german and english." "Please check with Gpg4win before translating this filename.", "gpg4win-compendium-en.pdf")); qCDebug(KLEOPATRA_LOG) << "Opening Compendium at:" << path; // The compendium is always installed. So this should work. Otherwise // we have debug output. QDesktopServices::openUrl(QUrl::fromLocalFile(path)); } void slotConfigCommitted(); void slotContextMenuRequested(QAbstractItemView *, const QPoint &p) { if (QMenu *const menu = qobject_cast(q->factory()->container(QStringLiteral("listview_popup"), q))) { menu->exec(p); } else { qCDebug(KLEOPATRA_LOG) << "no \"listview_popup\" in kleopatra's ui.rc file"; } } void slotFocusQuickSearch() { ui.searchBar->lineEdit()->setFocus(); } void toggleSmartcardView() { if (ui.scWidget->isVisible()) { ui.scWidget->hide(); ui.searchBar->show(); ui.tabWidget.show(); } else { ui.scWidget->show(); ui.searchBar->hide(); ui.tabWidget.hide(); ui.welcomeWidget->hide(); } } + void togglePadView(); + private: void setupActions(); QAbstractItemView *currentView() const { return ui.tabWidget.currentView(); } void checkWelcomePage() { - if (ui.scWidget->isVisible()) { + if (ui.scWidget->isVisible() || ui.padWidget->isVisible()) { return; } if (KeyCache::instance()->keys().empty()) { ui.searchBar->hide(); ui.tabWidget.hide(); ui.welcomeWidget->show(); } else { ui.welcomeWidget->hide(); ui.searchBar->show(); ui.tabWidget.show(); } } private: Kleo::KeyListController controller; bool firstShow : 1; struct UI { TabWidget tabWidget; SearchBar *searchBar; + PadWidget *padWidget; SmartCardWidget *scWidget; WelcomeWidget *welcomeWidget; explicit UI(MainWindow *q); } ui; QAction *focusToClickSearchAction; ClipboardMenu *clipboadMenu; }; MainWindow::Private::UI::UI(MainWindow *q) : tabWidget(q) { KDAB_SET_OBJECT_NAME(tabWidget); QWidget *mainWidget = new QWidget; QVBoxLayout *vbox = new QVBoxLayout; vbox->setSpacing(0); mainWidget->setLayout(vbox); searchBar = new SearchBar; vbox->addWidget(searchBar); tabWidget.connectSearchBar(searchBar); vbox->addWidget(&tabWidget); new KeyCacheOverlay(mainWidget, q); scWidget = new SmartCardWidget(); vbox->addWidget(scWidget); scWidget->hide(); welcomeWidget = new WelcomeWidget(); vbox->addWidget(welcomeWidget); welcomeWidget->hide(); + padWidget = new PadWidget(); + vbox->addWidget(padWidget); + padWidget->hide(); + q->setCentralWidget(mainWidget); } MainWindow::Private::Private(MainWindow *qq) : q(qq), controller(q), firstShow(true), ui(q) { KDAB_SET_OBJECT_NAME(controller); AbstractKeyListModel *flatModel = AbstractKeyListModel::createFlatKeyListModel(q); AbstractKeyListModel *hierarchicalModel = AbstractKeyListModel::createHierarchicalKeyListModel(q); KDAB_SET_OBJECT_NAME(flatModel); KDAB_SET_OBJECT_NAME(hierarchicalModel); controller.setFlatModel(flatModel); controller.setHierarchicalModel(hierarchicalModel); controller.setTabWidget(&ui.tabWidget); ui.tabWidget.setFlatModel(flatModel); ui.tabWidget.setHierarchicalModel(hierarchicalModel); setupActions(); connect(&controller, SIGNAL(contextMenuRequested(QAbstractItemView*,QPoint)), q, SLOT(slotContextMenuRequested(QAbstractItemView*,QPoint))); connect(ui.scWidget, &SmartCardWidget::backRequested, q, [this]() { auto action = q->actionCollection()->action(QStringLiteral("manage_smartcard")); Q_ASSERT(action); action->setChecked(false); }); connect(KeyCache::instance().get(), &KeyCache::keyListingDone, q, [this] () {checkWelcomePage();}); q->createGUI(QStringLiteral("kleopatra.rc")); q->setAcceptDrops(true); q->setAutoSaveSettings(); updateSearchBarClickMessage(); updateStatusBar(); } MainWindow::Private::~Private() {} MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : KXmlGuiWindow(parent, flags), d(new Private(this)) { resize(960, 440); } MainWindow::~MainWindow() {} void MainWindow::Private::setupActions() { KActionCollection *const coll = q->actionCollection(); const action_data action_data[] = { // most have been MOVED TO keylistcontroller.cpp // Tools menu #ifndef Q_OS_WIN { "tools_start_kwatchgnupg", i18n("GnuPG Log Viewer"), QString(), "kwatchgnupg", q, SLOT(gnupgLogViewer()), QString(), false, true }, #endif #ifdef Q_OS_WIN { "help_check_updates", i18n("Check for updates"), QString(), "gpg4win-compact", q, SLOT(forceUpdateCheck()), QString(), false, true }, { "help_show_compendium", i18n("Gpg4win Compendium"), QString(), "gpg4win-compact", q, SLOT(openCompendium()), QString(), false, true }, #endif + { + "pad_view", i18nc("Title for a generic data input / output area supporting text actions.", "Notepad"), + i18n("Switch to Pad view."), "edittext", q, SLOT(togglePadView()), QString(), true, true + }, // most have been MOVED TO keylistcontroller.cpp #if 0 { "configure_backend", i18n("Configure GnuPG Backend..."), QString(), 0, q, SLOT(configureBackend()), QString(), false, true }, #endif // Settings menu { "settings_self_test", i18n("Perform Self-Test"), QString(), nullptr, q, SLOT(selfTest()), QString(), false, true }, { "manage_smartcard", i18n("Manage Smartcards"), i18n("Edit or initialize a crypto hardware token."), "secure-card", q, SLOT(toggleSmartcardView()), QString(), true, true } // most have been MOVED TO keylistcontroller.cpp }; make_actions_from_data(action_data, /*sizeof action_data / sizeof *action_data,*/ coll); if (QAction *action = coll->action(QStringLiteral("configure_backend"))) { action->setMenuRole(QAction::NoRole); //prevent Qt OS X heuristics for config* actions } KStandardAction::close(q, SLOT(close()), coll); KStandardAction::quit(q, SLOT(closeAndQuit()), coll); KStandardAction::configureToolbars(q, SLOT(configureToolbars()), coll); KStandardAction::keyBindings(q, SLOT(editKeybindings()), coll); KStandardAction::preferences(qApp, SLOT(openOrRaiseConfigDialog()), coll); focusToClickSearchAction = new QAction(i18n("Set Focus to Quick Search"), q); coll->addAction(QStringLiteral("focus_to_quickseach"), focusToClickSearchAction); coll->setDefaultShortcut(focusToClickSearchAction, QKeySequence(Qt::ALT + Qt::Key_Q)); connect(focusToClickSearchAction, SIGNAL(triggered(bool)), q, SLOT(slotFocusQuickSearch())); clipboadMenu = new ClipboardMenu(q); clipboadMenu->setMainWindow(q); clipboadMenu->clipboardMenu()->setIcon(QIcon::fromTheme(QStringLiteral("edit-paste"))); clipboadMenu->clipboardMenu()->setDelayed(false); coll->addAction(QStringLiteral("clipboard_menu"), clipboadMenu->clipboardMenu()); q->setStandardToolBarMenuEnabled(true); controller.createActions(coll); ui.tabWidget.createActions(coll); } void MainWindow::Private::configureBackend() { QGpgME::CryptoConfig *const config = QGpgME::cryptoConfig(); if (!config) { KMessageBox::error(q, i18n("Could not configure the cryptography backend (gpgconf tool not found)"), i18n("Configuration Error")); return; } Kleo::CryptoConfigDialog dlg(config); const int result = dlg.exec(); // Forget all data parsed from gpgconf, so that we show updated information // when reopening the configuration dialog. config->clear(); if (result == QDialog::Accepted) { #if 0 // Tell other apps (e.g. kmail) that the gpgconf data might have changed QDBusMessage message = QDBusMessage::createSignal(QString(), "org.kde.kleo.CryptoConfig", "changed"); QDBusConnection::sessionBus().send(message); #endif } } void MainWindow::Private::slotConfigCommitted() { controller.updateConfig(); updateStatusBar(); } +void MainWindow::Private::togglePadView() +{ + if (ui.padWidget->isVisible()) { + ui.padWidget->hide(); + ui.searchBar->show(); + ui.tabWidget.show(); + } else { + ui.padWidget->show(); + ui.searchBar->hide(); + ui.tabWidget.hide(); + ui.welcomeWidget->hide(); + } +} + void MainWindow::closeEvent(QCloseEvent *e) { // KMainWindow::closeEvent() insists on quitting the application, // so do not let it touch the event... qCDebug(KLEOPATRA_LOG); if (d->controller.hasRunningCommands()) { if (d->controller.shutdownWarningRequired()) { const int ret = KMessageBox::warningContinueCancel(this, i18n("There are still some background operations ongoing. " "These will be terminated when closing the window. " "Proceed?"), i18n("Ongoing Background Tasks")); if (ret != KMessageBox::Continue) { e->ignore(); return; } } d->controller.cancelCommands(); if (d->controller.hasRunningCommands()) { // wait for them to be finished: setEnabled(false); QEventLoop ev; QTimer::singleShot(100, &ev, &QEventLoop::quit); connect(&d->controller, &KeyListController::commandsExecuting, &ev, &QEventLoop::quit); ev.exec(); if (d->controller.hasRunningCommands()) qCWarning(KLEOPATRA_LOG) << "controller still has commands running, this may crash now..."; setEnabled(true); } } if (isQuitting || qApp->isSavingSession()) { d->ui.tabWidget.saveViews(KSharedConfig::openConfig().data()); KConfigGroup grp(KConfigGroup(KSharedConfig::openConfig(), autoSaveGroup())); saveMainWindowSettings(grp); e->accept(); } else { e->ignore(); hide(); } } void MainWindow::showEvent(QShowEvent *e) { KXmlGuiWindow::showEvent(e); if (d->firstShow) { d->ui.tabWidget.loadViews(KSharedConfig::openConfig().data()); d->firstShow = false; } if (!savedGeometry.isEmpty()) { restoreGeometry(savedGeometry); } } void MainWindow::hideEvent(QHideEvent *e) { savedGeometry = saveGeometry(); KXmlGuiWindow::hideEvent(e); } void MainWindow::importCertificatesFromFile(const QStringList &files) { if (!files.empty()) { d->createAndStart(files); } } static QStringList extract_local_files(const QMimeData *data) { const QList urls = data->urls(); // begin workaround KDE/Qt misinterpretation of text/uri-list QList::const_iterator end = urls.end(); if (urls.size() > 1 && !urls.back().isValid()) { --end; } // end workaround QStringList result; std::transform(urls.begin(), end, std::back_inserter(result), std::mem_fn(&QUrl::toLocalFile)); result.erase(std::remove_if(result.begin(), result.end(), std::mem_fn(&QString::isEmpty)), result.end()); return result; } static bool can_decode_local_files(const QMimeData *data) { if (!data) { return false; } return !extract_local_files(data).empty(); } void MainWindow::dragEnterEvent(QDragEnterEvent *e) { qCDebug(KLEOPATRA_LOG); if (can_decode_local_files(e->mimeData())) { e->acceptProposedAction(); } } void MainWindow::dropEvent(QDropEvent *e) { qCDebug(KLEOPATRA_LOG); if (!can_decode_local_files(e->mimeData())) { return; } e->setDropAction(Qt::CopyAction); const QStringList files = extract_local_files(e->mimeData()); const unsigned int classification = classify(files); QMenu menu; QAction *const signEncrypt = menu.addAction(i18n("Sign/Encrypt...")); QAction *const decryptVerify = mayBeAnyMessageType(classification) ? menu.addAction(i18n("Decrypt/Verify...")) : nullptr; if (signEncrypt || decryptVerify) { menu.addSeparator(); } QAction *const importCerts = mayBeAnyCertStoreType(classification) ? menu.addAction(i18n("Import Certificates")) : nullptr; QAction *const importCRLs = mayBeCertificateRevocationList(classification) ? menu.addAction(i18n("Import CRLs")) : nullptr; if (importCerts || importCRLs) { menu.addSeparator(); } if (!signEncrypt && !decryptVerify && !importCerts && !importCRLs) { return; } menu.addAction(i18n("Cancel")); const QAction *const chosen = menu.exec(mapToGlobal(e->pos())); if (!chosen) { return; } if (chosen == signEncrypt) { d->createAndStart(files); } else if (chosen == decryptVerify) { d->createAndStart(files); } else if (chosen == importCerts) { d->createAndStart(files); } else if (chosen == importCRLs) { d->createAndStart(files); } e->accept(); } void MainWindow::readProperties(const KConfigGroup &cg) { qCDebug(KLEOPATRA_LOG); KXmlGuiWindow::readProperties(cg); savedGeometry = cg.readEntry("savedGeometry", QByteArray()); if (!savedGeometry.isEmpty()) { restoreGeometry(savedGeometry); } if (! cg.readEntry("hidden", false)) { show(); } } void MainWindow::saveProperties(KConfigGroup &cg) { qCDebug(KLEOPATRA_LOG); KXmlGuiWindow::saveProperties(cg); cg.writeEntry("hidden", isHidden()); if (isHidden()) { cg.writeEntry("savedGeometry", savedGeometry); } else { cg.writeEntry("savedGeometry", saveGeometry()); } } #include "moc_mainwindow.cpp" diff --git a/src/mainwindow.h b/src/mainwindow.h index bfe4e6e7b..05196abc5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,80 +1,81 @@ /* -*- mode: c++; c-basic-offset:4 -*- mainwindow.h This file is part of Kleopatra, the KDE keymanager Copyright (c) 2007 Klarälvdalens Datakonsult AB 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Kleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kleopatra 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __KLEOPATRA_MAINWINDOW_DESKTOP_H__ #define __KLEOPATRA_MAINWINDOW_DESKTOP_H__ #include #include class MainWindow : public KXmlGuiWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS); ~MainWindow(); public Q_SLOTS: void importCertificatesFromFile(const QStringList &files); protected: QByteArray savedGeometry; void closeEvent(QCloseEvent *e) override; void showEvent(QShowEvent *e) override; void hideEvent(QHideEvent *e) override; void dragEnterEvent(QDragEnterEvent *) override; void dropEvent(QDropEvent *) override; void readProperties(const KConfigGroup &cg) override; void saveProperties(KConfigGroup &cg) override; private: class Private; kdtools::pimpl_ptr d; Q_PRIVATE_SLOT(d, void closeAndQuit()) Q_PRIVATE_SLOT(d, void selfTest()) Q_PRIVATE_SLOT(d, void configureBackend()) Q_PRIVATE_SLOT(d, void configureToolbars()) Q_PRIVATE_SLOT(d, void editKeybindings()) Q_PRIVATE_SLOT(d, void gnupgLogViewer()) Q_PRIVATE_SLOT(d, void slotConfigCommitted()) Q_PRIVATE_SLOT(d, void slotContextMenuRequested(QAbstractItemView *, QPoint)) Q_PRIVATE_SLOT(d, void slotFocusQuickSearch()) + Q_PRIVATE_SLOT(d, void togglePadView()) Q_PRIVATE_SLOT(d, void toggleSmartcardView()) Q_PRIVATE_SLOT(d, void forceUpdateCheck()) Q_PRIVATE_SLOT(d, void openCompendium()) }; #endif /* __KLEOPATRA_MAINWINDOW_DESKTOP_H__ */ diff --git a/src/view/padwidget.cpp b/src/view/padwidget.cpp new file mode 100644 index 000000000..68224fed9 --- /dev/null +++ b/src/view/padwidget.cpp @@ -0,0 +1,304 @@ +/* -*- mode: c++; c-basic-offset:4 -*- + padwidget.cpp + + This file is part of Kleopatra, the KDE keymanager + Copyright (c) 2018 Intevation GmbH + + Kleopatra is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Kleopatra 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ +#include "padwidget.h" + +#include "kleopatra_debug.h" + +#include + +#include "crypto/gui/signencryptwidget.h" +#include "crypto/gui/resultitemwidget.h" + +#include "crypto/signencryptfilestask.h" +#include "crypto/decryptverifytask.h" +#include "utils/gnupg-helper.h" +#include "utils/input.h" +#include "utils/output.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace Kleo; +using namespace Kleo::Crypto; +using namespace Kleo::Crypto::Gui; + +class PadWidget::Private +{ +public: + Private(PadWidget *qq): + q(qq), + mEdit(new QTextEdit), + mCryptBtn(new QPushButton(QIcon::fromTheme("document-edit-sign-encrypt"), i18n("Sign / Encrypt Notepad"))), + mDecryptBtn(new QPushButton(QIcon::fromTheme("document-edit-decrypt-verify"), i18n("Decrypt / Verify Notepad"))), + mAdditionalInfoLabel(new QLabel), + mSigEncWidget(new SignEncryptWidget), + mProgressBar(new QProgressBar), + mProgressLabel(new QLabel), + mLastResultWidget(nullptr) + { + auto vLay = new QVBoxLayout(q); + + auto btnLay = new QHBoxLayout; + vLay->addLayout(btnLay); + btnLay->addWidget(mCryptBtn); + btnLay->addWidget(mDecryptBtn); + + mAdditionalInfoLabel->setWordWrap(true); + btnLay->addWidget(mAdditionalInfoLabel); + + btnLay->addStretch(-1); + + mProgressBar->setRange(0, 0); + mProgressBar->setVisible(false); + mProgressLabel->setVisible(false); + auto progLay = new QHBoxLayout; + + progLay->addWidget(mProgressLabel); + progLay->addWidget(mProgressBar); + + mStatusLay = new QVBoxLayout; + mStatusLay->addLayout(progLay); + vLay->addLayout(mStatusLay, 0.1); + + auto splitter = new QSplitter; + vLay->addWidget(splitter, 1); + + splitter->addWidget(mEdit); + + // The recipients area + auto recipientsWidget = new QWidget; + auto recipientsVLay = new QVBoxLayout(recipientsWidget); + auto protocolSelectionLay = new QHBoxLayout; + recipientsVLay->addLayout(protocolSelectionLay); + protocolSelectionLay->addWidget(new QLabel(i18n("

Recipients:

"))); + protocolSelectionLay->addStretch(-1); + // Once S/MIME is supported add radio for S/MIME here. + + recipientsVLay->addWidget(mSigEncWidget); + splitter->addWidget(recipientsWidget); + + mEdit->setPlaceholderText("Enter a message to encrypt or decrypt..."); + + auto fixedFont = QFont("Monospace", 10); + // This does not work well: + // QFontDatabase::systemFont(QFontDatabase::FixedFont); + + mEdit->setCurrentFont(fixedFont); + mEdit->setMinimumWidth(QFontMetrics(fixedFont).averageCharWidth() * 70); + + mSigEncWidget->setProtocol(GpgME::OpenPGP); + + updateCommitButton(); + + connect(mCryptBtn, &QPushButton::clicked, q, [this] () { + doEncryptSign(); + }); + + connect(mSigEncWidget, &SignEncryptWidget::operationChanged, q, [this] (const QString &) { + updateCommitButton(); + }); + + connect(mDecryptBtn, &QPushButton::clicked, q, [this] () { + doDecryptVerify(); + }); + } + + void cryptDone(const std::shared_ptr &result) + { + mCryptBtn->setEnabled(true); + mDecryptBtn->setEnabled(true); + mProgressBar->setVisible(false); + mProgressLabel->setVisible(false); + + mLastResultWidget = new ResultItemWidget(result); + mLastResultWidget->showCloseButton(true); + mStatusLay->addWidget(mLastResultWidget); + + connect(mLastResultWidget, &ResultItemWidget::closeButtonClicked, q, [this] () { + removeLastResultItem(); + }); + + if (result->errorCode()) { + if (!result->errorString().isEmpty()) { + KMessageBox::error(q, + result->errorString(), + i18nc("@title", "Error in crypto action")); + } + return; + } + mEdit->setPlainText(QString::fromUtf8(mOutputData)); + mOutputData.clear(); + } + + void doDecryptVerify() + { + doCryptoCommon(); + mProgressLabel->setText(i18n("Decrypt / Verify") + QStringLiteral("...")); + auto input = Input::createFromByteArray(&mInputData, i18n("Notepad")); + auto output = Output::createFromByteArray(&mOutputData, i18n("Notepad")); + + auto task = new DecryptVerifyTask(); + task->setInput(input); + task->setOutput(output); + try { + task->autodetectProtocolFromInput(); + } catch (const Kleo::Exception &e) { + KMessageBox::error(q, + e.message(), + i18nc("@title", "Error in crypto action")); + mCryptBtn->setEnabled(true); + mDecryptBtn->setEnabled(true); + mProgressBar->setVisible(false); + mProgressLabel->setVisible(false); + return; + } + + connect (task, &Task::result, q, [this, task] (const std::shared_ptr &result) { + qCDebug(KLEOPATRA_LOG) << "Decrypt / Verify done. Err:" << result->errorCode(); + task->deleteLater(); + cryptDone(result); + }); + task->start(); + } + + void removeLastResultItem() + { + if (mLastResultWidget) { + mStatusLay->removeWidget(mLastResultWidget); + delete mLastResultWidget; + mLastResultWidget = nullptr; + } + } + + void doCryptoCommon() + { + mCryptBtn->setEnabled(false); + mDecryptBtn->setEnabled(false); + mProgressBar->setVisible(true); + mProgressLabel->setVisible(true); + mInputData = mEdit->toPlainText().toUtf8(); + removeLastResultItem(); + } + + void doEncryptSign() + { + doCryptoCommon(); + mProgressLabel->setText(mSigEncWidget->currentOp() + QStringLiteral("...")); + auto input = Input::createFromByteArray(&mInputData, i18n("Notepad")); + auto output = Output::createFromByteArray(&mOutputData, i18n("Notepad")); + + auto task = new SignEncryptFilesTask(); + task->setInput(input); + task->setOutput(output); + + const auto sigKey = mSigEncWidget->signKey(); + if (!sigKey.isNull()) { + task->setSign(true); + std::vector signVector; + signVector.push_back(sigKey); + task->setSigners(signVector); + } else { + task->setSign(false); + } + task->setEncrypt(mSigEncWidget->encryptSymmetric() || mSigEncWidget->recipients().size()); + task->setRecipients(mSigEncWidget->recipients().toStdVector()); + task->setEncryptSymmetric(mSigEncWidget->encryptSymmetric()); + task->setAsciiArmor(true); + + connect (task, &Task::result, q, [this, task] (const std::shared_ptr &result) { + qCDebug(KLEOPATRA_LOG) << "Encrypt / Sign done. Err:" << result->errorCode(); + task->deleteLater(); + cryptDone(result); + }); + task->start(); + } + + void updateCommitButton() + { + mAdditionalInfoLabel->setVisible(false); + if (!mSigEncWidget->currentOp().isEmpty()) { + mCryptBtn->setDisabled(false); + mCryptBtn->setText(mSigEncWidget->currentOp() + QLatin1Char(' ') + i18n("Notepad")); + } else { + mCryptBtn->setText(i18n("Sign / Encrypt Notepad")); + mCryptBtn->setDisabled(true); + } + + if (Kleo::gpgComplianceP("de-vs")) { + bool de_vs = mSigEncWidget->isDeVsAndValid(); + mCryptBtn->setIcon(QIcon::fromTheme(de_vs + ? "security-high" + : "security-medium")); + mCryptBtn->setStyleSheet(QStringLiteral("background-color: ") + (de_vs + ? KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::PositiveBackground).color().name() + : KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::NegativeBackground).color().name())); + mAdditionalInfoLabel->setText(de_vs + ? i18nc("VS-NfD-conforming is a German standard for restricted documents for which special restrictions about algorithms apply. The string states that all cryptographic operations necessary for the communication are compliant with that.", + "VS-NfD-compliant communication possible.") + : i18nc("VS-NfD-conforming is a German standard for restricted documents for which special restrictions about algorithms apply. The string states that all cryptographic operations necessary for the communication are compliant with that.", + "VS-NfD-compliant communication not possible.")); + mAdditionalInfoLabel->setVisible(true); + } + } + +private: + PadWidget *q; + QTextEdit *mEdit; + QPushButton *mCryptBtn; + QPushButton *mDecryptBtn; + QLabel *mAdditionalInfoLabel; + QByteArray mInputData; + QByteArray mOutputData; + SignEncryptWidget *mSigEncWidget; + QProgressBar *mProgressBar; + QLabel *mProgressLabel; + QVBoxLayout *mStatusLay; + ResultItemWidget *mLastResultWidget; +}; + +PadWidget::PadWidget(QWidget *parent): + QWidget(parent), + d(new Private(this)) +{ +} diff --git a/src/view/padwidget.h b/src/view/padwidget.h new file mode 100644 index 000000000..8ff02ad32 --- /dev/null +++ b/src/view/padwidget.h @@ -0,0 +1,55 @@ +/* -*- mode: c++; c-basic-offset:4 -*- + padwidget.h + + This file is part of Kleopatra, the KDE keymanager + Copyright (c) 2018 Intevation GmbH + + Kleopatra is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Kleopatra 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef KLEOPATRA_VIEW_PADWIDGET +#define KLEOPATRA_VIEW_PADWIDGET + +#include +#include + +namespace Kleo +{ +/** The padwidget provides a general I/O area inside of kleopatra + * and can be used as an alternative view to the tabwidget. */ +class PadWidget: public QWidget +{ + Q_OBJECT +public: + explicit PadWidget(QWidget *parent = Q_NULLPTR); + +private: + class Private; + std::shared_ptr d; +}; +} // namespace Kleo + +#endif // DIALOGS_CLIPBOARD_H