Packard Bell Vibe 500: correct the path to a proper one in rbutil (proper directory...
[kugel-rb.git] / rbutil / rbutilqt / base / systeminfo.cpp
blob72a62ac2fbe80057723add59b22b287089fcb07e
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::FontUrl, "font_url", "" },
41 { SystemInfo::VoiceUrl, "voice_url", "" },
42 { SystemInfo::DoomUrl, "doom_url", "" },
43 { SystemInfo::ReleaseUrl, "release_url", "" },
44 { SystemInfo::DailyUrl, "daily_url", "" },
45 { SystemInfo::ServerConfUrl, "server_conf_url", "" },
46 { SystemInfo::GenlangUrl, "genlang_url", "" },
47 { SystemInfo::ThemesUrl, "themes_url", "" },
48 { SystemInfo::RbutilUrl, "rbutil_url", "" },
49 { SystemInfo::BleedingInfo, "bleeding_info", "" },
50 { SystemInfo::CurPlatformName, ":platform:/name", "" },
51 { SystemInfo::CurManual, ":platform:/manualname","rockbox-:platform:" },
52 { SystemInfo::CurBootloaderMethod, ":platform:/bootloadermethod", "none" },
53 { SystemInfo::CurBootloaderName, ":platform:/bootloadername", "" },
54 { SystemInfo::CurBootloaderFile, ":platform:/bootloaderfile", "" },
55 { SystemInfo::CurEncoder, ":platform:/encoder", "" },
56 { SystemInfo::CurBrand, ":platform:/brand", "" },
57 { SystemInfo::CurName, ":platform:/name", "" },
58 { SystemInfo::CurBuildserverModel, ":platform:/buildserver_modelname", "" },
59 { SystemInfo::CurConfigureModel, ":platform:/configure_modelname", "" },
62 //! pointer to setting object to NULL
63 QSettings* SystemInfo::systemInfos = NULL;
65 void SystemInfo::ensureSystemInfoExists()
67 //check and create settings object
68 if(systemInfos == NULL)
70 // only use built-in rbutil.ini
71 systemInfos = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
76 QVariant SystemInfo::value(enum SystemInfos info)
78 ensureSystemInfoExists();
80 // locate setting item
81 int i = 0;
82 while(SystemInfosList[i].info != info)
83 i++;
84 QString platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
85 QString s = SystemInfosList[i].name;
86 s.replace(":platform:", platform);
87 QString d = SystemInfosList[i].def;
88 d.replace(":platform:", platform);
89 qDebug() << "[SystemInfo] GET:" << s << systemInfos->value(s, d).toString();
90 return systemInfos->value(s, d);
93 QVariant SystemInfo::platformValue(QString platform, enum SystemInfos info)
95 ensureSystemInfoExists();
97 // locate setting item
98 int i = 0;
99 while(SystemInfosList[i].info != info)
100 i++;
102 QString s = SystemInfosList[i].name;
103 s.replace(":platform:", platform);
104 QString d = SystemInfosList[i].def;
105 d.replace(":platform:", platform);
106 qDebug() << "[SystemInfo] GET P:" << s << systemInfos->value(s, d).toString();
107 return systemInfos->value(s, d);
110 QStringList SystemInfo::platforms(enum SystemInfo::PlatformType type, QString variant)
112 ensureSystemInfoExists();
114 QStringList result;
115 systemInfos->beginGroup("platforms");
116 QStringList a = systemInfos->childKeys();
117 systemInfos->endGroup();
118 for(int i = 0; i < a.size(); i++)
120 QString target = systemInfos->value("platforms/"+a.at(i), "null").toString();
121 QRegExp regex("\\..*$");
122 QString targetbase = target;
123 targetbase.remove(regex);
124 // only add target if its not disabled unless Platform*Disabled requested
125 if(type != PlatformAllDisabled && type != PlatformBaseDisabled
126 && type != PlatformVariantDisabled
127 && systemInfos->value(target+"/status").toString() == "disabled")
128 continue;
129 // report only matching target if PlatformVariant* is requested
130 if((type == PlatformVariant || type == PlatformVariantDisabled)
131 && (targetbase != variant))
132 continue;
133 // report only base targets when PlatformBase* is requested
134 if((type == PlatformBase || type == PlatformBaseDisabled))
135 result.append(targetbase);
136 else
137 result.append(target);
139 result.removeDuplicates();
140 return result;
143 QStringList SystemInfo::languages()
145 ensureSystemInfoExists();
147 QStringList result;
148 systemInfos->beginGroup("languages");
149 QStringList a = systemInfos->childKeys();
150 for(int i = 0; i < a.size(); i++)
152 result.append(systemInfos->value(a.at(i), "null").toString());
154 systemInfos->endGroup();
155 return result;
159 QMap<int, QString> SystemInfo::usbIdMap(enum MapType type)
161 ensureSystemInfoExists();
163 QMap<int, QString> map;
164 // get a list of ID -> target name
165 QStringList platforms;
166 systemInfos->beginGroup("platforms");
167 platforms = systemInfos->childKeys();
168 systemInfos->endGroup();
170 QString t;
171 switch(type) {
172 case MapDevice:
173 t = "usbid";
174 break;
175 case MapError:
176 t = "usberror";
177 break;
178 case MapIncompatible:
179 t = "usbincompat";
180 break;
183 for(int i = 0; i < platforms.size(); i++)
185 systemInfos->beginGroup("platforms");
186 QString target = systemInfos->value(platforms.at(i)).toString();
187 systemInfos->endGroup();
188 systemInfos->beginGroup(target);
189 QStringList ids = systemInfos->value(t).toStringList();
190 int j = ids.size();
191 while(j--)
192 map.insert(ids.at(j).toInt(0, 16), target);
194 systemInfos->endGroup();
196 return map;