Implement option to search all open databases.

This commit is contained in:
Francois Ferrand 2013-05-01 13:55:43 +02:00
parent be24872bba
commit 41be9e8178
2 changed files with 35 additions and 17 deletions

View File

@ -181,30 +181,47 @@ bool Service::removeFirstDomain(QString & hostname)
return !hostname.isEmpty();
}
QList<Entry*> Service::searchEntries(const QString& text)
QList<Entry*> Service::searchEntries(Database* db, const QString& hostname)
{
QList<Entry*> 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<Entry*> Service::searchEntries(const QString& text)
{
//Get the list of databases to search
QList<Database*> databases;
if (HttpSettings::searchInAllDatabases()) {
for (int i = 0; i < m_dbTabWidget->count(); i++)
if (DatabaseWidget* dbWidget = qobject_cast<DatabaseWidget*>(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<Entry*> 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;
}

View File

@ -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<Entry*> searchEntries(Database* db, const QString& hostname);
QList<Entry*> searchEntries(const QString& text);
DatabaseTabWidget * const m_dbTabWidget;