summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/rbutilqt/base/serverinfo.cpp274
-rw-r--r--rbutil/rbutilqt/base/serverinfo.h8
-rw-r--r--rbutil/rbutilqt/rbutil.ini2
-rw-r--r--rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp3
4 files changed, 127 insertions, 160 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}
diff --git a/rbutil/rbutilqt/base/serverinfo.h b/rbutil/rbutilqt/base/serverinfo.h
index 7588521b09..6c68bd3f5d 100644
--- a/rbutil/rbutilqt/base/serverinfo.h
+++ b/rbutil/rbutilqt/base/serverinfo.h
@@ -22,6 +22,10 @@
22#define SERVERINFO_H 22#define SERVERINFO_H
23 23
24#include <QtCore> 24#include <QtCore>
25#define STATUS_RETIRED 0
26#define STATUS_UNUSABLE 1
27#define STATUS_UNSTABLE 2
28#define STATUS_STABLE 3
25 29
26class ServerInfo : public QObject 30class ServerInfo : public QObject
27{ 31{
@@ -47,10 +51,10 @@ class ServerInfo : public QObject
47 static void readBuildInfo(QString file); 51 static void readBuildInfo(QString file);
48 //! get a value from server info for a named platform. 52 //! get a value from server info for a named platform.
49 static QVariant platformValue(enum ServerInfos setting, QString platform = ""); 53 static QVariant platformValue(enum ServerInfos setting, QString platform = "");
54 //! Convert status number to string
55 static QString statusToString(int status);
50 56
51 private: 57 private:
52 //! set a value for a server info for a named platform.
53 static void setPlatformValue(enum ServerInfos setting, QString platform, QVariant value);
54 //! you shouldnt call this, its a fully static class 58 //! you shouldnt call this, its a fully static class
55 ServerInfo() {} 59 ServerInfo() {}
56 60
diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini
index 59a5ab3f6c..b92ddcd557 100644
--- a/rbutil/rbutilqt/rbutil.ini
+++ b/rbutil/rbutilqt/rbutil.ini
@@ -23,7 +23,7 @@ release_font_url=http://download.rockbox.org/release/%RELEASEVER%/rockbox-fonts-
23daily_font_url=http://download.rockbox.org/daily/fonts/rockbox-fonts.zip 23daily_font_url=http://download.rockbox.org/daily/fonts/rockbox-fonts.zip
24 24
25; other 25; other
26manual_url=http://download.rockbox.org/manual/%MANUALBASENAME%.%EXTENSION% 26manual_url=http://download.rockbox.org/manual/rockbox-%MODEL%%FORMAT%
27doom_url=http://download.rockbox.org/useful/rockdoom.zip 27doom_url=http://download.rockbox.org/useful/rockdoom.zip
28duke3d_url=http://download.rockbox.org/useful/duke3d.zip 28duke3d_url=http://download.rockbox.org/useful/duke3d.zip
29quake_url=http://download.rockbox.org/useful/quake.zip 29quake_url=http://download.rockbox.org/useful/quake.zip
diff --git a/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp b/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
index c223dee555..7d2016d6bd 100644
--- a/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
+++ b/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
@@ -42,8 +42,7 @@ QVariant SystemInfo::value(SystemInfo::SystemInfos info)
42{ 42{
43 switch(info) { 43 switch(info) {
44 case SystemInfo::ManualUrl: 44 case SystemInfo::ManualUrl:
45 //return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%"); 45 return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%");
46 return QString("https://unittest/manual/%MANUALBASENAME%.%EXTENSION%");
47 break; 46 break;
48 case SystemInfo::BleedingUrl: 47 case SystemInfo::BleedingUrl:
49 return QString("https://unittest/dev/rockbox-%MODEL%.zip"); 48 return QString("https://unittest/dev/rockbox-%MODEL%.zip");