Skip to content

Commit

Permalink
Add New/Preview Entry Attachments dialog and functionality (#11637)
Browse files Browse the repository at this point in the history
Closes #11506
Closes #3383

* This change adds a new opportunity to add attachments that don’t require a real file in the file system.
* Add a new dialog window to add and preview attachments and integrate it into the EntryAttachmentsWidget.
* Attachment preview support for images and plain text files.

Additional enhancements:
* Fix sizing of attachment columns
* Add padding to attachment table items
* Fix targeting of preview widget styling to not impact unintended children
  • Loading branch information
w15eacre authored Jan 12, 2025
1 parent 40ee047 commit dce34de
Show file tree
Hide file tree
Showing 16 changed files with 716 additions and 46 deletions.
69 changes: 61 additions & 8 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,21 @@ This may cause the affected plugins to malfunction.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntryAttachmentsDialog</name>
<message>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>File name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>File contents...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntryAttachmentsModel</name>
<message>
Expand Down Expand Up @@ -3863,14 +3878,6 @@ This may cause the affected plugins to malfunction.</source>
<source>Remove</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Rename selected attachment</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Rename</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open selected attachment</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -3980,6 +3987,18 @@ Error: %1</source>
Would you like to overwrite the existing attachment?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Preview</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to preview an attachment: Attachment not found</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntryAttributesModel</name>
Expand Down Expand Up @@ -6349,6 +6368,25 @@ Expect some bugs and minor issues, this version is meant for testing purposes.</
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NewEntryAttachmentsDialog</name>
<message>
<source>Attachment name cannot be empty</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Attachment with the same name already exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save attachment</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New entry attachment</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NixUtils</name>
<message>
Expand Down Expand Up @@ -7114,6 +7152,21 @@ Do you want to overwrite it?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewEntryAttachmentsDialog</name>
<message>
<source>Preview entry attachment</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No preview available</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Image format not supported</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QMessageBox</name>
<message>
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ set(gui_SOURCES
gui/entry/EntryAttachmentsModel.cpp
gui/entry/EntryAttachmentsWidget.cpp
gui/entry/EntryAttributesModel.cpp
gui/entry/NewEntryAttachmentsDialog.cpp
gui/entry/PreviewEntryAttachmentsDialog.cpp
gui/entry/EntryHistoryModel.cpp
gui/entry/EntryModel.cpp
gui/entry/EntryView.cpp
Expand Down
28 changes: 28 additions & 0 deletions src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,32 @@ namespace Tools

return pattern;
}

MimeType toMimeType(const QString& mimeName)
{
static QStringList textFormats = {
"text/",
"application/json",
"application/xml",
"application/soap+xml",
"application/x-yaml",
"application/protobuf",
};
static QStringList imageFormats = {"image/"};

static auto isCompatible = [](const QString& format, const QStringList& list) {
return std::any_of(
list.cbegin(), list.cend(), [&format](const auto& item) { return format.startsWith(item); });
};

if (isCompatible(mimeName, imageFormats)) {
return MimeType::Image;
}

if (isCompatible(mimeName, textFormats)) {
return MimeType::PlainText;
}

return MimeType::Unknown;
}
} // namespace Tools
9 changes: 9 additions & 0 deletions src/core/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ namespace Tools
QVariantMap qo2qvm(const QObject* object, const QStringList& ignoredProperties = {"objectName"});

QString substituteBackupFilePath(QString pattern, const QString& databasePath);

enum class MimeType : uint8_t
{
Image,
PlainText,
Unknown
};

MimeType toMimeType(const QString& mimeName);
} // namespace Tools

#endif // KEEPASSX_TOOLS_H
21 changes: 21 additions & 0 deletions src/gui/EntryPreviewWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -325,6 +328,9 @@
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
Expand Down Expand Up @@ -409,6 +415,9 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -482,6 +491,9 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand All @@ -494,6 +506,9 @@
<property name="accessibleName">
<string>Tags list</string>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="5">
Expand All @@ -516,6 +531,9 @@
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
Expand Down Expand Up @@ -1109,6 +1127,9 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="blendIn" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down
55 changes: 55 additions & 0 deletions src/gui/entry/EntryAttachmentsDialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EntryAttachmentsDialog</class>
<widget class="QDialog" name="EntryAttachmentsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="titleEdit">
<property name="placeholderText">
<string>File name</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="errorLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">color: #FF9696</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="attachmentTextEdit">
<property name="placeholderText">
<string>File contents...</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtons">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading

0 comments on commit dce34de

Please sign in to comment.