2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2015-05-22 21:46:55 +02:00
|
|
|
* Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "clearprivatedata.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "cookiejar.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2012-04-20 15:29:04 +02:00
|
|
|
#include "settings.h"
|
2014-03-09 21:51:42 +01:00
|
|
|
#include "datapaths.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "networkmanager.h"
|
2011-03-18 16:08:24 +01:00
|
|
|
#include "ui_clearprivatedata.h"
|
2011-04-28 18:31:48 +02:00
|
|
|
#include "iconprovider.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2014-07-08 19:01:07 +02:00
|
|
|
#include "cookiemanager.h"
|
|
|
|
#include "desktopnotificationsfactory.h"
|
|
|
|
#include "html5permissions/html5permissionsdialog.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QNetworkCookie>
|
2013-12-28 16:55:08 +01:00
|
|
|
#include <QMessageBox>
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QWebEngineSettings>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QNetworkDiskCache>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QSqlQuery>
|
2012-04-20 15:29:04 +02:00
|
|
|
#include <QCloseEvent>
|
2013-12-28 16:55:08 +01:00
|
|
|
#include <QFileInfo>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
ClearPrivateData::ClearPrivateData(QWidget* parent)
|
2011-10-26 19:23:50 +02:00
|
|
|
: QDialog(parent)
|
|
|
|
, ui(new Ui::ClearPrivateData)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-11-07 18:08:12 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
ui->setupUi(this);
|
|
|
|
ui->buttonBox->setFocus();
|
|
|
|
connect(ui->history, SIGNAL(clicked(bool)), this, SLOT(historyClicked(bool)));
|
2014-07-08 19:01:07 +02:00
|
|
|
connect(ui->clear, SIGNAL(clicked(bool)), this, SLOT(dialogAccepted()));
|
|
|
|
connect(ui->optimizeDb, SIGNAL(clicked(bool)), this, SLOT(optimizeDb()));
|
|
|
|
connect(ui->editCookies, SIGNAL(clicked()), this, SLOT(showCookieManager()));
|
|
|
|
connect(ui->editNotifs, SIGNAL(clicked()), this, SLOT(showNotifsPerms()));
|
|
|
|
connect(ui->editGeoloc, SIGNAL(clicked()), this, SLOT(showGeolocPerms()));
|
2012-04-20 15:29:04 +02:00
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("ClearPrivateData");
|
|
|
|
restoreState(settings.value("state", QByteArray()).toByteArray());
|
|
|
|
settings.endGroup();
|
2011-03-18 18:35:09 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
void ClearPrivateData::historyClicked(bool state)
|
|
|
|
{
|
|
|
|
ui->historyLength->setEnabled(state);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 17:29:12 +01:00
|
|
|
void ClearPrivateData::clearLocalStorage()
|
|
|
|
{
|
2014-03-09 21:51:42 +01:00
|
|
|
const QString profile = DataPaths::currentProfilePath();
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
QzTools::removeDir(profile + "/LocalStorage");
|
2012-03-23 17:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPrivateData::clearWebDatabases()
|
|
|
|
{
|
2014-03-09 21:51:42 +01:00
|
|
|
const QString profile = DataPaths::currentProfilePath();
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
QzTools::removeDir(profile + "/Databases");
|
2012-03-23 17:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPrivateData::clearCache()
|
|
|
|
{
|
2014-03-09 22:17:13 +01:00
|
|
|
QFile::remove(DataPaths::currentProfilePath() + "/ApplicationCache.db");
|
2012-03-23 17:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPrivateData::clearIcons()
|
|
|
|
{
|
2014-03-07 18:03:42 +01:00
|
|
|
IconProvider::instance()->clearIconsDatabase();
|
2012-03-23 17:29:12 +01:00
|
|
|
}
|
|
|
|
|
2012-04-20 15:29:04 +02:00
|
|
|
void ClearPrivateData::closeEvent(QCloseEvent* e)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("ClearPrivateData");
|
|
|
|
settings.setValue("state", saveState());
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void ClearPrivateData::dialogAccepted()
|
|
|
|
{
|
2011-07-30 17:57:14 +02:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
if (ui->history->isChecked()) {
|
2012-04-30 16:33:14 +02:00
|
|
|
qint64 start = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
qint64 end = 0;
|
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QDate today = QDate::currentDate();
|
|
|
|
const QDate week = today.addDays(1 - today.dayOfWeek());
|
|
|
|
const QDate month = QDate(today.year(), today.month(), 1);
|
2011-03-18 18:35:09 +01:00
|
|
|
|
|
|
|
switch (ui->historyLength->currentIndex()) {
|
|
|
|
case 0: //Later Today
|
2012-04-30 16:33:14 +02:00
|
|
|
end = QDateTime(today).toMSecsSinceEpoch();
|
2011-03-18 18:35:09 +01:00
|
|
|
break;
|
|
|
|
case 1: //Week
|
2012-04-30 16:33:14 +02:00
|
|
|
end = QDateTime(week).toMSecsSinceEpoch();
|
2011-03-18 18:35:09 +01:00
|
|
|
break;
|
|
|
|
case 2: //Month
|
2012-04-30 16:33:14 +02:00
|
|
|
end = QDateTime(month).toMSecsSinceEpoch();
|
2011-03-18 18:35:09 +01:00
|
|
|
break;
|
|
|
|
case 3: //All
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
if (end == 0) {
|
|
|
|
mApp->history()->clearHistory();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const QList<int> &indexes = mApp->history()->indexesFromTimeRange(start, end);
|
|
|
|
mApp->history()->deleteHistoryEntry(indexes);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
if (ui->cookies->isChecked()) {
|
2012-03-23 17:29:12 +01:00
|
|
|
mApp->cookieJar()->setAllCookies(QList<QNetworkCookie>());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
if (ui->cache->isChecked()) {
|
2012-03-23 17:29:12 +01:00
|
|
|
clearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui->databases->isChecked()) {
|
|
|
|
clearWebDatabases();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui->localStorage->isChecked()) {
|
|
|
|
clearLocalStorage();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2011-03-18 18:35:09 +01:00
|
|
|
if (ui->icons->isChecked()) {
|
2012-03-23 17:29:12 +01:00
|
|
|
clearIcons();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
QApplication::restoreOverrideCursor();
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2014-07-08 19:01:07 +02:00
|
|
|
ui->clear->setEnabled(false);
|
|
|
|
ui->clear->setText(tr("Done"));
|
|
|
|
|
|
|
|
QTimer::singleShot(1000, this, SLOT(close()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-04-20 15:29:04 +02:00
|
|
|
|
2013-12-28 16:55:08 +01:00
|
|
|
void ClearPrivateData::optimizeDb()
|
|
|
|
{
|
|
|
|
mApp->setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
const QString profilePath = DataPaths::currentProfilePath();
|
|
|
|
QString sizeBefore = QzTools::fileSizeToString(QFileInfo(profilePath + "/browsedata.db").size());
|
2013-12-28 16:55:08 +01:00
|
|
|
|
2014-10-14 17:46:52 +02:00
|
|
|
// Delete icons for entries older than 6 months
|
|
|
|
const QDateTime date = QDateTime::currentDateTime().addMonths(-6);
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare(QSL("DELETE FROM icons WHERE id IN (SELECT id FROM history WHERE date < ?)"));
|
|
|
|
query.addBindValue(date.toMSecsSinceEpoch());
|
|
|
|
query.exec();
|
|
|
|
|
|
|
|
query.clear();
|
|
|
|
query.exec(QSL("VACUUM"));
|
2013-12-28 16:55:08 +01:00
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
QString sizeAfter = QzTools::fileSizeToString(QFileInfo(profilePath + "/browsedata.db").size());
|
2013-12-28 16:55:08 +01:00
|
|
|
|
|
|
|
mApp->restoreOverrideCursor();
|
|
|
|
|
|
|
|
QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.<br/><br/><b>Database Size Before: </b>%1<br/><b>Database Size After: </b>%2").arg(sizeBefore, sizeAfter));
|
|
|
|
}
|
|
|
|
|
2014-07-08 19:01:07 +02:00
|
|
|
void ClearPrivateData::showCookieManager()
|
|
|
|
{
|
2015-09-25 22:31:04 +02:00
|
|
|
CookieManager* dialog = new CookieManager();
|
|
|
|
dialog->show();
|
2014-07-08 19:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPrivateData::showNotifsPerms()
|
|
|
|
{
|
2014-11-07 18:08:12 +01:00
|
|
|
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
|
2015-05-22 23:18:25 +02:00
|
|
|
dialog->showFeaturePermissions(QWebEnginePage::Notifications);
|
2014-11-07 18:08:12 +01:00
|
|
|
dialog->open();
|
2014-07-08 19:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPrivateData::showGeolocPerms()
|
|
|
|
{
|
2014-11-07 18:08:12 +01:00
|
|
|
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
|
2015-05-22 23:18:25 +02:00
|
|
|
dialog->showFeaturePermissions(QWebEnginePage::Geolocation);
|
2014-11-07 18:08:12 +01:00
|
|
|
dialog->open();
|
2014-07-08 19:01:07 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 15:29:04 +02:00
|
|
|
static const int stateDataVersion = 0x0001;
|
|
|
|
|
|
|
|
void ClearPrivateData::restoreState(const QByteArray &state)
|
|
|
|
{
|
|
|
|
QDataStream stream(state);
|
|
|
|
if (stream.atEnd()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int version = -1;
|
|
|
|
int historyIndex = -1;
|
|
|
|
bool databases = false;
|
|
|
|
bool localStorage = false;
|
|
|
|
bool cache = false;
|
|
|
|
bool cookies = false;
|
|
|
|
bool icons = false;
|
|
|
|
|
|
|
|
stream >> version;
|
|
|
|
if (version != stateDataVersion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream >> historyIndex;
|
|
|
|
stream >> databases;
|
|
|
|
stream >> localStorage;
|
|
|
|
stream >> cache;
|
|
|
|
stream >> cookies;
|
|
|
|
stream >> icons;
|
|
|
|
|
|
|
|
if (historyIndex != -1) {
|
|
|
|
ui->history->setChecked(true);
|
|
|
|
ui->historyLength->setEnabled(true);
|
|
|
|
ui->historyLength->setCurrentIndex(historyIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->databases->setChecked(databases);
|
|
|
|
ui->localStorage->setChecked(localStorage);
|
|
|
|
ui->cache->setChecked(cache);
|
|
|
|
ui->cookies->setChecked(cookies);
|
|
|
|
ui->icons->setChecked(icons);
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray ClearPrivateData::saveState()
|
|
|
|
{
|
|
|
|
// history - web database - local storage - cache - cookies - icons
|
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
stream << stateDataVersion;
|
|
|
|
|
|
|
|
if (!ui->history->isChecked()) {
|
|
|
|
stream << -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stream << ui->historyLength->currentIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
stream << ui->databases->isChecked();
|
|
|
|
stream << ui->localStorage->isChecked();
|
|
|
|
stream << ui->cache->isChecked();
|
|
|
|
stream << ui->cookies->isChecked();
|
|
|
|
stream << ui->icons->isChecked();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|