rbutil: Convert ServerInfo to singleton.

Change-Id: I29d94eb6bae084754e5e3f337c41de8354ba123c
This commit is contained in:
Dominik Riebeling 2020-11-19 19:54:25 +01:00
parent f8fb4274ee
commit f608de723c
7 changed files with 45 additions and 31 deletions

View file

@ -21,7 +21,15 @@
#include "systeminfo.h"
#include "Logger.h"
static QSettings* serverSettings = nullptr;
ServerInfo* ServerInfo::infoInstance = nullptr;
ServerInfo* ServerInfo::instance()
{
if (infoInstance == nullptr) {
infoInstance = new ServerInfo();
}
return infoInstance;
}
// server infos
const static struct {
@ -131,10 +139,10 @@ QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
return value;
}
QString ServerInfo::statusToString(int status)
QString ServerInfo::statusAsString(QString platform)
{
QString value;
switch(status)
switch(platformValue(CurStatus, platform).toInt())
{
case STATUS_RETIRED:
value = tr("Stable (Retired)");

View file

@ -18,6 +18,9 @@
*
****************************************************************************/
// Parse and provide information from build server via build-info file.
// This is a singleton.
#ifndef SERVERINFO_H
#define SERVERINFO_H
@ -47,17 +50,21 @@ class ServerInfo : public QObject
RelCandidateUrl,
};
static ServerInfo* instance();
//! read in buildinfo file
static void readBuildInfo(QString file);
void readBuildInfo(QString file);
//! get a value from server info for a named platform.
static QVariant platformValue(enum ServerInfos setting, QString platform = "");
//! Convert status number to string
static QString statusToString(int status);
QVariant platformValue(enum ServerInfos setting, QString platform = "");
//! Get status number as string
QString statusAsString(QString platform = "");
protected:
ServerInfo() : serverSettings(nullptr) {}
private:
//! you shouldnt call this, its a fully static class
ServerInfo() {}
static ServerInfo* infoInstance;
QSettings* serverSettings;
};

View file

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

View file

