1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

LocationCompleter: Bookmarks results are now ordered by count

This commit is contained in:
nowrep 2012-09-02 15:19:12 +02:00
parent cff5fce5da
commit ec70c7d43d
12 changed files with 114 additions and 46 deletions

View File

@ -29,6 +29,8 @@
ProfileUpdater::ProfileUpdater(const QString &profilePath)
: m_profilePath(profilePath)
{
// FIXME: Remove this line when releasing new version
update131();
}
void ProfileUpdater::checkProfile()
@ -69,55 +71,28 @@ void ProfileUpdater::updateProfile(const QString &current, const QString &profil
if (profileVersion == Updater::parseVersionFromString("1.0.0-b4")) {
update100b4();
update100rc1();
update100();
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.0.0-rc1")) {
update100rc1();
update100();
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.0.0")) {
update100();
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.1.0")) {
if (profileVersion == Updater::parseVersionFromString("1.1.0") ||
profileVersion == Updater::parseVersionFromString("1.1.5") ||
profileVersion == Updater::parseVersionFromString("1.1.8")) {
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.1.5")) {
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.1.8")) {
update118();
update120();
update130();
return;
}
if (profileVersion == Updater::parseVersionFromString("1.2.0")) {
update120();
update130();
return;
}
@ -126,6 +101,11 @@ void ProfileUpdater::updateProfile(const QString &current, const QString &profil
return;
}
if (profileVersion == Updater::parseVersionFromString("1.3.1")) {
update131();
return;
}
std::cout << "QupZilla: Incompatible profile version detected, overwriting profile data..." << std::endl;
copyDataToProfile();
@ -160,6 +140,8 @@ void ProfileUpdater::update100b4()
QSqlQuery query;
query.exec("CREATE TABLE IF NOT EXISTS search_engines (id INTEGER PRIMARY KEY, name TEXT, icon TEXT,"
"url TEXT, shortcut TEXT, suggestionsUrl TEXT, suggestionsParameters TEXT);");
update100rc1();
}
void ProfileUpdater::update100rc1()
@ -173,6 +155,8 @@ void ProfileUpdater::update100rc1()
query.exec("ALTER TABLE bookmarks ADD COLUMN toolbar_position NUMERIC");
query.exec("UPDATE bookmarks SET toolbar_position=0");
update100();
}
void ProfileUpdater::update100()
@ -183,6 +167,8 @@ void ProfileUpdater::update100()
QSqlQuery query;
query.exec("ALTER TABLE autofill ADD COLUMN last_used NUMERIC");
query.exec("UPDATE autofill SET last_used=0");
update118();
}
void ProfileUpdater::update118()
@ -192,6 +178,8 @@ void ProfileUpdater::update118()
QSqlQuery query;
query.exec("ALTER TABLE folders ADD COLUMN parent TEXT");
update120();
}
void ProfileUpdater::update120()
@ -213,6 +201,8 @@ void ProfileUpdater::update120()
query.exec("CREATE INDEX bookmarksUrl ON bookmarks(url ASC)");
db.commit();
update130();
}
void ProfileUpdater::update130()
@ -222,4 +212,16 @@ void ProfileUpdater::update130()
QSqlQuery query;
query.exec("ALTER TABLE bookmarks ADD COLUMN keyword TEXT");
update131();
}
void ProfileUpdater::update131()
{
std::cout << "QupZilla: Upgrading profile version from 1.3.1..." << std::endl;
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE bookmarks ADD COLUMN count NUMERIC");
query.exec("UPDATE bookmarks SET count=0");
}

View File

@ -38,6 +38,7 @@ private:
void update118();
void update120();
void update130();
void update131();
QString m_profilePath;
};

View File

@ -189,14 +189,27 @@ void BookmarksManager::itemControlClicked(QTreeWidgetItem* item)
if (!item || item->text(1).isEmpty()) {
return;
}
getQupZilla()->tabWidget()->addView(QUrl(item->text(1)), item->text(0));
int id = item->data(0, Qt::UserRole + 10).toInt();
mApp->bookmarksModel()->countUpBookmark(id);
const QUrl &url = QUrl::fromEncoded(item->text(1).toUtf8());
getQupZilla()->tabWidget()->addView(url, item->text(0));
}
void BookmarksManager::loadInNewTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
getQupZilla()->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
QAction* action = qobject_cast<QAction*>(sender());
if (!item || !action) {
return;
}
int id = item->data(0, Qt::UserRole + 10).toInt();
mApp->bookmarksModel()->countUpBookmark(id);
getQupZilla()->tabWidget()->addView(action->data().toUrl(), item->text(0), qzSettings->newTabPosition);
}
void BookmarksManager::deleteItem()

View File

