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