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