rbutil: Rework server info data handling.

Return status as int, not as string, and provide a separate function for
converting to string. This allows to filter based on the actual status,
not a (localized) status string, which is more robust.

Fix a regression that made players with missing status value show up as
retired.

Change-Id: I15f83ae0df484199b1b3b5b95069db8b4d425987
This commit is contained in:
Dominik Riebeling 2020-11-15 21:55:34 +01:00
parent af766ae10e
commit dec5421ca2
5 changed files with 21 additions and 23 deletions

View file

@ -27,18 +27,19 @@ static QSettings* serverSettings = nullptr;
const static struct { const static struct {
ServerInfo::ServerInfos info; ServerInfo::ServerInfos info;
const char* name; const char* name;
const char* def;
} ServerInfoList[] = { } ServerInfoList[] = {
{ ServerInfo::CurReleaseVersion, "release/:platform:" }, { ServerInfo::CurReleaseVersion, "release/:platform:", "" },
{ ServerInfo::CurReleaseUrl, "release/:platform:" }, { ServerInfo::CurReleaseUrl, "release/:platform:", "" },
{ ServerInfo::RelCandidateVersion, "release-candidate/:platform:" }, { ServerInfo::RelCandidateVersion, "release-candidate/:platform:", "" },
{ ServerInfo::RelCandidateUrl, "release-candidate/:platform:" }, { ServerInfo::RelCandidateUrl, "release-candidate/:platform:", "" },
{ ServerInfo::CurStatus, "status/:platform:" }, { ServerInfo::CurStatus, "status/:platform:", "-1" },
{ ServerInfo::ManualPdfUrl, "" }, { ServerInfo::ManualPdfUrl, "", "" },
{ ServerInfo::ManualHtmlUrl, "" }, { ServerInfo::ManualHtmlUrl, "", "" },
{ ServerInfo::ManualZipUrl, "" }, { ServerInfo::ManualZipUrl, "", "" },
{ ServerInfo::BleedingRevision, "bleeding/rev" }, { ServerInfo::BleedingRevision, "bleeding/rev", "" },
{ ServerInfo::BleedingDate, "bleeding/timestamp" }, { ServerInfo::BleedingDate, "bleeding/timestamp", "" },
{ ServerInfo::CurDevelUrl, "" }, { ServerInfo::CurDevelUrl, "", "" },
}; };
QMap<QString, QVariant> ServerInfo::serverInfos; QMap<QString, QVariant> ServerInfo::serverInfos;
@ -73,13 +74,10 @@ QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
// get value // get value
QVariant value = QString(); QVariant value = QString();
if(!s.isEmpty() && serverSettings) if(!s.isEmpty() && serverSettings)
value = serverSettings->value(s, ""); value = serverSettings->value(s, ServerInfoList[i].def);
// depending on the actual value we need more replacements. // depending on the actual value we need more replacements.
switch(info) { switch(info) {
case ServerInfo::CurStatus:
value = ServerInfo::statusToString(value.toInt());
break;
case CurReleaseVersion: case CurReleaseVersion:
case RelCandidateVersion: case RelCandidateVersion:
value = value.toStringList().at(0); value = value.toStringList().at(0);

View file

@ -386,8 +386,8 @@ void Config::setDevices()
// construct display name // construct display name
QString curname = SystemInfo::platformValue( QString curname = SystemInfo::platformValue(
SystemInfo::Name, platformList.at(it)).toString() + SystemInfo::Name, platformList.at(it)).toString() +
" (" +ServerInfo::platformValue( " (" + ServerInfo::statusToString(ServerInfo::platformValue(
ServerInfo::CurStatus, platformList.at(it)).toString() +")"; ServerInfo::CurStatus, platformList.at(it)).toInt()) +")";
LOG_INFO() << "add supported device:" << brands.at(c) << curname; LOG_INFO() << "add supported device:" << brands.at(c) << curname;
w2 = new QTreeWidgetItem(w, QStringList(curname)); w2 = new QTreeWidgetItem(w, QStringList(curname));
w2->setData(0, Qt::UserRole, platformList.at(it)); w2->setData(0, Qt::UserRole, platformList.at(it));

View file

@ -93,7 +93,7 @@ void SelectiveInstallWidget::updateVersion(void)
m_versions.clear(); m_versions.clear();
m_versions.insert("release", ServerInfo::platformValue(ServerInfo::CurReleaseVersion).toString()); m_versions.insert("release", ServerInfo::platformValue(ServerInfo::CurReleaseVersion).toString());
// Don't populate RC or development selections if target has been retired. // Don't populate RC or development selections if target has been retired.
if (ServerInfo::platformValue(ServerInfo::CurStatus) != tr("Stable (Retired)")) { if (ServerInfo::platformValue(ServerInfo::CurStatus).toInt() != STATUS_RETIRED) {
m_versions.insert("development", ServerInfo::platformValue(ServerInfo::BleedingRevision).toString()); m_versions.insert("development", ServerInfo::platformValue(ServerInfo::BleedingRevision).toString());
m_versions.insert("rc", ServerInfo::platformValue(ServerInfo::RelCandidateVersion).toString()); m_versions.insert("rc", ServerInfo::platformValue(ServerInfo::RelCandidateVersion).toString());
} }

View file

@ -408,7 +408,7 @@ void RbUtilQt::updateDevice()
QString brand = SystemInfo::platformValue(SystemInfo::Brand).toString(); QString brand = SystemInfo::platformValue(SystemInfo::Brand).toString();
QString name QString name
= QString("%1 (%2)").arg(SystemInfo::platformValue(SystemInfo::Name).toString(), = QString("%1 (%2)").arg(SystemInfo::platformValue(SystemInfo::Name).toString(),
ServerInfo::platformValue(ServerInfo::CurStatus).toString()); ServerInfo::statusToString(ServerInfo::platformValue(ServerInfo::CurStatus).toInt()));
ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name)); ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name));
QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString(); QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();

