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