From 41be9e8178fad610fa9086557c8e50e71e8addd0 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Wed, 1 May 2013 13:55:43 +0200 Subject: [PATCH] Implement option to search all open databases. --- src/http/Service.cpp | 51 +++++++++++++++++++++++++++++--------------- src/http/Service.h | 1 + 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/http/Service.cpp b/src/http/Service.cpp index 3f0b83050..fad340d07 100644 --- a/src/http/Service.cpp +++ b/src/http/Service.cpp @@ -181,30 +181,47 @@ bool Service::removeFirstDomain(QString & hostname) return !hostname.isEmpty(); } -QList Service::searchEntries(const QString& text) +QList Service::searchEntries(Database* db, const QString& hostname) { QList entries; + if (Group* rootGroup = db->rootGroup()) + Q_FOREACH (Entry* entry, rootGroup->search(hostname, Qt::CaseInsensitive)) { + QString title = entry->title(); + QString url = entry->url(); - //TODO: setting to search all databases [e.g. as long as the 'current' db is authentified + //Filter to match hostname in Title and Url fields + if ( (!title.isEmpty() && hostname.contains(title)) + || (!url.isEmpty() && hostname.contains(url)) + || (matchUrlScheme(title) && hostname.endsWith(QUrl(title).host())) + || (matchUrlScheme(url) && hostname.endsWith(QUrl(url).host())) ) + entries.append(entry); + } + return entries; +} + +QList Service::searchEntries(const QString& text) +{ + //Get the list of databases to search + QList databases; + if (HttpSettings::searchInAllDatabases()) { + for (int i = 0; i < m_dbTabWidget->count(); i++) + if (DatabaseWidget* dbWidget = qobject_cast(m_dbTabWidget->widget(i))) + if (Database* db = dbWidget->database()) + databases << db; + } + else if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget()) { + if (Database* db = dbWidget->database()) + databases << db; + } //Search entries matching the hostname QString hostname = QUrl(text).host(); - if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget()) - if (Database* db = dbWidget->database()) - if (Group* rootGroup = db->rootGroup()) - do { - Q_FOREACH (Entry* entry, rootGroup->search(hostname, Qt::CaseInsensitive)) { - QString title = entry->title(); - QString url = entry->url(); + QList entries; + do { + Q_FOREACH (Database* db, databases) + entries << searchEntries(db, hostname); + } while(entries.isEmpty() && removeFirstDomain(hostname)); - //Filter to match hostname in Title and Url fields - if ( (!title.isEmpty() && hostname.contains(title)) - || (!url.isEmpty() && hostname.contains(url)) - || (matchUrlScheme(title) && hostname.endsWith(QUrl(title).host())) - || (matchUrlScheme(url) && hostname.endsWith(QUrl(url).host())) ) - entries.append(entry); - } - } while(entries.isEmpty() && removeFirstDomain(hostname)); return entries; } diff --git a/src/http/Service.h b/src/http/Service.h index a9b7bd0e1..04d1188fe 100644 --- a/src/http/Service.h +++ b/src/http/Service.h @@ -52,6 +52,7 @@ private: class SortEntries; int sortPriority(const Entry *entry, const QString &host, const QString &submitUrl, const QString &baseSubmitUrl) const; KeepassHttpProtocol::Entry prepareEntry(const Entry* entry); + QList searchEntries(Database* db, const QString& hostname); QList searchEntries(const QString& text); DatabaseTabWidget * const m_dbTabWidget;