Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorPatrick Sean Klein <patrick@libklein.com>2021-10-24 18:20:04 +0300
committerJonathan White <support@dmapps.us>2021-10-25 06:41:57 +0300
commit20db504c3af80a5765afa66824dc3e69c1a0bb59 (patch)
tree887f85ff10b01d1236e1414aaef3b6987dc7b549 /src/gui
parent55f2bd41aaa42ad604a3d79d0f3d82eac8ea7ca0 (diff)
Implement "Overwrite attachment" confirmation dialog.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/entry/EntryAttachmentsWidget.cpp48
-rw-r--r--src/gui/entry/EntryAttachmentsWidget.h2
2 files changed, 33 insertions, 17 deletions
diff --git a/src/gui/entry/EntryAttachmentsWidget.cpp b/src/gui/entry/EntryAttachmentsWidget.cpp
index aeed9f4d2..33c97df96 100644
--- a/src/gui/entry/EntryAttachmentsWidget.cpp
+++ b/src/gui/entry/EntryAttachmentsWidget.cpp
@@ -152,7 +152,7 @@ void EntryAttachmentsWidget::insertAttachments()
if (filenames.isEmpty()) {
return;
}
- const auto confirmedFileNames = confirmLargeAttachments(filenames);
+ const auto confirmedFileNames = confirmAttachmentSelection(filenames);
if (confirmedFileNames.isEmpty()) {
return;
}
@@ -342,28 +342,44 @@ bool EntryAttachmentsWidget::insertAttachments(const QStringList& filenames, QSt
return errors.isEmpty();
}
-QStringList EntryAttachmentsWidget::confirmLargeAttachments(const QStringList& filenames)
+QStringList EntryAttachmentsWidget::confirmAttachmentSelection(const QStringList& filenames)
{
- const QString confirmation(tr("%1 is a big file (%2 MB).\nYour database may get very large and reduce "
- "performance.\n\nAre you sure to add this file?"));
QStringList confirmedFileNames;
for (const auto& file : filenames) {
- QFileInfo fileInfo(file);
- double size = fileInfo.size() / (1024.0 * 1024.0);
- // Ask for confirmation before adding files over 5 MB in size
- if (size > 5.0) {
- auto fileName = fileInfo.fileName();
+ const QFileInfo fileInfo(file);
+ auto fileName = fileInfo.fileName();
+
+ // Ask for confirmation if overwriting an existing attachment
+ if (m_entryAttachments->hasKey(fileName)) {
auto result = MessageBox::question(this,
- tr("Confirm Attachment"),
- confirmation.arg(fileName, QString::number(size, 'f', 1)),
- MessageBox::Yes | MessageBox::No,
+ tr("Confirm Overwrite Attachment"),
+ tr("Attachment \"%1\" already exists. \n"
+ "Would you like to overwrite the existing attachment?")
+ .arg(fileName),
+ MessageBox::Overwrite | MessageBox::No,
MessageBox::No);
- if (result == MessageBox::Yes) {
- confirmedFileNames << file;
+ if (result == MessageBox::No) {
+ continue;
+ }
+ }
+
+ // Ask for confirmation before adding files over 5 MB in size
+ double size = fileInfo.size() / (1024.0 * 1024.0);
+ if (size > 5.0) {
+ auto result =
+ MessageBox::question(this,
+ tr("Confirm Attachment"),
+ tr("%1 is a big file (%2 MB).\nYour database may get very large and reduce "
+ "performance.\n\nAre you sure to add this file?")
+ .arg(fileName, QString::number(size, 'f', 1)),
+ MessageBox::Yes | MessageBox::No,
+ MessageBox::No);
+ if (result == MessageBox::No) {
+ continue;
}
- } else {
- confirmedFileNames << file;
}
+
+ confirmedFileNames << file;
}
return confirmedFileNames;
diff --git a/src/gui/entry/EntryAttachmentsWidget.h b/src/gui/entry/EntryAttachmentsWidget.h
index 53d5076e2..9d64ed31b 100644
--- a/src/gui/entry/EntryAttachmentsWidget.h
+++ b/src/gui/entry/EntryAttachmentsWidget.h
@@ -69,7 +69,7 @@ private slots:
private:
bool insertAttachments(const QStringList& fileNames, QString& errorMessage);
- QStringList confirmLargeAttachments(const QStringList& filenames);
+ QStringList confirmAttachmentSelection(const QStringList& filenames);
bool eventFilter(QObject* watched, QEvent* event) override;