23f159885143e99b9102432de30b16c0488c478b
[vlc-remote] / src / 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 <QNetworkInterface>
20 #include "appsettings.h"
21
22 AppSettings::AppSettings() {
23 }
24
25 AppSettings::~AppSettings() {
26     ;
27 }
28 bool AppSettings::isConnected() {
29     QNetworkInterface wlan = QNetworkInterface::interfaceFromName("wlan0");
30     QNetworkInterface gprs = QNetworkInterface::interfaceFromName("gprs0");
31
32     if( (wlan.isValid() && wlan.flags().testFlag(QNetworkInterface::IsUp)) || (gprs.isValid() && gprs.flags().testFlag(QNetworkInterface::IsUp)) )
33     {
34         return true;
35     }
36     else
37     {
38         return false;
39     }
40 }
41 QStringList AppSettings::getAllAccounts() {
42     QStringList accounts;
43     QSettings sets;
44     sets.beginGroup("account");
45     accounts = sets.allKeys();
46     sets.endGroup();
47     return accounts;
48 }
49 QString AppSettings::getCurrentKey() {
50     QSettings sets;
51     return sets.value("config/currentKey", "").toString();
52 }
53 void AppSettings::setCurrentKey(QString key) {
54     QSettings sets;
55     sets.setValue("config/currentKey", key);
56 }
57 QString AppSettings::getCurrentIp() {
58     QSettings sets;
59     return sets.value("account/" + getCurrentKey(), "").toString();
60 }
61 void AppSettings::setCurrentIp(QString ip) {
62     QSettings sets;
63     sets.setValue("account/" + getCurrentKey(), ip);
64 }
65 VlcDirectory AppSettings::getHomeDirectory() {
66     QSettings sets;
67     VlcDirectory home;
68     home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString();
69     home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString();
70     return home;
71 }
72 bool AppSettings::setHomeDirectory(VlcDirectory dir) {
73     QSettings sets;
74     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name);
75     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path);
76     return true;
77 }
78 QList<VlcDirectory>* AppSettings::getFavourites() {
79     QSettings sets;
80     QList<VlcDirectory> * favourites = new QList<VlcDirectory>();
81
82     sets.beginGroup("config/accounts/" + getCurrentKey() + "/favourites");
83     foreach ( QString key, sets.allKeys())
84     {
85         VlcDirectory dir;
86         // key is name
87         dir.name = key;
88         // value is path
89         dir.path = sets.value(key, "~/").toString();
90         favourites->append(dir);
91     }
92     sets.endGroup();
93     return favourites;
94 }
95 bool AppSettings::addFavourite(VlcDirectory dir) {
96     QSettings sets;
97     // should check for existing first otherwise it overwrites
98     if (0 < sets.value("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, "").toString().length()) {
99         dir.name = "_" + dir.name;
100         return addFavourite(dir);
101     }
102     sets.setValue("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, dir.path);
103     return true;
104 }
105 bool AppSettings::deleteFavourite(VlcDirectory dir) {
106     QSettings sets;
107     sets.remove("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name);
108     return true;
109 }
110 int AppSettings::getStatusPollTimeout() {
111     return STATUS_POLL_TIMEOUT;
112 }
113 int AppSettings::getPingTimeout() {
114     return PING_TIMEOUT;
115 }
116 int AppSettings::getConnectionTimeout() {
117     return CONNECTION_TIMEOUT;
118 }
119 int AppSettings::getRetrieveArtTimeout() {
120     return RETRIEVE_ART_TIMEOUT;
121 }
122 int AppSettings::getRetryNetworkTimeout() {
123     return RETRY_NETWORK_TIMEOUT;
124 }
125 bool AppSettings::getShowUnknownFileTypes() {
126     return SHOW_UNKNOWN_FILETYPES;
127 }
128 bool AppSettings::getShowAlbumArt() {
129     return SHOW_ALBUM_ART;
130 }
131 bool AppSettings::getAlertOnClose() {
132     return ALERT_ON_CLOSE;
133 }
134 Orientation AppSettings::setOrientation(Orientation orientation) {
135     QSettings sets;
136     sets.setValue("config/orientation", (int)orientation);
137     return orientation;
138 }
139 Orientation AppSettings::getOrientation() {
140     QSettings sets;
141     return (Orientation)(sets.value("config/orientation", AUTO_ROTATE).toInt());
142 }
143