This repository has been archived by the owner on May 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscreencapsettings.cpp
198 lines (168 loc) · 5.18 KB
/
screencapsettings.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
#include "screencapsettings.h"
#include "utility.h"
ScreenCapSettings::ScreenCapSettings()
{
this->loadMainSettings();
}
/**
* @brief ScreenCapSettings::loadMainSettings
* Loads the application's setting.
*/
void ScreenCapSettings::loadMainSettings() {
QSettings settings(QSettings::UserScope, ORGANIZATION_NAME, APPLICATION_NAME);
this->capFilePath = settings.value(FILE_PATH, DEF_FILE_PATH).toString();
this->capTime = settings.value(CAP_TIME, DEF_CAP_TIME).toInt();
this->capDimensions = settings.value(CAP_DIMENSIONS, DEF_CAP_DIMENSIONS).toInt();
this->capIsOn = settings.value(CAP_IS_ON, DEF_CAP_IS_OFF).toInt();
this->isCapRandom = settings.value(CAP_IS_RANDOM, DEF_CAP_IS_RANDOM).toBool();
this->minimizeToTray = settings.value(MINIMIZE_TO_TRAY, DEF_MINIMIZE_TO_TRAY).toBool();
this->startMinimized = settings.value(START_MINIMIZED, DEF_START_MINIMIZED).toBool();
this->captureOnStartup = settings.value(CAP_STARTUP, DEF_CAP_STARTUP).toBool();
this->imgFormat = settings.value(CAP_IMG_FORMAT, DEF_IMG_FORMAT).toInt();
this->imgQuality = settings.value(CAP_IMG_QUALITY, DEF_IMG_QUALITY).toInt();
}
/**
* @brief ScreenCapSettings::SaveMainSettings
* Saves the main settings in the registry or a file.
*/
void ScreenCapSettings::SaveMainSettings() {
QSettings settings(QSettings::UserScope, ORGANIZATION_NAME, APPLICATION_NAME);
settings.setValue(FILE_PATH, this->capFilePath);
settings.setValue(CAP_TIME, this->capTime);
settings.setValue(CAP_DIMENSIONS, this->capDimensions);
settings.setValue(CAP_IS_ON, this->capIsOn);
settings.setValue(CAP_IS_RANDOM, this->isCapRandom);
settings.setValue(MINIMIZE_TO_TRAY, this->minimizeToTray);
settings.setValue(START_MINIMIZED, this->startMinimized);
settings.setValue(CAP_STARTUP, this->captureOnStartup);
settings.setValue(CAP_IMG_FORMAT, this->imgFormat);
settings.setValue(CAP_IMG_QUALITY, this->imgQuality);
}
/**
* @brief ScreenCapSettings::LoadDefaultValues
* Load the default values, this is called incase the application settings
* cannot be loaded.
*/
void ScreenCapSettings::LoadDefaultValues() {
this->capFilePath = DEF_FILE_PATH;
this->capTime = DEF_CAP_TIME;
this->capDimensions = DEF_CAP_DIMENSIONS;
this->capIsOn = DEF_CAP_IS_ON;
this->isCapRandom = DEF_CAP_IS_RANDOM;
this->minimizeToTray = DEF_MINIMIZE_TO_TRAY;
this->startMinimized = DEF_START_MINIMIZED;
this->captureOnStartup = DEF_CAP_STARTUP;
this->imgFormat = DEF_IMG_FORMAT;
this->imgQuality = DEF_IMG_QUALITY;
}
void ScreenCapSettings::SaveDefaultSettings() {
this->loadMainSettings();
this->SaveMainSettings();
}
bool ScreenCapSettings::ValidateSettings() {
if(this->capTime == 0) {
return false;
}
return true;
}
// Getters
QString ScreenCapSettings::GetFilePath() {
return this->capFilePath;
}
int ScreenCapSettings::GetCapDimensions() {
return this->capDimensions;
}
int ScreenCapSettings::GetCapTime() {
return this->capTime;
}
int ScreenCapSettings::GetCapIsOn() {
return this->capIsOn;
}
bool ScreenCapSettings::GetCapIsRandom() {
return this->isCapRandom;
}
bool ScreenCapSettings::GetMinimizeToTray()
{
return this->minimizeToTray;
}
bool ScreenCapSettings::GetStartMinimized()
{
return this->startMinimized;
}
bool ScreenCapSettings::GetCaptureOnStartup()
{
return this->captureOnStartup;
}
QMap<int, QString> ScreenCapSettings::GetListOfImgFormats()
{
QMap<int, QString> imgFormats;
for(int i = 0; i < IMG_FORMATS.length(); ++i) {
imgFormats[IMG_FORMAT_KEYS[i]] = IMG_FORMATS[i];
}
return imgFormats;
}
QMap<int, QString> ScreenCapSettings::GetListOfImgQualities() {
QMap<int, QString> imgQualities;
for(int i = 0; i < IMG_QUALITY.length(); ++i) {
imgQualities[IMG_QUALITY[i]] = IMG_QUALITY_NAME[i];
}
return imgQualities;
}
int ScreenCapSettings::GetImgQuality()
{
return this->imgQuality;
}
QString ScreenCapSettings::GetImgFormat()
{
if(this->imgFormat == JPG_FORMAT) {
return "JPG";
} else if(this->imgFormat == PNG_FORMAT) {
return "PNG";
} else {
return "JPG";
}
}
int ScreenCapSettings::GetImgFormatInt() {
return this->imgFormat;
}
// Setters
void ScreenCapSettings::SetFilePath(QString path) {
this->capFilePath = path;
}
void ScreenCapSettings::SetCapDimensions(int dimensions) {
this->capDimensions = dimensions;
}
void ScreenCapSettings::SetCapTime(int time) {
this->capTime = time;
}
void ScreenCapSettings::SetCapIsOn(int isOn) {
this->capIsOn = isOn;
}
void ScreenCapSettings::SetCapIsRandom(bool isRandom) {
this->isCapRandom = isRandom;
}
void ScreenCapSettings::SetMinimizeToTray(bool isSet)
{
this->minimizeToTray = isSet;
}
void ScreenCapSettings::SetStartMinimized(bool isSet)
{
this->startMinimized = isSet;
}
void ScreenCapSettings::SetCaptureOnStartup(bool isSet)
{
this->captureOnStartup = isSet;
}
void ScreenCapSettings::SetImgQuality(int quality)
{
if(quality > 100) {
quality = 100;
} else if(quality <= 0) {
quality = 1;
}
this->imgQuality = quality;
}
void ScreenCapSettings::SetImgFormat(int imgFormat)
{
this->imgFormat = imgFormat;
}