Commit c4dd5658 authored by Rinigus Saar's avatar Rinigus Saar

Allow to change the bookmaked status of the current page

parent d5ae304d
......@@ -6,6 +6,7 @@ set(angelfish_webapp_SRCS
../src/iconimageprovider.cpp
../src/sqlquerymodel.cpp
../src/urlutils.cpp
../src/urlobserver.cpp
../src/useragent.cpp
../src/tabsmodel.cpp
webapp-resources.qrc
......
......@@ -7,6 +7,7 @@ set(angelfish_SRCS
sqlquerymodel.cpp
urlutils.cpp
useragent.cpp
urlobserver.cpp
tabsmodel.cpp
desktopfilegenerator.cpp
)
......
......@@ -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);
......
......@@ -219,6 +219,11 @@ Kirigami.ApplicationWindow {
id: sheetLoader
}
UrlObserver {
id: urlObserver
url: currentWebView.url
}
// The menu at the bottom right
contextualActions: [
Kirigami.Action {
......@@ -270,15 +275,21 @@ Kirigami.ApplicationWindow {
}
},
Kirigami.Action {
id: bookmarkAction
checkable: true
checked: urlObserver.bookmarked
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);
}
}
},
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
......@@ -30,6 +30,7 @@
#include "browsermanager.h"
#include "iconimageprovider.h"
#include "tabsmodel.h"
#include "urlobserver.h"
#include "urlutils.h"
#include "useragent.h"
#include "desktopfilegenerator.h"
......@@ -73,6 +74,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// Exported types
qmlRegisterType<BookmarksHistoryModel>("org.kde.mobile.angelfish", 1, 0, "BookmarksHistoryModel");
qmlRegisterType<UrlObserver>("org.kde.mobile.angelfish", 1, 0, "UrlObserver");
qmlRegisterType<UserAgent>("org.kde.mobile.angelfish", 1, 0, "UserAgentGenerator");
qmlRegisterType<TabsModel>("org.kde.mobile.angelfish", 1, 0, "TabsModel");
......
/***************************************************************************
* *
* Copyright 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#include "urlobserver.h"
#include "browsermanager.h"
UrlObserver::UrlObserver(QObject *parent) : QObject(parent)
{
connect(BrowserManager::instance(), &BrowserManager::databaseTableChanged,
this, &UrlObserver::onDatabaseTableChanged);
}
QString UrlObserver::url() const
{
return m_url;
}
void UrlObserver::setUrl(const QString &url)
{
m_url = url;
updateBookmarked();
emit urlChanged(url);
}
bool UrlObserver::bookmarked() const
{
return m_bookmarked;
}
void UrlObserver::onDatabaseTableChanged(QString table)
{
if (table != QStringLiteral("bookmarks"))
return;
updateBookmarked();
}
void UrlObserver::updateBookmarked()
{
bool b = BrowserManager::instance()->isBookmarked(m_url);
if (b != m_bookmarked) {
m_bookmarked = b;
emit bookmarkedChanged(m_bookmarked);
}
}
/***************************************************************************
* *
* Copyright 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#ifndef URLOBSERVER_H
#define URLOBSERVER_H
#include <QObject>
#include <QString>
class UrlObserver : public QObject
{
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(bool bookmarked READ bookmarked NOTIFY bookmarkedChanged)
Q_OBJECT
public:
explicit UrlObserver(QObject *parent = nullptr);
QString url() const;
void setUrl(const QString &url);
bool bookmarked() const;
signals:
void urlChanged(QString url);
void bookmarkedChanged(bool bookmarked);
private:
void onDatabaseTableChanged(QString table);
void updateBookmarked();
private:
QString m_url;
bool m_bookmarked = false;
};
#endif // URLOBSERVER_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