diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2020-11-28 20:47:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2020-12-03 22:25:12 +0100 |
commit | b064a6cbb58a0db1a70fbac2e82242ce0c7509b1 (patch) | |
tree | c9090d367d237cbd408afbd24d5809e55a1a2653 /rbutil/rbutilqt/base/serverinfo.cpp | |
parent | 78a01db47cac5fa67aeee6f1c5134f89c3e4944a (diff) | |
download | rockbox-b064a6cbb58a0db1a70fbac2e82242ce0c7509b1.tar.gz rockbox-b064a6cbb58a0db1a70fbac2e82242ce0c7509b1.zip |
rbutil: Rework and merge player and build server info handling.
Handling the data for players from rbutil.ini and the build-info data
from the server is closely related. Splitting things up into different
classes only creates tightly coupling, which is unnecessary, and the
need to differentiate between them in the application.
Merge both classes into a single one and rework handling so the
application doesn't have to deal with two separate classes anymore.
Furthermore, change URL templates to use new values from build-info
instead of hard coding them.
Change-Id: Ica550973ce23d1559110782add52bc214eba552d
Diffstat (limited to 'rbutil/rbutilqt/base/serverinfo.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/serverinfo.cpp | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/rbutil/rbutilqt/base/serverinfo.cpp b/rbutil/rbutilqt/base/serverinfo.cpp deleted file mode 100644 index 5fee75f689..0000000000 --- a/rbutil/rbutilqt/base/serverinfo.cpp +++ /dev/null | |||
@@ -1,157 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2010 by Dominik Wenger | ||
10 | * | ||
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. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #include "serverinfo.h" | ||
20 | #include "rbsettings.h" | ||
21 | #include "systeminfo.h" | ||
22 | #include "Logger.h" | ||
23 | |||
24 | ServerInfo* ServerInfo::infoInstance = nullptr; | ||
25 | |||
26 | ServerInfo* ServerInfo::instance() | ||
27 | { | ||
28 | if (infoInstance == nullptr) { | ||
29 | infoInstance = new ServerInfo(); | ||
30 | } | ||
31 | return infoInstance; | ||
32 | } | ||
33 | |||
34 | // server infos | ||
35 | const static struct { | ||
36 | ServerInfo::ServerInfos info; | ||
37 | const char* name; | ||
38 | const char* def; | ||
39 | } ServerInfoList[] = { | ||
40 | { ServerInfo::CurReleaseVersion, "release/:platform:", "" }, | ||
41 | { ServerInfo::CurReleaseUrl, "release/:platform:", "" }, | ||
42 | { ServerInfo::RelCandidateVersion, "release-candidate/:platform:", "" }, | ||
43 | { ServerInfo::RelCandidateUrl, "release-candidate/:platform:", "" }, | ||
44 | { ServerInfo::DailyVersion, "daily/:platform:", "" }, | ||
45 | { ServerInfo::DailyUrl, "daily/:platform:", "" }, | ||
46 | { ServerInfo::CurStatus, "status/:platform:", "-1" }, | ||
47 | { ServerInfo::BleedingRevision, "bleeding/rev", "" }, | ||
48 | { ServerInfo::BleedingDate, "bleeding/timestamp", "" }, | ||
49 | { ServerInfo::CurDevelUrl, "", "" }, | ||
50 | }; | ||
51 | |||
52 | void ServerInfo::readBuildInfo(QString file) | ||
53 | { | ||
54 | if (serverSettings) | ||
55 | delete serverSettings; | ||
56 | serverSettings = new QSettings(file, QSettings::IniFormat); | ||
57 | } | ||
58 | |||
59 | |||
60 | QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform) | ||
61 | { | ||
62 | // locate setting item in server info file | ||
63 | int i = 0; | ||
64 | while(ServerInfoList[i].info != info) | ||
65 | i++; | ||
66 | |||
67 | // replace setting name | ||
68 | if(platform.isEmpty()) | ||
69 | platform = RbSettings::value(RbSettings::CurrentPlatform).toString(); | ||
70 | |||
71 | // split of variant for platform. | ||
72 | // we can have an optional variant part in the platform string. | ||
73 | // For build info we don't use that. | ||
74 | platform = platform.split('.').at(0); | ||
75 | |||
76 | QString s = ServerInfoList[i].name; | ||
77 | s.replace(":platform:", platform); | ||
78 | |||
79 | // get value | ||
80 | QVariant value = QString(); | ||
81 | if(!s.isEmpty() && serverSettings) | ||
82 | value = serverSettings->value(s, ServerInfoList[i].def); | ||
83 | |||
84 | // depending on the actual value we need more replacements. | ||
85 | switch(info) { | ||
86 | case CurReleaseVersion: | ||
87 | case RelCandidateVersion: | ||
88 | case DailyVersion: | ||
89 | value = value.toStringList().at(0); | ||
90 | break; | ||
91 | case CurReleaseUrl: | ||
92 | case RelCandidateUrl: | ||
93 | case DailyUrl: | ||
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() && info == CurReleaseUrl) | ||
99 | value = SystemInfo::value(SystemInfo::BuildUrl, | ||
100 | SystemInfo::BuildRelease).toString() | ||
101 | .replace("%MODEL%", platform) | ||
102 | .replace("%RELVERSION%", version); | ||
103 | else if(!version.isEmpty() && info == RelCandidateUrl) | ||
104 | value = SystemInfo::value(SystemInfo::BuildUrl, | ||
105 | SystemInfo::BuildCandidate).toString() | ||
106 | .replace("%MODEL%", platform) | ||
107 | .replace("%RELVERSION%", version); | ||
108 | else if(!version.isEmpty() && info == DailyUrl) | ||
109 | value = SystemInfo::value(SystemInfo::BuildUrl, | ||
110 | SystemInfo::BuildDaily).toString() | ||
111 | .replace("%MODEL%", platform) | ||
112 | .replace("%RELVERSION%", version); | ||
113 | } | ||
114 | break; | ||
115 | case CurDevelUrl: | ||
116 | value = SystemInfo::value(SystemInfo::BuildUrl, | ||
117 | SystemInfo::BuildCurrent).toString() | ||
118 | .replace("%MODEL%", platform); | ||
119 | break; | ||
120 | case BleedingDate: | ||
121 | // TODO: get rid of this, it's location specific. | ||
122 | value = QDateTime::fromString(value.toString(), | ||
123 | "yyyyMMddThhmmssZ").toString(Qt::ISODate); | ||
124 | break; | ||
125 | |||
126 | default: | ||
127 | break; | ||
128 | } | ||
129 | |||
130 | LOG_INFO() << "Server:" << value; | ||
131 | return value; | ||
132 | } | ||
133 | |||
134 | QString ServerInfo::statusAsString(QString platform) | ||
135 | { | ||
136 | QString value; | ||
137 | switch(platformValue(CurStatus, platform).toInt()) | ||
138 | { | ||
139 | case STATUS_RETIRED: | ||
140 | value = tr("Stable (Retired)"); | ||
141 | break; | ||
142 | case STATUS_UNUSABLE: | ||
143 | value = tr("Unusable"); | ||
144 | break; | ||
145 | case STATUS_UNSTABLE: | ||
146 | value = tr("Unstable"); | ||
147 | break; | ||
148 | case STATUS_STABLE: | ||
149 | value = tr("Stable"); | ||
150 | break; | ||
151 | default: | ||
152 | value = tr("Unknown"); | ||
153 | break; | ||
154 | } | ||
155 | |||
156 | return value; | ||
157 | } | ||