forked from AdunanzA/Tsunami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingswindow.cpp.bak
141 lines (120 loc) · 4.04 KB
/
settingswindow.cpp.bak
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
#include "settingswindow.h"
#include "ui_settingswindow.h"
QString settingswindow::settingsFileName = "tsunami.ini";
QSettings::Format settingswindow::settingsFileFormat = QSettings::IniFormat;
settingswindow::settingswindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::settingswindow)
{
ui->setupUi(this);
ui->txtDownloadPath->installEventFilter(this);
loadSettings();
connect(ui->cmbLanguage, SIGNAL(activated(int)), this, SLOT(setCurrentLanguage(int)));
}
settingswindow::~settingswindow()
{
delete ui;
}
void settingswindow::loadSettings()
{
// QSettings settings(settingsFileName, settingsFileFormat);
// settings.sync();
// QStringList Groups = settings.childGroups();
// foreach (QString group, Groups) {
// QTreeWidgetItem *wi = new QTreeWidgetItem(ui->treeWidget);
// wi->setForeground(0, QColor(255,255,255));
// wi->setText(0, group);
// settings.beginGroup(group);
// QStringList List = settings.allKeys();
// foreach (QString item, List) {
// QTreeWidgetItem *wi2 = new QTreeWidgetItem(wi);
// wi2->setForeground(0, QColor(180,180,180));
// wi2->setText(0, item);
// }
// settings.endGroup();
// }
QSettings settings(settingsFileName, settingsFileFormat);
QString downloadPath = settings.value("Download/downloadPath", QCoreApplication::applicationDirPath()).toString();
QString debugLevel = settings.value("Debug/Level", "Info").toString();
QString currentLanguage = settings.value("Language").toString();
// Find Combobox Index from Language string on ini file
int index = ui->cmbLanguage->findText(currentLanguage, Qt::MatchFlag::MatchFixedString);
setCurrentLanguage(index);
setDownloadPath(downloadPath);
setDebugLevel(debugLevel);
}
void settingswindow::saveSettings()
{
QSettings settings(settingsFileName, settingsFileFormat);
settings.beginGroup("Download");
settings.setValue("downloadPath", getDownloadPath());
settings.endGroup();
settings.setValue("Debug/Level", getDebugLevel());
}
void settingswindow::setLastBrowsedDir(const QString &path)
{
QSettings settings(settingsFileName, settingsFileFormat);
settings.setValue("Download/lastBrowsedDir", path);
}
QString settingswindow::getLastBrowsedDir()
{
QSettings settings(settingsFileName, settingsFileFormat);
return settings.value("Download/lastBrowsedDir", QCoreApplication::applicationDirPath()).toString();
}
QString settingswindow::getDownloadPath() const
{
return p_downloadPath;
}
void settingswindow::setDownloadPath(const QString &value)
{
ui->txtDownloadPath->setText(value);
p_downloadPath = value;
}
bool settingswindow::eventFilter(QObject *object, QEvent *event)
{
if(object == ui->txtDownloadPath && event->type() == QEvent::MouseButtonPress) {
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose download path"),
getDownloadPath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) {
setDownloadPath(dir);
}
}
return false;
}
void settingswindow::on_btnSave_released()
{
saveSettings();
}
void settingswindow::on_btnCancel_released()
{
loadSettings();
}
QString settingswindow::getDebugLevel() const
{
return p_debugLevel;
}
void settingswindow::setDebugLevel(const QString &value)
{
ui->cmbDebugLevel->setCurrentText(value);
p_debugLevel = value;
}
void settingswindow::setCurrentLanguage(int value)
{
QSettings settings(settingsFileName, settingsFileFormat);
p_appLanguage = ui->cmbLanguage->itemText(value);
ui->cmbLanguage->setCurrentIndex(value);
settings.setValue("Language", p_appLanguage);
}
QString settingswindow::getCurrentLanguage() const
{
return p_appLanguage;
}
void settingswindow::changeEvent(QEvent *e)
{
if(e->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}