MPEGPlayer: Skip to next file when there is a problem with a video file in all-play...
[kugel-rb.git] / rbutil / rbutilqt / base / systeminfo.cpp
blobb4931686990ac83adc9c6dc49a44100bfbefa06d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2010 by Dominik Wenger
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "systeminfo.h"
21 #include "rbsettings.h"
23 #include <QSettings>
25 #if defined(Q_OS_LINUX)
26 #include <unistd.h>
27 #endif
30 // device settings
31 const static struct {
32 SystemInfo::SystemInfos info;
33 const char* name;
34 const char* def;
35 } SystemInfosList[] = {
36 { SystemInfo::ManualUrl, "manual_url", "" },
37 { SystemInfo::BleedingUrl, "bleeding_url", "" },
38 { SystemInfo::BootloaderUrl, "bootloader_url", "" },
39 { SystemInfo::BootloaderInfoUrl, "bootloader_info_url", "" },
40 { SystemInfo::ReleaseFontUrl, "release_font_url", "" },
41 { SystemInfo::DailyFontUrl, "daily_font_url", "" },
42 { SystemInfo::DailyVoiceUrl, "daily_voice_url", "" },
43 { SystemInfo::ReleaseVoiceUrl, "release_voice_url", "" },
44 { SystemInfo::DoomUrl, "doom_url", "" },
45 { SystemInfo::ReleaseUrl, "release_url", "" },
46 { SystemInfo::DailyUrl, "daily_url", "" },
47 { SystemInfo::ServerConfUrl, "server_conf_url", "" },
48 { SystemInfo::GenlangUrl, "genlang_url", "" },
49 { SystemInfo::ThemesUrl, "themes_url", "" },
50 { SystemInfo::ThemesInfoUrl, "themes_info_url", "" },
51 { SystemInfo::RbutilUrl, "rbutil_url", "" },
52 { SystemInfo::BleedingInfo, "bleeding_info", "" },
53 { SystemInfo::CurPlatformName, ":platform:/name", "" },
54 { SystemInfo::CurManual, ":platform:/manualname","rockbox-:platform:" },
55 { SystemInfo::CurBootloaderMethod, ":platform:/bootloadermethod", "none" },
56 { SystemInfo::CurBootloaderName, ":platform:/bootloadername", "" },
57 { SystemInfo::CurBootloaderFile, ":platform:/bootloaderfile", "" },
58 { SystemInfo::CurEncoder, ":platform:/encoder", "" },
59 { SystemInfo::CurBrand, ":platform:/brand", "" },
60 { SystemInfo::CurName, ":platform:/name", "" },
61 { SystemInfo::CurBuildserverModel, ":platform:/buildserver_modelname", "" },
62 { SystemInfo::CurConfigureModel, ":platform:/configure_modelname", "" },
65 //! pointer to setting object to NULL
66 QSettings* SystemInfo::systemInfos = NULL;
68 void SystemInfo::ensureSystemInfoExists()
70 //check and create settings object
71 if(systemInfos == NULL)
73 // only use built-in rbutil.ini
74 systemInfos = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
79 QVariant SystemInfo::value(enum SystemInfos info)
81 ensureSystemInfoExists();
83 // locate setting item
84 int i = 0;
85 while(SystemInfosList[i].info != info)
86 i++;
87 QString platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
88 QString s = SystemInfosList[i].name;
89 s.replace(":platform:", platform);
90 QString d = SystemInfosList[i].def;
91 d.replace(":platform:", platform);
92 qDebug() << "[SystemInfo] GET:" << s << systemInfos->value(s, d).toString();
93 return systemInfos->value(s, d);
96 QVariant SystemInfo::platformValue(QString platform, enum SystemInfos info)
98 ensureSystemInfoExists();
100 // locate setting item
101 int i = 0;
102 while(SystemInfosList[i].info != info)
103 i++;
105 QString s = SystemInfosList[i].name;
106 s.replace(":platform:", platform);
107 QString d = SystemInfosList[i].def;
108 d.replace(":platform:", platform);
109 qDebug() << "[SystemInfo] GET P:" << s << systemInfos->value(s, d).toString();
110 return systemInfos->value(s, d);
113 QStringList SystemInfo::platforms(enum SystemInfo::PlatformType type, QString variant)
115 ensureSystemInfoExists();
117 QStringList result;
118 systemInfos->beginGroup("platforms");
119 QStringList a = systemInfos->childKeys();
120 systemInfos->endGroup();
121 for(int i = 0; i < a.size(); i++)
123 QString target = systemInfos->value("platforms/"+a.at(i), "null").toString();
124 QRegExp regex("\\..*$");
125 QString targetbase = target;
126 targetbase.remove(regex);
127 // only add target if its not disabled unless Platform*Disabled requested
128 if(type != PlatformAllDisabled && type != PlatformBaseDisabled
129 && type != PlatformVariantDisabled
130 && systemInfos->value(target+"/status").toString() == "disabled")
131 continue;
132 // report only matching target if PlatformVariant* is requested
133 if((type == PlatformVariant || type == PlatformVariantDisabled)
134 && (targetbase != variant))
135 continue;
136 // report only base targets when PlatformBase* is requested
137 if((type == PlatformBase || type == PlatformBaseDisabled))
138 result.append(targetbase);
139 else
140 result.append(target);
142 result.removeDuplicates();
143 return result;
146 QStringList SystemInfo::languages()
148 ensureSystemInfoExists();
150 QStringList result;
151 systemInfos->beginGroup("languages");
152 QStringList a = systemInfos->childKeys();
153 for(int i = 0; i < a.size(); i++)
155 result.append(systemInfos->value(a.at(i), "null").toString());
157 systemInfos->endGroup();
158 return result;
162 QMap<int, QString> SystemInfo::usbIdMap(enum MapType type)
164 ensureSystemInfoExists();
166 QMap<int, QString> map;
167 // get a list of ID -> target name
168 QStringList platforms;
169 systemInfos->beginGroup("platforms");
170 platforms = systemInfos->childKeys();
171 systemInfos->endGroup();
173 QString t;
174 switch(type) {
175 case MapDevice:
176 t = "usbid";
177 break;
178 case MapError:
179 t = "usberror";
180 break;
181 case MapIncompatible:
182 t = "usbincompat";
183 break;
186 for(int i = 0; i < platforms.size(); i++)
188 systemInfos->beginGroup("platforms");
189 QString target = systemInfos->value(platforms.at(i)).toString();
190 systemInfos->endGroup();
191 systemInfos->beginGroup(target);
192 QStringList ids = systemInfos->value(t).toStringList();
193 int j = ids.size();
194 while(j--)
195 map.insert(ids.at(j).toInt(0, 16), target);
197 systemInfos->endGroup();
199 return map;