Support "eject" on OS X.
[maemo-rb.git] / rbutil / rbutilqt / base / serverinfo.cpp
blob8d91309e6695f7e1e09c56fac307a6f7c3fb62df
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2010 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include "serverinfo.h"
20 #include "rbsettings.h"
21 #include "systeminfo.h"
23 #if defined(Q_OS_LINUX)
24 #include <unistd.h>
25 #endif
27 // server infos
28 const static struct {
29 ServerInfo::ServerInfos info;
30 const char* name;
31 const char* def;
32 } ServerInfoList[] = {
33 { ServerInfo::CurReleaseVersion, ":platform:/releaseversion", "" },
34 { ServerInfo::CurReleaseUrl, ":platform:/releaseurl", "" },
35 { ServerInfo::RelCandidateVersion, ":platform:/rcversion", "" },
36 { ServerInfo::RelCandidateUrl, ":platform:/rcurl", "" },
37 { ServerInfo::CurStatus, ":platform:/status", "Unknown" },
38 { ServerInfo::ManualPdfUrl, ":platform:/manual_pdf", "" },
39 { ServerInfo::ManualHtmlUrl, ":platform:/manual_html", "" },
40 { ServerInfo::ManualZipUrl, ":platform:/manual_zip", "" },
41 { ServerInfo::BleedingRevision, "bleedingrev", "" },
42 { ServerInfo::BleedingDate, "bleedingdate", "" },
43 { ServerInfo::CurDevelUrl, ":platform:/develurl", "" },
46 QMap<QString, QVariant> ServerInfo::serverInfos;
48 void ServerInfo::readBuildInfo(QString file)
50 QString releaseBaseUrl = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
51 QString develBaseUrl = SystemInfo::value(SystemInfo::BleedingUrl).toString();
52 QString manualBaseUrl = SystemInfo::value(SystemInfo::ManualUrl).toString();
54 QSettings info(file, QSettings::IniFormat);
56 QString developmentRevision = info.value("bleeding/rev").toString();
57 setValue(ServerInfo::BleedingRevision, developmentRevision);
58 QDateTime date = QDateTime::fromString(info.value("bleeding/timestamp").toString(), "yyyyMMddThhmmssZ");
59 setValue(ServerInfo::BleedingDate, date.toString(Qt::ISODate));
61 info.beginGroup("release");
62 QStringList releasekeys = info.allKeys();
63 info.endGroup();
64 info.beginGroup("release-candidate");
65 QStringList rckeys = info.allKeys();
66 info.endGroup();
68 // get base platforms, handle variants with platforms in the loop
69 QStringList platforms = SystemInfo::platforms(SystemInfo::PlatformBaseDisabled);
70 for(int i = 0; i < platforms.size(); i++)
72 // check if there are rbutil-variants of the current platform and handle
73 // them the same time.
74 QStringList variants;
75 variants = SystemInfo::platforms(SystemInfo::PlatformVariantDisabled, platforms.at(i));
76 QString releaseVersion;
77 QString releaseUrl;
78 QString relCandidateVersion;
79 QString relCandidateUrl;
80 // support two formats for "release" sections:
81 // - <target>=<version>. In this case the URL is constructed.
82 // - <target>=<version>,<url>.
83 info.beginGroup("release");
84 if(releasekeys.contains(platforms.at(i))) {
85 QStringList entry = info.value(platforms.at(i)).toStringList();
86 releaseVersion = entry.at(0);
87 if(entry.size() > 1) {
88 releaseUrl = entry.at(1);
90 else if(!releaseVersion.isEmpty()) {
91 // construct release download URL
92 releaseUrl = releaseBaseUrl;
93 releaseUrl.replace("%MODEL%", platforms.at(i));
94 releaseUrl.replace("%RELVERSION%", releaseVersion);
97 info.endGroup();
98 // "release-candidate" section currently only support the 2nd format.
99 info.beginGroup("release-candidate");
100 if(rckeys.contains(platforms.at(i))) {
101 QStringList entry = info.value(platforms.at(i)).toStringList();
102 if(entry.size() > 1) {
103 relCandidateVersion = entry.at(0);
104 relCandidateUrl = entry.at(1);
107 info.endGroup();
109 // "bleeding" section (development) does not provide individual
110 // information but only a global revision value.
111 QString develUrl = develBaseUrl;
112 develUrl.replace("%MODEL%", platforms.at(i));
113 develUrl.replace("%RELVERSION%", developmentRevision);
115 info.beginGroup("status");
116 QString status = tr("Unknown");
117 switch(info.value(platforms.at(i)).toInt())
119 case 1:
120 status = tr("Unusable");
121 break;
122 case 2:
123 status = tr("Unstable");
124 break;
125 case 3:
126 status = tr("Stable");
127 break;
128 default:
129 break;
131 info.endGroup();
133 // manual URLs
134 QString manualPdfUrl = manualBaseUrl;
135 QString manualHtmlUrl = manualBaseUrl;
136 QString manualZipUrl = manualBaseUrl;
138 QString buildservermodel = SystemInfo::platformValue(platforms.at(i),
139 SystemInfo::CurBuildserverModel).toString();
140 QString modelman = SystemInfo::platformValue(platforms.at(i),
141 SystemInfo::CurManual).toString();
142 QString manualBaseName = "rockbox-";
144 if(modelman.isEmpty()) manualBaseName += buildservermodel;
145 else manualBaseName += modelman;
147 manualPdfUrl.replace("%EXTENSION%", "pdf");
148 manualPdfUrl.replace("%MANUALBASENAME%", manualBaseName);
149 manualHtmlUrl.replace("%EXTENSION%", "html");
150 manualHtmlUrl.replace("%MANUALBASENAME%", manualBaseName + "/rockbox-build");
151 manualZipUrl.replace("%EXTENSION%", "zip");
152 manualZipUrl.replace("%MANUALBASENAME%", manualBaseName + "-html");
154 // set variants (if any)
155 for(int j = 0; j < variants.size(); ++j) {
156 setPlatformValue(variants.at(j), ServerInfo::CurStatus, status);
157 if(!releaseUrl.isEmpty()) {
158 setPlatformValue(variants.at(j), ServerInfo::CurReleaseVersion, releaseVersion);
159 setPlatformValue(variants.at(j), ServerInfo::CurReleaseUrl, releaseUrl);
161 if(!relCandidateUrl.isEmpty()) {
162 setPlatformValue(variants.at(j), ServerInfo::RelCandidateVersion, relCandidateVersion);
163 setPlatformValue(variants.at(j), ServerInfo::RelCandidateUrl, relCandidateUrl);
165 setPlatformValue(variants.at(j), ServerInfo::CurDevelUrl, develUrl);
167 setPlatformValue(variants.at(j), ServerInfo::ManualPdfUrl, manualPdfUrl);
168 setPlatformValue(variants.at(j), ServerInfo::ManualHtmlUrl, manualHtmlUrl);
169 setPlatformValue(variants.at(j), ServerInfo::ManualZipUrl, manualZipUrl);
175 QVariant ServerInfo::value(enum ServerInfos info)
177 // locate info item
178 int i = 0;
179 while(ServerInfoList[i].info != info)
180 i++;
182 QString s = ServerInfoList[i].name;
183 s.replace(":platform:", RbSettings::value(RbSettings::CurrentPlatform).toString());
184 qDebug() << "[ServerInfo] GET:" << s << serverInfos.value(s, ServerInfoList[i].def).toString();
185 return serverInfos.value(s, ServerInfoList[i].def);
188 void ServerInfo::setValue(enum ServerInfos setting, QVariant value)
190 QString empty;
191 return setPlatformValue(empty, setting, value);
194 void ServerInfo::setPlatformValue(QString platform, enum ServerInfos info, QVariant value)
196 // locate setting item
197 int i = 0;
198 while(ServerInfoList[i].info != info)
199 i++;
201 QString s = ServerInfoList[i].name;
202 s.replace(":platform:", platform);
203 serverInfos.insert(s, value);
204 qDebug() << "[ServerInfo] SET:" << s << serverInfos.value(s).toString();
207 QVariant ServerInfo::platformValue(QString platform, enum ServerInfos info)
209 // locate setting item
210 int i = 0;
211 while(ServerInfoList[i].info != info)
212 i++;
214 QString s = ServerInfoList[i].name;
215 s.replace(":platform:", platform);
216 QString d = ServerInfoList[i].def;
217 d.replace(":platform:", platform);
218 qDebug() << "[ServerInfo] GET:" << s << serverInfos.value(s, d).toString();
219 return serverInfos.value(s, d);