diff --git a/src/browsermanager.cpp b/src/browsermanager.cpp index 8002105..33b5556 100644 --- a/src/browsermanager.cpp +++ b/src/browsermanager.cpp @@ -1,121 +1,121 @@ /*************************************************************************** * Copyright 2014 Sebastian Kügler * * * * 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 "browsermanager.h" #include #include #include using namespace AngelFish; BrowserManager::BrowserManager(QObject *parent) : QObject(parent), m_bookmarks(nullptr), m_history(nullptr), m_settings(new QSettings) { } BrowserManager::~BrowserManager() { history()->save(); bookmarks()->save(); delete m_settings; } void BrowserManager::reload() { qDebug() << "BookmarksManager::reload()"; } UrlModel* BrowserManager::bookmarks() { // qDebug() << "BookmarksManager::bookmarks()"; if (!m_bookmarks) { m_bookmarks = new UrlModel(QStringLiteral("bookmarks.json"), this); m_bookmarks->load(); } return m_bookmarks; } UrlModel* BrowserManager::history() { // qDebug() << "BrowserManager::history()"; if (!m_history) { m_history = new UrlModel(QStringLiteral("history.json"), this); m_history->load(); } return m_history; } void BrowserManager::addBookmark(const QVariantMap& bookmarkdata) { qDebug() << "Add bookmark"; qDebug() << " data: " << bookmarkdata; bookmarks()->add(QJsonObject::fromVariantMap(bookmarkdata)); } void BrowserManager::removeBookmark(const QString& url) { bookmarks()->remove(url); } void BrowserManager::addToHistory(const QVariantMap& pagedata) { // qDebug() << "Add History"; // qDebug() << " data: " << pagedata; history()->add(QJsonObject::fromVariantMap(pagedata)); emit historyChanged(); } void BrowserManager::removeFromHistory(const QString& url) { history()->remove(url); emit historyChanged(); } QString BrowserManager::urlFromUserInput(const QString& input) { QUrl url = QUrl::fromUserInput(input); return url.toString(); } -void BrowserManager::setHomepage(const QString homepage) +void BrowserManager::setHomepage(const QString& homepage) { m_settings->setValue("browser/homepage", homepage); emit homepageChanged(); } QString BrowserManager::homepage() { return m_settings->value("browser/homepage", "https://searx.me").toString(); } -void BrowserManager::setSearchBaseUrl(const QString searchBaseUrl) +void BrowserManager::setSearchBaseUrl(const QString& searchBaseUrl) { m_settings->setValue("browser/searchBaseUrl", searchBaseUrl); emit searchBaseUrlChanged(); } QString BrowserManager::searchBaseUrl() { return m_settings->value("browser/searchBaseUrl", "https://searx.me/?q=").toString(); } diff --git a/src/browsermanager.h b/src/browsermanager.h index 50f28c2..a33ac36 100644 --- a/src/browsermanager.h +++ b/src/browsermanager.h @@ -1,91 +1,91 @@ /*************************************************************************** * * * Copyright 2014 Sebastian Kügler * * * * 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 BOOKMARKSMANAGER_H #define BOOKMARKSMANAGER_H #include #include #include "urlmodel.h" class QSettings; namespace AngelFish { /** * @class BookmarksManager * @short Access to Bookmarks and History. This is a singleton for * administration and access to the various models and browser-internal * data. */ class BrowserManager : public QObject { Q_OBJECT Q_PROPERTY(QAbstractListModel* bookmarks READ bookmarks NOTIFY bookmarksChanged) Q_PROPERTY(QAbstractListModel* history READ history NOTIFY historyChanged) Q_PROPERTY(QString homepage READ homepage WRITE setHomepage NOTIFY homepageChanged) Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY searchBaseUrlChanged) public: BrowserManager(QObject *parent = nullptr); ~BrowserManager(); UrlModel* bookmarks(); UrlModel* history(); QString homepage(); QString searchBaseUrl(); Q_INVOKABLE static QString urlFromUserInput(const QString &input); signals: void updated(); void bookmarksChanged(); void historyChanged(); void homepageChanged(); void searchBaseUrlChanged(); public slots: void reload(); void addBookmark(const QVariantMap &bookmarkdata); void removeBookmark(const QString &url); void addToHistory(const QVariantMap &pagedata); void removeFromHistory(const QString &url); - void setHomepage(const QString homepage); - void setSearchBaseUrl(const QString searchBaseUrl); + void setHomepage(const QString& homepage); + void setSearchBaseUrl(const QString& searchBaseUrl); private: UrlModel* m_bookmarks; UrlModel* m_history; QSettings* m_settings; }; } // namespace #endif //BOOKMARKSMANAGER_H