1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2010 by Dominik Wenger
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"
25 #if defined(Q_OS_LINUX)
32 SystemInfo::SystemInfos info
;
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::ReleaseVoiceUrl
, "release_voice_url", "" },
43 { SystemInfo::DoomUrl
, "doom_url", "" },
44 { SystemInfo::ReleaseUrl
, "release_url", "" },
45 { SystemInfo::DailyUrl
, "daily_url", "" },
46 { SystemInfo::ServerConfUrl
, "server_conf_url", "" },
47 { SystemInfo::GenlangUrl
, "genlang_url", "" },
48 { SystemInfo::ThemesUrl
, "themes_url", "" },
49 { SystemInfo::ThemesInfoUrl
, "themes_info_url", "" },
50 { SystemInfo::RbutilUrl
, "rbutil_url", "" },
51 { SystemInfo::BleedingInfo
, "bleeding_info", "" },
52 { SystemInfo::CurPlatformName
, ":platform:/name", "" },
53 { SystemInfo::CurManual
, ":platform:/manualname","rockbox-:platform:" },
54 { SystemInfo::CurBootloaderMethod
, ":platform:/bootloadermethod", "none" },
55 { SystemInfo::CurBootloaderName
, ":platform:/bootloadername", "" },
56 { SystemInfo::CurBootloaderFile
, ":platform:/bootloaderfile", "" },
57 { SystemInfo::CurEncoder
, ":platform:/encoder", "" },
58 { SystemInfo::CurBrand
, ":platform:/brand", "" },
59 { SystemInfo::CurName
, ":platform:/name", "" },
60 { SystemInfo::CurBuildserverModel
, ":platform:/buildserver_modelname", "" },
61 { SystemInfo::CurConfigureModel
, ":platform:/configure_modelname", "" },
64 //! pointer to setting object to NULL
65 QSettings
* SystemInfo::systemInfos
= NULL
;
67 void SystemInfo::ensureSystemInfoExists()
69 //check and create settings object
70 if(systemInfos
== NULL
)
72 // only use built-in rbutil.ini
73 systemInfos
= new QSettings(":/ini/rbutil.ini", QSettings::IniFormat
, 0);
78 QVariant
SystemInfo::value(enum SystemInfos info
)
80 ensureSystemInfoExists();
82 // locate setting item
84 while(SystemInfosList
[i
].info
!= info
)
86 QString platform
= RbSettings::value(RbSettings::CurrentPlatform
).toString();
87 QString s
= SystemInfosList
[i
].name
;
88 s
.replace(":platform:", platform
);
89 QString d
= SystemInfosList
[i
].def
;
90 d
.replace(":platform:", platform
);
91 qDebug() << "[SystemInfo] GET:" << s
<< systemInfos
->value(s
, d
).toString();
92 return systemInfos
->value(s
, d
);
95 QVariant
SystemInfo::platformValue(QString platform
, enum SystemInfos info
)
97 ensureSystemInfoExists();
99 // locate setting item
101 while(SystemInfosList
[i
].info
!= info
)
104 QString s
= SystemInfosList
[i
].name
;
105 s
.replace(":platform:", platform
);
106 QString d
= SystemInfosList
[i
].def
;
107 d
.replace(":platform:", platform
);
108 qDebug() << "[SystemInfo] GET P:" << s
<< systemInfos
->value(s
, d
).toString();
109 return systemInfos
->value(s
, d
);
112 QStringList
SystemInfo::platforms(enum SystemInfo::PlatformType type
, QString variant
)
114 ensureSystemInfoExists();
117 systemInfos
->beginGroup("platforms");
118 QStringList a
= systemInfos
->childKeys();
119 systemInfos
->endGroup();
120 for(int i
= 0; i
< a
.size(); i
++)
122 QString target
= systemInfos
->value("platforms/"+a
.at(i
), "null").toString();
123 QRegExp
regex("\\..*$");
124 QString targetbase
= target
;
125 targetbase
.remove(regex
);
126 // only add target if its not disabled unless Platform*Disabled requested
127 if(type
!= PlatformAllDisabled
&& type
!= PlatformBaseDisabled
128 && type
!= PlatformVariantDisabled
129 && systemInfos
->value(target
+"/status").toString() == "disabled")
131 // report only matching target if PlatformVariant* is requested
132 if((type
== PlatformVariant
|| type
== PlatformVariantDisabled
)
133 && (targetbase
!= variant
))
135 // report only base targets when PlatformBase* is requested
136 if((type
== PlatformBase
|| type
== PlatformBaseDisabled
))
137 result
.append(targetbase
);
139 result
.append(target
);
141 result
.removeDuplicates();
145 QStringList
SystemInfo::languages()
147 ensureSystemInfoExists();
150 systemInfos
->beginGroup("languages");
151 QStringList a
= systemInfos
->childKeys();
152 for(int i
= 0; i
< a
.size(); i
++)
154 result
.append(systemInfos
->value(a
.at(i
), "null").toString());
156 systemInfos
->endGroup();
161 QMap
<int, QString
> SystemInfo::usbIdMap(enum MapType type
)
163 ensureSystemInfoExists();
165 QMap
<int, QString
> map
;
166 // get a list of ID -> target name
167 QStringList platforms
;
168 systemInfos
->beginGroup("platforms");
169 platforms
= systemInfos
->childKeys();
170 systemInfos
->endGroup();
180 case MapIncompatible
:
185 for(int i
= 0; i
< platforms
.size(); i
++)
187 systemInfos
->beginGroup("platforms");
188 QString target
= systemInfos
->value(platforms
.at(i
)).toString();
189 systemInfos
->endGroup();
190 systemInfos
->beginGroup(target
);
191 QStringList ids
= systemInfos
->value(t
).toStringList();
194 map
.insert(ids
.at(j
).toInt(0, 16), target
);
196 systemInfos
->endGroup();