Dooble
dooble_settings.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_settings_h
29 #define dooble_settings_h
30 
31 #include <QFuture>
32 #include <QFutureWatcher>
33 #include <QMainWindow>
34 #include <QPointer>
35 #include <QProgressDialog>
36 #include <QReadWriteLock>
37 #include <QSqlDatabase>
38 #include <QUrl>
39 #include <QWebEnginePage>
40 
41 #include "ui_dooble_settings.h"
42 
43 class dooble_settings: public QMainWindow
44 {
45  Q_OBJECT
46 
47  public:
48  enum Panels
49  {
50  CACHE_PANEL = 0,
51  DISPLAY_PANEL,
52  HISTORY_PANEL,
53  PRIVACY_PANEL,
54  WEB_PANEL,
55  WINDOWS_PANEL
56  };
57 
58  dooble_settings(void);
59  static QString cookie_policy_string(int index);
60  static QString zoom_frame_location_string(int index);
61  static QStringList s_spell_checker_dictionaries;
62  static QVariant setting(const QString &key,
63  const QVariant &default_value = QVariant());
64  static bool has_dooble_credentials(void);
65  static bool has_dooble_credentials_temporary(void);
66  static bool set_setting(const QString &key, const QVariant &value);
67  static bool site_has_javascript_block_popup_exception(const QUrl &url);
68  static int site_feature_permission(const QUrl &url,
69  QWebEnginePage::Feature feature);
70  static void remove_setting(const QString &key);
71  void restore(bool read_database);
72  void set_site_feature_permission(const QUrl &url,
73  QWebEnginePage::Feature feature,
74  bool state);
75  void show_panel(dooble_settings::Panels panel);
76 
77  public slots:
78  void show(void);
79  void showNormal(void);
80 
81  protected:
82  void closeEvent(QCloseEvent *event);
83  void keyPressEvent(QKeyEvent *event);
84  void resizeEvent(QResizeEvent *event);
85 
86  private:
87  QFuture<QList<QByteArray> > m_pbkdf2_future;
88  QFutureWatcher<QList<QByteArray> > m_pbkdf2_future_watcher;
89  QPointer<QProgressDialog> m_pbkdf2_dialog;
90  Ui_dooble_settings m_ui;
91  static QHash<QUrl, char> s_javascript_block_popup_exceptions;
92  static QMap<QString, QVariant> s_settings;
93  static QMultiMap<QUrl, QPair<int, bool> > s_site_features_permissions;
94  static QReadWriteLock s_settings_mutex;
95  static QString s_http_user_agent;
96  static void create_tables(QSqlDatabase &db);
97  void new_javascript_block_popup_exception(const QUrl &url);
98  void prepare_fonts(void);
99  void prepare_icons(void);
100  void prepare_proxy(bool save);
101  void prepare_table_statistics(void);
102  void purge_database_data(void);
103  void purge_features_permissions(void);
104  void purge_javascript_block_popup_exceptions(void);
105  void save_fonts(void);
106  void save_javascript_block_popup_exception(const QUrl &url, bool state);
107  void save_settings(void);
108 
109  private slots:
110  void slot_apply(void);
111  void slot_clear_cache(void);
112  void slot_features_permissions_item_changed(QTableWidgetItem *item);
113  void slot_javascript_block_popups_exceptions_item_changed
114  (QTableWidgetItem *item);
115  void slot_new_javascript_block_popup_exception(const QUrl &url);
116  void slot_new_javascript_block_popup_exception(void);
117  void slot_page_button_clicked(void);
118  void slot_pbkdf2_future_finished(void);
119  void slot_populate(void);
120  void slot_proxy_type_changed(int index);
121  void slot_remove_all_features_permissions(void);
122  void slot_remove_all_javascript_block_popup_exceptions(void);
123  void slot_remove_selected_features_permissions(void);
124  void slot_remove_selected_javascript_block_popup_exceptions(void);
125  void slot_reset(void);
126  void slot_reset_credentials(void);
127  void slot_reset_user_agent(void);
128  void slot_save_credentials(void);
129 
130  signals:
131  void applied(void);
132  void dooble_credentials_authenticated(bool state);
133  void dooble_credentials_created(void);
134  void populated(void);
135 };
136 
137 #endif
Definition: dooble_settings.h:43