mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-03-19 12:56:02 -04:00
Implement best matches only option with browser integration (#1822)
This commit is contained in:
parent
963ac75389
commit
48295efe0d
@ -67,7 +67,6 @@ void BrowserOptionDialog::loadSettings()
|
||||
// hide unimplemented options
|
||||
// TODO: fix this
|
||||
m_ui->showNotification->hide();
|
||||
m_ui->bestMatchOnly->hide();
|
||||
|
||||
if (settings.sortByUsername()) {
|
||||
m_ui->sortByUsername->setChecked(true);
|
||||
|
@ -530,21 +530,30 @@ QList<Entry*> BrowserService::sortEntries(QList<Entry*>& pwEntries, const QStrin
|
||||
const QString submitUrl = url.toString(QUrl::StripTrailingSlash);
|
||||
const QString baseSubmitUrl = url.toString(QUrl::StripTrailingSlash | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
|
||||
|
||||
QMultiMap<int, const Entry*> priorities;
|
||||
for (const Entry* entry : pwEntries) {
|
||||
// Build map of prioritized entries
|
||||
QMultiMap<int, Entry*> priorities;
|
||||
for (Entry* entry : pwEntries) {
|
||||
priorities.insert(sortPriority(entry, host, submitUrl, baseSubmitUrl), entry);
|
||||
}
|
||||
|
||||
QList<Entry*> results;
|
||||
QString field = BrowserSettings::sortByTitle() ? "Title" : "UserName";
|
||||
std::sort(pwEntries.begin(), pwEntries.end(), [&priorities, &field](const Entry* left, const Entry* right) {
|
||||
int res = priorities.key(left) - priorities.key(right);
|
||||
if (res == 0) {
|
||||
return QString::localeAwareCompare(left->attributes()->value(field), right->attributes()->value(field)) < 0;
|
||||
for (int i = 100; i >= 0; i -= 5) {
|
||||
if (priorities.count(i) > 0) {
|
||||
// Sort same priority entries by Title or UserName
|
||||
auto entries = priorities.values(i);
|
||||
std::sort(entries.begin(), entries.end(), [&priorities, &field](Entry* left, Entry* right) {
|
||||
return QString::localeAwareCompare(left->attributes()->value(field), right->attributes()->value(field)) < 0;
|
||||
});
|
||||
results << entries;
|
||||
if (BrowserSettings::bestMatchOnly() && !pwEntries.isEmpty()) {
|
||||
// Early out once we find the highest batch of matches
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res < 0;
|
||||
});
|
||||
}
|
||||
|
||||
return pwEntries;
|
||||
return results;
|
||||
}
|
||||
|
||||
bool BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm, const QString& url, const QString& host, const QString& submitHost, const QString& realm)
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
static bool showNotification(); //TODO!!
|
||||
static void setShowNotification(bool showNotification);
|
||||
static bool bestMatchOnly(); //TODO!!
|
||||
static bool bestMatchOnly();
|
||||
static void setBestMatchOnly(bool bestMatchOnly);
|
||||
static bool unlockDatabase();
|
||||
static void setUnlockDatabase(bool unlockDatabase);
|
||||
@ -46,7 +46,7 @@ public:
|
||||
static void setAlwaysAllowAccess(bool alwaysAllowAccess);
|
||||
static bool alwaysAllowUpdate();
|
||||
static void setAlwaysAllowUpdate(bool alwaysAllowUpdate);
|
||||
static bool searchInAllDatabases();//TODO!!
|
||||
static bool searchInAllDatabases();
|
||||
static void setSearchInAllDatabases(bool searchInAllDatabases);
|
||||
static bool supportKphFields();
|
||||
static void setSupportKphFields(bool supportKphFields);
|
||||
|
Loading…
x
Reference in New Issue
Block a user