Add mce-dev into control build templates for dbus support
[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 bool AppSettings::_haveCurrentKey            = false;
23 QString AppSettings::_currentKey             = "";
24 bool AppSettings::_haveCurrentIp             = false;
25 QString AppSettings::_currentIp              = "";
26 bool AppSettings::_haveConnectionTimeout     = false;
27 int  AppSettings::_connectionTimeout         = 0;
28 bool AppSettings::_havePingTimeout           = false;
29 int  AppSettings::_pingTimeout               = 0;
30 bool AppSettings::_haveStatusPollTimeout     = false;
31 int  AppSettings::_statusPollTimeout         = 0;
32 bool AppSettings::_haveRetrieveArtTimeout    = false;
33 int  AppSettings::_retrieveArtTimeout        = 0;
34 bool AppSettings::_haveRetryNetworkTimeout   = false;
35 int  AppSettings::_retryNetworkTimeout       = 0;
36 bool AppSettings::_haveShowUnknownFileTypes  = false;
37 bool AppSettings::_showUnknownFileTypes      = false;
38 bool AppSettings::_haveShowAlbumArt          = false;
39 bool AppSettings::_showAlbumArt              = false;
40 bool AppSettings::_haveAlertOnClose          = false;
41 bool AppSettings::_alertOnClose              = false;
42 bool AppSettings::_haveOrientation           = false;
43 Orientation AppSettings::_orientation        = LANDSCAPE;
44
45 AppSettings::AppSettings() {
46 }
47
48 AppSettings::~AppSettings() {
49     ;
50 }
51 bool AppSettings::isConnected() {
52     QNetworkInterface wlan = QNetworkInterface::interfaceFromName("wlan0");
53     QNetworkInterface gprs = QNetworkInterface::interfaceFromName("gprs0");
54     return ( (wlan.isValid() && wlan.flags().testFlag(QNetworkInterface::IsUp)) || (gprs.isValid() && gprs.flags().testFlag(QNetworkInterface::IsUp)) );
55 }
56 QStringList AppSettings::getAllAccounts() {
57     QStringList accounts;
58     QSettings sets;
59     sets.beginGroup("account");
60     accounts = sets.allKeys();
61     sets.endGroup();
62     return accounts;
63 }
64 QString AppSettings::getCurrentKey() {
65     if (!_haveCurrentKey) {
66         QSettings sets;
67         _currentKey = sets.value("config/currentKey", "").toString();
68         _haveCurrentKey = true;
69     }
70     return _currentKey;
71 }
72 QString AppSettings::setCurrentKey(QString currentKey) {
73     QSettings sets;
74     sets.setValue("config/currentKey", currentKey);
75     _currentKey = currentKey;
76     _haveCurrentKey = true;
77     return _currentKey;
78 }
79 QString AppSettings::getCurrentIp() {
80     if (!_haveCurrentIp) {
81         QSettings sets;
82         _currentIp = sets.value("account/" + getCurrentKey(), "").toString();
83         _haveCurrentIp = true;
84     }
85     return _currentIp;
86 }
87 QString AppSettings::setCurrentIp(QString currentIp) {
88     QSettings sets;
89     sets.setValue("account/" + getCurrentKey(), currentIp);
90     _currentIp = currentIp;
91     _haveCurrentIp = true;
92     return _currentIp;
93 }
94 VlcDirectory AppSettings::getHomeDirectory() {
95     QSettings sets;
96     VlcDirectory home;
97     home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString();
98     home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString();
99     return home;
100 }
101 bool AppSettings::setHomeDirectory(VlcDirectory dir) {
102     QSettings sets;
103     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name);
104     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path);
105     return true;
106 }
107 QList<VlcDirectory>* AppSettings::getFavourites() {
108     QSettings sets;
109     QList<VlcDirectory> * favourites = new QList<VlcDirectory>();
110
111     sets.beginGroup("config/accounts/" + getCurrentKey() + "/favourites");
112     foreach ( QString key, sets.allKeys())
113     {
114         VlcDirectory dir;
115         // key is name
116         dir.name = key;
117         // value is path
118         dir.path = sets.value(key, "~/").toString();
119         favourites->append(dir);
120     }
121     sets.endGroup();
122     return favourites;
123 }
124 bool AppSettings::addFavourite(VlcDirectory dir) {
125     QSettings sets;
126     // should check for existing first otherwise it overwrites
127     if (0 < sets.value("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, "").toString().length()) {
128         dir.name = "_" + dir.name;
129         return addFavourite(dir); // recurse
130     }
131     sets.setValue("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, dir.path);
132     return true;
133 }
134 bool AppSettings::deleteFavourite(VlcDirectory dir) {
135     QSettings sets;
136     sets.remove("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name);
137     return true;
138 }
139 int AppSettings::getStatusPollTimeout() {
140     if (!_haveStatusPollTimeout) {
141         QSettings sets;
142         _statusPollTimeout = sets.value("config/statusPollTimeout", STATUS_POLL_TIMEOUT).toInt();
143         _haveStatusPollTimeout = true;
144     }
145     return _statusPollTimeout;
146 }
147 int AppSettings::setStatusPollTimeout(int statusPollTimeout) {
148     QSettings sets;
149     sets.setValue("config/statusPollTimeout", statusPollTimeout);
150     _statusPollTimeout = statusPollTimeout;
151     _haveStatusPollTimeout = true;
152     return _statusPollTimeout;
153 }
154 int AppSettings::getPingTimeout() {
155     if (!_havePingTimeout) {
156         QSettings sets;
157         _pingTimeout = sets.value("config/pingTimeout", PING_TIMEOUT).toInt();
158         _havePingTimeout = true;
159     }
160     return _pingTimeout;
161 }
162 int AppSettings::setPingTimeout(int pingTimeout) {
163     QSettings sets;
164     sets.setValue("config/pingTimeout", pingTimeout);
165     _pingTimeout = pingTimeout;
166     _havePingTimeout = true;
167     return _pingTimeout;
168 }
169 int AppSettings::getConnectionTimeout() {
170     if (!_haveConnectionTimeout) {
171         QSettings sets;
172         _connectionTimeout = sets.value("config/connectionTimeout", CONNECTION_TIMEOUT).toInt();
173         _haveConnectionTimeout = true;
174     }
175     return _connectionTimeout;
176 }
177 int AppSettings::setConnectionTimeout(int connectionTimeout) {
178     QSettings sets;
179     sets.setValue("config/connectionTimeout", connectionTimeout);
180     _connectionTimeout = connectionTimeout;
181     _haveConnectionTimeout = true;
182     return _connectionTimeout;
183 }
184 int AppSettings::getRetrieveArtTimeout() {
185     if (!_haveRetrieveArtTimeout) {
186         QSettings sets;
187         _retrieveArtTimeout = sets.value("config/retrieveArtTimeout", RETRIEVE_ART_TIMEOUT).toInt();
188         _haveRetrieveArtTimeout = true;
189     }
190     return _retrieveArtTimeout;
191 }
192 int AppSettings::setRetrieveArtTimeout(int retrieveArtTimeout) {
193     QSettings sets;
194     sets.setValue("config/retrieveArtTimeout", retrieveArtTimeout);
195     _retrieveArtTimeout = retrieveArtTimeout;
196     _haveRetrieveArtTimeout = true;
197     return _retrieveArtTimeout;
198 }
199 int AppSettings::getRetryNetworkTimeout() {
200     if (!_haveRetryNetworkTimeout) {
201         QSettings sets;
202         _retryNetworkTimeout = sets.value("config/retryNetworkTimeout", RETRY_NETWORK_TIMEOUT).toInt();
203         _haveRetryNetworkTimeout = true;
204     }
205     return _retryNetworkTimeout;
206 }
207 int AppSettings::setRetryNetworkTimeout(int retryNetworkTimeout) {
208     QSettings sets;
209     sets.setValue("config/retryNetworkTimeout", retryNetworkTimeout);
210     _retryNetworkTimeout = retryNetworkTimeout;
211     _haveRetryNetworkTimeout = true;
212     return _retryNetworkTimeout;
213 }
214 bool AppSettings::getShowUnknownFileTypes() {
215     if (!_haveShowUnknownFileTypes) {
216         QSettings sets;
217         _showUnknownFileTypes = sets.value("config/showUnknownFileTypes", SHOW_UNKNOWN_FILETYPES).toBool();
218         _haveShowUnknownFileTypes = true;
219     }
220     return _showUnknownFileTypes;
221 }
222 bool AppSettings::setShowUnknownFileTypes(bool showUnknownFileTypes) {
223     QSettings sets;
224     sets.setValue("config/showUnknownFileTypes", showUnknownFileTypes);
225     _showUnknownFileTypes = showUnknownFileTypes;
226     _haveShowUnknownFileTypes = true;
227     return _showUnknownFileTypes;
228 }
229 bool AppSettings::getShowAlbumArt() {
230     if (!_haveShowAlbumArt) {
231         QSettings sets;
232         _showAlbumArt = sets.value("config/showAlbumArt", SHOW_ALBUM_ART).toBool();
233         _haveShowAlbumArt = true;
234     }
235     return _showAlbumArt;
236 }
237 bool AppSettings::setShowAlbumArt(bool showAlbumArt) {
238     QSettings sets;
239     sets.setValue("config/showAlbumArt", showAlbumArt);
240     _showAlbumArt = showAlbumArt;
241     _haveShowAlbumArt = true;
242     return _showAlbumArt;
243 }
244 bool AppSettings::getAlertOnClose() {
245     if (!_haveAlertOnClose) {
246         QSettings sets;
247         _alertOnClose = sets.value("config/alertOnClose", ALERT_ON_CLOSE).toBool();
248         _haveAlertOnClose = true;
249     }
250     return _alertOnClose;
251 }
252 bool AppSettings::setAlertOnClose(bool alertOnClose) {
253     QSettings sets;
254     sets.setValue("config/alertOnClose", alertOnClose);
255     _alertOnClose = alertOnClose;
256     _haveAlertOnClose = true;
257     return _alertOnClose;
258 }
259 Orientation AppSettings::getOrientation() {
260     if (!_haveOrientation) {
261         QSettings sets;
262         return (Orientation)(sets.value("config/orientation", AUTO_ROTATE).toInt());
263         _haveOrientation = true;
264     }
265     return _orientation;
266 }
267 Orientation AppSettings::setOrientation(Orientation orientation) {
268     QSettings sets;
269     sets.setValue("config/orientation", (int)orientation);
270     _orientation = orientation;
271     _haveOrientation = true;
272     return _orientation;
273 }
274