Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple autotype sequences for a single entry #1390

Merged
merged 9 commits into from
Feb 5, 2018

Conversation

TheZ3ro
Copy link
Contributor

@TheZ3ro TheZ3ro commented Jan 16, 2018

Description

This PR:

Motivation and context

Fixes #559

How has this been tested?

Manually and with make tests

Screenshots (if appropriate):

istantanea_2018-01-16_22-04-43
istantanea_2018-01-19_00-52-21

Types of changes

  • ✅ New feature (non-breaking change which adds functionality)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]
  • ✅ I have added tests to cover my changes.

@TheZ3ro TheZ3ro added this to the v2.3.0 milestone Jan 16, 2018
@TheZ3ro TheZ3ro requested a review from a team January 16, 2018 21:11
@TheZ3ro
Copy link
Contributor Author

TheZ3ro commented Jan 18, 2018

Ready for review 🏁

@TheZ3ro TheZ3ro force-pushed the feature/multiple-autotype-matches branch from 1c3bf07 to 354727c Compare January 24, 2018 21:50
@weslly weslly self-requested a review January 25, 2018 18:15
{
if (m_executor) {
delete m_executor;
m_executor = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change m_executor to a QPointer and remove nullptr assignments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AutoTypeExecutor doesn't inherit from QObject so you can't use QPointer here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any strong objections against changing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that this triggers some error with the linker

I would prefer changing this in a follow up PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't cause linker errors.

m_currentGlobalKey = key;
m_currentGlobalModifiers = modifiers;
return true;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop redundant else.

return true;
} else {
return false;
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

}

QList<QString> sequences = autoTypeSequences(entry);
if(sequences.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if.

entryList << entry;
sequenceHash.insert(entry, sequence);
const QList<QString> sequences = autoTypeSequences(entry, windowTitle);
for (QString sequence : sequences) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QString&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a QList<QString>, adding & trigger this compiler error error: binding ‘const QString’ to reference of type ‘QString&’ discards qualifiers

Copy link
Member

@phoerious phoerious Jan 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, well. const QString& it is then. ;-)

protected:
void keyPressEvent(QKeyEvent* event) override;

private Q_SLOTS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slots

@@ -170,8 +170,7 @@ void EditEntryWidget::setupAutoType()

m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->inheritSequenceButton);
m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->customSequenceButton);
m_autoTypeWindowSequenceGroup->addButton(m_autoTypeUi->defaultWindowSequenceButton);
m_autoTypeWindowSequenceGroup->addButton(m_autoTypeUi->customWindowSequenceButton);
//m_autoTypeWindowSequenceGroup->addButton(m_autoTypeUi->customWindowSequenceButton);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

QString sequenceDisabled("{TEST_DISABLED}");
QString sequenceOrphan("{TEST_ORPHAN}");

Database* db = new Database();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QScopedPointer

return;
Q_ASSERT(m_inAutoType);

m_inAutoType = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a QMutex, which is tried with tryLock().

return;
}

m_inAutoType = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When changed to a QMutex, use a QMutexLocker here.

@TheZ3ro TheZ3ro force-pushed the feature/multiple-autotype-matches branch 2 times, most recently from d9f4ca8 to 0f42bfb Compare January 29, 2018 18:46
@weslly
Copy link
Contributor

weslly commented Jan 30, 2018

@TheZ3ro It duplicates the entry item if I click 'Cancel' and call the auto-type dialog again:

screen shot 2018-01-30 at 7 35 28 pm

For some reason it doesn't happen on some entries.

EDIT: It seems to be happening on entries with another cloned entry in the recycle bin, even though the entry title is different.

@TheZ3ro
Copy link
Contributor Author

TheZ3ro commented Jan 30, 2018

@weslly I can't reproduce it on GNU/Linux. Cloned a bunch of entry, deleted some of them, still no duplicate when clicking on "Cancel".
Can you check out if the "Recycle Bin" group has autotype disabled?

@weslly
Copy link
Contributor

weslly commented Jan 31, 2018

@TheZ3ro I tried with a new database with only one entry and without the recycle bin group and still got it (this time on the 1st attempt, without canceling first):

image

@TheZ3ro
Copy link
Contributor Author

TheZ3ro commented Jan 31, 2018

@weslly Ok, I've sort it out.

If you have the MatchTitle and MatchURL option enabled, in some cases you will end up with 2 or even 3 repeated sequence since:

  • First sequence comes from matching entry Title with window-Title
  • Second sequence comes from matching entry URL with window-Title
  • Eventually, a third sequence comes from window association

Using a QSet is a viable option, duplicated sequences won't be inserted

@TheZ3ro TheZ3ro force-pushed the feature/multiple-autotype-matches branch from 0f42bfb to a9b9575 Compare January 31, 2018 20:55
@weslly
Copy link
Contributor

weslly commented Feb 1, 2018

@TheZ3ro the duplicate sequence bug is fixed now but I noticed the window no longer activates after selecting the entry on macOS (it does work on linux though). Probably raiseLastActiveWindow isn't working correctly.

I'll try to find what's causing this.

@phoerious phoerious changed the base branch from develop to release/2.3.0 February 1, 2018 20:41
@weslly
Copy link
Contributor

weslly commented Feb 1, 2018

@TheZ3ro actually the window activates after selecting the auto-type entry, but only if I click it with the mouse. If I just press enter to get the 1st item it closes the window without performing the sequence.

@@ -56,21 +58,20 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
QLabel* descriptionLabel = new QLabel(tr("Select entry to Auto-Type:"), this);
layout->addWidget(descriptionLabel);

connect(m_view, SIGNAL(activated(QModelIndex)), SLOT(emitEntryActivated(QModelIndex)));
connect(m_view, SIGNAL(clicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex)));
connect(m_view, SIGNAL(activated(QModelIndex)), SLOT(emitMatchActivated(QModelIndex)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This signal is being completely ignored on macOS. This may be the reason, but I have no idea why it worked before:

https://stackoverflow.com/questions/31650780/when-does-a-qtreeview-emit-the-activated-signal-on-mac

@@ -82,20 +83,20 @@ void AutoTypeSelectDialog::done(int r)
QDialog::done(r);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs a keyPressEvent() method to catch the return/enter key on macOS and emit the activated signal:

image

Copy link
Contributor Author

@TheZ3ro TheZ3ro Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely enought, this is already implemented in the EntryView class

void EntryView::keyPressEvent(QKeyEvent* event)

The EntryView (on Mac) it's emitting the activated signal and the autotypeSelectDialog is connected to it. I don't see why it's not working 🤔

Edit: got it, preparing the fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: Now I've figure out why it worked before. Now the signal it's called emitMatchActivated and the EntryView is emitting the emitEntryActivated one :D

@TheZ3ro nice!

@TheZ3ro TheZ3ro force-pushed the feature/multiple-autotype-matches branch from a9b9575 to aa54c7b Compare February 4, 2018 22:33
@TheZ3ro
Copy link
Contributor Author

TheZ3ro commented Feb 4, 2018

@weslly opted for a different fix, can you test it out?

@weslly
Copy link
Contributor

weslly commented Feb 4, 2018

@TheZ3ro just tested, working fine now :)

@TheZ3ro TheZ3ro merged commit 4206fd9 into release/2.3.0 Feb 5, 2018
@TheZ3ro TheZ3ro deleted the feature/multiple-autotype-matches branch February 5, 2018 10:09
phoerious added a commit that referenced this pull request Feb 27, 2018
- 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants