forked from teroaij/tvkaistagui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsdialog.cpp
253 lines (214 loc) · 8.45 KB
/
settingsdialog.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include <QDesktopServices>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QUrl>
#include "mainwindow.h"
#include "texteditordialog.h"
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
SettingsDialog::SettingsDialog(QSettings *settings, QWidget *parent) :
QDialog(parent), ui(new Ui::SettingsDialog), m_settings(settings),
m_usernameChanged(false)
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), SLOT(acceptChanges()));
connect(ui->downloadDirToolButton, SIGNAL(clicked()), SLOT(openDirectoryDialog()));
connect(ui->recoverCommandLinkButton, SIGNAL(clicked()), SLOT(recoverPassword()));
connect(ui->orderCommandLinkButton, SIGNAL(clicked()), SLOT(orderTVkaista()));
connect(ui->advancedPushButton, SIGNAL(toggled(bool)), SLOT(toggleAdvancedSettings(bool)));
connect(ui->filePlayerToolButton, SIGNAL(clicked()), SLOT(editFilePlayerPath()));
connect(ui->streamPlayerToolButton, SIGNAL(clicked()), SLOT(editStreamPlayerPath()));
connect(ui->flashPlayerToolButton, SIGNAL(clicked()), SLOT(editFlashPlayerPath()));
QStringList fontSizeOptions;
fontSizeOptions << trUtf8("Pieni") << trUtf8("Normaali") << trUtf8("Suuri") << trUtf8("Erittäin suuri");
QStringList doubleClickOptions;
doubleClickOptions << trUtf8("Suoratoistetaan ohjelma") << trUtf8("Ladataan ohjelma");
ui->fontSizeComboBox->addItems(fontSizeOptions);
ui->doubleClickComboBox->addItems(doubleClickOptions);
toggleAdvancedSettings(false);
loadSettings();
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
bool SettingsDialog::isUsernameChanged() const
{
return m_usernameChanged;
}
void SettingsDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void SettingsDialog::acceptChanges()
{
saveSettings();
accept();
}
void SettingsDialog::openDirectoryDialog()
{
QString dirPath = QDir::fromNativeSeparators(ui->downloadDirLineEdit->text());
dirPath = QFileDialog::getExistingDirectory(this, trUtf8("Valitse hakemisto"), dirPath);
if (!dirPath.isEmpty()) {
ui->downloadDirLineEdit->setText(QDir::toNativeSeparators(dirPath));
}
}
void SettingsDialog::recoverPassword()
{
if (!QDesktopServices::openUrl(QUrl("http://www.tvkaista.com/login/recover/"))) {
QMessageBox msgBox(this);
msgBox.setWindowTitle(windowTitle());
msgBox.setText(trUtf8("Web-sivun avaaminen epäonnistui. Palauta salasana osoitteessa "
"http://wwww.tvkaista.com/login/recover/"));
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
return;
}
}
void SettingsDialog::orderTVkaista()
{
if (!QDesktopServices::openUrl(QUrl("http://www.tvkaista.com/order/"))) {
QMessageBox msgBox(this);
msgBox.setWindowTitle(windowTitle());
msgBox.setText(trUtf8("Web-sivun avaaminen epäonnistui. Tilaa TV-kaista osoitteesta "
"http://wwww.tvkaista.com/order/"));
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
return;
}
}
void SettingsDialog::toggleAdvancedSettings(bool checked)
{
ui->advancedSettingsLine->setVisible(checked);
ui->proxyLabel->setVisible(checked);
ui->proxyHostLineEdit->setVisible(checked);
ui->proxyPortLabel->setVisible(checked);
ui->proxyPortSpinBox->setVisible(checked);
}
void SettingsDialog::editFilePlayerPath()
{
TextEditorDialog dialog(this);
dialog.setText(ui->filePlayerLineEdit->text());
if (dialog.exec() == QDialog::Accepted) {
ui->filePlayerLineEdit->setText(dialog.text());
}
}
void SettingsDialog::editStreamPlayerPath()
{
TextEditorDialog dialog(this);
dialog.setText(ui->streamPlayerLineEdit->text());
if (dialog.exec() == QDialog::Accepted) {
ui->streamPlayerLineEdit->setText(dialog.text());
}
}
void SettingsDialog::editFlashPlayerPath()
{
TextEditorDialog dialog(this);
dialog.setText(ui->flashPlayerLineEdit->text());
if (dialog.exec() == QDialog::Accepted) {
ui->flashPlayerLineEdit->setText(dialog.text());
}
}
void SettingsDialog::loadSettings()
{
m_settings->beginGroup("client");
ui->usernameLineEdit->setText(m_settings->value("username").toString());
ui->passwordLineEdit->setText(MainWindow::decodePassword(m_settings->value("password").toString()));
m_settings->beginGroup("proxy");
ui->proxyHostLineEdit->setText(m_settings->value("host").toString());
ui->proxyPortSpinBox->setValue(m_settings->value("port", 8080).toInt());
m_settings->endGroup();
m_settings->endGroup();
m_settings->beginGroup("mainWindow");
int fontSize = m_settings->value("fontSize", 10).toInt();
int fontIndex = 1;
if (fontSize <= 8) fontIndex = 0;
else if (fontSize <= 10) fontIndex = 1;
else if (fontSize <= 16) fontIndex = 2;
else if (fontSize <= 22) fontIndex = 3;
ui->fontSizeComboBox->setCurrentIndex(fontIndex);
if (m_settings->value("doubleClick").toString() == "download") {
ui->doubleClickComboBox->setCurrentIndex(1);
}
else {
ui->doubleClickComboBox->setCurrentIndex(0);
}
ui->posterCheckBox->setChecked(m_settings->value("posterVisible", true).toBool());
ui->deleteFromDiskCheckBox->setChecked(m_settings->value("deleteFromDisk", false).toBool());
m_settings->endGroup();
m_settings->beginGroup("downloads");
QString dir = m_settings->value("directory").toString();
QString filenameFormat = m_settings->value("filenameFormat").toString();
m_settings->endGroup();
m_settings->beginGroup("mediaPlayer");
QString streamCommand = m_settings->value("stream").toString();
QString fileCommand = m_settings->value("file").toString();
QString flashCommand = m_settings->value("flash").toString();
m_settings->endGroup();
if (dir.isEmpty()) {
dir = MainWindow::defaultDownloadDirectory();
}
ui->downloadDirLineEdit->setText(dir);
ui->filenameFormatLineEdit->setText(filenameFormat);
if (streamCommand.isEmpty()) {
streamCommand = MainWindow::defaultStreamPlayerCommand();
}
if (fileCommand.isEmpty()) {
fileCommand = MainWindow::defaultFilePlayerCommand();
}
ui->streamPlayerLineEdit->setText(streamCommand);
ui->streamPlayerLineEdit->setCursorPosition(0);
ui->filePlayerLineEdit->setText(fileCommand);
ui->filePlayerLineEdit->setCursorPosition(0);
ui->flashPlayerLineEdit->setText(flashCommand);
ui->flashPlayerLineEdit->setCursorPosition(0);
}
void SettingsDialog::saveSettings()
{
m_settings->beginGroup("client");
QString username = ui->usernameLineEdit->text().trimmed();
QString password = MainWindow::encodePassword(ui->passwordLineEdit->text().trimmed());
m_usernameChanged = m_settings->value("username") != username ||
m_settings->value("password") != password;
m_settings->setValue("username", username);
m_settings->setValue("password", password);
m_settings->beginGroup("proxy");
m_settings->setValue("host", ui->proxyHostLineEdit->text());
m_settings->setValue("port", ui->proxyPortSpinBox->value());
m_settings->endGroup();
m_settings->endGroup();
m_settings->beginGroup("mainWindow");
int fontIndex = ui->fontSizeComboBox->currentIndex();
int fontSize = 10;
if (fontIndex == 0) fontSize = 8;
else if (fontIndex == 1) fontSize = 10;
else if (fontIndex == 2) fontSize = 16;
else if (fontIndex == 3) fontSize = 22;
m_settings->setValue("fontSize", fontSize);
if (ui->doubleClickComboBox->currentIndex() == 0) {
m_settings->setValue("doubleClick", "stream");
}
else {
m_settings->setValue("doubleClick", "download");
}
m_settings->setValue("posterVisible", ui->posterCheckBox->isChecked());
m_settings->setValue("deleteFromDisk", ui->deleteFromDiskCheckBox->isChecked());
m_settings->endGroup();
m_settings->beginGroup("downloads");
m_settings->setValue("directory", ui->downloadDirLineEdit->text());
m_settings->setValue("filenameFormat", ui->filenameFormatLineEdit->text());
m_settings->endGroup();
m_settings->beginGroup("mediaPlayer");
m_settings->setValue("stream", ui->streamPlayerLineEdit->text());
m_settings->setValue("file", ui->filePlayerLineEdit->text());
m_settings->setValue("flash", ui->flashPlayerLineEdit->text());
m_settings->endGroup();
}