New icon, version bump, updated translations
[someplayer] / src / settingsform.cpp
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20
21 #include "settingsform.h"
22 #include "ui_settingsform.h"
23 #include <QDebug>
24 #include <QFile>
25 #include "someplayer.h"
26 #include "fmtxsettingsdialog.h"
27
28 using namespace SomePlayer::Storage;
29
30 SettingsForm::SettingsForm(QWidget *parent) :
31                 QWidget(parent),
32                 ui(new Ui::SettingsForm)
33 {
34         ui->setupUi(this);
35         Config config;
36         QString albumSorting = config.getValue("ui/albumsorting").toString();
37         QString showTrackLenght = config.getValue("ui/showtracklenght").toString();
38         QString orientation = config.getValue("ui/orientation").toString();
39         QString icons_theme = config.getValue("ui/iconstheme").toString();
40         QString gradient = config.getValue("ui/gradient").toString();
41         QString language = config.getValue("ui/language").toString();
42         QString track_color = config.getValue("ui/trackcolor").toString();
43         ui->albumsSortDButton->setChecked(true);        // defaule sorting
44         ui->showTrackLenghtYButton->setChecked(true);   // show by default
45         ui->orientationLButton->setChecked(true);
46         ui->iconsWButton->setChecked(true);
47         ui->gradientYButton->setChecked(true);
48         ui->engLangButton->setChecked(true);
49         ui->cBlueButton->setChecked(true);
50         ui->pauseHPNoButton->setChecked(true);
51         ui->hwKeysBox->setChecked(false);
52         ui->hwkeysLabel->setEnabled(false);
53         ui->hwTControlButton->setEnabled(false);
54         ui->hwVolumeButton->setEnabled(false);
55         ui->fmtxGroupBox->setChecked(false);
56         if (albumSorting == "alphabet") {
57                 ui->albumsSortAButton->setChecked(true);
58         }
59         if (showTrackLenght == "no") {
60                 ui->showTrackLenghtNButton->setChecked(true);
61         }
62         if (orientation == "portrait") {
63                 ui->orientationPButton->setChecked(true);
64         } else if (orientation == "auto") {
65                 ui->orientationAButton->setChecked(true);
66         }
67         if (icons_theme == "black") {
68                 ui->iconstBButton->setChecked(true);
69         }
70         if (gradient == "no") {
71                 ui->gradientNButton->setChecked(true);
72         }
73         if (language == "ru") {
74                 ui->ruLangButton->setChecked(true);
75         }
76         if (language == "cn") {
77                 ui->cnLangButton->setChecked(true);
78         }
79         if (track_color == "black") {
80                 ui->cBlackButton->setChecked(true);
81         } else if (track_color == "magenta") {
82                 ui->cMagentaButton->setChecked(true);
83         } else if (track_color == "Red") {
84                 ui->cRedButton->setChecked(true);
85         } else if (track_color == "yellow") {
86                 ui->cYellowButton->setChecked(true);
87         } else if (track_color == "white") {
88                 ui->cWhiteButton->setChecked(true);
89         } else if (track_color == "dark") {
90                 ui->cDarkButton->setChecked(true);
91         } else if (track_color == "light") {
92                 ui->cLightButton->setChecked(true);
93         }
94         if (config.getValue("hw/hpautopause").toString() == "yes") {
95                 ui->pauseHPYesButton->setChecked(true);
96         }
97         if (config.getValue("hw/zoomkeys").toString() == "enabled") {
98                 ui->hwKeysBox->setChecked(true);
99                 ui->hwkeysLabel->setEnabled(true);
100                 ui->hwTControlButton->setEnabled(true);
101                 ui->hwVolumeButton->setEnabled(true);
102         }
103         QString behavior = config.getValue("hw/zoom_action").toString();
104         if (behavior == "volume") {
105                 ui->hwVolumeButton->setChecked(true);
106         } else if (behavior == "track") {
107                 ui->hwTControlButton->setChecked(true);
108         } else {
109                 ui->hwVolumeButton->setChecked(true);
110                 config.setValue("hw/zoom_action", "volume");
111         }
112         if (config.getValue("fmtx/enabled").toString() == "yes") {
113                 ui->fmtxGroupBox->setChecked(true);
114                 emit fmtxSettingsChanged();
115         }
116         if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
117                 ui->langBox->hide();
118         } // refactor this when more translations will be added
119         connect (ui->albumsSortAButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_alphabet(bool)));
120         connect (ui->albumsSortDButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_date(bool)));
121         connect (ui->showTrackLenghtNButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_no(bool)));
122         connect (ui->showTrackLenghtYButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_yes(bool)));
123         connect (ui->orientationAButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_auto(bool)));
124         connect (ui->orientationLButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_landscape(bool)));
125         connect (ui->orientationPButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_portrait(bool)));
126         connect (ui->iconstBButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_black(bool)));
127         connect (ui->iconsWButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_white(bool)));
128         connect (ui->gradientNButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_no(bool)));
129         connect (ui->gradientYButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_yes(bool)));
130         connect (ui->engLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_en(bool)));
131         connect (ui->ruLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_ru(bool)));
132         connect (ui->cnLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_cn(bool)));
133         connect (ui->cBlackButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_black(bool)));
134         connect (ui->cBlueButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_blue(bool)));
135         connect (ui->cDarkButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_dark(bool)));
136         connect (ui->cLightButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_light(bool)));
137         connect (ui->cMagentaButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_magenta(bool)));
138         connect (ui->cRedButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_red(bool)));
139         connect (ui->cWhiteButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_white(bool)));
140         connect (ui->cYellowButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_yellow(bool)));
141         connect (ui->pauseHPNoButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_no(bool)));
142         connect (ui->pauseHPYesButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_yes(bool)));
143         connect (ui->hwKeysBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_hw_settings(bool)));
144         connect (ui->hwVolumeButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_volume_control(bool)));
145         connect (ui->hwTControlButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_track_control(bool)));
146         connect (ui->uiButton, SIGNAL(clicked()), this, SLOT(_toggle_view_ui()));
147         connect (ui->hwButton, SIGNAL(clicked()), this, SLOT(_toggle_view_hw()));
148         connect (ui->libraryButton, SIGNAL(clicked()), this, SLOT(_toggle_view_lib()));
149         connect (ui->fmtxSettingsButton, SIGNAL(clicked()), this, SLOT(_open_fmtx_settings()));
150         connect (ui->fmtxGroupBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_fmtx_settings(bool)));
151         _toggle_view_ui();
152         setAttribute(Qt::WA_Maemo5StackedWindow);
153         setWindowFlags(Qt::Window | windowFlags());
154 }
155
156 SettingsForm::~SettingsForm()
157 {
158         delete ui;
159 }
160
161 void SettingsForm::_set_album_sorting_date(bool checked) {
162         if (!checked) return;
163         Config config;
164         config.setValue("ui/albumsorting", "date");
165         emit libraryOptionsChanged();
166 }
167
168 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
169         if (!checked) return;
170         Config config;
171         config.setValue("ui/albumsorting", "alphabet");
172         emit libraryOptionsChanged();
173 }
174
175 void SettingsForm::_set_track_lenght_show_no(bool checked) {
176         if (!checked) return;
177         Config config;
178         config.setValue("ui/showtracklenght", "no");
179         emit libraryOptionsChanged();
180 }
181
182 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
183         if (!checked) return;
184         Config config;
185         config.setValue("ui/showtracklenght", "yes");
186         emit libraryOptionsChanged();
187 }
188
189 void SettingsForm::_set_orientation_auto(bool checked) {
190         if (!checked) return;
191         Config config;
192         config.setValue("ui/orientation", "auto");
193         emit orientationChanged();
194 }
195
196 void SettingsForm::_set_orientation_landscape(bool checked) {
197         if (!checked) return;
198         Config config;
199         config.setValue("ui/orientation", "landscape");
200         emit orientationChanged();
201 }
202
203 void SettingsForm::_set_orientation_portrait(bool checked) {
204         if (!checked) return;
205         Config config;
206         config.setValue("ui/orientation", "portrait");
207         emit orientationChanged();
208 }
209
210 void SettingsForm::_set_icons_black(bool checked) {
211         if (!checked) return;
212         Config config;
213         config.setValue("ui/iconstheme", "black");
214         emit iconsChanged();
215 }
216
217 void SettingsForm::_set_icons_white(bool checked) {
218         if (!checked) return;
219         Config config;
220         config.setValue("ui/iconstheme", "white");
221         emit iconsChanged();
222 }
223
224 void SettingsForm::_set_gradient_no(bool checked) {
225         if (!checked) return;
226         Config config;
227         config.setValue("ui/gradient", "no");
228         emit gradientChanged();
229 }
230
231 void SettingsForm::_set_gradient_yes(bool checked) {
232         if (!checked) return;
233         Config config;
234         config.setValue("ui/gradient", "yes");
235         emit gradientChanged();
236 }
237
238 void SettingsForm::_set_color_black(bool checked) {
239         if (!checked) return;
240         Config config;
241         config.setValue("ui/trackcolor", "black");
242         emit trackColorChanged();
243 }
244
245 void SettingsForm::_set_color_blue(bool checked) {
246         if (!checked) return;
247         Config config;
248         config.setValue("ui/trackcolor", "blue");
249         emit trackColorChanged();
250 }
251
252 void SettingsForm::_set_color_dark(bool checked) {
253         if (!checked) return;
254         Config config;
255         config.setValue("ui/trackcolor", "dark");
256         emit trackColorChanged();
257 }
258
259 void SettingsForm::_set_color_light(bool checked) {
260         if (!checked) return;
261         Config config;
262         config.setValue("ui/trackcolor", "light");
263         emit trackColorChanged();
264 }
265
266 void SettingsForm::_set_color_magenta(bool checked) {
267         if (!checked) return;
268         Config config;
269         config.setValue("ui/trackcolor", "magenta");
270         emit trackColorChanged();
271 }
272
273 void SettingsForm::_set_color_red(bool checked) {
274         if (!checked) return;
275         Config config;
276         config.setValue("ui/trackcolor", "red");
277         emit trackColorChanged();
278 }
279
280 void SettingsForm::_set_color_white(bool checked) {
281         if (!checked) return;
282         Config config;
283         config.setValue("ui/trackcolor", "white");
284         emit trackColorChanged();
285 }
286
287 void SettingsForm::_set_color_yellow(bool checked) {
288         if (!checked) return;
289         Config config;
290         config.setValue("ui/trackcolor", "yellow");
291         emit trackColorChanged();
292 }
293
294 void SettingsForm::_set_lang_en(bool checked) {
295         if (!checked) return;
296         Config config;
297         config.setValue("ui/language", "en");
298         emit translationChanged();
299 }
300
301 void SettingsForm::_set_lang_ru(bool checked) {
302         if (!checked) return;
303         Config config;
304         config.setValue("ui/language", "ru");
305         emit translationChanged();
306 }
307
308 void SettingsForm::_set_lang_cn(bool checked) {
309         if (!checked) return;
310         Config config;
311         config.setValue("ui/language", "cn");
312         emit translationChanged();
313 }
314
315 void SettingsForm::_set_pause_hp_no(bool checked) {
316         if (!checked) return;
317         Config config;
318         config.setValue("hw/hpautopause", "no");
319 }
320
321 void SettingsForm::_set_pause_hp_yes(bool checked) {
322         if (!checked) return;
323         Config config;
324         config.setValue("hw/hpautopause", "yes");
325 }
326
327 void SettingsForm::_toggle_hw_settings(bool checked) {
328         Config config;
329         config.setValue("hw/zoomkeys", checked ? "enabled" : "disabled");
330         ui->hwkeysLabel->setEnabled(checked);
331         ui->hwTControlButton->setEnabled(checked);
332         ui->hwVolumeButton->setEnabled(checked);
333         emit hwZoomPolicyChanged();
334 }
335
336 void SettingsForm::_set_hw_track_control(bool checked) {
337         if (!checked) return;
338         Config config;
339         config.setValue("hw/zoom_action", "track");
340 }
341
342 void SettingsForm::_set_hw_volume_control(bool checked) {
343         if (!checked) return;
344         Config config;
345         config.setValue("hw/zoom_action", "volume");
346 }
347
348 void SettingsForm::_toggle_view_ui() {
349         ui->hwButton->setChecked(false);
350         ui->libraryButton->setChecked(false);
351         ui->uiButton->setChecked(true);
352         ui->stackedWidget->setCurrentIndex(0);
353 }
354
355 void SettingsForm::_toggle_view_lib() {
356         ui->hwButton->setChecked(false);
357         ui->uiButton->setChecked(false);
358         ui->libraryButton->setChecked(true);
359         ui->stackedWidget->setCurrentIndex(1);
360 }
361
362 void SettingsForm::_toggle_view_hw() {
363         ui->uiButton->setChecked(false);
364         ui->libraryButton->setChecked(false);
365         ui->hwButton->setChecked(true);
366         ui->stackedWidget->setCurrentIndex(2);
367 }
368
369 void SettingsForm::updateTranslations() {
370         ui->retranslateUi(this);
371 }
372
373 void SettingsForm::landscapeMode() {
374         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
375         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
376         ui->cButtonsLayout->removeWidget(ui->cRedButton);
377         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
378         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
379         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
380         ui->cButtonsLayout->removeWidget(ui->cLightButton);
381         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
382         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
383         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
384         ui->cButtonsLayout->addWidget(ui->cRedButton, 0, 2);
385         ui->cButtonsLayout->addWidget(ui->cYellowButton, 0, 3);
386         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 1, 0);
387         ui->cButtonsLayout->addWidget(ui->cBlackButton, 1, 1);
388         ui->cButtonsLayout->addWidget(ui->cLightButton, 1, 2);
389         ui->cButtonsLayout->addWidget(ui->cDarkButton, 1, 3);
390
391         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
392         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
393         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
394         ui->orientationGridLayout->addWidget(ui->orientationLButton);
395         ui->orientationGridLayout->addWidget(ui->orientationAButton);
396         ui->orientationGridLayout->addWidget(ui->orientationPButton);
397 }
398
399 void SettingsForm::portraitMode() {
400         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
401         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
402         ui->cButtonsLayout->removeWidget(ui->cRedButton);
403         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
404         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
405         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
406         ui->cButtonsLayout->removeWidget(ui->cLightButton);
407         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
408         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
409         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
410         ui->cButtonsLayout->addWidget(ui->cRedButton, 1, 0);
411         ui->cButtonsLayout->addWidget(ui->cYellowButton, 1, 1);
412         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 2, 0);
413         ui->cButtonsLayout->addWidget(ui->cBlackButton, 2, 1);
414         ui->cButtonsLayout->addWidget(ui->cLightButton, 3, 0);
415         ui->cButtonsLayout->addWidget(ui->cDarkButton, 3, 1);
416
417         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
418         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
419         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
420         ui->orientationGridLayout->addWidget(ui->orientationLButton, 0, 0);
421         ui->orientationGridLayout->addWidget(ui->orientationAButton, 0, 1);
422         ui->orientationGridLayout->addWidget(ui->orientationPButton, 1, 0, 1, 2);
423 }
424
425 void SettingsForm::_open_fmtx_settings() {
426         FmtxSettingsDialog dialog(this);
427         dialog.exec();
428         Config config;
429         config.setValue("fmtx/station_name", dialog.stationName());
430         config.setValue("fmtx/frequency", dialog.frequency());
431         emit fmtxSettingsChanged();
432 }
433
434 void SettingsForm::_toggle_fmtx_settings(bool checked) {
435         Config config;
436         config.setValue("fmtx/enabled", checked ? "yes" : "no");
437         emit fmtxSettingsChanged();
438 }