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