From d56dd53d0a5a0000f24cc4d866946d2bdbebc8a7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 14 Mar 2018 20:28:38 +0100 Subject: [PATCH] Make from Configuration form a main window, with menu bar Initial attempt Issue #274 Signed-off-by: Szczepan Zalega --- src/GUI/Tray.cpp | 19 ++++++++---- src/GUI/Tray.h | 8 +++++- src/ui/mainwindow.cpp | 67 +++++++++++++++++++++++++++---------------- src/ui/mainwindow.h | 2 ++ src/ui/mainwindow.ui | 24 +++++++++++++++- 5 files changed, 89 insertions(+), 31 deletions(-) diff --git a/src/GUI/Tray.cpp b/src/GUI/Tray.cpp index 375a9ae0..aad35e2d 100644 --- a/src/GUI/Tray.cpp +++ b/src/GUI/Tray.cpp @@ -32,12 +32,14 @@ TODO #include "nitrokey-applet.h" #include #include +#include Tray::Tray(QObject *_parent, bool _debug_mode, bool _extended_config, StorageActions *actions) : QObject(_parent), trayMenu(nullptr), trayMenuPasswdSubMenu(nullptr), + file_menu(nullptr), worker(nullptr) { main_window = _parent; @@ -50,8 +52,6 @@ Tray::Tray(QObject *_parent, bool _debug_mode, bool _extended_config, initActionsForStick20(); initCommonActions(); - generateMenu(true); - mapper_TOTP = new QSignalMapper(this); mapper_HOTP = new QSignalMapper(this); mapper_PWS = new QSignalMapper(this); @@ -148,9 +148,7 @@ bool Tray::eventFilter(QObject *obj, QEvent *event) { return QObject::eventFilter(obj, event); } - void Tray::generateMenu(bool init, std::function run_before) { - { static QMutex mtx; QMutexLocker locker(&mtx); @@ -189,8 +187,12 @@ bool Tray::eventFilter(QObject *obj, QEvent *event) { trayMenu->addAction(quitAction); trayIcon->setContextMenu(trayMenu.get()); + + if (file_menu != nullptr){ + trayMenu->setTitle(tr("Menu")); + file_menu->addMenu(trayMenu.get()); + } } -} void Tray::initActionsForStick10() { UnlockPasswordSafeAction = new QAction(tr("Unlock password safe"), main_window); @@ -687,3 +689,10 @@ void Tray::setAdmin_mode(bool _admin_mode) { ExtendedConfigActive = _admin_mode; } +void Tray::setFile_menu(QMenuBar *file_menu) { + Tray::file_menu = file_menu; + generateMenu(true); + if (trayMenu!= nullptr) + file_menu->addMenu(trayMenu.get()); +} + diff --git a/src/GUI/Tray.h b/src/GUI/Tray.h index 7148488e..99f52c16 100644 --- a/src/GUI/Tray.h +++ b/src/GUI/Tray.h @@ -50,6 +50,7 @@ public slots: #include #include #include +#include #include "StorageActions.h" class Tray : public QObject { @@ -104,8 +105,13 @@ private slots: // QMenu *trayMenuTOTPSubMenu; // QMenu *trayMenuHOTPSubMenu; QMenu *trayMenuSubSpecialConfigure; + QMenuBar* file_menu; +public: + void setFile_menu(QMenuBar *file_menu); + +private: - QAction *quitAction; + QAction *quitAction; QAction *configureAction; QAction *resetAction; QAction *configureActionStick20; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 73eba592..8822c3de 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -47,7 +47,13 @@ #include "src/core/SecureString.h" #include -#include +#include "src/core/ScopedGuard.h" +#include "src/core/ThreadWorker.h" +#include "hotpslot.h" + +#include +#include + using nm = nitrokey::NitrokeyManager; static const QString communication_error_message = QApplication::tr("Communication error. Please reinsert the device."); @@ -95,7 +101,7 @@ void MainWindow::load_settings(){ ui->spin_PWS_time->setValue(settings.value("clipboard/PWS_time", 60).toInt()); ui->spin_OTP_time->setValue(settings.value("clipboard/OTP_time", 120).toInt()); ui->cb_device_connection_message->setChecked(settings.value("main/connection_message", true).toBool()); - ui->cb_check_symlink->setChecked(settings.value("storage/check_symlink", true).toBool()); + ui->cb_check_symlink->setChecked(settings.value("storage/check_symlink", false).toBool()); #ifndef Q_OS_LINUX ui->cb_check_symlink->setEnabled(false); #endif @@ -206,6 +212,12 @@ MainWindow::MainWindow(QWidget *parent): first_run(); load_settings(); + +// tray.regenerateMenu(); + tray.setFile_menu(menuBar()); + ui->tabWidget->setEnabled(false); +// startConfiguration(); + show(); } void MainWindow::first_run(){ @@ -283,7 +295,10 @@ void MainWindow::initialTimeReset() { return; } - if (!libada::i()->is_time_synchronized()) { + QFuture is_time_synchronized = QtConcurrent::run(libada::i().get(), &libada::is_time_synchronized); + is_time_synchronized.waitForFinished(); + + if (!is_time_synchronized.result()) { bool answer = csApplet()->detailedYesOrNoBox(tr("Time is out-of-sync") + " - " + RESET_NITROKEYS_TIME, WARNING_DEVICES_CLOCK_NOT_DESYNCHRONIZED, false); if (answer) { @@ -1110,12 +1125,13 @@ void MainWindow::SetupPasswordSafeConfig(void) { ui->PWS_ComboBoxSelectSlot->setEnabled(PWS_Access); ui->PWS_ButtonEnable->setVisible(!PWS_Access); + ui->PWS_Lock->setVisible(PWS_Access); ui->PWS_EditSlotName->setMaxLength(PWS_SLOTNAME_LENGTH); ui->PWS_EditPassword->setMaxLength(PWS_PASSWORD_LENGTH); ui->PWS_EditLoginName->setMaxLength(PWS_LOGINNAME_LENGTH); - ui->PWS_CheckBoxHideSecret->setChecked(TRUE); + ui->PWS_CheckBoxHideSecret->setChecked(true); ui->PWS_EditPassword->setEchoMode(QLineEdit::Password); } @@ -1504,15 +1520,9 @@ void MainWindow::on_DeviceDisconnected() { tray.showTrayMessage(tr("Nitrokey disconnected")); } - if(this->isVisible()){ - this->close(); - csApplet()->messageBox(tr("Closing window due to device disconnection")); - } + ui->tabWidget->setEnabled(false); } -#include "src/core/ThreadWorker.h" -#include "hotpslot.h" - void MainWindow::on_DeviceConnected() { if (debug_mode) qDebug("on_DeviceConnected"); @@ -1520,25 +1530,17 @@ void MainWindow::on_DeviceConnected() { if (debug_mode) emit ShortOperationBegins(tr("Connecting device")); - //TODO share device state to improve performance + ui->statusBar->showMessage(tr("Device connected. Waiting for initialization...")); + try{ - libada::i()->get_status(); + auto result = QtConcurrent::run(libada::i().get(), &libada::get_status); + result.waitForFinished(); } catch (LongOperationInProgressException &e){ long_operation_in_progress = true; return; } - QSettings settings; - if(settings.value("main/connection_message", true).toBool()){ - - auto connected_device_model = libada::i()->isStorageDeviceConnected() ? - tr("Nitrokey Storage connected") : - tr("Nitrokey Pro connected"); - ui->statusBar->showMessage(connected_device_model); - tray.showTrayMessage(tr("Nitrokey connected"), connected_device_model); - } - initialTimeReset(); new ThreadWorker( @@ -1589,7 +1591,19 @@ void MainWindow::on_DeviceConnected() { )); } #endif - }, this); + }, this); + startConfiguration(); + ui->tabWidget->setEnabled(true); + + QSettings settings; + if(settings.value("main/connection_message", true).toBool()){ + + auto connected_device_model = libada::i()->isStorageDeviceConnected() ? + tr("Nitrokey Storage connected") : + tr("Nitrokey Pro connected"); + ui->statusBar->showMessage(connected_device_model); + tray.showTrayMessage(tr("Nitrokey connected"), connected_device_model); + } } void MainWindow::on_KeepDeviceOnline() { @@ -1722,3 +1736,8 @@ void MainWindow::on_btn_select_debug_file_path_clicked() auto filename = QFileDialog::getSaveFileName(this, tr("Debug file location (will be overwritten)")); ui->edit_debug_file_path->setText(filename); } + +void MainWindow::on_PWS_Lock_clicked() +{ + startLockDeviceAction(true); +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 38a61c91..36a0a021 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -193,6 +193,8 @@ private slots: void on_btn_select_debug_file_path_clicked(); + void on_PWS_Lock_clicked(); + public: void generateOTPConfig(OTPSlot *slot); unsigned int get_supported_secret_length_base32() const; diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index 5242cb0f..7611bc00 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -60,6 +60,11 @@ false + + + Start + + OTP Slot Configuration @@ -1283,10 +1288,17 @@ + + + + Lock Device + + + - 24 + 42 @@ -1626,6 +1638,16 @@ false + + + + 0 + 0 + 932 + 20 + + +