Commit 04200f89 authored by Rinigus Saar's avatar Rinigus Saar

Allow to change the bookmaked status of the current page

parent d5ae304d
......@@ -50,6 +50,11 @@ void BrowserManager::removeBookmark(const QString &url)
m_dbmanager->removeBookmark(url);
}
bool BrowserManager::isBookmarked(const QString &url) const
{
return m_dbmanager->isBookmarked(url);
}
void BrowserManager::addToHistory(const QVariantMap &pagedata)
{
// qDebug() << "Add History";
......
......@@ -68,6 +68,7 @@ signals:
public slots:
void addBookmark(const QVariantMap &bookmarkdata);
void removeBookmark(const QString &url);
bool isBookmarked(const QString &url) const;
void addToHistory(const QVariantMap &pagedata);
void removeFromHistory(const QString &url);
......
......@@ -270,15 +270,40 @@ Kirigami.ApplicationWindow {
}
},
Kirigami.Action {
id: bookmarkAction
checkable: true
checked: BrowserManager.isBookmarked(currentWebView.url)
icon.name: "bookmarks"
text: i18n("Add bookmark")
text: checked ? i18n("Bookmarked") : i18n("Bookmark")
onTriggered: {
print("Adding bookmark");
var request = new Object;// FIXME
request.url = currentWebView.url;
request.title = currentWebView.title;
request.icon = currentWebView.icon;
BrowserManager.addBookmark(request);
if (checked) {
var request = new Object;// FIXME
request.url = currentWebView.url;
request.title = currentWebView.title;
request.icon = currentWebView.icon;
BrowserManager.addBookmark(request);
} else {
BrowserManager.removeBookmark(currentWebView.url);
}
}
property var _connections: Item {
Connections {
target: webBrowser
onCurrentWebViewChanged: bookmarkAction.evaluateChecked()
}
Connections {
target: currentWebView
onUrlChanged: bookmarkAction.evaluateChecked()
}
Connections {
target: BrowserManager
onDatabaseTableChanged: bookmarkAction.evaluateChecked()
}
}
function evaluateChecked() {
checked = BrowserManager.isBookmarked(currentWebView.url);
}
},
Kirigami.Action {
......
......@@ -189,6 +189,23 @@ void DBManager::removeRecord(const QString &table, const QString &url)
emit databaseTableChanged(table);
}
bool DBManager::hasRecord(const QString &table, const QString &url) const
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT 1 FROM %1 WHERE url = :url").arg(table));
query.bindValue(QStringLiteral(":url"), url);
if (!query.exec()) {
qWarning() << Q_FUNC_INFO << "Failed to execute SQL statement";
qWarning() << query.lastQuery();
qWarning() << query.lastError();
return false;
}
while (query.next()) {
return true;
}
return false;
}
void DBManager::updateIconRecord(const QString &table, const QString &url, const QString &iconSource)
{
if (url.isEmpty())
......@@ -228,6 +245,11 @@ void DBManager::removeBookmark(const QString &url)
removeRecord(QStringLiteral("bookmarks"), url);
}
bool DBManager::isBookmarked(const QString &url) const
{
return hasRecord(QStringLiteral("bookmarks"), url);
}
void DBManager::addToHistory(const QVariantMap &pagedata)
{
addRecord(QStringLiteral("history"), pagedata);
......
......@@ -44,6 +44,7 @@ signals:
public:
void addBookmark(const QVariantMap &bookmarkdata);
void removeBookmark(const QString &url);
bool isBookmarked(const QString &url) const;
void addToHistory(const QVariantMap &pagedata);
void removeFromHistory(const QString &url);
......@@ -74,6 +75,7 @@ private:
void removeRecord(const QString &table, const QString &url);
void updateIconRecord(const QString &table, const QString &url, const QString &iconSource);
void setLastVisitedRecord(const QString &table, const QString &url);
bool hasRecord(const QString &table, const QString &url) const;
};
#endif // DBMANAGER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment