Skip to content

Commit

Permalink
Merge pull request #201 from siteshwar/sb-198
Browse files Browse the repository at this point in the history
Do not show 'about:*' pages in history
  • Loading branch information
Raine Mäkeläinen committed Oct 14, 2014
2 parents 798c4f3 + 37650cd commit 85a1d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/dbworker.cpp
Expand Up @@ -140,7 +140,7 @@ int DBWorker::createLink(int tabId, QString url, QString title)

int linkId = createLink(url, title, "");

if (!addToHistory(linkId)) {
if (addToHistory(linkId, url) == Error) {
qWarning() << Q_FUNC_INFO << "failed to add url to history" << url;
}

Expand Down Expand Up @@ -313,7 +313,8 @@ void DBWorker::navigateTo(int tabId, QString url, QString title, QString path) {
clearDeprecatedTabHistory(tabId, currentLink.linkId());

int linkId = createLink(url, title, path);
if (!addToHistory(linkId)) {

if (addToHistory(linkId, url) == Error) {
qWarning() << Q_FUNC_INFO << "failed to add url to history" << url;
}

Expand Down Expand Up @@ -448,28 +449,34 @@ int DBWorker::getNextLinkIdFromTabHistory(int tabHistoryId)
}

// Adds url to table history if it is not already there
bool DBWorker::addToHistory(int linkId)
HistoryResult DBWorker::addToHistory(int linkId, QString url)
{
#ifdef DEBUG_LOGS
qDebug() << "link id:" << linkId;
#endif

// Skip adding any urls with 'about:' prefix
if (url.startsWith("about:")) {
return Skipped;
}

QSqlQuery query = prepare("SELECT link_id FROM history WHERE link_id = ?;");
query.bindValue(0, linkId);
if (!execute(query)) {
return false;
return Error;
}

if (query.first()) {
query = prepare("UPDATE history SET date = ? WHERE link_id = ?;");
query.bindValue(0, QDateTime::currentDateTimeUtc().toTime_t());
query.bindValue(1, linkId);
return execute(query);
return execute(query) ? Added : Error;
}

query = prepare("INSERT INTO history (link_id, date) VALUES (?, ?);");
query.bindValue(0, linkId);
query.bindValue(1, QDateTime::currentDateTimeUtc().toTime_t());
return execute(query);
return execute(query) ? Added : Error;
}

void DBWorker::clearHistory()
Expand Down Expand Up @@ -563,7 +570,7 @@ int DBWorker::createLink(QString url, QString title, QString thumbPath)
void DBWorker::getHistory(const QString &filter)
{
// Skip empty titles always
QString filterQuery("WHERE (NULLIF(link.title, '') IS NOT NULL AND %1) ");
QString filterQuery("WHERE (NULLIF(link.title, '') IS NOT NULL AND link.url NOT LIKE 'about:%' AND %1) ");
if (!filter.isEmpty()) {
filterQuery = filterQuery.arg(QString("(link.url LIKE :search OR link.title LIKE :search)"));
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/dbworker.h
Expand Up @@ -24,9 +24,12 @@
// comma-separated types
typedef QMap<QString, QString> SettingsMap;

enum HistoryResult { Error, Added, Skipped };

class DBWorker : public QObject
{
Q_OBJECT

public:
DBWorker(QObject *parent = 0);

Expand Down Expand Up @@ -72,7 +75,7 @@ public slots:
Link getLink(int linkId);
Link getLink(QString url);
void updateLink(int linkId, QString url, QString title, QString thumbPath);
bool addToHistory(int linkId);
HistoryResult addToHistory(int linkId, QString url);
int addToTabHistory(int tabId, int linkId);
Link getLinkFromTabHistory(int tabHistoryId);
Link getCurrentLink(int tabId);
Expand Down

0 comments on commit 85a1d69

Please sign in to comment.