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 <QPointer>
34 #include <QProgressDialog>
35 #include <QReadWriteLock>
36 #include <QSqlDatabase>
37 #include <QTimer>
38 #include <QUrl>
39 #include <QWebEnginePage>
40 
41 #include "dooble_main_window.h"
42 #include "ui_dooble_settings.h"
43 
44 class QStandardItemModel;
45 
47 {
48  Q_OBJECT
49 
50  public:
51  enum class Panels
52  {
53  CACHE_PANEL = 0,
54  DISPLAY_PANEL,
55  HISTORY_PANEL,
56  PRIVACY_PANEL,
57  WEB_PANEL,
58  WINDOWS_PANEL
59  };
60 
61  dooble_settings(void);
62  static QString cookie_policy_string(int index);
63  static QString use_material_icons(void);
64  static QString zoom_frame_location_string(int index);
65  static QStringList s_spell_checker_dictionaries;
66  static QVariant getenv(const QString &n);
67  static QVariant setting(const QString &k,
68  const QVariant &default_value = QVariant(""));
69  static bool has_dooble_credentials(void);
70  static bool has_dooble_credentials_temporary(void);
71  static bool set_setting(const QString &key, const QVariant &value);
72  static bool site_has_javascript_block_popup_exception(const QUrl &url);
73  static int main_menu_bar_visible_key(void);
74  static int site_feature_permission(const QUrl &url,
75  QWebEnginePage::Feature feature);
76  static void prepare_web_engine_environment_variables(void);
77  static void remove_setting(const QString &key);
78  void add_shortcut(QObject *object);
79  void restore(bool read_database);
80  void set_settings_path(const QString &path);
81  void set_site_feature_permission(const QUrl &url,
82  QWebEnginePage::Feature feature,
83  bool state);
84  void show_normal(QWidget *parent);
85  void show_panel(dooble_settings::Panels panel);
86 
87  public slots:
88  void show(void);
89 
90  protected:
91  void closeEvent(QCloseEvent *event);
92  void keyPressEvent(QKeyEvent *event);
93  void resizeEvent(QResizeEvent *event);
94 
95  private:
96  QFuture<QList<QByteArray> > m_pbkdf2_future;
97  QFutureWatcher<QList<QByteArray> > m_pbkdf2_future_watcher;
98  QPointer<QProgressDialog> m_pbkdf2_dialog;
99  QStandardItemModel *m_shortcuts_model;
100  QTimer m_timer;
101  Ui_dooble_settings m_ui;
102  static QHash<QString, QString> s_web_engine_settings_environment;
103  static QHash<QUrl, char> s_javascript_block_popup_exceptions;
104  static QMap<QString, QVariant> s_getenv;
105  static QMap<QString, QVariant> s_settings;
106  static QMultiMap<QUrl, QPair<int, bool> > s_site_features_permissions;
107  static QReadWriteLock s_getenv_mutex;
108  static QReadWriteLock s_settings_mutex;
109  static QString s_http_user_agent;
110  static void create_tables(QSqlDatabase &db);
111  void new_javascript_block_popup_exception(const QUrl &url);
112  void prepare_application_fonts(void);
113  void prepare_fonts(void);
114  void prepare_icons(void);
115  void prepare_proxy(bool save);
116  void prepare_shortcuts(void);
117  void prepare_table_statistics(void);
118  void prepare_web_engine_settings(void);
119  void purge_database_data(void);
120  void purge_features_permissions(void);
121  void purge_javascript_block_popup_exceptions(void);
122  void save_fonts(void);
123  void save_javascript_block_popup_exception(const QUrl &url, bool state);
124  void save_settings(void);
125 
126  void showEvent(QShowEvent *event)
127  {
128  dooble_main_window::showEvent(event);
129 
130  if(!m_timer.isActive())
131  m_timer.start();
132  }
133 
134  void show_qtwebengine_dictionaries_warning_label(void);
135 
136  private slots:
137  void slot_apply(void);
138  void slot_clear_cache(void);
139  void slot_features_permissions_item_changed(QTableWidgetItem *item);
140  void slot_general_timer_timeout(void);
141  void slot_javascript_block_popups_exceptions_item_changed
142  (QTableWidgetItem *item);
143  void slot_new_javascript_block_popup_exception(const QUrl &url);
144  void slot_new_javascript_block_popup_exception(void);
145  void slot_page_button_clicked(void);
146  void slot_password_changed(void);
147  void slot_pbkdf2_future_finished(void);
148  void slot_populate(void);
149  void slot_proxy_type_changed(void);
150  void slot_remove_all_features_permissions(void);
151  void slot_remove_all_javascript_block_popup_exceptions(void);
152  void slot_remove_selected_features_permissions(void);
153  void slot_remove_selected_javascript_block_popup_exceptions(void);
154  void slot_reset(void);
155  void slot_reset_credentials(void);
156  void slot_reset_user_agent(void);
157  void slot_save_credentials(void);
158  void slot_select_application_font(void);
159  void slot_web_engine_settings_item_changed(QTableWidgetItem *item);
160 
161  signals:
162  void applied(void);
163  void dooble_credentials_authenticated(bool state);
164  void dooble_credentials_created(void);
165  void populated(void);
166 };
167 
168 #endif
Definition: dooble_main_window.h:35
Definition: dooble_settings.h:47