Improve entry attachments view#1298
Conversation
src/gui/DetailsWidget.ui
Outdated
| <widget class="QTabWidget" name="tabWidget"> | ||
| <property name="currentIndex"> | ||
| <number>0</number> | ||
| <number>4</number> |
There was a problem hiding this comment.
Revert this to 0. QtCreator mixed this up
There was a problem hiding this comment.
Maybe it is better to activate the first tab in the constructor (to not depend on the form state)?
There was a problem hiding this comment.
I think the currentIndex is needed in the xml anyway, just set it to 0 so we don't add extra code for it
tests/TestEntryModel.cpp
Outdated
|
|
||
| entryAttachments->set("2nd", QByteArray("456")); | ||
| entryAttachments->set("2nd", QByteArray("789")); | ||
| entryAttachments->set("2nd", QByteArray("7895")); |
There was a problem hiding this comment.
Сhanged to have different size ("456" - 3 bytes, "7895" - 4 bytes, I check the size in the next lines). This is not critical, I can remove the changes.
There was a problem hiding this comment.
Just to be consistent with the 123-456-789 can you replace the final 5 with a 0 ?
Merely style reasons
src/gui/DetailsWidget.cpp
Outdated
| } | ||
| } | ||
|
|
||
| void DetailsWidget::openAttachment(const QModelIndex& index) |
There was a problem hiding this comment.
Can't we use the openAttachment from the EditEntryWidget class? Or alternatively declaring it static in a different class and point both of them to the static one? This is just repeated code and I would like to leave the detailsWidget light
There was a problem hiding this comment.
Agree with you. I'll fix it tonight.
There was a problem hiding this comment.
@TheZ3ro perhaps it is better to create a separate widget to display/edit the attachments. With the functionality of adding, deleting and opening files (which can be turned off in the details view).
There was a problem hiding this comment.
It's fine opening files from the details view, it's the extra code that I don't really like.
Making a separate widget and import it will be very nice and convenient
149b117 to
8f8aea4
Compare
|
@TheZ3ro I added a widget to edit/view the attachments |
70749c4 to
35e3670
Compare
35e3670 to
a80e078
Compare
|
@TheZ3ro I rebase changes on top of the develop branch ;) |
|
@frostasm this is great, good work! |
|
This is working fine and ready to merge, waiting someone else review, ping @keepassxreboot/core-developers Nice PR follow-up idea: add keyboard actions for enter and cancel keys for open and remove attachments |
|
@fonic thank you :)
@TheZ3ro good idea. What keyboard shortcuts would be helpful for each role?
Possible improvements:
I have free time on the weekends and can implement the described proposal. |
|
@frostasm can you report those proposal in a new issue? So we can track them for a new PR. |
|
@TheZ3ro okay 👍 |
|
@droidmonkey can you review the changes? |
|
Probably not for a while |
| if (m_ui->tabWidget->count() < 4) { | ||
| m_ui->tabWidget->insertTab(static_cast<int>(AttributesTab), m_attributesWidget, "Attributes"); | ||
| m_ui->tabWidget->insertTab(static_cast<int>(AutotypeTab), m_autotypeWidget, "Autotype"); | ||
| if (m_ui->tabWidget->count() < 5) { |
There was a problem hiding this comment.
Can we somehow get rid of this hard-coded number? Maybe create a vector first and use its length or so. Or maybe even clear the tab widget and re-add stuff every time. This number looks awfully easy to overlook.
There was a problem hiding this comment.
I completely agree with you about the magic numbers. I think it is necessary to refactor DetailsWidget in another pull request. I can do that after this changes will be merged. If you don't mind.
There was a problem hiding this comment.
I think it would be enough to simply clear out the widget and add stuff as needed (I guess it's unlikely that this would impact performance massively).
src/gui/DetailsWidget.cpp
Outdated
| if (m_ui->tabWidget->count() < 5) { | ||
| m_ui->tabWidget->insertTab(static_cast<int>(AttributesTab), m_attributesTabWidget, "Attributes"); | ||
| m_ui->tabWidget->insertTab(static_cast<int>(AttachmentsTab), m_attachmentsTabWidget, "Attachments"); | ||
| m_ui->tabWidget->insertTab(static_cast<int>(AutotypeTab), m_autotypeTabWidget, "Autotype"); |
There was a problem hiding this comment.
All three tab labels need to be translatable.
| @@ -209,9 +226,8 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup) | |||
| m_ui->stackedWidget->setCurrentIndex(GroupPreview); | |||
There was a problem hiding this comment.
A general note about getSelectedEntry and getSelected group: I know this is not your code, but these methods shouldn't be called get<WHATEVER> if they have side-effects.
| @@ -209,9 +226,8 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup) | |||
| m_ui->stackedWidget->setCurrentIndex(GroupPreview); | |||
|
|
|||
| if (m_ui->tabWidget->count() > 2) { | |||
There was a problem hiding this comment.
See comment above about magic numbers. At this point I would actually prefer clearing out the tab widget and re-adding needed items unconditionally.
| m_attachmentsModel->setEntryAttachments(m_entryAttachments); | ||
| m_ui->attachmentsView->setModel(m_attachmentsModel); | ||
| m_ui->attachmentsView->horizontalHeader()->setStretchLastSection(true); | ||
| m_ui->attachmentsView->horizontalHeader()->resizeSection(EntryAttachmentsModel::NameColumn, 400); |
There was a problem hiding this comment.
I would prefer if you disabled row numbers here. They make the table look like a spreadsheet.
|
|
||
| bool eventFilter(QObject* watched, QEvent* event) override; | ||
|
|
||
| Ui::EntryAttachmentsWidget* m_ui; |
There was a problem hiding this comment.
Use QScopedPointer and remove delete from destructor.
|
|
||
| Ui::EntryAttachmentsWidget* m_ui; | ||
| EntryAttachments* m_entryAttachments; | ||
| EntryAttachmentsModel* const m_attachmentsModel; |
There was a problem hiding this comment.
These two should be QPointers.
There was a problem hiding this comment.
I think that it is not necessary, they are only used internally (they are not re-assigned in the process of work)
There was a problem hiding this comment.
No, but it also doesn't hurt anybody and may catch errors further down the road. Who knows where these objects are used in 5 months...
There was a problem hiding this comment.
BTW I really only mean QPointers, not QSharedPointers or QScopedPointers. QPointers simply guard the pointer and reset to 0 if the QObject is deallocated. They don't count references or own anything and they can be converted to and from raw pointers.
| return errors.isEmpty(); | ||
| } | ||
|
|
||
| bool EntryAttachmentsWidget::openAttachment(const QModelIndex& index, QString* errorMessage) |
There was a problem hiding this comment.
non-const reference for errorMessage instead of pointer to QString.
| <width>400</width> | ||
| <height>366</height> | ||
| <width>448</width> | ||
| <height>370</height> |
There was a problem hiding this comment.
You should completely remove widget sizes here (click the little reset button in QtDesigner's property view).
| <x>0</x> | ||
| <y>0</y> | ||
| <width>589</width> | ||
| <height>300</height> |
3065eb8 to
adef56e
Compare
adef56e to
2045342
Compare
|
@phoerious thanks for the detailed review 👍. About magic numbers and bad function names. If you don't mind, I would refactor this widget in my next PR. Because current pull request relate only to the introduction of the new functionality and not to the refactoring of the existing one. |
|
Ok, fair enough. Just don't forget about it. |
097c67b to
accb902
Compare
|
@phoerious I think I finished :D |
phoerious
left a comment
There was a problem hiding this comment.
Just one follow-up request, rest looks fab.
| if (role == Qt::DisplayRole) { | ||
| const QString key = keyByIndex(index); | ||
| switch (column) { | ||
| case Columns::NameColumn: |
There was a problem hiding this comment.
I would replace the inner switch/case statements with if/else if as well. Perhaps even flatten this structure to a single level, since DisplayRole && NameColumn have the same action as EditRole && NameColumn, so it can be reduced to a single condition. DisplayRole && SizeColumn and EditRole && SizeColumn are also very similar, so they could be reduced to a return guard and another return if the previous condition wasn't met.
There was a problem hiding this comment.
Much nicer and shorter. Thanks.
accb902 to
4721c9f
Compare
4721c9f to
80636ab
Compare
|
@phoerious @TheZ3ro thanks :) |
|
Well, thank you. 😄 |
- Add support for KDBX 4.0, Argon2 and ChaCha20 [#148, #1179, #1230, #1494] - Add SSH Agent feature [#1098, #1450, #1463] - Add preview panel with details of the selected entry [#879, #1338] - Add more and configurable columns to entry table and allow copying of values by double click [#1305] - Add KeePassXC-Browser API as a replacement for KeePassHTTP [#608] - Deprecate KeePassHTTP [#1392] - Add support for Steam one-time passwords [#1206] - Add support for multiple Auto-Type sequences for a single entry [#1390] - Adjust YubiKey HMAC-SHA1 challenge-response key generation for KDBX 4.0 [#1060] - Replace qHttp with cURL for website icon downloads [#1460] - Remove lock file [#1231] - Add option to create backup file before saving [#1385] - Ask to save a generated password before closing the entry password generator [#1499] - Resolve placeholders recursively [#1078] - Add Auto-Type button to the toolbar [#1056] - Improve window focus handling for Auto-Type dialogs [#1204, #1490] - Auto-Type dialog and password generator can now be exited with ESC [#1252, #1412] - Add optional dark tray icon [#1154] - Add new "Unsafe saving" option to work around saving problems with file sync services [#1385] - Add IBus support to AppImage and additional image formats to Windows builds [#1534, #1537] - Add diceware password generator to CLI [#1406] - Add --key-file option to CLI [#816, #824] - Add DBus interface for opening and closing KeePassXC databases [#283] - Add KDBX compression options to database settings [#1419] - Discourage use of old fixed-length key files in favor of arbitrary files [#1326, #1327] - Correct reference resolution in entry fields [#1486] - Fix window state and recent databases not being remembered on exit [#1453] - Correct history item generation when configuring TOTP for an entry [#1446] - Correct multiple TOTP bugs [#1414] - Automatic saving after every change is now a default [#279] - Allow creation of new entries during search [#1398] - Correct menu issues on macOS [#1335] - Allow compilation on OpenBSD [#1328] - Improve entry attachments view [#1139, #1298] - Fix auto lock for Gnome and Xfce [#910, #1249] - Don't remember key files in file dialogs when the setting is disabled [#1188] - Improve database merging and conflict resolution [#807, #1165] - Fix macOS pasteboard issues [#1202] - Improve startup times on some platforms [#1205] - Hide the notes field by default [#1124] - Toggle main window by clicking tray icon with the middle mouse button [#992] - Fix custom icons not copied over when databases are merged [#1008] - Allow use of DEL key to delete entries [#914] - Correct intermittent crash due to stale history items [#1527] - Sanitize newline characters in title, username and URL fields [#1502] - Reopen previously opened databases in correct order [#774] - Use system's zxcvbn library if available [#701] - Implement various i18n improvements [#690, #875, #1436]
Improve entry attachments view.
Description
Motivation and context
In my opinion, the tableview more user friendly than a listview.
How has this been tested?
Manually.
Screenshots (if appropriate):
EditEntryWidget
Details view
Types of changes
Checklist:
-DWITH_ASAN=ON. [REQUIRED]