@ -42,9 +42,9 @@ void ManualWidget::updateManual()
if(!m_platform.isEmpty())
{
ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
.arg(ServerInfo::platformValue(ServerInfo::ManualPdfUrl, m_platform).toString()));
.arg(ServerInfo::instance()->platformValue(ServerInfo::ManualPdfUrl, m_platform).toString()));
ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
.arg(ServerInfo::platformValue(ServerInfo::ManualHtmlUrl, m_platform).toString()));
.arg(ServerInfo::instance()->platformValue(ServerInfo::ManualHtmlUrl, m_platform).toString()));
}
else {
ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
@ -65,7 +65,7 @@ void ManualWidget::downloadManual(void)
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return;
}
QString manual = ServerInfo::platformValue(ServerInfo::ManualPdfUrl).toString();
QString manual = ServerInfo::instance()->platformValue(ServerInfo::ManualPdfUrl).toString();
ProgressLoggerGui* logger = new ProgressLoggerGui(this);
logger->show();
@ -75,12 +75,12 @@ void ManualWidget::downloadManual(void)
installer->setCache(true);
if(ui.radioPdf->isChecked()) {
installer->setUrl(ServerInfo::platformValue(
installer->setUrl(ServerInfo::instance()->platformValue(
ServerInfo::ManualPdfUrl, m_platform).toString());
installer->setLogSection("Manual (PDF)");
}
else {
installer->setUrl(ServerInfo::platformValue(
installer->setUrl(ServerInfo::instance()->platformValue(
ServerInfo::ManualZipUrl, m_platform).toString());
installer->setLogSection("Manual (HTML)");
}

View file

@ -69,7 +69,7 @@ void SelectiveInstallWidget::selectedVersionChanged(int index)
if(current == "development")
ui.selectedDescription->setText(tr("The development version is "
"updated on every code change. Last update was on %1").arg(
ServerInfo::platformValue(ServerInfo::BleedingDate).toString()));
ServerInfo::instance()->platformValue(ServerInfo::BleedingDate).toString()));
if(current == "rc")
ui.selectedDescription->setText(tr("This will eventually become the "
"next Rockbox version. Install it to help testing."));
@ -91,11 +91,11 @@ void SelectiveInstallWidget::updateVersion(void)
// re-populate all version items
m_versions.clear();
m_versions.insert("release", ServerInfo::platformValue(ServerInfo::CurReleaseVersion).toString());
m_versions.insert("release", ServerInfo::instance()->platformValue(ServerInfo::CurReleaseVersion).toString());
// Don't populate RC or development selections if target has been retired.
if (ServerInfo::platformValue(ServerInfo::CurStatus).toInt() != STATUS_RETIRED) {
m_versions.insert("development", ServerInfo::platformValue(ServerInfo::BleedingRevision).toString());
m_versions.insert("rc", ServerInfo::platformValue(ServerInfo::RelCandidateVersion).toString());
if (ServerInfo::instance()->platformValue(ServerInfo::CurStatus).toInt() != STATUS_RETIRED) {
m_versions.insert("development", ServerInfo::instance()->platformValue(ServerInfo::BleedingRevision).toString());
m_versions.insert("rc", ServerInfo::instance()->platformValue(ServerInfo::RelCandidateVersion).toString());
}
ui.selectedVersion->clear();
@ -385,11 +385,11 @@ void SelectiveInstallWidget::installRockbox(void)
RbSettings::setValue(RbSettings::Build, selected);
RbSettings::sync();
if(selected == "release") url = ServerInfo::platformValue(
if(selected == "release") url = ServerInfo::instance()->platformValue(
ServerInfo::CurReleaseUrl, m_target).toString();
else if(selected == "development") url = ServerInfo::platformValue(
else if(selected == "development") url = ServerInfo::instance()->platformValue(
ServerInfo::CurDevelUrl, m_target).toString();
else if(selected == "rc") url = ServerInfo::platformValue(
else if(selected == "rc") url = ServerInfo::instance()->platformValue(
ServerInfo::RelCandidateUrl, m_target).toString();
//! install build

View file

@ -252,7 +252,7 @@ void RbUtilQt::downloadDone(bool error)
// read info into ServerInfo object
buildInfo.open();
ServerInfo::readBuildInfo(buildInfo.fileName());
ServerInfo::instance()->readBuildInfo(buildInfo.fileName());
buildInfo.close();
ui.statusbar->showMessage(tr("Download build information finished."), 5000);
@ -408,7 +408,7 @@ void RbUtilQt::updateDevice()
QString brand = SystemInfo::platformValue(SystemInfo::Brand).toString();
QString name
= QString("%1 (%2)").arg(SystemInfo::platformValue(SystemInfo::Name).toString(),
ServerInfo::statusToString(ServerInfo::platformValue(ServerInfo::CurStatus).toInt()));
ServerInfo::instance()->statusAsString());
ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name));
QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
@ -789,7 +789,7 @@ void RbUtilQt::changeEvent(QEvent *e)
if(e->type() == QEvent::LanguageChange) {
ui.retranslateUi(this);
buildInfo.open();
ServerInfo::readBuildInfo(buildInfo.fileName());
ServerInfo::instance()->readBuildInfo(buildInfo.fileName());
buildInfo.close();
updateDevice();
} else {

View file

@ -110,11 +110,11 @@ void TestServerInfo::testMain()
tf.write(testinfo);
tf.close();
ServerInfo::readBuildInfo(filename);
ServerInfo::instance()->readBuildInfo(filename);
unsigned int i;
for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
QString result = ServerInfo::platformValue(testdata[i].entry, testdata[i].target).toString();
QString result = ServerInfo::instance()->platformValue(testdata[i].entry, testdata[i].target).toString();
QCOMPARE(result, QString(testdata[i].expected));
}
}