Impemented controling via keyboard
[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 (track_color == "black") {
77                 ui->cBlackButton->setChecked(true);
78         } else if (track_color == "magenta") {
79                 ui->cMagentaButton->setChecked(true);
80         } else if (track_color == "Red") {
81                 ui->cRedButton->setChecked(true);
82         } else if (track_color == "yellow") {
83                 ui->cYellowButton->setChecked(true);
84         } else if (track_color == "white") {
85                 ui->cWhiteButton->setChecked(true);
86         } else if (track_color == "dark") {
87                 ui->cDarkButton->setChecked(true);
88         } else if (track_color == "light") {
89                 ui->cLightButton->setChecked(true);
90         }
91         if (config.getValue("hw/hpautopause").toString() == "yes") {
92                 ui->pauseHPYesButton->setChecked(true);
93         }
94         if (config.getValue("hw/zoomkeys").toString() == "enabled") {
95                 ui->hwKeysBox->setChecked(true);
96                 ui->hwkeysLabel->setEnabled(true);
97                 ui->hwTControlButton->setEnabled(true);
98                 ui->hwVolumeButton->setEnabled(true);
99         }
100         QString behavior = config.getValue("hw/zoom_action").toString();
101         if (behavior == "volume") {
102                 ui->hwVolumeButton->setChecked(true);
103         } else if (behavior == "track") {
104                 ui->hwTControlButton->setChecked(true);
105         } else {
106                 ui->hwVolumeButton->setChecked(true);
107                 config.setValue("hw/zoom_action", "volume");
108         }
109         if (config.getValue("fmtx/enabled").toString() == "yes") {
110                 ui->fmtxGroupBox->setChecked(true);
111                 emit fmtxSettingsChanged();
112         }
113         if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
114                 ui->langBox->hide();
115         } // refactor this when more translations will be added
116         connect (ui->albumsSortAButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_alphabet(bool)));
117         connect (ui->albumsSortDButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_date(bool)));
118         connect (ui->showTrackLenghtNButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_no(bool)));
119         connect (ui->showTrackLenghtYButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_yes(bool)));
120         connect (ui->orientationAButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_auto(bool)));
121         connect (ui->orientationLButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_landscape(bool)));
122         connect (ui->orientationPButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_portrait(bool)));
123         connect (ui->iconstBButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_black(bool)));
124         connect (ui->iconsWButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_white(bool)));
125         connect (ui->gradientNButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_no(bool)));
126         connect (ui->gradientYButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_yes(bool)));
127         connect (ui->engLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_en(bool)));
128         connect (ui->ruLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_ru(bool)));
129         connect (ui->cBlackButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_black(bool)));
130         connect (ui->cBlueButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_blue(bool)));
131         connect (ui->cDarkButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_dark(bool)));
132         connect (ui->cLightButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_light(bool)));
133         connect (ui->cMagentaButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_magenta(bool)));
134         connect (ui->cRedButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_red(bool)));
135         connect (ui->cWhiteButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_white(bool)));
136         connect (ui->cYellowButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_yellow(bool)));
137         connect (ui->pauseHPNoButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_no(bool)));
138         connect (ui->pauseHPYesButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_yes(bool)));
139         connect (ui->hwKeysBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_hw_settings(bool)));
140         connect (ui->hwVolumeButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_volume_control(bool)));
141         connect (ui->hwTControlButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_track_control(bool)));
142         connect (ui->uiButton, SIGNAL(clicked()), this, SLOT(_toggle_view_ui()));
143         connect (ui->hwButton, SIGNAL(clicked()), this, SLOT(_toggle_view_hw()));
144         connect (ui->libraryButton, SIGNAL(clicked()), this, SLOT(_toggle_view_lib()));
145         connect (ui->fmtxSettingsButton, SIGNAL(clicked()), this, SLOT(_open_fmtx_settings()));
146         connect (ui->fmtxGroupBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_fmtx_settings(bool)));
147         _toggle_view_ui();
148         setAttribute(Qt::WA_Maemo5StackedWindow);
149         setWindowFlags(Qt::Window | windowFlags());
150 }
151
152 SettingsForm::~SettingsForm()
153 {
154         delete ui;
155 }
156
157 void SettingsForm::_set_album_sorting_date(bool checked) {
158         if (!checked) return;
159         Config config;
160         config.setValue("ui/albumsorting", "date");
161         emit libraryOptionsChanged();
162 }
163
164 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
165         if (!checked) return;
166         Config config;
167         config.setValue("ui/albumsorting", "alphabet");
168         emit libraryOptionsChanged();
169 }
170
171 void SettingsForm::_set_track_lenght_show_no(bool checked) {
172         if (!checked) return;
173         Config config;
174         config.setValue("ui/showtracklenght", "no");
175         emit libraryOptionsChanged();
176 }
177
178 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
179         if (!checked) return;
180         Config config;
181         config.setValue("ui/showtracklenght", "yes");
182         emit libraryOptionsChanged();
183 }
184
185 void SettingsForm::_set_orientation_auto(bool checked) {
186         if (!checked) return;
187         Config config;
188         config.setValue("ui/orientation", "auto");
189         emit orientationChanged();
190 }
191
192 void SettingsForm::_set_orientation_landscape(bool checked) {
193         if (!checked) return;
194         Config config;
195         config.setValue("ui/orientation", "landscape");
196         emit orientationChanged();
197 }
198
199 void SettingsForm::_set_orientation_portrait(bool checked) {
200         if (!checked) return;
201         Config config;
202         config.setValue("ui/orientation", "portrait");
203         emit orientationChanged();
204 }
205
206 void SettingsForm::_set_icons_black(bool checked) {
207         if (!checked) return;
208         Config config;
209         config.setValue("ui/iconstheme", "black");
210         emit iconsChanged();
211 }
212
213 void SettingsForm::_set_icons_white(bool checked) {
214         if (!checked) return;
215         Config config;
216         config.setValue("ui/iconstheme", "white");
217         emit iconsChanged();
218 }
219
220 void SettingsForm::_set_gradient_no(bool checked) {
221         if (!checked) return;
222         Config config;
223         config.setValue("ui/gradient", "no");
224         emit gradientChanged();
225 }
226
227 void SettingsForm::_set_gradient_yes(bool checked) {
228         if (!checked) return;
229         Config config;
230         config.setValue("ui/gradient", "yes");
231         emit gradientChanged();
232 }
233
234 void SettingsForm::_set_color_black(bool checked) {
235         if (!checked) return;
236         Config config;
237         config.setValue("ui/trackcolor", "black");
238         emit trackColorChanged();
239 }
240
241 void SettingsForm::_set_color_blue(bool checked) {
242         if (!checked) return;
243         Config config;
244         config.setValue("ui/trackcolor", "blue");
245         emit trackColorChanged();
246 }
247
248 void SettingsForm::_set_color_dark(bool checked) {
249         if (!checked) return;
250         Config config;
251         config.setValue("ui/trackcolor", "dark");
252         emit trackColorChanged();
253 }
254
255 void SettingsForm::_set_color_light(bool checked) {
256         if (!checked) return;
257         Config config;
258         config.setValue("ui/trackcolor", "light");
259         emit trackColorChanged();
260 }
261
262 void SettingsForm::_set_color_magenta(bool checked) {
263         if (!checked) return;
264         Config config;
265         config.setValue("ui/trackcolor", "magenta");
266         emit trackColorChanged();
267 }
268
269 void SettingsForm::_set_color_red(bool checked) {
270         if (!checked) return;
271         Config config;
272         config.setValue("ui/trackcolor", "red");
273         emit trackColorChanged();
274 }
275
276 void SettingsForm::_set_color_white(bool checked) {
277         if (!checked) return;
278         Config config;
279         config.setValue("ui/trackcolor", "white");
280         emit trackColorChanged();
281 }
282
283 void SettingsForm::_set_color_yellow(bool checked) {
284         if (!checked) return;
285         Config config;
286         config.setValue("ui/trackcolor", "yellow");
287         emit trackColorChanged();
288 }
289
290 void SettingsForm::_set_lang_en(bool checked) {
291         if (!checked) return;
292         Config config;
293         config.setValue("ui/language", "en");
294         emit translationChanged();
295 }
296
297 void SettingsForm::_set_lang_ru(bool checked) {
298         if (!checked) return;
299         Config config;
300         config.setValue("ui/language", "ru");
301         emit translationChanged();
302 }
303
304 void SettingsForm::_set_pause_hp_no(bool checked) {
305         if (!checked) return;
306         Config config;
307         config.setValue("hw/hpautopause", "no");
308 }
309
310 void SettingsForm::_set_pause_hp_yes(bool checked) {
311         if (!checked) return;
312         Config config;
313         config.setValue("hw/hpautopause", "yes");
314 }
315
316 void SettingsForm::_toggle_hw_settings(bool checked) {
317         Config config;
318         config.setValue("hw/zoomkeys", checked ? "enabled" : "disabled");
319         ui->hwkeysLabel->setEnabled(checked);
320         ui->hwTControlButton->setEnabled(checked);
321         ui->hwVolumeButton->setEnabled(checked);
322         emit hwZoomPolicyChanged();
323 }
324
325 void SettingsForm::_set_hw_track_control(bool checked) {
326         if (!checked) return;
327         Config config;
328         config.setValue("hw/zoom_action", "track");
329 }
330
331 void SettingsForm::_set_hw_volume_control(bool checked) {
332         if (!checked) return;
333         Config config;
334         config.setValue("hw/zoom_action", "volume");
335 }
336
337 void SettingsForm::_toggle_view_ui() {
338         ui->hwButton->setChecked(false);
339         ui->libraryButton->setChecked(false);
340         ui->uiButton->setChecked(true);
341         ui->stackedWidget->setCurrentIndex(0);
342 }
343
344 void SettingsForm::_toggle_view_lib() {
345         ui->hwButton->setChecked(false);
346         ui->uiButton->setChecked(false);
347         ui->libraryButton->setChecked(true);
348         ui->stackedWidget->setCurrentIndex(1);
349 }
350
351 void SettingsForm::_toggle_view_hw() {
352         ui->uiButton->setChecked(false);
353         ui->libraryButton->setChecked(false);
354         ui->hwButton->setChecked(true);
355         ui->stackedWidget->setCurrentIndex(2);
356 }
357
358 void SettingsForm::updateTranslations() {
359         ui->retranslateUi(this);
360 }
361
362 void SettingsForm::landscapeMode() {
363         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
364         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
365         ui->cButtonsLayout->removeWidget(ui->cRedButton);
366         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
367         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
368         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
369         ui->cButtonsLayout->removeWidget(ui->cLightButton);
370         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
371         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
372         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
373         ui->cButtonsLayout->addWidget(ui->cRedButton, 0, 2);
374         ui->cButtonsLayout->addWidget(ui->cYellowButton, 0, 3);
375         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 1, 0);
376         ui->cButtonsLayout->addWidget(ui->cBlackButton, 1, 1);
377         ui->cButtonsLayout->addWidget(ui->cLightButton, 1, 2);
378         ui->cButtonsLayout->addWidget(ui->cDarkButton, 1, 3);
379
380         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
381         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
382         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
383         ui->orientationGridLayout->addWidget(ui->orientationLButton);
384         ui->orientationGridLayout->addWidget(ui->orientationAButton);
385         ui->orientationGridLayout->addWidget(ui->orientationPButton);
386 }
387
388 void SettingsForm::portraitMode() {
389         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
390         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
391         ui->cButtonsLayout->removeWidget(ui->cRedButton);
392         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
393         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
394         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
395         ui->cButtonsLayout->removeWidget(ui->cLightButton);
396         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
397         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
398         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
399         ui->cButtonsLayout->addWidget(ui->cRedButton, 1, 0);
400         ui->cButtonsLayout->addWidget(ui->cYellowButton, 1, 1);
401         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 2, 0);
402         ui->cButtonsLayout->addWidget(ui->cBlackButton, 2, 1);
403         ui->cButtonsLayout->addWidget(ui->cLightButton, 3, 0);
404         ui->cButtonsLayout->addWidget(ui->cDarkButton, 3, 1);
405
406         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
407         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
408         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
409         ui->orientationGridLayout->addWidget(ui->orientationLButton, 0, 0);
410         ui->orientationGridLayout->addWidget(ui->orientationAButton, 0, 1);
411         ui->orientationGridLayout->addWidget(ui->orientationPButton, 1, 0, 1, 2);
412 }
413
414 void SettingsForm::_open_fmtx_settings() {
415         FmtxSettingsDialog dialog(this);
416         dialog.exec();
417         Config config;
418         config.setValue("fmtx/station_name", dialog.stationName());
419         config.setValue("fmtx/frequency", dialog.frequency());
420         emit fmtxSettingsChanged();
421 }
422
423 void SettingsForm::_toggle_fmtx_settings(bool checked) {
424         Config config;
425         config.setValue("fmtx/enabled", checked ? "yes" : "no");
426         emit fmtxSettingsChanged();
427 }