Polish translation
[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 #include "fmtxsettingsdialog.h"
27
28 using namespace SomePlayer::Storage;
29
30 SettingsForm::SettingsForm(QWidget *parent) :
31                 QWidget(parent),
32                 ui(new Ui::SettingsForm)
33 {
34         ui->setupUi(this);
35         Config config;
36
37         _color_map << "blue" << "magenta" << "red" << "yellow" <<
38                         "white" << "black" << "light" << "dark";
39         _lang_map << "en" << "it" << "pl" << "ru" << "zh_CN" << "zh_TW";
40
41         QString albumSorting = config.getValue("ui/albumsorting").toString();
42         QString showTrackLenght = config.getValue("ui/showtracklenght").toString();
43         QString orientation = config.getValue("ui/orientation").toString();
44         QString icons_theme = config.getValue("ui/iconstheme").toString();
45         QString gradient = config.getValue("ui/gradient").toString();
46         QString language = config.getValue("ui/language").toString();
47         QString track_color = config.getValue("ui/trackcolor").toString();
48         ui->albumsSortDButton->setChecked(true);        // defaule sorting
49         ui->showTrackLenghtYButton->setChecked(true);   // show by default
50         ui->orientationLButton->setChecked(true);
51         ui->iconsWButton->setChecked(true);
52         ui->gradientYButton->setChecked(true);
53         ui->langComboBox->setCurrentIndex(_lang_map.indexOf(language));
54         ui->colorComboBox->setCurrentIndex(_color_map.indexOf(track_color));
55         ui->pauseHPNoButton->setChecked(true);
56         ui->hwKeysBox->setChecked(false);
57         ui->hwkeysLabel->setEnabled(false);
58         ui->hwTControlButton->setEnabled(false);
59         ui->hwVolumeButton->setEnabled(false);
60         ui->fmtxGroupBox->setChecked(false);
61         if (albumSorting == "alphabet") {
62                 ui->albumsSortAButton->setChecked(true);
63         }
64         if (showTrackLenght == "no") {
65                 ui->showTrackLenghtNButton->setChecked(true);
66         }
67         if (orientation == "portrait") {
68                 ui->orientationPButton->setChecked(true);
69         } else if (orientation == "auto") {
70                 ui->orientationAButton->setChecked(true);
71         }
72         if (icons_theme == "black") {
73                 ui->iconstBButton->setChecked(true);
74         }
75         if (gradient == "no") {
76                 ui->gradientNButton->setChecked(true);
77         }
78         if (config.getValue("hw/hpautopause").toString() == "yes") {
79                 ui->pauseHPYesButton->setChecked(true);
80         }
81         if (config.getValue("hw/zoomkeys").toString() == "enabled") {
82                 ui->hwKeysBox->setChecked(true);
83                 ui->hwkeysLabel->setEnabled(true);
84                 ui->hwTControlButton->setEnabled(true);
85                 ui->hwVolumeButton->setEnabled(true);
86         }
87         QString behavior = config.getValue("hw/zoom_action").toString();
88         if (behavior == "volume") {
89                 ui->hwVolumeButton->setChecked(true);
90         } else if (behavior == "track") {
91                 ui->hwTControlButton->setChecked(true);
92         } else {
93                 ui->hwVolumeButton->setChecked(true);
94                 config.setValue("hw/zoom_action", "volume");
95         }
96         if (config.getValue("fmtx/enabled").toString() == "yes") {
97                 ui->fmtxGroupBox->setChecked(true);
98                 emit fmtxSettingsChanged();
99         }
100         if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
101                 ui->langBox->hide();
102         } // refactor this when more translations will be added
103         connect (ui->albumsSortAButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_alphabet(bool)));
104         connect (ui->albumsSortDButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_date(bool)));
105         connect (ui->showTrackLenghtNButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_no(bool)));
106         connect (ui->showTrackLenghtYButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_yes(bool)));
107         connect (ui->orientationAButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_auto(bool)));
108         connect (ui->orientationLButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_landscape(bool)));
109         connect (ui->orientationPButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_portrait(bool)));
110         connect (ui->iconstBButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_black(bool)));
111         connect (ui->iconsWButton, SIGNAL(toggled(bool)), this, SLOT(_set_icons_white(bool)));
112         connect (ui->gradientNButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_no(bool)));
113         connect (ui->gradientYButton, SIGNAL(toggled(bool)), this, SLOT(_set_gradient_yes(bool)));
114         connect (ui->pauseHPNoButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_no(bool)));
115         connect (ui->pauseHPYesButton, SIGNAL(toggled(bool)), this, SLOT(_set_pause_hp_yes(bool)));
116         connect (ui->hwKeysBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_hw_settings(bool)));
117         connect (ui->hwVolumeButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_volume_control(bool)));
118         connect (ui->hwTControlButton, SIGNAL(toggled(bool)), this, SLOT(_set_hw_track_control(bool)));
119         connect (ui->uiButton, SIGNAL(clicked()), this, SLOT(_toggle_view_ui()));
120         connect (ui->hwButton, SIGNAL(clicked()), this, SLOT(_toggle_view_hw()));
121         connect (ui->libraryButton, SIGNAL(clicked()), this, SLOT(_toggle_view_lib()));
122         connect (ui->fmtxSettingsButton, SIGNAL(clicked()), this, SLOT(_open_fmtx_settings()));
123         connect (ui->fmtxGroupBox, SIGNAL(toggled(bool)), this, SLOT(_toggle_fmtx_settings(bool)));
124         connect (ui->colorComboBox, SIGNAL(activated(int)), this, SLOT(_set_color(int)));
125         connect (ui->langComboBox, SIGNAL(activated(int)), this, SLOT(_set_language(int)));
126         _toggle_view_ui();
127         setAttribute(Qt::WA_Maemo5StackedWindow);
128         setWindowFlags(Qt::Window | windowFlags());
129 }
130
131 SettingsForm::~SettingsForm()
132 {
133         delete ui;
134 }
135
136 void SettingsForm::_set_album_sorting_date(bool checked) {
137         if (!checked) return;
138         Config config;
139         config.setValue("ui/albumsorting", "date");
140         emit libraryOptionsChanged();
141 }
142
143 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
144         if (!checked) return;
145         Config config;
146         config.setValue("ui/albumsorting", "alphabet");
147         emit libraryOptionsChanged();
148 }
149
150 void SettingsForm::_set_track_lenght_show_no(bool checked) {
151         if (!checked) return;
152         Config config;
153         config.setValue("ui/showtracklenght", "no");
154         emit libraryOptionsChanged();
155 }
156
157 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
158         if (!checked) return;
159         Config config;
160         config.setValue("ui/showtracklenght", "yes");
161         emit libraryOptionsChanged();
162 }
163
164 void SettingsForm::_set_orientation_auto(bool checked) {
165         if (!checked) return;
166         Config config;
167         config.setValue("ui/orientation", "auto");
168         emit orientationChanged();
169 }
170
171 void SettingsForm::_set_orientation_landscape(bool checked) {
172         if (!checked) return;
173         Config config;
174         config.setValue("ui/orientation", "landscape");
175         emit orientationChanged();
176 }
177
178 void SettingsForm::_set_orientation_portrait(bool checked) {
179         if (!checked) return;
180         Config config;
181         config.setValue("ui/orientation", "portrait");
182         emit orientationChanged();
183 }
184
185 void SettingsForm::_set_icons_black(bool checked) {
186         if (!checked) return;
187         Config config;
188         config.setValue("ui/iconstheme", "black");
189         emit iconsChanged();
190 }
191
192 void SettingsForm::_set_icons_white(bool checked) {
193         if (!checked) return;
194         Config config;
195         config.setValue("ui/iconstheme", "white");
196         emit iconsChanged();
197 }
198
199 void SettingsForm::_set_gradient_no(bool checked) {
200         if (!checked) return;
201         Config config;
202         config.setValue("ui/gradient", "no");
203         emit gradientChanged();
204 }
205
206 void SettingsForm::_set_gradient_yes(bool checked) {
207         if (!checked) return;
208         Config config;
209         config.setValue("ui/gradient", "yes");
210         emit gradientChanged();
211 }
212
213 void SettingsForm::_set_color(int code) {
214         Config config;
215         config.setValue("ui/trackcolor", _color_map[code]);
216         emit trackColorChanged();
217 }
218
219 void SettingsForm::_set_language(int code) {
220         Config config;
221         config.setValue("ui/language", _lang_map[code]);
222         emit translationChanged();
223 }
224
225 void SettingsForm::_set_pause_hp_no(bool checked) {
226         if (!checked) return;
227         Config config;
228         config.setValue("hw/hpautopause", "no");
229 }
230
231 void SettingsForm::_set_pause_hp_yes(bool checked) {
232         if (!checked) return;
233         Config config;
234         config.setValue("hw/hpautopause", "yes");
235 }
236
237 void SettingsForm::_toggle_hw_settings(bool checked) {
238         Config config;
239         config.setValue("hw/zoomkeys", checked ? "enabled" : "disabled");
240         ui->hwkeysLabel->setEnabled(checked);
241         ui->hwTControlButton->setEnabled(checked);
242         ui->hwVolumeButton->setEnabled(checked);
243         emit hwZoomPolicyChanged();
244 }
245
246 void SettingsForm::_set_hw_track_control(bool checked) {
247         if (!checked) return;
248         Config config;
249         config.setValue("hw/zoom_action", "track");
250 }
251
252 void SettingsForm::_set_hw_volume_control(bool checked) {
253         if (!checked) return;
254         Config config;
255         config.setValue("hw/zoom_action", "volume");
256 }
257
258 void SettingsForm::_toggle_view_ui() {
259         ui->hwButton->setChecked(false);
260         ui->libraryButton->setChecked(false);
261         ui->uiButton->setChecked(true);
262         ui->stackedWidget->setCurrentIndex(0);
263 }
264
265 void SettingsForm::_toggle_view_lib() {
266         ui->hwButton->setChecked(false);
267         ui->uiButton->setChecked(false);
268         ui->libraryButton->setChecked(true);
269         ui->stackedWidget->setCurrentIndex(1);
270 }
271
272 void SettingsForm::_toggle_view_hw() {
273         ui->uiButton->setChecked(false);
274         ui->libraryButton->setChecked(false);
275         ui->hwButton->setChecked(true);
276         ui->stackedWidget->setCurrentIndex(2);
277 }
278
279 void SettingsForm::updateTranslations() {
280         Config config;
281         ui->retranslateUi(this);
282         ui->langComboBox->setCurrentIndex(_lang_map.indexOf(config.getValue("ui/language").toString()));
283         ui->colorComboBox->setCurrentIndex(_color_map.indexOf(config.getValue("ui/trackcolor").toString()));
284 }
285
286 void SettingsForm::landscapeMode() {
287         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
288         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
289         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
290         ui->orientationGridLayout->addWidget(ui->orientationLButton);
291         ui->orientationGridLayout->addWidget(ui->orientationAButton);
292         ui->orientationGridLayout->addWidget(ui->orientationPButton);
293 }
294
295 void SettingsForm::portraitMode() {
296         ui->orientationGridLayout->removeWidget(ui->orientationAButton);
297         ui->orientationGridLayout->removeWidget(ui->orientationLButton);
298         ui->orientationGridLayout->removeWidget(ui->orientationPButton);
299         ui->orientationGridLayout->addWidget(ui->orientationLButton, 0, 0);
300         ui->orientationGridLayout->addWidget(ui->orientationAButton, 0, 1);
301         ui->orientationGridLayout->addWidget(ui->orientationPButton, 1, 0, 1, 2);
302 }
303
304 void SettingsForm::_open_fmtx_settings() {
305         FmtxSettingsDialog dialog(this);
306         dialog.exec();
307         Config config;
308         config.setValue("fmtx/station_name", dialog.stationName());
309         config.setValue("fmtx/frequency", dialog.frequency());
310         emit fmtxSettingsChanged();
311 }
312
313 void SettingsForm::_toggle_fmtx_settings(bool checked) {
314         Config config;
315         config.setValue("fmtx/enabled", checked ? "yes" : "no");
316         emit fmtxSettingsChanged();
317 }