2 * SomePlayer - An alternate music player for Maemo 5
3 * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
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.
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.
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.
21 #include "settingsform.h"
22 #include "ui_settingsform.h"
25 #include "someplayer.h"
26 #include "fmtxsettingsdialog.h"
28 using namespace SomePlayer::Storage;
30 SettingsForm::SettingsForm(QWidget *parent) :
32 ui(new Ui::SettingsForm)
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);
59 if (showTrackLenght == "no") {
60 ui->showTrackLenghtNButton->setChecked(true);
62 if (orientation == "portrait") {
63 ui->orientationPButton->setChecked(true);
64 } else if (orientation == "auto") {
65 ui->orientationAButton->setChecked(true);
67 if (icons_theme == "black") {
68 ui->iconstBButton->setChecked(true);
70 if (gradient == "no") {
71 ui->gradientNButton->setChecked(true);
73 if (language == "ru") {
74 ui->ruLangButton->setChecked(true);
76 if (language == "cn") {
77 ui->cnLangButton->setChecked(true);
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);
94 if (config.getValue("hw/hpautopause").toString() == "yes") {
95 ui->pauseHPYesButton->setChecked(true);
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);
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);
109 ui->hwVolumeButton->setChecked(true);
110 config.setValue("hw/zoom_action", "volume");
112 if (config.getValue("fmtx/enabled").toString() == "yes") {
113 ui->fmtxGroupBox->setChecked(true);
114 emit fmtxSettingsChanged();
116 if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
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)));
152 setAttribute(Qt::WA_Maemo5StackedWindow);
153 setWindowFlags(Qt::Window | windowFlags());
156 SettingsForm::~SettingsForm()
161 void SettingsForm::_set_album_sorting_date(bool checked) {
162 if (!checked) return;
164 config.setValue("ui/albumsorting", "date");
165 emit libraryOptionsChanged();
168 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
169 if (!checked) return;
171 config.setValue("ui/albumsorting", "alphabet");
172 emit libraryOptionsChanged();
175 void SettingsForm::_set_track_lenght_show_no(bool checked) {
176 if (!checked) return;
178 config.setValue("ui/showtracklenght", "no");
179 emit libraryOptionsChanged();
182 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
183 if (!checked) return;
185 config.setValue("ui/showtracklenght", "yes");
186 emit libraryOptionsChanged();
189 void SettingsForm::_set_orientation_auto(bool checked) {
190 if (!checked) return;
192 config.setValue("ui/orientation", "auto");
193 emit orientationChanged();
196 void SettingsForm::_set_orientation_landscape(bool checked) {
197 if (!checked) return;
199 config.setValue("ui/orientation", "landscape");
200 emit orientationChanged();
203 void SettingsForm::_set_orientation_portrait(bool checked) {
204 if (!checked) return;
206 config.setValue("ui/orientation", "portrait");
207 emit orientationChanged();
210 void SettingsForm::_set_icons_black(bool checked) {
211 if (!checked) return;
213 config.setValue("ui/iconstheme", "black");
217 void SettingsForm::_set_icons_white(bool checked) {
218 if (!checked) return;
220 config.setValue("ui/iconstheme", "white");
224 void SettingsForm::_set_gradient_no(bool checked) {
225 if (!checked) return;
227 config.setValue("ui/gradient", "no");
228 emit gradientChanged();
231 void SettingsForm::_set_gradient_yes(bool checked) {
232 if (!checked) return;
234 config.setValue("ui/gradient", "yes");
235 emit gradientChanged();
238 void SettingsForm::_set_color_black(bool checked) {
239 if (!checked) return;
241 config.setValue("ui/trackcolor", "black");
242 emit trackColorChanged();
245 void SettingsForm::_set_color_blue(bool checked) {
246 if (!checked) return;
248 config.setValue("ui/trackcolor", "blue");
249 emit trackColorChanged();
252 void SettingsForm::_set_color_dark(bool checked) {
253 if (!checked) return;
255 config.setValue("ui/trackcolor", "dark");
256 emit trackColorChanged();
259 void SettingsForm::_set_color_light(bool checked) {
260 if (!checked) return;
262 config.setValue("ui/trackcolor", "light");
263 emit trackColorChanged();
266 void SettingsForm::_set_color_magenta(bool checked) {
267 if (!checked) return;
269 config.setValue("ui/trackcolor", "magenta");
270 emit trackColorChanged();
273 void SettingsForm::_set_color_red(bool checked) {
274 if (!checked) return;
276 config.setValue("ui/trackcolor", "red");
277 emit trackColorChanged();
280 void SettingsForm::_set_color_white(bool checked) {
281 if (!checked) return;
283 config.setValue("ui/trackcolor", "white");
284 emit trackColorChanged();
287 void SettingsForm::_set_color_yellow(bool checked) {
288 if (!checked) return;
290 config.setValue("ui/trackcolor", "yellow");
291 emit trackColorChanged();
294 void SettingsForm::_set_lang_en(bool checked) {
295 if (!checked) return;
297 config.setValue("ui/language", "en");
298 emit translationChanged();
301 void SettingsForm::_set_lang_ru(bool checked) {
302 if (!checked) return;
304 config.setValue("ui/language", "ru");
305 emit translationChanged();
308 void SettingsForm::_set_lang_cn(bool checked) {
309 if (!checked) return;
311 config.setValue("ui/language", "cn");
312 emit translationChanged();
315 void SettingsForm::_set_pause_hp_no(bool checked) {
316 if (!checked) return;
318 config.setValue("hw/hpautopause", "no");
321 void SettingsForm::_set_pause_hp_yes(bool checked) {
322 if (!checked) return;
324 config.setValue("hw/hpautopause", "yes");
327 void SettingsForm::_toggle_hw_settings(bool checked) {
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();
336 void SettingsForm::_set_hw_track_control(bool checked) {
337 if (!checked) return;
339 config.setValue("hw/zoom_action", "track");
342 void SettingsForm::_set_hw_volume_control(bool checked) {
343 if (!checked) return;
345 config.setValue("hw/zoom_action", "volume");
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);
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);
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);
369 void SettingsForm::updateTranslations() {
370 ui->retranslateUi(this);
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);
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);
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);
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);
425 void SettingsForm::_open_fmtx_settings() {
426 FmtxSettingsDialog dialog(this);
429 config.setValue("fmtx/station_name", dialog.stationName());
430 config.setValue("fmtx/frequency", dialog.frequency());
431 emit fmtxSettingsChanged();
434 void SettingsForm::_toggle_fmtx_settings(bool checked) {
436 config.setValue("fmtx/enabled", checked ? "yes" : "no");
437 emit fmtxSettingsChanged();