1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[LocationCompleter] Sort results by last visit date

Closes #1390
This commit is contained in:
David Rosca 2014-06-17 14:55:32 +02:00
parent ac52b742b2
commit 7cbc588cc1
3 changed files with 8 additions and 38 deletions

View File

@ -46,29 +46,6 @@ void LocationCompleterModel::setCompletions(const QList<QStandardItem*> &items)
appendColumn(items);
}
void LocationCompleterModel::showMostVisited()
{
clear();
QSqlQuery query;
query.exec("SELECT id, url, title FROM history ORDER BY count DESC LIMIT 15");
while (query.next()) {
QStandardItem* item = new QStandardItem();
const QUrl url = query.value(1).toUrl();
item->setIcon(IconProvider::iconForUrl(url));
item->setText(url.toEncoded());
item->setData(query.value(0), IdRole);
item->setData(query.value(2), TitleRole);
item->setData(url, UrlRole);
item->setData(QVariant(false), BookmarkRole);
setTabPosition(item);
appendRow(item);
}
}
QSqlQuery LocationCompleterModel::createDomainQuery(const QString &text)
{
if (text.isEmpty() || text == QLatin1String("www.")) {
@ -85,7 +62,7 @@ QSqlQuery LocationCompleterModel::createDomainQuery(const QString &text)
query.append(QLatin1String("url LIKE ? OR url LIKE ? OR "));
}
query.append(QLatin1String("(url LIKE ? OR url LIKE ?) ORDER BY count DESC LIMIT 1"));
query.append(QLatin1String("(url LIKE ? OR url LIKE ?) LIMIT 1"));
QSqlQuery sqlQuery;
sqlQuery.prepare(query);
@ -125,7 +102,7 @@ QSqlQuery LocationCompleterModel::createHistoryQuery(const QString &searchString
}
}
query.append(QLatin1String("LIMIT ?"));
query.append(QLatin1String("ORDER BY date DESC LIMIT ?"));
QSqlQuery sqlQuery;
sqlQuery.prepare(query);

View File

@ -44,7 +44,6 @@ public:
explicit LocationCompleterModel(QObject* parent = 0);
void setCompletions(const QList<QStandardItem*> &items);
void showMostVisited();
static QSqlQuery createHistoryQuery(const QString &searchString, int limit, bool exactMatch = false);
static QSqlQuery createDomainQuery(const QString &text);

View File

@ -77,15 +77,9 @@ void LocationCompleterRefreshJob::slotFinished()
static bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2)
{
// Move bookmarks up
bool i1Bookmark = i1->data(LocationCompleterModel::BookmarkRole).toBool();
bool i2Bookmark = i2->data(LocationCompleterModel::BookmarkRole).toBool();
if (i1Bookmark && i2Bookmark) {
return i1->data(LocationCompleterModel::CountRole).toInt() >
i2->data(LocationCompleterModel::CountRole).toInt();
}
return i1Bookmark;
int i1Count = i1->data(LocationCompleterModel::CountRole).toInt();
int i2Count = i2->data(LocationCompleterModel::CountRole).toInt();
return i1Count > i2Count;
}
void LocationCompleterRefreshJob::runJob()
@ -121,9 +115,6 @@ void LocationCompleterRefreshJob::runJob()
}
}
// Sort by count
qSort(m_items.begin(), m_items.end(), countBiggerThan);
// Get domain completion
if (!m_searchString.isEmpty() && qzSettings->useInlineCompletion) {
QSqlQuery domainQuery = LocationCompleterModel::createDomainQuery(m_searchString);
@ -167,6 +158,9 @@ void LocationCompleterRefreshJob::completeFromHistory()
}
}
// Sort by count
qSort(m_items.begin(), m_items.end(), countBiggerThan);
// Search in history
if (showType == HistoryAndBookmarks || showType == History) {
const int historyLimit = 20;