Added Bluetooth AVRCP support via HAL/DBus
[someplayer] / src / config.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 #include "config.h"
21 #include <QString>
22 #include <QDir>
23
24 using namespace SomePlayer::Storage;
25
26 Config::Config()
27 {
28         _settings = new QSettings(QString(applicationDir())+"/settings.ini", QSettings::IniFormat);
29         if (_settings->value("ui/iconstheme").toString() == "")
30                 _settings->setValue("ui/iconstheme", "white");
31         if (_settings->value("ui/albumsorting").toString() == "")
32                 _settings->setValue("ui/albumsorting", "date");
33         if (_settings->value("ui/gradient").toString() == "")
34                 _settings->setValue("ui/gradient", "yes");
35         if (_settings->value("ui/language").toString() == "")
36                 _settings->setValue("ui/language", "en");
37         if (_settings->value("ui/trackcolor").toString() == "")
38                 _settings->setValue("ui/trackcolor", "blue");
39         _equalizer_settings = new QSettings(QString(applicationDir())+"/equalizer.ini", QSettings::IniFormat);
40 }
41
42 Config::~Config() {
43         delete _settings;
44         delete _equalizer_settings;
45 }
46
47 QString Config::applicationDir() {
48         QString path = QDir::homePath()+"/.someplayer";
49         QDir appdir(path);
50         if (!appdir.exists(path)) {
51                 appdir.mkdir(path);
52         }
53         return path;
54 }
55
56 QVariant Config::getValue(QString key) {
57         return _settings->value(key);
58 }
59
60 void Config::setValue(QString key, QVariant value) {
61         _settings->setValue(key, value);
62 }
63
64 QStringList Config::getEqualizerPresets() {
65         QStringList presets = _equalizer_settings->value("equalizer/presets").toStringList();
66         return presets;
67 }
68
69 double Config::getEqualizerValue(QString band, QString preset) {
70         QString section;
71         if (preset.isEmpty()) {
72                 section = "equalizer";
73         } else {
74                 section = "equalizer_preset_"+preset;
75         }
76         return _equalizer_settings->value(section+"/"+band).toDouble();
77 }
78
79 void Config::setEqualizerValue(QString band, double value) {
80         _equalizer_settings->setValue("equalizer/"+band, value);
81 }
82
83 void Config::saveEqualizer(QString preset) {
84         QString section = QString("equalizer_preset_%1/%2").arg(preset);
85         QStringList presets = getEqualizerPresets();
86         if (!presets.contains(preset)) presets.append(preset);
87         _equalizer_settings->setValue("equalizer/presets", presets);
88         for (int i = 0; i < 10; i++) {
89                 QString band = QString("band%1").arg(i);
90                 _equalizer_settings->setValue(section.arg(band), getEqualizerValue(band));
91         }
92 }
93
94 bool Config::equalizerEnabled() {
95         return _equalizer_settings->value("equalizer/enabled").toBool();
96 }
97
98 void Config::setEqualizerEnabled(bool enabled) {
99         _equalizer_settings->setValue("equalizer/enabled", enabled);
100 }