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)
37 _color_map << "blue" << "magenta" << "red" << "yellow" <<
38 "white" << "black" << "light" << "dark";
39 _lang_map << "en" << "it" << "pl" << "ru" << "zh_CN" << "zh_TW";
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);
64 if (showTrackLenght == "no") {
65 ui->showTrackLenghtNButton->setChecked(true);
67 if (orientation == "portrait") {
68 ui->orientationPButton->setChecked(true);
69 } else if (orientation == "auto") {
70 ui->orientationAButton->setChecked(true);
72 if (icons_theme == "black") {
73 ui->iconstBButton->setChecked(true);
75 if (gradient == "no") {
76 ui->gradientNButton->setChecked(true);
78 if (config.getValue("hw/hpautopause").toString() == "yes") {
79 ui->pauseHPYesButton->setChecked(true);
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);
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);
93 ui->hwVolumeButton->setChecked(true);
94 config.setValue("hw/zoom_action", "volume");
96 if (config.getValue("fmtx/enabled").toString() == "yes") {
97 ui->fmtxGroupBox->setChecked(true);
98 emit fmtxSettingsChanged();
100 if (!QFile::exists(QString(_APPLICATION_PATH_)+"/someplayer_ru.qm")) {
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)));
127 setAttribute(Qt::WA_Maemo5StackedWindow);
128 setWindowFlags(Qt::Window | windowFlags());
131 SettingsForm::~SettingsForm()
136 void SettingsForm::_set_album_sorting_date(bool checked) {
137 if (!checked) return;
139 config.setValue("ui/albumsorting", "date");
140 emit libraryOptionsChanged();
143 void SettingsForm::_set_album_sorting_alphabet(bool checked) {
144 if (!checked) return;
146 config.setValue("ui/albumsorting", "alphabet");
147 emit libraryOptionsChanged();
150 void SettingsForm::_set_track_lenght_show_no(bool checked) {
151 if (!checked) return;
153 config.setValue("ui/showtracklenght", "no");
154 emit libraryOptionsChanged();
157 void SettingsForm::_set_track_lenght_show_yes(bool checked) {
158 if (!checked) return;
160 config.setValue("ui/showtracklenght", "yes");
161 emit libraryOptionsChanged();
164 void SettingsForm::_set_orientation_auto(bool checked) {
165 if (!checked) return;
167 config.setValue("ui/orientation", "auto");
168 emit orientationChanged();
171 void SettingsForm::_set_orientation_landscape(bool checked) {
172 if (!checked) return;
174 config.setValue("ui/orientation", "landscape");
175 emit orientationChanged();
178 void SettingsForm::_set_orientation_portrait(bool checked) {
179 if (!checked) return;
181 config.setValue("ui/orientation", "portrait");
182 emit orientationChanged();
185 void SettingsForm::_set_icons_black(bool checked) {
186 if (!checked) return;
188 config.setValue("ui/iconstheme", "black");
192 void SettingsForm::_set_icons_white(bool checked) {
193 if (!checked) return;
195 config.setValue("ui/iconstheme", "white");
199 void SettingsForm::_set_gradient_no(bool checked) {
200 if (!checked) return;
202 config.setValue("ui/gradient", "no");
203 emit gradientChanged();
206 void SettingsForm::_set_gradient_yes(bool checked) {
207 if (!checked) return;
209 config.setValue("ui/gradient", "yes");
210 emit gradientChanged();
213 void SettingsForm::_set_color(int code) {
215 config.setValue("ui/trackcolor", _color_map[code]);
216 emit trackColorChanged();
219 void SettingsForm::_set_language(int code) {
221 config.setValue("ui/language", _lang_map[code]);
222 emit translationChanged();
225 void SettingsForm::_set_pause_hp_no(bool checked) {
226 if (!checked) return;
228 config.setValue("hw/hpautopause", "no");
231 void SettingsForm::_set_pause_hp_yes(bool checked) {
232 if (!checked) return;
234 config.setValue("hw/hpautopause", "yes");
237 void SettingsForm::_toggle_hw_settings(bool checked) {
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();
246 void SettingsForm::_set_hw_track_control(bool checked) {
247 if (!checked) return;
249 config.setValue("hw/zoom_action", "track");
252 void SettingsForm::_set_hw_volume_control(bool checked) {
253 if (!checked) return;
255 config.setValue("hw/zoom_action", "volume");
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);
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);
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);
279 void SettingsForm::updateTranslations() {
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()));
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);
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);
304 void SettingsForm::_open_fmtx_settings() {
305 FmtxSettingsDialog dialog(this);
308 config.setValue("fmtx/station_name", dialog.stationName());
309 config.setValue("fmtx/frequency", dialog.frequency());
310 emit fmtxSettingsChanged();
313 void SettingsForm::_toggle_fmtx_settings(bool checked) {
315 config.setValue("fmtx/enabled", checked ? "yes" : "no");
316 emit fmtxSettingsChanged();