Fix entry partial matching rules.

This commit is contained in:
Francois Ferrand 2013-05-01 12:16:17 +02:00
parent 8f33c5235b
commit 53b30e267c

View File

@ -167,7 +167,7 @@ bool Service::removeFirstDomain(QString & hostname)
return !hostname.isEmpty(); return !hostname.isEmpty();
} }
QList<Entry*> Service::searchEntries(const QString &text) QList<Entry*> Service::searchEntries(const QString& text)
{ {
QList<Entry*> entries; QList<Entry*> entries;
@ -175,19 +175,19 @@ QList<Entry*> Service::searchEntries(const QString &text)
//Search entries matching the hostname //Search entries matching the hostname
QString hostname = QUrl(text).host(); QString hostname = QUrl(text).host();
if (DatabaseWidget * dbWidget = m_dbTabWidget->currentDatabaseWidget()) if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget())
if (Database * db = dbWidget->database()) if (Database* db = dbWidget->database())
if (Group * rootGroup = db->rootGroup()) if (Group* rootGroup = db->rootGroup())
do { do {
Q_FOREACH (Entry * entry, rootGroup->search(hostname, Qt::CaseInsensitive)) { Q_FOREACH (Entry* entry, rootGroup->search(hostname, Qt::CaseInsensitive)) {
QString title = entry->title(); QString title = entry->title();
QString url = entry->url(); QString url = entry->url();
//Filter to match hostname in Title and Url fields //Filter to match hostname in Title and Url fields
if ( hostname.contains(title) if ( (!title.isEmpty() && hostname.contains(title))
|| hostname.contains(url) || (!url.isEmpty() && hostname.contains(url))
|| (matchUrlScheme(title) && hostname.contains(QUrl(title).host())) || (matchUrlScheme(title) && hostname.endsWith(QUrl(title).host()))
|| (matchUrlScheme(url) && hostname.contains(QUrl(url).host())) ) || (matchUrlScheme(url) && hostname.endsWith(QUrl(url).host())) )
entries.append(entry); entries.append(entry);
} }
} while(entries.isEmpty() && removeFirstDomain(hostname)); } while(entries.isEmpty() && removeFirstDomain(hostname));