/
resetwindow.cpp
95 lines (87 loc) · 2.88 KB
/
resetwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright 2011 Anand Bose <anandbose@in.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "resetwindow.h"
#include <QtCore/QDir>
#include <QtCore/QDirIterator>
#include <QtWebKit/QWebSettings>
ResetWindow::ResetWindow()
{
clearCacheCheckBox = new QCheckBox(tr("Clear cache"));
clearCookiesCheckBox = new QCheckBox(tr("Clear cookies"));
clearHistoryCheckBox = new QCheckBox(tr("Clear browsing history"));
clearBookmarksCheckBox = new QCheckBox(tr("Clear bookmarks"));
clearPreferencesCheckBox = new QCheckBox(tr("Clear preferences"));
resetButton = new QPushButton(tr("Reset"));
closeButton = new QPushButton(tr("Close"));
buttonLayout = new QHBoxLayout;
mainLayout = new QVBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(resetButton);
buttonLayout->addWidget(closeButton);
mainLayout->addWidget(clearCacheCheckBox);
mainLayout->addWidget(clearCookiesCheckBox);
mainLayout->addWidget(clearHistoryCheckBox);
mainLayout->addWidget(clearBookmarksCheckBox);
mainLayout->addWidget(clearPreferencesCheckBox);
mainLayout->addLayout(buttonLayout);
mainLayout->setContentsMargins(5,25,5,5);
setLayout(mainLayout);
setTitle(tr("Reset Browser Settings"));
connect(resetButton,SIGNAL(clicked()),this,SLOT(doReset()));
connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
}
void ResetWindow::doReset()
{
QDir dir = QDir::home();
dir.cd(".WebRender");
if(clearCacheCheckBox->checkState() == Qt::Checked)
{
dir.cd("Cache");
deleteDir(dir.absolutePath());
dir.cdUp();
}
if(clearCookiesCheckBox->checkState() == Qt::Checked)
{
dir.cd("Cookies");
deleteDir(dir.absolutePath());
dir.cdUp();
dir.cd("LocalStorage");
deleteDir(dir.absolutePath());
dir.cdUp();
dir.cd("OfflineStorage");
deleteDir(dir.absolutePath());
dir.cdUp();
}
if(clearHistoryCheckBox->checkState() == Qt::Checked)
dir.remove("historyFile");
if(clearBookmarksCheckBox->checkState() == Qt::Checked)
dir.remove("bookmarksFile");
if(clearPreferencesCheckBox->checkState() == Qt::Checked)
dir.remove("preferencesFile");
}
void ResetWindow::deleteDir(QString dir)
{
QDirIterator i(dir, QDirIterator::Subdirectories);
QDir Dir(dir);
while(i.hasNext())
{
i.next();
Dir.remove(i.filePath());
}
}