mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Smarter address bar completer now shows better search results
- thanks to Franz Fellner closes #506
This commit is contained in:
parent
bca8d9b5f3
commit
6e3d7d581b
@ -11,9 +11,11 @@ Version 1.3.5
|
|||||||
* Save x as ... actions will always show file dialog
|
* Save x as ... actions will always show file dialog
|
||||||
* possibility to choose to use external download manager on every download
|
* possibility to choose to use external download manager on every download
|
||||||
* remember last section in preferences
|
* remember last section in preferences
|
||||||
|
* smarter address bar completer will show better search results
|
||||||
* new User Agent manager lets you set User Agent per site
|
* new User Agent manager lets you set User Agent per site
|
||||||
* new restore session page lets you choose which tabs you want to restore
|
* new restore session page lets you choose which tabs you want to restore
|
||||||
* new scheme handler for file protocol allows browsing through directories
|
* new scheme handler for file protocol allows browsing through directories
|
||||||
|
* new option to show loading progress in address bar
|
||||||
* fixed visibility of navigation bar in fullscreen
|
* fixed visibility of navigation bar in fullscreen
|
||||||
* fixed bad position of add tab button when there is a lot of tabs
|
* fixed bad position of add tab button when there is a lot of tabs
|
||||||
* fixed gui with RTL languages
|
* fixed gui with RTL languages
|
||||||
|
@ -46,15 +46,10 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
|
|||||||
Type showType = (Type) qzSettings->showLocationSuggestions;
|
Type showType = (Type) qzSettings->showLocationSuggestions;
|
||||||
|
|
||||||
int limit = string.size() < 3 ? 25 : 15;
|
int limit = string.size() < 3 ? 25 : 15;
|
||||||
QString searchString = QString("%%1%").arg(string);
|
|
||||||
QList<QUrl> urlList;
|
QList<QUrl> urlList;
|
||||||
QSqlQuery query;
|
|
||||||
|
|
||||||
if (showType == HistoryAndBookmarks || showType == Bookmarks) {
|
if (showType == HistoryAndBookmarks || showType == Bookmarks) {
|
||||||
query.prepare("SELECT id, url, title, icon FROM bookmarks WHERE title LIKE ? OR url LIKE ? LIMIT ?");
|
QSqlQuery query = createQuery(string, QString(), limit, true, false);
|
||||||
query.addBindValue(searchString);
|
|
||||||
query.addBindValue(searchString);
|
|
||||||
query.addBindValue(limit);
|
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
while (query.next()) {
|
while (query.next()) {
|
||||||
@ -66,6 +61,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
|
|||||||
item->setData(query.value(0), IdRole);
|
item->setData(query.value(0), IdRole);
|
||||||
item->setData(query.value(2), TitleRole);
|
item->setData(query.value(2), TitleRole);
|
||||||
item->setData(QVariant(true), BookmarkRole);
|
item->setData(QVariant(true), BookmarkRole);
|
||||||
|
item->setData(string, SearchStringRole);
|
||||||
appendRow(item);
|
appendRow(item);
|
||||||
urlList.append(url);
|
urlList.append(url);
|
||||||
}
|
}
|
||||||
@ -74,10 +70,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showType == HistoryAndBookmarks || showType == History) {
|
if (showType == HistoryAndBookmarks || showType == History) {
|
||||||
query.prepare("SELECT id, url, title FROM history WHERE title LIKE ? OR url LIKE ? ORDER BY count DESC LIMIT ?");
|
QSqlQuery query = createQuery(string, "count DESC", limit, false, false);
|
||||||
query.addBindValue(searchString);
|
|
||||||
query.addBindValue(searchString);
|
|
||||||
query.addBindValue(limit);
|
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
while (query.next()) {
|
while (query.next()) {
|
||||||
@ -93,6 +86,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
|
|||||||
item->setData(query.value(0), IdRole);
|
item->setData(query.value(0), IdRole);
|
||||||
item->setData(query.value(2), TitleRole);
|
item->setData(query.value(2), TitleRole);
|
||||||
item->setData(QVariant(false), BookmarkRole);
|
item->setData(QVariant(false), BookmarkRole);
|
||||||
|
item->setData(string, SearchStringRole);
|
||||||
|
|
||||||
appendRow(item);
|
appendRow(item);
|
||||||
}
|
}
|
||||||
@ -119,3 +113,54 @@ void LocationCompleterModel::showMostVisited()
|
|||||||
appendRow(item);
|
appendRow(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSqlQuery LocationCompleterModel::createQuery(QString searchString, QString orderBy, int limit, bool bookmarks, bool exactMatch)
|
||||||
|
{
|
||||||
|
QString query = "SELECT id, url, title";
|
||||||
|
QStringList searchList;
|
||||||
|
|
||||||
|
if (bookmarks) {
|
||||||
|
query.append(", icon FROM bookmarks ");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
query.append(" FROM history ");
|
||||||
|
}
|
||||||
|
|
||||||
|
query.append("WHERE ");
|
||||||
|
if (exactMatch) {
|
||||||
|
query.append("title LIKE ? OR url LIKE ? ");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
searchList = searchString.split(' ', QString::SkipEmptyParts);
|
||||||
|
const int slSize = searchList.size();
|
||||||
|
for (int i = 0; i < slSize; ++i) {
|
||||||
|
query.append("(title LIKE ? OR url LIKE ?) ");
|
||||||
|
if (i < slSize - 1) {
|
||||||
|
query.append("AND ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!orderBy.isEmpty()) {
|
||||||
|
query.append("ORDER BY " + orderBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.append(" LIMIT ?");
|
||||||
|
|
||||||
|
QSqlQuery sqlQuery;
|
||||||
|
sqlQuery.prepare(query);
|
||||||
|
|
||||||
|
if (exactMatch) {
|
||||||
|
sqlQuery.addBindValue(QString("%%1%").arg(searchString));
|
||||||
|
sqlQuery.addBindValue(QString("%%1%").arg(searchString));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach(const QString & str, searchList) {
|
||||||
|
sqlQuery.addBindValue(QString("%%1%").arg(str));
|
||||||
|
sqlQuery.addBindValue(QString("%%1%").arg(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlQuery.addBindValue(limit);
|
||||||
|
|
||||||
|
return sqlQuery;
|
||||||
|
}
|
||||||
|
@ -20,13 +20,16 @@
|
|||||||
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
|
class QSqlQuery;
|
||||||
|
|
||||||
class LocationCompleterModel : public QStandardItemModel
|
class LocationCompleterModel : public QStandardItemModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Role {
|
enum Role {
|
||||||
TitleRole = Qt::UserRole + 1,
|
TitleRole = Qt::UserRole + 1,
|
||||||
BookmarkRole = Qt::UserRole + 2,
|
BookmarkRole = Qt::UserRole + 2,
|
||||||
IdRole = Qt::UserRole + 3
|
IdRole = Qt::UserRole + 3,
|
||||||
|
SearchStringRole = Qt::UserRole + 4
|
||||||
};
|
};
|
||||||
explicit LocationCompleterModel(QObject* parent = 0);
|
explicit LocationCompleterModel(QObject* parent = 0);
|
||||||
|
|
||||||
@ -42,9 +45,11 @@ private:
|
|||||||
HistoryAndBookmarks = 0,
|
HistoryAndBookmarks = 0,
|
||||||
History = 1,
|
History = 1,
|
||||||
Bookmarks = 2,
|
Bookmarks = 2,
|
||||||
Nothing = 3
|
Nothing = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QSqlQuery createQuery(QString searchString, QString orderBy, int limit, bool bookmarks, bool exactMatch);
|
||||||
|
|
||||||
QString m_lastCompletion;
|
QString m_lastCompletion;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user