Add file details

This commit is contained in:
Martchus 2018-12-21 01:14:41 +01:00
parent d2b096bfda
commit 75075725a6
7 changed files with 83 additions and 20 deletions

View File

@ -106,6 +106,7 @@ set(REQUIRED_ICONS
document-new
document-open
document-open-recent
document-properties
document-save
document-save-as
edit-clear

View File

@ -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<bool (MainWindow::*)(void)>(&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.
*/

View File

@ -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<Ui::MainWindow> m_ui;
Io::PasswordFile m_file;

View File

@ -2,14 +2,6 @@
<ui version="4.0">
<class>QtGui::MainWindow</class>
<widget class="QMainWindow" name="QtGui::MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>848</width>
<height>444</height>
</rect>
</property>
<property name="windowTitle">
<string>Password Manager</string>
</property>
@ -182,8 +174,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>848</width>
<height>21</height>
<width>513</width>
<height>30</height>
</rect>
</property>
<widget class="QMenu" name="menuProgramm">
@ -204,6 +196,7 @@
<addaction name="actionSaveAs"/>
<addaction name="actionExport"/>
<addaction name="actionShowContainingDirectory"/>
<addaction name="actionDetails"/>
<addaction name="actionAlwaysCreateBackup"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
@ -546,10 +539,11 @@
</action>
<action name="actionCopyFields">
<property name="icon">
<iconset theme="edit-copy"/>
<iconset theme="edit-copy">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Copy selected field(s)</string>
<string>&amp;Copy selected field(s)</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
@ -557,15 +551,24 @@
</action>
<action name="actionPasteFields">
<property name="icon">
<iconset theme="edit-paste"/>
<iconset theme="edit-paste">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Paste to selected field(s)</string>
<string>&amp;Paste to selected field(s)</string>
</property>
<property name="shortcut">
<string>Ctrl+V</string>
</property>
</action>
<action name="actionDetails">
<property name="icon">
<iconset theme="document-properties"/>
</property>
<property name="text">
<string>Details ...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View File

@ -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(

View File

@ -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()) {

View File

@ -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