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
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
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.
18 #include <QStringList>
19 #include <QNetworkInterface>
20 #include "appsettings.h"
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;
45 AppSettings::AppSettings() {
48 AppSettings::~AppSettings() {
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)) );
56 QStringList AppSettings::getAllAccounts() {
59 sets.beginGroup("account");
60 accounts = sets.allKeys();
64 QString AppSettings::getCurrentKey() {
65 if (!_haveCurrentKey) {
67 _currentKey = sets.value("config/currentKey", "").toString();
68 _haveCurrentKey = true;
72 QString AppSettings::setCurrentKey(QString currentKey) {
74 sets.setValue("config/currentKey", currentKey);
75 _currentKey = currentKey;
76 _haveCurrentKey = true;
79 QString AppSettings::getCurrentIp() {
80 if (!_haveCurrentIp) {
82 _currentIp = sets.value("account/" + getCurrentKey(), "").toString();
83 _haveCurrentIp = true;
87 QString AppSettings::setCurrentIp(QString currentIp) {
89 sets.setValue("account/" + getCurrentKey(), currentIp);
90 _currentIp = currentIp;
91 _haveCurrentIp = true;
94 VlcDirectory AppSettings::getHomeDirectory() {
97 home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString();
98 home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString();
101 bool AppSettings::setHomeDirectory(VlcDirectory dir) {
103 sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name);
104 sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path);
107 QList<VlcDirectory>* AppSettings::getFavourites() {
109 QList<VlcDirectory> * favourites = new QList<VlcDirectory>();
111 sets.beginGroup("config/accounts/" + getCurrentKey() + "/favourites");
112 foreach ( QString key, sets.allKeys())
118 dir.path = sets.value(key, "~/").toString();
119 favourites->append(dir);
124 bool AppSettings::addFavourite(VlcDirectory dir) {
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
131 sets.setValue("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, dir.path);
134 bool AppSettings::deleteFavourite(VlcDirectory dir) {
136 sets.remove("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name);
139 int AppSettings::getStatusPollTimeout() {
140 if (!_haveStatusPollTimeout) {
142 _statusPollTimeout = sets.value("config/statusPollTimeout", STATUS_POLL_TIMEOUT).toInt();
143 _haveStatusPollTimeout = true;
145 return _statusPollTimeout;
147 int AppSettings::setStatusPollTimeout(int statusPollTimeout) {
149 sets.setValue("config/statusPollTimeout", statusPollTimeout);
150 _statusPollTimeout = statusPollTimeout;
151 _haveStatusPollTimeout = true;
152 return _statusPollTimeout;
154 int AppSettings::getPingTimeout() {
155 if (!_havePingTimeout) {
157 _pingTimeout = sets.value("config/pingTimeout", PING_TIMEOUT).toInt();
158 _havePingTimeout = true;
162 int AppSettings::setPingTimeout(int pingTimeout) {
164 sets.setValue("config/pingTimeout", pingTimeout);
165 _pingTimeout = pingTimeout;
166 _havePingTimeout = true;
169 int AppSettings::getConnectionTimeout() {
170 if (!_haveConnectionTimeout) {
172 _connectionTimeout = sets.value("config/connectionTimeout", CONNECTION_TIMEOUT).toInt();
173 _haveConnectionTimeout = true;
175 return _connectionTimeout;
177 int AppSettings::setConnectionTimeout(int connectionTimeout) {
179 sets.setValue("config/connectionTimeout", connectionTimeout);
180 _connectionTimeout = connectionTimeout;
181 _haveConnectionTimeout = true;
182 return _connectionTimeout;
184 int AppSettings::getRetrieveArtTimeout() {
185 if (!_haveRetrieveArtTimeout) {
187 _retrieveArtTimeout = sets.value("config/retrieveArtTimeout", RETRIEVE_ART_TIMEOUT).toInt();
188 _haveRetrieveArtTimeout = true;
190 return _retrieveArtTimeout;
192 int AppSettings::setRetrieveArtTimeout(int retrieveArtTimeout) {
194 sets.setValue("config/retrieveArtTimeout", retrieveArtTimeout);
195 _retrieveArtTimeout = retrieveArtTimeout;
196 _haveRetrieveArtTimeout = true;
197 return _retrieveArtTimeout;
199 int AppSettings::getRetryNetworkTimeout() {
200 if (!_haveRetryNetworkTimeout) {
202 _retryNetworkTimeout = sets.value("config/retryNetworkTimeout", RETRY_NETWORK_TIMEOUT).toInt();
203 _haveRetryNetworkTimeout = true;
205 return _retryNetworkTimeout;
207 int AppSettings::setRetryNetworkTimeout(int retryNetworkTimeout) {
209 sets.setValue("config/retryNetworkTimeout", retryNetworkTimeout);
210 _retryNetworkTimeout = retryNetworkTimeout;
211 _haveRetryNetworkTimeout = true;
212 return _retryNetworkTimeout;
214 bool AppSettings::getShowUnknownFileTypes() {
215 if (!_haveShowUnknownFileTypes) {
217 _showUnknownFileTypes = sets.value("config/showUnknownFileTypes", SHOW_UNKNOWN_FILETYPES).toBool();
218 _haveShowUnknownFileTypes = true;
220 return _showUnknownFileTypes;
222 bool AppSettings::setShowUnknownFileTypes(bool showUnknownFileTypes) {
224 sets.setValue("config/showUnknownFileTypes", showUnknownFileTypes);
225 _showUnknownFileTypes = showUnknownFileTypes;
226 _haveShowUnknownFileTypes = true;
227 return _showUnknownFileTypes;
229 bool AppSettings::getShowAlbumArt() {
230 if (!_haveShowAlbumArt) {
232 _showAlbumArt = sets.value("config/showAlbumArt", SHOW_ALBUM_ART).toBool();
233 _haveShowAlbumArt = true;
235 return _showAlbumArt;
237 bool AppSettings::setShowAlbumArt(bool showAlbumArt) {
239 sets.setValue("config/showAlbumArt", showAlbumArt);
240 _showAlbumArt = showAlbumArt;
241 _haveShowAlbumArt = true;
242 return _showAlbumArt;
244 bool AppSettings::getAlertOnClose() {
245 if (!_haveAlertOnClose) {
247 _alertOnClose = sets.value("config/alertOnClose", ALERT_ON_CLOSE).toBool();
248 _haveAlertOnClose = true;
250 return _alertOnClose;
252 bool AppSettings::setAlertOnClose(bool alertOnClose) {
254 sets.setValue("config/alertOnClose", alertOnClose);
255 _alertOnClose = alertOnClose;
256 _haveAlertOnClose = true;
257 return _alertOnClose;
259 Orientation AppSettings::getOrientation() {
260 if (!_haveOrientation) {
262 return (Orientation)(sets.value("config/orientation", AUTO_ROTATE).toInt());
263 _haveOrientation = true;
267 Orientation AppSettings::setOrientation(Orientation orientation) {
269 sets.setValue("config/orientation", (int)orientation);
270 _orientation = orientation;
271 _haveOrientation = true;