Moved timeout constants to appsettings in preparatino for adding to user configuratio...
[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 QString AppSettings::getCurrentKey() {
42     QSettings sets;
43     return sets.value("config/currentKey", "").toString();
44 }
45 QString AppSettings::getCurrentIp() {
46     QSettings sets;
47     return sets.value("account/" + getCurrentKey(), "").toString();
48 }
49 VlcDirectory AppSettings::getHomeDirectory() {
50     QSettings sets;
51     VlcDirectory home;
52     home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString();
53     home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString();
54     return home;
55 }
56 bool AppSettings::setHomeDirectory(VlcDirectory dir) {
57     QSettings sets;
58     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name);
59     sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path);
60     return true;
61 }
62 QList<VlcDirectory>* AppSettings::getFavourites() {
63     QSettings sets;
64     QList<VlcDirectory> * favourites = new QList<VlcDirectory>();
65
66     sets.beginGroup("config/accounts/" + getCurrentKey() + "/favourites");
67     foreach ( QString key, sets.allKeys())
68     {
69         VlcDirectory dir;
70         // key is name
71         dir.name = key;
72         // value is path
73         dir.path = sets.value(key, "~/").toString();
74         favourites->append(dir);
75     }
76     sets.endGroup();
77     return favourites;
78 }
79 bool AppSettings::addFavourite(VlcDirectory dir) {
80     QSettings sets;
81     // should check for existing first otherwise it overwrites
82     if (0 < sets.value("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, "").toString().length()) {
83         dir.name = "_" + dir.name;
84         return addFavourite(dir);
85     }
86     sets.setValue("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name, dir.path);
87     return true;
88 }
89 bool AppSettings::deleteFavourite(VlcDirectory dir) {
90     QSettings sets;
91     sets.remove("config/accounts/" + getCurrentKey() + "/favourites/" + dir.name);
92     return true;
93 }
94 int AppSettings::getStatusPollTimeout() {
95     return STATUS_POLL_TIMEOUT;
96 }
97 int AppSettings::getPingTimeout() {
98     return PING_TIMEOUT;
99 }
100 int AppSettings::getConnectionTimeout() {
101     return CONNECTION_TIMEOUT;
102 }
103 int AppSettings::getRetrieveArtTimeout() {
104     return RETRIEVE_ART_TIMEOUT;
105 }
106 int AppSettings::getRetryNetworkTimeout() {
107     return RETRY_NETWORK_TIMEOUT;
108 }
109 bool AppSettings::getShowUnknownFileTypes() {
110     return SHOW_UNKNOWN_FILETYPES;
111 }
112 Orientation AppSettings::setOrientation(Orientation orientation) {
113     QSettings sets;
114     sets.setValue("config/orientation", (int)orientation);
115     return orientation;
116 }
117 Orientation AppSettings::getOrientation() {
118     QSettings sets;
119     return (Orientation)(sets.value("config/orientation", AUTO_ROTATE).toInt());
120 }
121