@ -368,6 +368,14 @@ bool BookmarksModel::changeIcon(int id, const QIcon &icon)
return true;
}
void BookmarksModel::countUpBookmark(int id)
{
QSqlQuery query;
query.prepare("UPDATE bookmarks SET count = count + 1 WHERE id=?");
query.addBindValue(id);
query.exec();
}
bool BookmarksModel::createFolder(const QString &name)
{
if (isFolder(name)) {

View File

@ -88,6 +88,8 @@ public:
bool editBookmark(int id, const QString &title = QString(), const QUrl &url = QUrl(), const QString &folder = QString());
bool changeIcon(int id, const QIcon &icon);
void countUpBookmark(int id);
bool createFolder(const QString &name);
void removeFolder(const QString &name);

View File

@ -63,12 +63,23 @@ void LocationCompleter::showMostVisited()
void LocationCompleter::currentChanged(const QModelIndex &index)
{
int bookmarkId = -1;
QString completion = index.data().toString();
if (completion.isEmpty()) {
completion = m_originalText;
}
emit showCompletion(completion);
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
bool ok = false;
int id = index.data(LocationCompleterModel::IdRole).toInt(&ok);
if (ok) {
bookmarkId = id;
}
}
emit showCompletion(completion, bookmarkId);
}
void LocationCompleter::popupClosed()

View File

@ -38,7 +38,7 @@ public:
void closePopup();
signals:
void showCompletion(const QString &);
void showCompletion(const QString &, int bookmarkId);
void completionActivated();
public slots:

View File

@ -49,7 +49,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
QList<QUrl> urlList;
if (showType == HistoryAndBookmarks || showType == Bookmarks) {
QSqlQuery query = createQuery(string, QString("history.count DESC"), urlList, limit, true, false);
QSqlQuery query = createQuery(string, "bookmarks.count DESC", urlList, limit, true);
query.exec();
while (query.next()) {
@ -70,7 +70,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
}
if (showType == HistoryAndBookmarks || showType == History) {
QSqlQuery query = createQuery(string, "count DESC", urlList, limit, false, false);
QSqlQuery query = createQuery(string, "count DESC", urlList, limit);
query.exec();
while (query.next()) {
@ -110,7 +110,8 @@ void LocationCompleterModel::showMostVisited()
}
}
QSqlQuery LocationCompleterModel::createQuery(QString searchString, QString orderBy, const QList<QUrl> &alreadyFound, int limit, bool bookmarks, bool exactMatch)
QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const QString &orderBy,
const QList<QUrl> &alreadyFound, int limit, bool bookmarks, bool exactMatch)
{
QString table = bookmarks ? "bookmarks" : "history";
QString query = QString("SELECT %1.id, %1.url, %1.title").arg(table);

View File

@ -49,7 +49,8 @@ private:
Nothing = 4
};
QSqlQuery createQuery(QString searchString, QString orderBy, const QList<QUrl> &alreadyFound, int limit, bool bookmarks, bool exactMatch);
QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList<QUrl> &alreadyFound,
int limit, bool bookmarks = false, bool exactMatch = false);
QString m_lastCompletion;

View File

@ -50,6 +50,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_pasteAndGoAction(0)
, m_clearAction(0)
, m_holdingAlt(false)
, m_completerBookmarkId(-1)
, m_loadProgress(0)
, m_loadFinished(true)
{
@ -76,7 +77,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
addWidget(down, LineEdit::RightSide);
m_completer.setLocationBar(this);
connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
connect(&m_completer, SIGNAL(showCompletion(QString, int)), this, SLOT(showCompletion(QString, int)));
connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter()));
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
@ -109,9 +110,13 @@ void LocationBar::updatePlaceHolderText()
setPlaceholderText(tr("Enter URL address or search on %1").arg(mApp->searchEnginesManager()->activeEngine().name));
}
void LocationBar::showCompletion(const QString &newText)
void LocationBar::showCompletion(const QString &newText, int bookmarkId)
{
m_completerBookmarkId = bookmarkId;
LineEdit::setText(newText);
// Move cursor to the end
end(false);
}
@ -146,6 +151,12 @@ QUrl LocationBar::createUrl()
void LocationBar::urlEnter()
{
if (m_completerBookmarkId != -1) {
mApp->bookmarksModel()->countUpBookmark(m_completerBookmarkId);
m_completerBookmarkId = -1;
}
m_completer.closePopup();
m_webView->setFocus();
@ -161,6 +172,8 @@ void LocationBar::textEdit()
m_completer.closePopup();
}
m_completerBookmarkId = -1;
showGoButton();
}

View File

@ -71,7 +71,7 @@ private slots:
void pasteAndGo();
void updatePlaceHolderText();
void showCompletion(const QString &newText);
void showCompletion(const QString &newText, int bookmarkId);
void onLoadProgress(int progress);
void onLoadFinished();
@ -107,6 +107,8 @@ private:
bool m_rssIconVisible;
bool m_holdingAlt;
int m_completerBookmarkId;
int m_loadProgress;
bool m_loadFinished;
};

View File

@ -63,7 +63,10 @@ void BookmarksSideBar::itemControlClicked(QTreeWidgetItem* item)
return;
}
QUrl url = QUrl::fromEncoded(item->text(1).toUtf8());
int id = item->data(0, Qt::UserRole + 10).toInt();
mApp->bookmarksModel()->countUpBookmark(id);
const QUrl &url = QUrl::fromEncoded(item->text(1).toUtf8());
p_QupZilla->tabWidget()->addView(url, item->text(0));
}
@ -73,15 +76,26 @@ void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem* item)
return;
}
QUrl url = QUrl::fromEncoded(item->text(1).toUtf8());
int id = item->data(0, Qt::UserRole + 10).toInt();
mApp->bookmarksModel()->countUpBookmark(id);
const QUrl &url = QUrl::fromEncoded(item->text(1).toUtf8());
p_QupZilla->loadAddress(url);
}
void BookmarksSideBar::loadInNewTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
p_QupZilla->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
QAction* action = qobject_cast<QAction*>(sender());
if (!item || !action) {
return;
}
int id = item->data(0, Qt::UserRole + 10).toInt();
mApp->bookmarksModel()->countUpBookmark(id);
p_QupZilla->tabWidget()->addView(action->data().toUrl(), item->text(0), qzSettings->newTabPosition);
}
void BookmarksSideBar::copyAddress()