File indexing completed on 2024-05-12 04:57:57

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #ifndef BOOKMARKS_H
0019 #define BOOKMARKS_H
0020 
0021 #include <QObject>
0022 #include <QVariant>
0023 
0024 #include "qzcommon.h"
0025 
0026 class QUrl;
0027 
0028 class BookmarkItem;
0029 class BookmarksModel;
0030 class AutoSaver;
0031 
0032 class FALKON_EXPORT Bookmarks : public QObject
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit Bookmarks(QObject* parent = nullptr);
0037     ~Bookmarks();
0038 
0039     void loadSettings();
0040 
0041     bool showOnlyIconsInToolbar() const;
0042     bool showOnlyTextInToolbar() const;
0043 
0044     BookmarkItem* rootItem() const;
0045     BookmarkItem* toolbarFolder() const;
0046     BookmarkItem* menuFolder() const;
0047     BookmarkItem* unsortedFolder() const;
0048     BookmarkItem* lastUsedFolder() const;
0049 
0050     BookmarksModel* model() const;
0051 
0052     bool isBookmarked(const QUrl &url);
0053     bool canBeModified(BookmarkItem* item) const;
0054 
0055     // Search bookmarks (urls only) for exact url match
0056     QList<BookmarkItem*> searchBookmarks(const QUrl &url) const;
0057     // Search bookmarks for contains match through all properties
0058     QList<BookmarkItem*> searchBookmarks(const QString &string, int limit = -1, Qt::CaseSensitivity sensitive = Qt::CaseInsensitive) const;
0059     // Search bookmarks for exact match of keyword
0060     QList<BookmarkItem*> searchKeyword(const QString &keyword) const;
0061 
0062     void addBookmark(BookmarkItem* parent, BookmarkItem* item);
0063     void insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item);
0064     bool removeBookmark(BookmarkItem* item);
0065     void changeBookmark(BookmarkItem* item);
0066 
0067 public Q_SLOTS:
0068     void setShowOnlyIconsInToolbar(bool state);
0069     void setShowOnlyTextInToolbar(bool state);
0070 
0071 Q_SIGNALS:
0072     // Item was added to bookmarks
0073     void bookmarkAdded(BookmarkItem* item);
0074     // Item was removed from bookmarks
0075     void bookmarkRemoved(BookmarkItem* item);
0076     // Item data has changed
0077     void bookmarkChanged(BookmarkItem* item);
0078 
0079     void showOnlyIconsInToolbarChanged(bool show);
0080     void showOnlyTextInToolbarChanged(bool show);
0081 
0082 private Q_SLOTS:
0083     void saveSettings();
0084 
0085 private:
0086     void init();
0087     void loadBookmarks();
0088     void saveBookmarks();
0089 
0090     void loadBookmarksFromMap(const QVariantMap &map);
0091     void readBookmarks(const QVariantList &list, BookmarkItem* parent);
0092     QVariantList writeBookmarks(BookmarkItem* parent);
0093 
0094     void search(QList<BookmarkItem*>* items, BookmarkItem* parent, const QUrl &url) const;
0095     void search(QList<BookmarkItem*>* items, BookmarkItem* parent, const QString &string, int limit, Qt::CaseSensitivity sensitive) const;
0096     void searchKeyword(QList<BookmarkItem*>* items, BookmarkItem* parent, const QString &keyword) const;
0097 
0098     BookmarkItem* m_root;
0099     BookmarkItem* m_folderToolbar;
0100     BookmarkItem* m_folderMenu;
0101     BookmarkItem* m_folderUnsorted;
0102     BookmarkItem* m_lastFolder;
0103 
0104     BookmarksModel* m_model;
0105     AutoSaver* m_autoSaver;
0106 
0107     bool m_showOnlyIconsInToolbar;
0108     bool m_showOnlyTextInToolbar;
0109 };
0110 
0111 #endif // BOOKMARKS_H