Dooble
Loading...
Searching...
No Matches
dooble_history.h
1/*
2** Copyright (c) 2008 - present, Alexis Megas.
3** All rights reserved.
4**
5** Redistribution and use in source and binary forms, with or without
6** modification, are permitted provided that the following conditions
7** are met:
8** 1. Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** 2. Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** 3. The name of the author may not be used to endorse or promote products
14** derived from Dooble without specific prior written permission.
15**
16** DOOBLE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25** DOOBLE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef dooble_history_h
29#define dooble_history_h
30
31#include <QAtomicInteger>
32#include <QFuture>
33#include <QIcon>
34#include <QReadWriteLock>
35#include <QSqlDatabase>
36#include <QTimer>
37#include <QWebEngineHistoryItem>
38
39class QAction;
40class QStandardItemModel;
41typedef QList<QPair<QIcon, QString> > QListPairIconString;
42typedef QList<QUrl> QListUrl;
43typedef QList<QVector<QByteArray> > QListVectorByteArray;
44
45class dooble_history: public QObject
46{
47 Q_OBJECT
48
49 public:
50 enum class HistoryItem
51 {
52 FAVICON = 0,
53 FAVORITE,
54 LAST_VISITED,
55 NUMBER_OF_VISITS,
56 TITLE,
57 URL,
58 URL_DIGEST
59 };
60
61 dooble_history(void);
63 QHash<QUrl, QHash<dooble_history::HistoryItem, QVariant> >
64 history(void) const;
65 QList<QAction *> last_n_actions(int n) const;
66 QList<QUrl> previous_session_tabs(void) const;
67 QStandardItemModel *favorites_model(void) const;
68 bool is_favorite(const QUrl &url) const;
69 void abort(void);
70 void purge_all(void);
71 void purge_favorites(void);
72 void purge_history(void);
73 void remove_favorite(const QUrl &url);
74 void remove_items_list(const QList<QUrl> &url);
75 void save_favicon(const QIcon &icon, const QUrl &url);
76 void save_favorite(const QUrl &url, bool state);
77 void save_item(const QIcon &icon,
78 const QWebEngineHistoryItem &item,
79 bool force);
80 void save_session_tabs(const QList<QUrl> &urls);
81
82 private:
83 QAtomicInteger<short> m_interrupt;
84 QFuture<void> m_populate_future;
85 QFuture<void> m_purge_future;
86 QHash<QUrl, QHash<dooble_history::HistoryItem, QVariant> > m_history;
87 QMultiMap<QDateTime, QUrl> m_history_date_time;
88 QStandardItemModel *m_favorites_model;
89 QTimer m_purge_timer;
90 mutable QReadWriteLock m_history_mutex;
91 void create_tables(QSqlDatabase &db);
92 void populate(const QByteArray &authentication_key,
93 const QByteArray &encryption_key);
94 void purge(const QByteArray &authentication_key,
95 const QByteArray &encryption_key);
96 void update_favorite
97 (const QHash<dooble_history::HistoryItem, QVariant> &hash);
98
99 private slots:
100 void slot_populate(void);
101 void slot_populated_favorites(const QListVectorByteArray &favorites);
102 void slot_remove_items(const QListUrl &urls);
103 void slot_purge_timer_timeout(void);
104
105 signals:
106 void icon_updated(const QIcon &icon, const QUrl &url);
107 void item_updated(const QIcon &icon, const QWebEngineHistoryItem &item);
108 void new_item(const QIcon &icon, const QWebEngineHistoryItem &item);
109 void populated(const QListPairIconString &list);
110 void populated(void);
111 void populated_favorites(const QListVectorByteArray &favorites);
112 void remove_items(const QListUrl &urls);
113};
114
115#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
116inline size_t
117#else
118inline uint
119#endif
120qHash(const dooble_history::HistoryItem &key,
121#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
122 size_t seed)
123#else
124 uint seed)
125#endif
126{
127 return ::qHash(static_cast<uint> (key), seed);
128}
129
130#endif
Definition dooble_history.h:46