Fixed settings save bug
[someplayer] / src / settingsdialog.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 "settingsdialog.h"
22 #include "ui_settingsdialog.h"
23
24 using namespace SomePlayer::Storage;
25
26 SettingsDialog::SettingsDialog(QWidget *parent) :
27                 QDialog(parent),
28                 ui(new Ui::SettingsDialog)
29 {
30         ui->setupUi(this);
31         Config config;
32         QString albumSorting = config.getValue("ui/albumsorting").toString();
33         QString showTrackLenght = config.getValue("ui/showtracklenght").toString();
34         QString orientation = config.getValue("ui/orientation").toString();
35         ui->albumsSortAButton->setChecked(true);        // defaule sorting
36         ui->showTrackLenghtYButton->setChecked(true);   // show by default
37         ui->orientationLButton->setChecked(true);
38         if (albumSorting == "date") {
39                 ui->albumsSortDButton->setChecked(true);
40         }
41         if (showTrackLenght == "no") {
42                 ui->showTrackLenghtNButton->setChecked(true);
43         }
44         if (orientation == "portrait") {
45                 ui->orientationPButton->setChecked(true);
46         } else if (orientation == "auto") {
47                 ui->orientationAButton->setChecked(true);
48         }
49         connect (ui->albumsSortAButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_alphabet(bool)));
50         connect (ui->albumsSortDButton, SIGNAL(toggled(bool)), this, SLOT(_set_album_sorting_date(bool)));
51         connect (ui->showTrackLenghtNButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_no(bool)));
52         connect (ui->showTrackLenghtYButton, SIGNAL(toggled(bool)), this, SLOT(_set_track_lenght_show_yes(bool)));
53         connect (ui->orientationAButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_auto(bool)));
54         connect (ui->orientationLButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_landscape(bool)));
55         connect (ui->orientationPButton, SIGNAL(toggled(bool)), this, SLOT(_set_orientation_portrait(bool)));
56
57         // disabled to 1.4.0
58         ui->albumSortingGroupBox->setVisible(false);
59 }
60
61 SettingsDialog::~SettingsDialog()
62 {
63         delete ui;
64 }
65
66 void SettingsDialog::_set_album_sorting_date(bool checked) {
67         if (!checked) return;
68         Config config;
69         config.setValue("ui/albumsorting", "date");
70 }
71
72 void SettingsDialog::_set_album_sorting_alphabet(bool checked) {
73         if (!checked) return;
74         Config config;
75         config.setValue("ui/albumsorting", "alphabet");
76 }
77
78 void SettingsDialog::_set_track_lenght_show_no(bool checked) {
79         if (!checked) return;
80         Config config;
81         config.setValue("ui/showtracklenght", "no");
82 }
83
84 void SettingsDialog::_set_track_lenght_show_yes(bool checked) {
85         if (!checked) return;
86         Config config;
87         config.setValue("ui/showtracklenght", "yes");
88 }
89
90 void SettingsDialog::_set_orientation_auto(bool checked) {
91         if (!checked) return;
92         Config config;
93         config.setValue("ui/orientation", "auto");
94 }
95
96 void SettingsDialog::_set_orientation_landscape(bool checked) {
97         if (!checked) return;
98         Config config;
99         config.setValue("ui/orientation", "landscape");
100 }
101
102 void SettingsDialog::_set_orientation_portrait(bool checked) {
103         if (!checked) return;
104         Config config;
105         config.setValue("ui/orientation", "portrait");
106 }
107