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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
#include "settingswidget.h"
#include "ui_settingswidget.h"
#include <QMessageBox>
extern QString defaultUserAgentStr;
SettingsWidget::SettingsWidget(QWidget *parent, QString engineCachePath, QString enginePersistentStoragePath) :
QWidget(parent),
ui(new Ui::SettingsWidget)
{
ui->setupUi(this);
ui->disableVideosCheckBox->hide();//impl later
this->engineCachePath = engineCachePath;
this->enginePersistentStoragePath = enginePersistentStoragePath;
ui->closeButtonActionComboBox->setCurrentIndex(settings.value("closeButtonActionCombo",0).toInt());
ui->notificationCheckBox->setChecked(settings.value("disableNotificationPopups",false).toBool());
ui->muteAudioCheckBox->setChecked(settings.value("muteAudio",false).toBool());
ui->autoPlayMediaCheckBox->setChecked(settings.value("autoPlayMedia",false).toBool());
ui->themeComboBox->setCurrentText(utils::toCamelCase(settings.value("windowTheme","light").toString()));
ui->userAgentLineEdit->setText(settings.value("useragent",defaultUserAgentStr).toString());
this->setCurrentPasswordText("Current Password: <i>"
+QByteArray::fromBase64(settings.value("asdfg").toString().toUtf8())+"</i>");
applyThemeQuirks();
ui->setUserAgent->setEnabled(false);
}
SettingsWidget::~SettingsWidget()
{
delete ui;
}
void SettingsWidget::refresh()
{
ui->cacheSize->setText(utils::refreshCacheSize(cachePath()));
ui->cookieSize->setText(utils::refreshCacheSize(persistentStoragePath()));
}
void SettingsWidget::updateDefaultUAButton(const QString engineUA)
{
bool isDefault = QString::compare(engineUA,defaultUserAgentStr,Qt::CaseInsensitive) == 0;
ui->defaultUserAgentButton->setEnabled(!isDefault);
if(ui->userAgentLineEdit->text().trimmed().isEmpty()){
ui->userAgentLineEdit->setText(engineUA);
}
}
QString SettingsWidget::cachePath()
{
return engineCachePath;
}
QString SettingsWidget::persistentStoragePath()
{
return enginePersistentStoragePath;
}
void SettingsWidget::on_deleteCache_clicked()
{
QMessageBox msgBox;
msgBox.setText("This will delete app cache! Application cache makes application load faster.");
msgBox.setIconPixmap(QPixmap(":/icons/information-line.png").scaled(42,42,Qt::KeepAspectRatio,Qt::SmoothTransformation));
msgBox.setInformativeText("Delete Application cache ?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:{
utils::delete_cache(this->cachePath());
refresh();
break;
}
case QMessageBox::No:
break;
}
}
void SettingsWidget::on_deletePersistentData_clicked()
{
QMessageBox msgBox;
msgBox.setText("This will delete app Persistent Data ! Persistent data includes persistent cookies, HTML5 local storage, and visited links.");
msgBox.setIconPixmap(QPixmap(":/icons/information-line.png").scaled(42,42,Qt::KeepAspectRatio,Qt::SmoothTransformation));
msgBox.setInformativeText("Delete Application Cookies ?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:{
utils::delete_cache(this->persistentStoragePath());
refresh();
break;
}
case QMessageBox::No:
break;
}
}
void SettingsWidget::on_notificationCheckBox_toggled(bool checked)
{
settings.setValue("disableNotificationPopups",checked);
}
void SettingsWidget::on_themeComboBox_currentTextChanged(const QString &arg1)
{
applyThemeQuirks();
settings.setValue("windowTheme",QString(arg1).toLower());
emit updateWindowTheme();
emit updatePageTheme();
}
void SettingsWidget::applyThemeQuirks()
{
//little quirks
if(QString::compare(ui->themeComboBox->currentText(),"dark",Qt::CaseInsensitive)==0)
{
ui->label_7->setStyleSheet("color:#c2c5d1;padding: 0px 8px 0px 8px;background:transparent;");
}else{
ui->label_7->setStyleSheet("color:#1e1f21;padding: 0px 8px 0px 8px;background:transparent;");
}
}
void SettingsWidget::on_muteAudioCheckBox_toggled(bool checked)
{
settings.setValue("muteAudio",checked);
emit muteToggled(checked);
}
void SettingsWidget::on_autoPlayMediaCheckBox_toggled(bool checked)
{
settings.setValue("autoPlayMedia",checked);
emit autoPlayMediaToggled(checked);
}
void SettingsWidget::on_defaultUserAgentButton_clicked()
{
ui->userAgentLineEdit->setText(defaultUserAgentStr);
emit userAgentChanged(ui->userAgentLineEdit->text());
}
void SettingsWidget::on_userAgentLineEdit_textChanged(const QString &arg1)
{
bool isDefault = QString::compare(arg1.trimmed(),defaultUserAgentStr,Qt::CaseInsensitive) == 0;
bool isPrevious= QString::compare(arg1.trimmed(),settings.value("useragent",defaultUserAgentStr).toString(),Qt::CaseInsensitive) == 0;
if(isDefault == false && arg1.trimmed().isEmpty()==false)
{
ui->defaultUserAgentButton->setEnabled(false);
ui->setUserAgent->setEnabled(false);
}
if(isPrevious == false && arg1.trimmed().isEmpty() == false)
{
ui->setUserAgent->setEnabled(true);
ui->defaultUserAgentButton->setEnabled(true);
}
if(isPrevious){
ui->defaultUserAgentButton->setEnabled(true);
ui->setUserAgent->setEnabled(false);
}
}
void SettingsWidget::on_setUserAgent_clicked()
{
if(ui->userAgentLineEdit->text().trimmed().isEmpty()){
QMessageBox::information(this,QApplication::applicationName()+"| Error",
"Cannot set an empty UserAgent String.");
return;
}
emit userAgentChanged(ui->userAgentLineEdit->text());
}
void SettingsWidget::on_disableVideosCheckBox_toggled(bool checked)
{
settings.setValue("disableVideos",checked);
}
void SettingsWidget::on_closeButtonActionComboBox_currentIndexChanged(int index)
{
settings.setValue("closeButtonActionCombo",index);
}
void SettingsWidget::appLockSetChecked(bool checked)
{
ui->applock_checkbox->setChecked(checked);
}
void SettingsWidget::setCurrentPasswordText(QString str)
{
ui->current_password->setText(str);
}
void SettingsWidget::on_applock_checkbox_toggled(bool checked)
{
if(settings.value("asdfg").isValid()){
settings.setValue("lockscreen",checked);
}else{
settings.setValue("lockscreen",false);
}
if(checked){
emit init_lock();
}
}
|