Skip to content

Commit

Permalink
LocationCompleter: Bookmarks results are now ordered by count
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed Sep 2, 2012
1 parent cff5fce commit ec70c7d
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 45 deletions.
60 changes: 31 additions & 29 deletions src/lib/app/profileupdater.cpp
Expand Up @@ -29,6 +29,8 @@
ProfileUpdater::ProfileUpdater(const QString &profilePath)
: m_profilePath(profilePath)
{
// FIXME: Remove this line when releasing new version
update131();
}

void ProfileUpdater::checkProfile()
Expand Down Expand Up @@ -69,60 +71,38 @@ 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")) {
update118();
update120();
update130();
return;
}

if (profileVersion == Updater::parseVersionFromString("1.1.5")) {
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.8")) {
update118();
if (profileVersion == Updater::parseVersionFromString("1.2.0")) {
update120();
update130();
return;
}

if (profileVersion == Updater::parseVersionFromString("1.2.0")) {
update120();
if (profileVersion == Updater::parseVersionFromString("1.3.0")) {
update130();
return;
}

if (profileVersion == Updater::parseVersionFromString("1.3.0")) {
update130();
if (profileVersion == Updater::parseVersionFromString("1.3.1")) {
update131();
return;
}

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -192,6 +178,8 @@ void ProfileUpdater::update118()

QSqlQuery query;
query.exec("ALTER TABLE folders ADD COLUMN parent TEXT");

update120();
}

void ProfileUpdater::update120()
Expand All @@ -213,6 +201,8 @@ void ProfileUpdater::update120()
query.exec("CREATE INDEX bookmarksUrl ON bookmarks(url ASC)");

db.commit();

update130();
}

void ProfileUpdater::update130()
Expand All @@ -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");
}
1 change: 1 addition & 0 deletions src/lib/app/profileupdater.h
Expand Up @@ -38,6 +38,7 @@ class ProfileUpdater
void update118();
void update120();
void update130();
void update131();

QString m_profilePath;
};
Expand Down
19 changes: 16 additions & 3 deletions src/lib/bookmarks/bookmarksmanager.cpp
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions src/lib/bookmarks/bookmarksmodel.cpp
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bookmarks/bookmarksmodel.h
Expand Up @@ -88,6 +88,8 @@ class QT_QUPZILLA_EXPORT BookmarksModel : public QObject
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);

Expand Down
13 changes: 12 additions & 1 deletion src/lib/navigation/completer/locationcompleter.cpp
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/navigation/completer/locationcompleter.h
Expand Up @@ -38,7 +38,7 @@ class QT_QUPZILLA_EXPORT LocationCompleter : public QObject
void closePopup();

signals:
void showCompletion(const QString &);
void showCompletion(const QString &, int bookmarkId);
void completionActivated();

public slots:
Expand Down
7 changes: 4 additions & 3 deletions src/lib/navigation/completer/locationcompletermodel.cpp
Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/navigation/completer/locationcompletermodel.h
Expand Up @@ -49,7 +49,8 @@ public slots:
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;

Expand Down
17 changes: 15 additions & 2 deletions src/lib/navigation/locationbar.cpp
Expand Up @@ -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)
{
Expand All @@ -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()));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();

Expand All @@ -161,6 +172,8 @@ void LocationBar::textEdit()
m_completer.closePopup();
}

m_completerBookmarkId = -1;

showGoButton();
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/navigation/locationbar.h
Expand Up @@ -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();
Expand Down Expand Up @@ -107,6 +107,8 @@ private slots:

bool m_rssIconVisible;
bool m_holdingAlt;
int m_completerBookmarkId;

int m_loadProgress;
bool m_loadFinished;
};
Expand Down
22 changes: 18 additions & 4 deletions src/lib/sidebar/bookmarkssidebar.cpp
Expand Up @@ -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));
}

Expand All @@ -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()
Expand Down

0 comments on commit ec70c7d

Please sign in to comment.