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 (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);
91 if (config.getValue("hw/hpautopause").toString() == "yes") {
92 ui->pauseHPYesButton->setChecked(true);
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);
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);
106 ui->hwVolumeButton->setChecked(true);
107 config.setValue("hw/zoom_action", "volume");
109 if (config.getValue("fmtx/enabled").toString() == "yes") {
110 ui->fmtxGroupBox->setChecked(true);
111 emit fmtxSettingsChanged();
113 if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
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)));
148 setAttribute(Qt::WA_Maemo5StackedWindow);
149 setWindowFlags(Qt::Window | windowFlags());
152 SettingsForm::~SettingsForm()
157 void SettingsForm::_set_album_sorting_date(bool checked) {
158 if (!checked) return;
160 config.setValue("ui/albumsorting", "date");
161 emit libraryOptionsChanged();
164 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
165 if (!checked) return;
167 config.setValue("ui/albumsorting", "alphabet");
168 emit libraryOptionsChanged();
171 void SettingsForm::_set_track_lenght_show_no(bool checked) {
172 if (!checked) return;
174 config.setValue("ui/showtracklenght", "no");
175 emit libraryOptionsChanged();
178 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
179 if (!checked) return;
181 config.setValue("ui/showtracklenght", "yes");
182 emit libraryOptionsChanged();
185 void SettingsForm::_set_orientation_auto(bool checked) {
186 if (!checked) return;
188 config.setValue("ui/orientation", "auto");
189 emit orientationChanged();
192 void SettingsForm::_set_orientation_landscape(bool checked) {
193 if (!checked) return;
195 config.setValue("ui/orientation", "landscape");
196 emit orientationChanged();
199 void SettingsForm::_set_orientation_portrait(bool checked) {
200 if (!checked) return;
202 config.setValue("ui/orientation", "portrait");
203 emit orientationChanged();
206 void SettingsForm::_set_icons_black(bool checked) {
207 if (!checked) return;
209 config.setValue("ui/iconstheme", "black");
213 void SettingsForm::_set_icons_white(bool checked) {
214 if (!checked) return;
216 config.setValue("ui/iconstheme", "white");
220 void SettingsForm::_set_gradient_no(bool checked) {
221 if (!checked) return;
223 config.setValue("ui/gradient", "no");
224 emit gradientChanged();
227 void SettingsForm::_set_gradient_yes(bool checked) {
228 if (!checked) return;
230 config.setValue("ui/gradient", "yes");
231 emit gradientChanged();
234 void SettingsForm::_set_color_black(bool checked) {
235 if (!checked) return;
237 config.setValue("ui/trackcolor", "black");
238 emit trackColorChanged();
241 void SettingsForm::_set_color_blue(bool checked) {
242 if (!checked) return;
244 config.setValue("ui/trackcolor", "blue");
245 emit trackColorChanged();
248 void SettingsForm::_set_color_dark(bool checked) {
249 if (!checked) return;
251 config.setValue("ui/trackcolor", "dark");
252 emit trackColorChanged();
255 void SettingsForm::_set_color_light(bool checked) {
256 if (!checked) return;
258 config.setValue("ui/trackcolor", "light");
259 emit trackColorChanged();
262 void SettingsForm::_set_color_magenta(bool checked) {
263 if (!checked) return;
265 config.setValue("ui/trackcolor", "magenta");
266 emit trackColorChanged();
269 void SettingsForm::_set_color_red(bool checked) {
270 if (!checked) return;
272 config.setValue("ui/trackcolor", "red");
273 emit trackColorChanged();
276 void SettingsForm::_set_color_white(bool checked) {
277 if (!checked) return;
279 config.setValue("ui/trackcolor", "white");
280 emit trackColorChanged();
283 void SettingsForm::_set_color_yellow(bool checked) {
284 if (!checked) return;
286 config.setValue("ui/trackcolor", "yellow");
287 emit trackColorChanged();
290 void SettingsForm::_set_lang_en(bool checked) {
291 if (!checked) return;
293 config.setValue("ui/language", "en");
294 emit translationChanged();
297 void SettingsForm::_set_lang_ru(bool checked) {
298 if (!checked) return;
300 config.setValue("ui/language", "ru");
301 emit translationChanged();
304 void SettingsForm::_set_pause_hp_no(bool checked) {
305 if (!checked) return;
307 config.setValue("hw/hpautopause", "no");
310 void SettingsForm::_set_pause_hp_yes(bool checked) {
311 if (!checked) return;
313 config.setValue("hw/hpautopause", "yes");
316 void SettingsForm::_toggle_hw_settings(bool checked) {
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();
325 void SettingsForm::_set_hw_track_control(bool checked) {
326 if (!checked) return;
328 config.setValue("hw/zoom_action", "track");
331 void SettingsForm::_set_hw_volume_control(bool checked) {
332 if (!checked) return;
334 config.setValue("hw/zoom_action", "volume");
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);
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);
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);
358 void SettingsForm::updateTranslations() {
359 ui->retranslateUi(this);
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);
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);
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);
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);
414 void SettingsForm::_open_fmtx_settings() {
415 FmtxSettingsDialog dialog(this);
418 config.setValue("fmtx/station_name", dialog.stationName());
419 config.setValue("fmtx/frequency", dialog.frequency());
420 emit fmtxSettingsChanged();
423 void SettingsForm::_toggle_fmtx_settings(bool checked) {
425 config.setValue("fmtx/enabled", checked ? "yes" : "no");
426 emit fmtxSettingsChanged();