babef8cf3e2fc47e5f9fce27780708611405a1b1
[vlc-remote] / appsettings.cpp
1 /*   VLC-REMOTE for MAEMO 5
2 *   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 #include <QStringList>
19 #include "appsettings.h"
20
21 AppSettings::AppSettings() {
22 }
23
24 AppSettings::~AppSettings() {
25     ;
26 }
27
28 QString AppSettings::getCurrentKey() {
29     QSettings sets;
30     return sets.value("config/currentKey", "").toString();
31 }
32 QString AppSettings::getCurrentIp() {
33     QSettings sets;
34     return sets.value("account/" + getCurrentKey(), "").toString();
35 }
36 VlcDirectory AppSettings::getHomeDirectory() {
37     QSettings sets;
38     VlcDirectory home;
39     home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString();
40     home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString();
41     return home;
42 }
43 bool AppSettings::setHomeDirectory(VlcDirectory dir) {
44     QSettings sets;
45     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name);
46     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path);
47     return true;
48 }
49 QList<VlcDirectory>* AppSettings::getFavourites() {
50     QSettings sets;
51     QList<VlcDirectory> * favourites = new QList<VlcDirectory>();
52
53     sets.beginGroup("config/accounts/" + getCurrentKey() + "/favourites");
54     foreach ( QString key, sets.allKeys())
55     {
56         VlcDirectory dir;
57         // key is name
58         dir.name = key;
59         // value is path
60         dir.path = sets.value(key, "~/").toString();
61         favourites->append(dir);
62     }
63     sets.endGroup();
64     return favourites;
65 }
66 bool AppSettings::addFavourite(VlcDirectory dir) {
67     QSettings sets;
68     // should check for existing first otherwise it overwrites
69     if (0 < sets.value("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, "").toString().length()) {
70         dir.name = "_" + dir.name;
71         return addFavourite(dir);
72     }
73     sets.setValue("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, dir.path);
74     return true;
75 }
76 bool AppSettings::deleteFavourite(VlcDirectory dir) {
77     QSettings sets;
78     sets.remove("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name);
79     return true;
80 }
81 Orientation AppSettings::setOrientation(Orientation orientation) {
82     QSettings sets;
83     sets.setValue("config/orientation", (int)orientation);
84     return orientation;
85 }
86 Orientation AppSettings::getOrientation() {
87     QSettings sets;
88     return (Orientation)(sets.value("config/orientation", AUTO_ROTATE).toInt());
89 }
90