summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/serverinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base/serverinfo.cpp')
-rw-r--r--rbutil/rbutilqt/base/serverinfo.cpp274
1 files changed, 119 insertions, 155 deletions
diff --git a/rbutil/rbutilqt/base/serverinfo.cpp b/rbutil/rbutilqt/base/serverinfo.cpp
index 5a0719f375..c4d51d4431 100644
--- a/rbutil/rbutilqt/base/serverinfo.cpp
+++ b/rbutil/rbutilqt/base/serverinfo.cpp
@@ -21,184 +21,148 @@
21#include "systeminfo.h" 21#include "systeminfo.h"
22#include "Logger.h" 22#include "Logger.h"
23 23
24static QSettings* serverSettings = nullptr;
25
24// server infos 26// server infos
25const static struct { 27const static struct {
26 ServerInfo::ServerInfos info; 28 ServerInfo::ServerInfos info;
27 const char* name; 29 const char* name;
28 const char* def;
29} ServerInfoList[] = { 30} ServerInfoList[] = {
30 { ServerInfo::CurReleaseVersion, ":platform:/releaseversion", "" }, 31 { ServerInfo::CurReleaseVersion, "release/:platform:" },
31 { ServerInfo::CurReleaseUrl, ":platform:/releaseurl", "" }, 32 { ServerInfo::CurReleaseUrl, "release/:platform:" },
32 { ServerInfo::RelCandidateVersion, ":platform:/rcversion", "" }, 33 { ServerInfo::RelCandidateVersion, "release-candidate/:platform:" },
33 { ServerInfo::RelCandidateUrl, ":platform:/rcurl", "" }, 34 { ServerInfo::RelCandidateUrl, "release-candidate/:platform:" },
34 { ServerInfo::CurStatus, ":platform:/status", "Unknown" }, 35 { ServerInfo::CurStatus, "status/:platform:" },
35 { ServerInfo::ManualPdfUrl, ":platform:/manual_pdf", "" }, 36 { ServerInfo::ManualPdfUrl, "" },
36 { ServerInfo::ManualHtmlUrl, ":platform:/manual_html", "" }, 37 { ServerInfo::ManualHtmlUrl, "" },
37 { ServerInfo::ManualZipUrl, ":platform:/manual_zip", "" }, 38 { ServerInfo::ManualZipUrl, "" },
38 { ServerInfo::BleedingRevision, "bleedingrev", "" }, 39 { ServerInfo::BleedingRevision, "bleeding/rev" },
39 { ServerInfo::BleedingDate, "bleedingdate", "" }, 40 { ServerInfo::BleedingDate, "bleeding/timestamp" },
40 { ServerInfo::CurDevelUrl, ":platform:/develurl", "" }, 41 { ServerInfo::CurDevelUrl, "" },
41}; 42};
42 43
43QMap<QString, QVariant> ServerInfo::serverInfos; 44QMap<QString, QVariant> ServerInfo::serverInfos;
44 45
45void ServerInfo::readBuildInfo(QString file) 46void ServerInfo::readBuildInfo(QString file)
46{ 47{
47 QString releaseBaseUrl = SystemInfo::value(SystemInfo::ReleaseUrl).toString(); 48 if (serverSettings)
48 QString develBaseUrl = SystemInfo::value(SystemInfo::BleedingUrl).toString(); 49 delete serverSettings;
49 QString manualBaseUrl = SystemInfo::value(SystemInfo::ManualUrl).toString(); 50 serverSettings = new QSettings(file, QSettings::IniFormat);
50
51 QSettings info(file, QSettings::IniFormat);
52
53 QString developmentRevision = info.value("bleeding/rev").toString();
54 setPlatformValue(ServerInfo::BleedingRevision, "", developmentRevision);
55 QDateTime date = QDateTime::fromString(info.value("bleeding/timestamp").toString(), "yyyyMMddThhmmssZ");
56 setPlatformValue(ServerInfo::BleedingDate, "", date.toString(Qt::ISODate));
57
58 info.beginGroup("release");
59 QStringList releasekeys = info.allKeys();
60 info.endGroup();
61 info.beginGroup("release-candidate");
62 QStringList rckeys = info.allKeys();
63 info.endGroup();
64
65 // get base platforms, handle variants with platforms in the loop
66 QStringList platforms = SystemInfo::platforms(SystemInfo::PlatformBaseDisabled);
67 for(int i = 0; i < platforms.size(); i++)
68 {
69 // check if there are rbutil-variants of the current platform and handle
70 // them the same time.
71 QStringList variants;
72 variants = SystemInfo::platforms(SystemInfo::PlatformVariantDisabled, platforms.at(i));
73 QString releaseVersion;
74 QString releaseUrl;
75 QString relCandidateVersion;
76 QString relCandidateUrl;
77 // support two formats for "release" sections:
78 // - <target>=<version>. In this case the URL is constructed.
79 // - <target>=<version>,<url>.
80 info.beginGroup("release");
81 if(releasekeys.contains(platforms.at(i))) {
82 QStringList entry = info.value(platforms.at(i)).toStringList();
83 releaseVersion = entry.at(0);
84 if(entry.size() > 1) {
85 releaseUrl = entry.at(1);
86 }
87 else if(!releaseVersion.isEmpty()) {
88 // construct release download URL
89 releaseUrl = releaseBaseUrl;
90 releaseUrl.replace("%MODEL%", platforms.at(i));
91 releaseUrl.replace("%RELVERSION%", releaseVersion);
92 }
93 }
94 info.endGroup();
95 // "release-candidate" section currently only support the 2nd format.
96 info.beginGroup("release-candidate");
97 if(rckeys.contains(platforms.at(i))) {
98 QStringList entry = info.value(platforms.at(i)).toStringList();
99 if(entry.size() > 1) {
100 relCandidateVersion = entry.at(0);
101 relCandidateUrl = entry.at(1);
102 }
103 }
104 info.endGroup();
105
106 // "bleeding" section (development) does not provide individual
107 // information but only a global revision value.
108 QString develUrl = develBaseUrl;
109 develUrl.replace("%MODEL%", platforms.at(i));
110 develUrl.replace("%RELVERSION%", developmentRevision);
111
112 info.beginGroup("status");
113 QString status = tr("Unknown");
114 switch(info.value(platforms.at(i), -1).toInt())
115 {
116 case 0:
117 status = tr("Stable (Retired)");
118 break;
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;
130 }
131 info.endGroup();
132
133 // manual URLs
134 QString manualPdfUrl = manualBaseUrl;
135 QString manualHtmlUrl = manualBaseUrl;
136 QString manualZipUrl = manualBaseUrl;
137
138 QString buildservermodel = SystemInfo::platformValue(
139 SystemInfo::BuildserverModel, platforms.at(i)).toString();
140 QString modelman = SystemInfo::platformValue(
141 SystemInfo::Manual, platforms.at(i)).toString();
142 QString manualBaseName = "rockbox-";
143
144 if(modelman.isEmpty()) manualBaseName += buildservermodel;
145 else manualBaseName += modelman;
146
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");
153
154 // set variants (if any)
155 for(int j = 0; j < variants.size(); ++j) {
156 setPlatformValue(ServerInfo::CurStatus, variants.at(j), status);
157 if(!releaseUrl.isEmpty()) {
158 setPlatformValue(ServerInfo::CurReleaseVersion, variants.at(j), releaseVersion);
159 setPlatformValue(ServerInfo::CurReleaseUrl, variants.at(j), releaseUrl);
160 }
161 if(!relCandidateUrl.isEmpty()) {
162 setPlatformValue(ServerInfo::RelCandidateVersion, variants.at(j), relCandidateVersion);
163 setPlatformValue(ServerInfo::RelCandidateUrl, variants.at(j), relCandidateUrl);
164 }
165 setPlatformValue(ServerInfo::CurDevelUrl, variants.at(j), develUrl);
166
167 setPlatformValue(ServerInfo::ManualPdfUrl, variants.at(j), manualPdfUrl);
168 setPlatformValue(ServerInfo::ManualHtmlUrl, variants.at(j), manualHtmlUrl);
169 setPlatformValue(ServerInfo::ManualZipUrl, variants.at(j), manualZipUrl);
170 }
171 }
172} 51}
173 52
174 53
175void ServerInfo::setPlatformValue(enum ServerInfos info, QString platform, QVariant value)
176{
177 // locate setting item
178 int i = 0;
179 while(ServerInfoList[i].info != info)
180 i++;
181
182 QString s = ServerInfoList[i].name;
183 s.replace(":platform:", platform);
184 serverInfos.insert(s, value);
185 LOG_INFO() << "SET:" << s << serverInfos.value(s).toString();
186}
187
188QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform) 54QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
189{ 55{
190 // locate setting item 56 // locate setting item in server info file
191 int i = 0; 57 int i = 0;
192 while(ServerInfoList[i].info != info) 58 while(ServerInfoList[i].info != info)
193 i++; 59 i++;
194 60
61 // replace setting name
195 if(platform.isEmpty()) 62 if(platform.isEmpty())
196 platform = RbSettings::value(RbSettings::CurrentPlatform).toString(); 63 platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
197 64
65 // split of variant for platform.
66 // we can have an optional variant part in the platform string.
67 // For build info we don't use that.
68 platform = platform.split('.').at(0);
69
198 QString s = ServerInfoList[i].name; 70 QString s = ServerInfoList[i].name;
199 s.replace(":platform:", platform); 71 s.replace(":platform:", platform);
200 QString d = ServerInfoList[i].def; 72
201 d.replace(":platform:", platform); 73 // get value
202 LOG_INFO() << "GET:" << s << serverInfos.value(s, d).toString(); 74 QVariant value = QString();
203 return serverInfos.value(s, d); 75 if(!s.isEmpty() && serverSettings)
76 value = serverSettings->value(s, "");
77
78 // depending on the actual value we need more replacements.
79 switch(info) {
80 case ServerInfo::CurStatus:
81 value = ServerInfo::statusToString(value.toInt());
82 break;
83 case CurReleaseVersion:
84 value = value.toStringList().at(0);
85 break;
86 case RelCandidateVersion:
87 // currently only the <version>,<url> format is supported here.
88 if (value.toStringList().size() > 1)
89 value = value.toStringList().at(0);
90 else
91 value.clear();
92 break;
93 case CurReleaseUrl:
94 {
95 QString version = value.toStringList().at(0);
96 if(value.toStringList().size() > 1)
97 value = value.toStringList().at(1);
98 else if(!version.isEmpty()) // if value is empty, return empty url.
99 value = SystemInfo::value(SystemInfo::ReleaseUrl).toString()
100 .replace("%MODEL%", platform)
101 .replace("%RELVERSION%", version);
102 }
103 break;
104 case RelCandidateUrl:
105 if(value.toStringList().size() > 1)
106 value = value.toStringList().at(1);
107 else
108 value.clear();
109 break;
110 case CurDevelUrl:
111 value = SystemInfo::value(SystemInfo::BleedingUrl).toString()
112 .replace("%MODEL%", platform);
113 break;
114 case ManualPdfUrl:
115 case ManualZipUrl:
116 case ManualHtmlUrl:
117 {
118 QString url = SystemInfo::value(SystemInfo::ManualUrl).toString();
119 QString modelman = SystemInfo::platformValue(
120 SystemInfo::Manual, platform).toString();
121 url.replace("%MODEL%", modelman.isEmpty() ? platform : modelman);
122 if(info == ManualPdfUrl)
123 url.replace("%FORMAT%", ".pdf");
124 else if(info == ManualZipUrl)
125 url.replace("%FORMAT%", "-html.zip");
126 else if(info == ManualHtmlUrl)
127 url.replace("%FORMAT%", "/rockbox-build.html");
128 value = url;
129 }
130 break;
131 case BleedingDate:
132 // TODO: get rid of this, it's location specific.
133 value = QDateTime::fromString(value.toString(),
134 "yyyyMMddThhmmssZ").toString(Qt::ISODate);
135 break;
136
137 default:
138 break;
139 }
140
141 LOG_INFO() << "Server:" << value;
142 return value;
143}
144
145QString ServerInfo::statusToString(int status)
146{
147 QString value;
148 switch(status)
149 {
150 case STATUS_RETIRED:
151 value = tr("Stable (Retired)");
152 break;
153 case STATUS_UNUSABLE:
154 value = tr("Unusable");
155 break;
156 case STATUS_UNSTABLE:
157 value = tr("Unstable");
158 break;
159 case STATUS_STABLE:
160 value = tr("Stable");
161 break;
162 default:
163 value = tr("Unknown");
164 break;
165 }
166
167 return value;
204} 168}