View file

@ -65,21 +65,21 @@ struct testvector {
const struct testvector testdata[] = const struct testvector testdata[] =
{ {
{ "archosfmrecorder", ServerInfo::CurReleaseVersion, "3.11.2" }, { "archosfmrecorder", ServerInfo::CurReleaseVersion, "3.11.2" },
{ "archosfmrecorder", ServerInfo::CurStatus, "Stable" }, { "archosfmrecorder", ServerInfo::CurStatus, "3" },
{ "iaudiom3", ServerInfo::CurReleaseVersion, "3.11.2" }, { "iaudiom3", ServerInfo::CurReleaseVersion, "3.11.2" },
{ "iaudiom3", ServerInfo::CurReleaseUrl, "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" }, { "iaudiom3", ServerInfo::CurReleaseUrl, "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" },
{ "sansae200", ServerInfo::CurReleaseVersion, "3.11.2" }, { "sansae200", ServerInfo::CurReleaseVersion, "3.11.2" },
{ "sansae200", ServerInfo::CurReleaseUrl, "https://unittest/release/3.11.2/rockbox-sansae200-3.11.2.zip" }, { "sansae200", ServerInfo::CurReleaseUrl, "https://unittest/release/3.11.2/rockbox-sansae200-3.11.2.zip" },
{ "iriverh100", ServerInfo::CurReleaseVersion, "3.11.2" }, { "iriverh100", ServerInfo::CurReleaseVersion, "3.11.2" },
{ "iriverh100", ServerInfo::CurReleaseUrl, "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" }, { "iriverh100", ServerInfo::CurReleaseUrl, "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" },
{ "iriverh100", ServerInfo::CurStatus, "Unstable" }, { "iriverh100", ServerInfo::CurStatus, "2" },
{ "iriverh100", ServerInfo::CurDevelUrl, "https://unittest/dev/rockbox-iriverh100.zip" }, { "iriverh100", ServerInfo::CurDevelUrl, "https://unittest/dev/rockbox-iriverh100.zip" },
{ "iriverh300", ServerInfo::CurReleaseVersion, "" }, { "iriverh300", ServerInfo::CurReleaseVersion, "" },
{ "iriverh300", ServerInfo::CurReleaseUrl, "" }, { "iriverh300", ServerInfo::CurReleaseUrl, "" },
{ "iriverh300", ServerInfo::CurStatus, "Unusable" }, { "iriverh300", ServerInfo::CurStatus, "1" },
{ "iriverh10", ServerInfo::CurReleaseVersion, "" }, { "iriverh10", ServerInfo::CurReleaseVersion, "" },
{ "iriverh10", ServerInfo::CurReleaseUrl, "" }, { "iriverh10", ServerInfo::CurReleaseUrl, "" },
{ "iriverh10", ServerInfo::CurStatus, "Stable (Retired)" }, { "iriverh10", ServerInfo::CurStatus, "0" },
{ "gigabeatfx", ServerInfo::RelCandidateVersion, "f9dce96" }, { "gigabeatfx", ServerInfo::RelCandidateVersion, "f9dce96" },
{ "gigabeatfx", ServerInfo::RelCandidateUrl, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" }, { "gigabeatfx", ServerInfo::RelCandidateUrl, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" },
{ "archosfmrecorder", ServerInfo::RelCandidateVersion, "f9dce96" }, { "archosfmrecorder", ServerInfo::RelCandidateVersion, "f9dce96" },