Settings for autopausing
[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         if (albumSorting == "alphabet") {
51                 ui->albumsSortAButton->setChecked(true);
52         }
53         if (showTrackLenght == "no") {
54                 ui->showTrackLenghtNButton->setChecked(true);
55         }
56         if (orientation == "portrait") {
57                 ui->orientationPButton->setChecked(true);
58         } else if (orientation == "auto") {
59                 ui->orientationAButton->setChecked(true);
60         }
61         if (icons_theme == "black") {
62                 ui->iconstBButton->setChecked(true);
63         }
64         if (gradient == "no") {
65                 ui->gradientNButton->setChecked(true);
66         }
67         if (language == "ru") {
68                 ui->ruLangButton->setChecked(true);
69         }
70         if (track_color == "black") {
71                 ui->cBlackButton->setChecked(true);
72         } else if (track_color == "magenta") {
73                 ui->cMagentaButton->setChecked(true);
74         } else if (track_color == "Red") {
75                 ui->cRedButton->setChecked(true);
76         } else if (track_color == "yellow") {
77                 ui->cYellowButton->setChecked(true);
78         } else if (track_color == "white") {
79                 ui->cWhiteButton->setChecked(true);
80         } else if (track_color == "dark") {
81                 ui->cDarkButton->setChecked(true);
82         } else if (track_color == "light") {
83                 ui->cLightButton->setChecked(true);
84         }
85         if (config.getValue("playback/hpautopause").toString() == "yes") {
86                 ui->pauseHPYesButton->setChecked(true);
87         }
88         if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
89                 ui->langBox->hide();
90         } // refactor this when more translations will be added
91         connect (ui->albumsSortAButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_alphabet(bool)));
92         connect (ui->albumsSortDButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_date(bool)));
93         connect (ui->showTrackLenghtNButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_no(bool)));
94         connect (ui->showTrackLenghtYButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_yes(bool)));
95         connect (ui->orientationAButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_auto(bool)));
96         connect (ui->orientationLButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_landscape(bool)));
97         connect (ui->orientationPButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_portrait(bool)));
98         connect (ui->iconstBButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_black(bool)));
99         connect (ui->iconsWButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_white(bool)));
100         connect (ui->gradientNButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_no(bool)));
101         connect (ui->gradientYButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_yes(bool)));
102         connect (ui->engLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_en(bool)));
103         connect (ui->ruLangButton, SIGNAL(toggled(bool)), this, SLOT(_set_lang_ru(bool)));
104         connect (ui->cBlackButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_black(bool)));
105         connect (ui->cBlueButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_blue(bool)));
106         connect (ui->cDarkButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_dark(bool)));
107         connect (ui->cLightButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_light(bool)));
108         connect (ui->cMagentaButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_magenta(bool)));
109         connect (ui->cRedButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_red(bool)));
110         connect (ui->cWhiteButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_white(bool)));
111         connect (ui->cYellowButton, SIGNAL(toggled(bool)), this, SLOT(_set_color_yellow(bool)));
112         connect (ui->pauseHPNoButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_no(bool)));
113         connect (ui->pauseHPYesButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_yes(bool)));
114         setAttribute(Qt::WA_Maemo5StackedWindow);
115         setWindowFlags(Qt::Window | windowFlags());
116 }
117
118 SettingsForm::~SettingsForm()
119 {
120         delete ui;
121 }
122
123 void SettingsForm::_set_album_sorting_date(bool checked) {
124         if (!checked) return;
125         Config config;
126         config.setValue("ui/albumsorting", "date");
127         emit libraryOptionsChanged();
128 }
129
130 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
131         if (!checked) return;
132         Config config;
133         config.setValue("ui/albumsorting", "alphabet");
134         emit libraryOptionsChanged();
135 }
136
137 void SettingsForm::_set_track_lenght_show_no(bool checked) {
138         if (!checked) return;
139         Config config;
140         config.setValue("ui/showtracklenght", "no");
141         emit libraryOptionsChanged();
142 }
143
144 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
145         if (!checked) return;
146         Config config;
147         config.setValue("ui/showtracklenght", "yes");
148         emit libraryOptionsChanged();
149 }
150
151 void SettingsForm::_set_orientation_auto(bool checked) {
152         if (!checked) return;
153         Config config;
154         config.setValue("ui/orientation", "auto");
155         emit orientationChanged();
156 }
157
158 void SettingsForm::_set_orientation_landscape(bool checked) {
159         if (!checked) return;
160         Config config;
161         config.setValue("ui/orientation", "landscape");
162         emit orientationChanged();
163 }
164
165 void SettingsForm::_set_orientation_portrait(bool checked) {
166         if (!checked) return;
167         Config config;
168         config.setValue("ui/orientation", "portrait");
169         emit orientationChanged();
170 }
171
172 void SettingsForm::_set_icons_black(bool checked) {
173         if (!checked) return;
174         Config config;
175         config.setValue("ui/iconstheme", "black");
176         emit iconsChanged();
177 }
178
179 void SettingsForm::_set_icons_white(bool checked) {
180         if (!checked) return;
181         Config config;
182         config.setValue("ui/iconstheme", "white");
183         emit iconsChanged();
184 }
185
186 void SettingsForm::_set_gradient_no(bool checked) {
187         if (!checked) return;
188         Config config;
189         config.setValue("ui/gradient", "no");
190         emit gradientChanged();
191 }
192
193 void SettingsForm::_set_gradient_yes(bool checked) {
194         if (!checked) return;
195         Config config;
196         config.setValue("ui/gradient", "yes");
197         emit gradientChanged();
198 }
199
200 void SettingsForm::_set_color_black(bool checked) {
201         if (!checked) return;
202         Config config;
203         config.setValue("ui/trackcolor", "black");
204         emit trackColorChanged();
205 }
206
207 void SettingsForm::_set_color_blue(bool checked) {
208         if (!checked) return;
209         Config config;
210         config.setValue("ui/trackcolor", "blue");
211         emit trackColorChanged();
212 }
213
214 void SettingsForm::_set_color_dark(bool checked) {
215         if (!checked) return;
216         Config config;
217         config.setValue("ui/trackcolor", "dark");
218         emit trackColorChanged();
219 }
220
221 void SettingsForm::_set_color_light(bool checked) {
222         if (!checked) return;
223         Config config;
224         config.setValue("ui/trackcolor", "light");
225         emit trackColorChanged();
226 }
227
228 void SettingsForm::_set_color_magenta(bool checked) {
229         if (!checked) return;
230         Config config;
231         config.setValue("ui/trackcolor", "magenta");
232         emit trackColorChanged();
233 }
234
235 void SettingsForm::_set_color_red(bool checked) {
236         if (!checked) return;
237         Config config;
238         config.setValue("ui/trackcolor", "red");
239         emit trackColorChanged();
240 }
241
242 void SettingsForm::_set_color_white(bool checked) {
243         if (!checked) return;
244         Config config;
245         config.setValue("ui/trackcolor", "white");
246         emit trackColorChanged();
247 }
248
249 void SettingsForm::_set_color_yellow(bool checked) {
250         if (!checked) return;
251         Config config;
252         config.setValue("ui/trackcolor", "yellow");
253         emit trackColorChanged();
254 }
255
256 void SettingsForm::_set_lang_en(bool checked) {
257         if (!checked) return;
258         Config config;
259         config.setValue("ui/language", "en");
260         emit translationChanged();
261 }
262
263 void SettingsForm::_set_lang_ru(bool checked) {
264         if (!checked) return;
265         Config config;
266         config.setValue("ui/language", "ru");
267         emit translationChanged();
268 }
269
270 void SettingsForm::_set_pause_hp_no(bool checked) {
271         if (!checked) return;
272         Config config;
273         config.setValue("playback/hpautopause", "no");
274 }
275
276 void SettingsForm::_set_pause_hp_yes(bool checked) {
277         if (!checked) return;
278         Config config;
279         config.setValue("playback/hpautopause", "yes");
280 }
281
282 void SettingsForm::updateTranslations() {
283         ui->retranslateUi(this);
284 }
285
286 void SettingsForm::landscapeMode() {
287         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
288         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
289         ui->cButtonsLayout->removeWidget(ui->cRedButton);
290         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
291         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
292         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
293         ui->cButtonsLayout->removeWidget(ui->cLightButton);
294         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
295         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
296         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
297         ui->cButtonsLayout->addWidget(ui->cRedButton, 0, 2);
298         ui->cButtonsLayout->addWidget(ui->cYellowButton, 0, 3);
299         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 1, 0);
300         ui->cButtonsLayout->addWidget(ui->cBlackButton, 1, 1);
301         ui->cButtonsLayout->addWidget(ui->cLightButton, 1, 2);
302         ui->cButtonsLayout->addWidget(ui->cDarkButton, 1, 3);
303
304         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
305         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
306         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
307         ui->orientationGridLayout->addWidget(ui->orientationLButton);
308         ui->orientationGridLayout->addWidget(ui->orientationAButton);
309         ui->orientationGridLayout->addWidget(ui->orientationPButton);
310 }
311
312 void SettingsForm::portraitMode() {
313         ui->cButtonsLayout->removeWidget(ui->cBlueButton);
314         ui->cButtonsLayout->removeWidget(ui->cMagentaButton);
315         ui->cButtonsLayout->removeWidget(ui->cRedButton);
316         ui->cButtonsLayout->removeWidget(ui->cYellowButton);
317         ui->cButtonsLayout->removeWidget(ui->cWhiteButton);
318         ui->cButtonsLayout->removeWidget(ui->cBlackButton);
319         ui->cButtonsLayout->removeWidget(ui->cLightButton);
320         ui->cButtonsLayout->removeWidget(ui->cDarkButton);
321         ui->cButtonsLayout->addWidget(ui->cBlueButton, 0, 0);
322         ui->cButtonsLayout->addWidget(ui->cMagentaButton, 0, 1);
323         ui->cButtonsLayout->addWidget(ui->cRedButton, 1, 0);
324         ui->cButtonsLayout->addWidget(ui->cYellowButton, 1, 1);
325         ui->cButtonsLayout->addWidget(ui->cWhiteButton, 2, 0);
326         ui->cButtonsLayout->addWidget(ui->cBlackButton, 2, 1);
327         ui->cButtonsLayout->addWidget(ui->cLightButton, 3, 0);
328         ui->cButtonsLayout->addWidget(ui->cDarkButton, 3, 1);
329
330         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
331         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
332         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
333         ui->orientationGridLayout->addWidget(ui->orientationLButton, 0, 0);
334         ui->orientationGridLayout->addWidget(ui->orientationAButton, 0, 1);
335         ui->orientationGridLayout->addWidget(ui->orientationPButton, 1, 0, 1, 2);
336 }