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 #include <QMessageBox>
29 #include <QWebEngineProfile>
30
31 #include "dooble.h"
32 #include "dooble_accepted_or_blocked_domains.h"
33 #include "dooble_application.h"
34 #include "dooble_certificate_exceptions.h"
35 #include "dooble_certificate_exceptions_menu_widget.h"
36 #include "dooble_charts.h"
37 #include "dooble_clear_items.h"
38 #include "dooble_cookies.h"
39 #include "dooble_downloads.h"
40 #include "dooble_favicons.h"
41 #include "dooble_history.h"
42 #include "dooble_search_engines_popup.h"
43
dooble_clear_items(QWidget * parent)44 dooble_clear_items::dooble_clear_items(QWidget *parent):QDialog(parent)
45 {
46 m_ui.setupUi(this);
47 connect(&m_timer,
48 SIGNAL(timeout(void)),
49 this,
50 SLOT(slot_timeout(void)));
51 connect(m_ui.buttonBox->button(QDialogButtonBox::Apply),
52 SIGNAL(clicked(void)),
53 this,
54 SLOT(slot_clear_items(void)));
55 connect(m_ui.download_history,
56 SIGNAL(toggled(bool)),
57 this,
58 SLOT(slot_download_history_toggled(bool)));
59 connect(this,
60 SIGNAL(cookies_cleared(void)),
61 dooble::s_application,
62 SIGNAL(cookies_cleared(void)));
63 connect(this,
64 SIGNAL(favorites_cleared(void)),
65 dooble::s_application,
66 SIGNAL(favorites_cleared(void)));
67 connect(this,
68 SIGNAL(history_cleared(void)),
69 dooble::s_application,
70 SIGNAL(history_cleared(void)));
71 new QShortcut(QKeySequence(tr("Ctrl+W")), this, SLOT(close(void)));
72
73 foreach(auto check_box, findChildren<QCheckBox *> ())
74 {
75 check_box->setChecked
76 (dooble_settings::setting(QString("dooble_clear_items_%1").
77 arg(check_box->objectName())).toBool());
78 connect(check_box,
79 SIGNAL(toggled(bool)),
80 this,
81 SLOT(slot_check_box_toggled(bool)));
82 }
83 }
84
slot_check_box_toggled(bool state)85 void dooble_clear_items::slot_check_box_toggled(bool state)
86 {
87 auto check_box = qobject_cast<QCheckBox *> (sender());
88
89 if(!check_box)
90 return;
91
92 dooble_settings::set_setting
93 (QString("dooble_clear_items_%1").arg(check_box->objectName()), state);
94 }
95
slot_clear_items(void)96 void dooble_clear_items::slot_clear_items(void)
97 {
98 if(m_ui.download_history->isChecked())
99 if(!dooble::s_downloads->is_finished())
100 {
101 QMessageBox mb(this);
102
103 mb.setIcon(QMessageBox::Question);
104 mb.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
105 mb.setText
106 (tr("Downloads are in progress. If you continue, downloads will "
107 "be canceled. Are you sure that you wish to proceed?"));
108 mb.setWindowIcon(windowIcon());
109 mb.setWindowModality(Qt::ApplicationModal);
110 mb.setWindowTitle(tr("Dooble: Confirmation"));
111
112 if(mb.exec() != QMessageBox::Yes)
113 {
114 QApplication::processEvents();
115 return;
116 }
117
118 QApplication::processEvents();
119 }
120
121 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
122
123 if(m_ui.accepted_blocked_domains->isChecked())
124 dooble::s_accepted_or_blocked_domains->purge();
125
126 if(m_ui.certificate_exceptions->isChecked())
127 {
128 dooble::s_certificate_exceptions->purge();
129 dooble_certificate_exceptions_menu_widget::purge();
130 }
131
132 if(m_ui.charts->isChecked())
133 dooble_charts::purge();
134
135 if(m_ui.cookies->isChecked())
136 {
137 dooble_cookies::purge();
138 emit cookies_cleared();
139 }
140
141 if(m_ui.download_history->isChecked())
142 dooble::s_downloads->purge();
143
144 if(m_ui.favicons->isChecked())
145 dooble_favicons::purge();
146
147 if(m_ui.favorites->isChecked())
148 {
149 dooble::s_history->purge_favorites();
150 emit favorites_cleared();
151 }
152
153 if(m_ui.history->isChecked())
154 {
155 dooble::s_history->purge_history();
156 emit history_cleared();
157 }
158
159 if(m_ui.search_engines->isChecked())
160 {
161 dooble::s_search_engines_window->purge();
162 emit search_engines_cleared();
163 }
164
165 if(m_ui.visited_links->isChecked())
166 QWebEngineProfile::defaultProfile()->clearAllVisitedLinks();
167
168 QApplication::restoreOverrideCursor();
169 }
170
slot_download_history_toggled(bool state)171 void dooble_clear_items::slot_download_history_toggled(bool state)
172 {
173 if(state)
174 m_timer.start();
175 else
176 {
177 m_timer.stop();
178 slot_timeout();
179 }
180 }
181
slot_timeout(void)182 void dooble_clear_items::slot_timeout(void)
183 {
184 if(dooble::s_downloads->is_finished())
185 {
186 m_ui.download_history->setIcon(QIcon());
187 m_ui.download_history->setIconSize(QSize(0, 0));
188 m_ui.download_history->setToolTip("");
189 }
190 else
191 {
192 m_ui.download_history->setIcon
193 (QIcon(":/Miscellaneous/certificate_warning.png"));
194 m_ui.download_history->setIconSize(QSize(16, 16));
195 m_ui.download_history->setToolTip(tr("Active downloads exist."));
196 }
197 }
198