-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.cpp
205 lines (171 loc) · 5.32 KB
/
settings.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
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
/**
* This file is Copyright 2012
* Kristian Beres <[email protected]>
*
* Other copyrights also apply to some parts of this work. Please
* see the individual file headers for details.
*
* 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. See the file
* COPYING included with this distribution for more information.
*/
#include "settings.h"
#include "simplecrypt.h"
#include <QtCore>
Settings::Settings(){
this->width = 350;
this->height = 80;
this->duration = 5;
this->seconds = 30; // refresh time
this->positionX = 1;
this->positionY = 1;
pSettings = new QSettings("Katropine", "GmailSniffer");
pSettings->beginGroup("User");
this->setUserName(pSettings->value("username").toString());
SimpleCrypt crypt(Settings::salt);
QString hash = crypt.decryptToString(pSettings->value("password").toString());
this->setPassword(hash);
this->setBrowser(pSettings->value("browser").toInt());
this->setBrowserCmd(pSettings->value("browser_cmd").toString());
int refresh = this->seconds;
if(pSettings->value("refresh").toInt() > 0){
refresh = pSettings->value("refresh").toInt();
}
this->setRefreshTime(refresh);
pSettings->endGroup();
pSettings->beginGroup("Notifiction");
this->setSystemNotifier(pSettings->value("use_sys_notification").toBool());
this->setAlertSound(pSettings->value("use_alert_sound").toBool());
this->setPositoinX(pSettings->value("position_x").toInt());
this->setPositoinY(pSettings->value("position_y").toInt());
this->setWidth(pSettings->value("width").toInt());
this->setHeight(pSettings->value("height").toInt());
this->setDuration(pSettings->value("duration").toInt());
pSettings->endGroup();
pSettings->beginGroup("Geometry");
this->setSnifferPosition(pSettings->value("position").toRect());
pSettings->endGroup();
}
void Settings::setUserName(QString userName){
this->userName = userName;
}
void Settings::setPassword(QString password){
this->password = password;
}
void Settings::setBrowserCmd(QString browserCmd){
this->browserCmd = browserCmd;
}
void Settings::setBrowser(int browser){
this->browser = browser;
}
void Settings::setRefreshTime(int seconds){
this->seconds = seconds;
}
// notification
void Settings::setPositoinX(int x){
this->positionX = x;
}
void Settings::setPositoinY(int y){
this->positionY = y;
}
void Settings::setWidth(int width){
this->width = width;
}
void Settings::setHeight(int height){
this->height = height;
}
void Settings::setDuration(int duration){
this->duration = duration;
}
void Settings::setSnifferPosition(QRect rect){
this->snifferPosition = rect;
}
void Settings::setSystemNotifier(bool sysNotify){
this->sysNotify = sysNotify;
}
void Settings::setAlertSound(bool alertSound){
this->alertSound = alertSound;
}
QString Settings::getUserName(){
return this->userName;
}
QString Settings::getPassword(){
return this->password;
}
QString Settings::getBrowserCmd(){
return this->browserCmd;
}
int Settings::getBrowser(){
return this->browser;
}
int Settings::getPositionX(){
return this->positionX;
}
int Settings::getPositionY(){
return this->positionY;
}
int Settings::getWidth(){
return this->width;
}
int Settings::getHeight(){
return this->height;
}
int Settings::getDuration(){
return this->duration;
}
int Settings::getRefreshTime(){
return this->seconds;
}
QRect Settings::getSnifferPosition(){
return this->snifferPosition;
}
bool Settings::getSystemNotifier(){
return this->sysNotify;
}
bool Settings::getAlertSound(){
return this->alertSound;
}
void Settings::save(){
pSettings->beginGroup("User");
if(!this->userName.isEmpty()){
pSettings->setValue("username", this->userName);
}
if(!this->password.isEmpty()){
SimpleCrypt crypt(Settings::salt);
QString hash = crypt.encryptToString(this->password);
pSettings->setValue("password", hash);
}
if(!this->browserCmd.isEmpty()){
pSettings->setValue("browser", this->browser);
pSettings->setValue("browser_cmd", this->browserCmd);
}
pSettings->setValue("refresh", this->seconds);
pSettings->endGroup();
pSettings->beginGroup("Notifiction");
pSettings->setValue("use_sys_notification", this->sysNotify);
pSettings->setValue("use_alert_sound", this->alertSound);
pSettings->setValue("position_x", this->positionX);
pSettings->setValue("position_y", this->positionY);
pSettings->setValue("width",this->width);
pSettings->setValue("height", this->height);
pSettings->setValue("duration", this->duration);
pSettings->endGroup();
pSettings->beginGroup("Geometry");
pSettings->setValue("position", this->snifferPosition);
pSettings->endGroup();
}
QString Settings::fetchBrowserCommand(const int browserID){
QMap<int, QString> browser;
browser.insert(0, "default");
browser.insert(1, "firefox");
browser.insert(2, "chromium");
browser.insert(3, "opera");
browser.insert(4, "iceweasel");
browser.insert(5, "konqueror");
return browser[browserID];
}
Settings::~Settings(){
delete pSettings;
}