diff --git a/CMakeLists.txt b/CMakeLists.txt index 01b7218..e86c436 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ set(REQUIRED_ICONS document-new document-open document-open-recent + document-properties document-save document-save-as edit-clear diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 2ad4a8e..aa92871 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -189,6 +189,7 @@ MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWi // -> file related actions connect(m_ui->actionSave, &QAction::triggered, this, &MainWindow::saveFile); connect(m_ui->actionExport, &QAction::triggered, this, &MainWindow::exportFile); + connect(m_ui->actionDetails, &QAction::triggered, this, &MainWindow::showFileDetails); connect(m_ui->actionShowContainingDirectory, &QAction::triggered, this, &MainWindow::showContainingDirectory); connect(m_ui->actionClose, &QAction::triggered, this, &MainWindow::closeFile); connect(m_ui->actionCreate, &QAction::triggered, this, static_cast(&MainWindow::createFile)); @@ -585,6 +586,7 @@ void MainWindow::updateUiStatus() m_ui->actionSave->setEnabled(fileOpened); m_ui->actionSaveAs->setEnabled(fileOpened); m_ui->actionExport->setEnabled(fileOpened); + m_ui->actionDetails->setEnabled(fileOpened); m_ui->actionShowContainingDirectory->setEnabled(fileOpened); m_ui->actionClose->setEnabled(fileOpened); m_ui->actionChangepassword->setEnabled(fileOpened); @@ -626,6 +628,18 @@ void MainWindow::applyDefaultExpanding(const QModelIndex &parent) } } +/*! + * \brief Returns the save options (to be) used when saving the file next time. + */ +PasswordFileSaveFlags MainWindow::saveOptions() const +{ + auto options = PasswordFileSaveFlags::Compression | PasswordFileSaveFlags::PasswordHashing; + if (!m_file.password().empty()) { + options |= PasswordFileSaveFlags::Encryption; + } + return options; +} + /*! * \brief Returns a string with the values of all selected fields. * \remarks Columns are sparated with \\t, rows with \\n. @@ -848,11 +862,7 @@ bool MainWindow::saveFile() // save the file QString msg; try { - auto flags = PasswordFileSaveFlags::Compression | PasswordFileSaveFlags::PasswordHashing; - if (!m_file.password().empty()) { - flags |= PasswordFileSaveFlags::Encryption; - } - m_file.save(flags); + m_file.save(saveOptions()); } catch (const CryptoException &ex) { msg = tr("The password list couldn't be saved due to encryption failure.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(ex.what())); } catch (...) { @@ -1264,6 +1274,14 @@ void MainWindow::showTableViewContextMenu() contextMenu.exec(QCursor::pos()); } +void MainWindow::showFileDetails() +{ + if (!m_file.isOpen()) { + return; + } + QMessageBox::information(this, tr("File details"), QString::fromStdString(m_file.summary(saveOptions()))); +} + /*! * \brief Copies the selected cells to the clipboard and clears the clipboard after \a x milli seconds again. */ diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 5a511ba..686baee 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -101,6 +101,7 @@ private slots: void showTreeViewContextMenu(); void showTableViewContextMenu(); // other + void showFileDetails(); void showContainingDirectory(); void clearClipboard(); void setSomethingChanged(); @@ -115,6 +116,7 @@ private: void updateUiStatus(); void updateWindowTitle(); void applyDefaultExpanding(const QModelIndex &parent); + Io::PasswordFileSaveFlags saveOptions() const; std::unique_ptr m_ui; Io::PasswordFile m_file; diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 8bff526..58fbcfa 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -2,14 +2,6 @@ QtGui::MainWindow - - - 0 - 0 - 848 - 444 - - Password Manager @@ -182,8 +174,8 @@ 0 0 - 848 - 21 + 513 + 30 @@ -204,6 +196,7 @@ + @@ -546,10 +539,11 @@ - + + .. - Copy selected field(s) + &Copy selected field(s) Ctrl+C @@ -557,15 +551,24 @@ - + + .. - Paste to selected field(s) + &Paste to selected field(s) Ctrl+V + + + + + + Details ... + + diff --git a/qml/main.qml b/qml/main.qml index 97123ba..c15c9f7 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -143,6 +143,16 @@ Kirigami.ApplicationWindow { "Change password for " + nativeInterface.filePath) shortcut: "Ctrl+P" }, + Kirigami.Action { + text: qsTr("Details") + enabled: nativeInterface.fileOpen + iconName: "document-properties" + onTriggered: { + leftMenu.resetMenu() + fileSummaryDialog.show() + } + shortcut: "Ctrl+I" + }, Kirigami.Action { text: nativeInterface.entryFilter.length === 0 ? qsTr("Search") : qsTr( "Adjust search") @@ -224,6 +234,23 @@ Kirigami.ApplicationWindow { } } + BasicDialog { + id: fileSummaryDialog + standardButtons: Controls.Dialog.Ok + title: qsTr("File details") + + Controls.Label { + id: fileSummaryLabel + text: "No file summary available" + textFormat: Text.RichText + } + + function show() { + fileSummaryLabel.text = nativeInterface.computeFileSummary() + this.open() + } + } + FileDialog { id: fileDialog title: selectExisting ? qsTr("Select an existing file") : qsTr( diff --git a/quickgui/controller.cpp b/quickgui/controller.cpp index 1eca0c3..7589694 100644 --- a/quickgui/controller.cpp +++ b/quickgui/controller.cpp @@ -191,7 +191,7 @@ void Controller::close() } } -void Controller::save() +PasswordFileSaveFlags Controller::prepareSaving() { auto flags = PasswordFileSaveFlags::Compression | PasswordFileSaveFlags::PasswordHashing; if (!m_password.isEmpty()) { @@ -201,7 +201,12 @@ void Controller::save() } else { m_file.clearPassword(); } + return flags; +} +void Controller::save() +{ + const auto flags = prepareSaving(); try { #if defined(Q_OS_ANDROID) && defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER) if (!m_nativeUrl.isEmpty()) { diff --git a/quickgui/controller.h b/quickgui/controller.h index 739e434..d56801a 100644 --- a/quickgui/controller.h +++ b/quickgui/controller.h @@ -100,6 +100,8 @@ public slots: void handleFileSelectionCanceled(); void undo(); void redo(); + Io::PasswordFileSaveFlags prepareSaving(); + QString computeFileSummary(); signals: void filePathChanged(const QString &newFilePath); @@ -347,6 +349,11 @@ inline void Controller::redo() #endif } +inline QString Controller::computeFileSummary() +{ + return QString::fromStdString(m_file.summary(prepareSaving())); +} + } // namespace QtGui #endif // QT_QUICK_GUI_CONTROLLER_H