Fix problems with platform retrieval.
[kugel-rb.git] / rbutil / rbutilqt / base / systeminfo.cpp
bloba941f43078164a33ebeaca6c914994bd9c728d28
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 QString SystemInfo::name(QString platform)
161 ensureSystemInfoExists();
162 return systemInfos->value(platform + "/name").toString();
165 QString SystemInfo::brand(QString platform)
167 ensureSystemInfoExists();
168 return systemInfos->value(platform + "/brand").toString();
171 QMap<int, QString> SystemInfo::usbIdMap(enum MapType type)
173 ensureSystemInfoExists();
175 QMap<int, QString> map;
176 // get a list of ID -> target name
177 QStringList platforms;
178 systemInfos->beginGroup("platforms");
179 platforms = systemInfos->childKeys();
180 systemInfos->endGroup();
182 QString t;
183 switch(type) {
184 case MapDevice:
185 t = "usbid";
186 break;
187 case MapError:
188 t = "usberror";
189 break;
190 case MapIncompatible:
191 t = "usbincompat";
192 break;
195 for(int i = 0; i < platforms.size(); i++)
197 systemInfos->beginGroup("platforms");
198 QString target = systemInfos->value(platforms.at(i)).toString();
199 systemInfos->endGroup();
200 systemInfos->beginGroup(target);
201 QStringList ids = systemInfos->value(t).toStringList();
202 int j = ids.size();
203 while(j--)
204 map.insert(ids.at(j).toInt(0, 16), target);
206 systemInfos->endGroup();
208 return map;