mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
rbutil: Convert ServerInfo to singleton.
Change-Id: I29d94eb6bae084754e5e3f337c41de8354ba123c
This commit is contained in:
parent
f8fb4274ee
commit
f608de723c
7 changed files with 45 additions and 31 deletions
|
|
@ -21,7 +21,15 @@
|
||||||
#include "systeminfo.h"
|
#include "systeminfo.h"
|
||||||
#include "Logger.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
|
// server infos
|
||||||
const static struct {
|
const static struct {
|
||||||
|
|
@ -131,10 +139,10 @@ QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ServerInfo::statusToString(int status)
|
QString ServerInfo::statusAsString(QString platform)
|
||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
switch(status)
|
switch(platformValue(CurStatus, platform).toInt())
|
||||||
{
|
{
|
||||||
case STATUS_RETIRED:
|
case STATUS_RETIRED:
|
||||||
value = tr("Stable (Retired)");
|
value = tr("Stable (Retired)");
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Parse and provide information from build server via build-info file.
|
||||||
|
// This is a singleton.
|
||||||
|
|
||||||
#ifndef SERVERINFO_H
|
#ifndef SERVERINFO_H
|
||||||
#define SERVERINFO_H
|
#define SERVERINFO_H
|
||||||
|
|
||||||
|
|
@ -47,17 +50,21 @@ class ServerInfo : public QObject
|
||||||
RelCandidateUrl,
|
RelCandidateUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ServerInfo* instance();
|
||||||
|
|
||||||
//! read in buildinfo file
|
//! read in buildinfo file
|
||||||
static void readBuildInfo(QString file);
|
void readBuildInfo(QString file);
|
||||||
//! get a value from server info for a named platform.
|
//! get a value from server info for a named platform.
|
||||||
static QVariant platformValue(enum ServerInfos setting, QString platform = "");
|
QVariant platformValue(enum ServerInfos setting, QString platform = "");
|
||||||
//! Convert status number to string
|
//! Get status number as string
|
||||||
static QString statusToString(int status);
|
QString statusAsString(QString platform = "");
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ServerInfo() : serverSettings(nullptr) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! you shouldnt call this, its a fully static class
|
static ServerInfo* infoInstance;
|
||||||
ServerInfo() {}
|
QSettings* serverSettings;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -385,9 +385,8 @@ void Config::setDevices()
|
||||||
continue;
|
continue;
|
||||||
// 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::statusToString(ServerInfo::platformValue(
|
+ " (" + ServerInfo::instance()->statusAsString(platformList.at(it)) + ")";
|
||||||
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));
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ void ManualWidget::updateManual()
|
||||||
if(!m_platform.isEmpty())
|
if(!m_platform.isEmpty())
|
||||||
{
|
{
|
||||||
ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
|
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>")
|
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 {
|
else {
|
||||||
ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
|
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) {
|
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString manual = ServerInfo::platformValue(ServerInfo::ManualPdfUrl).toString();
|
QString manual = ServerInfo::instance()->platformValue(ServerInfo::ManualPdfUrl).toString();
|
||||||
|
|
||||||
ProgressLoggerGui* logger = new ProgressLoggerGui(this);
|
ProgressLoggerGui* logger = new ProgressLoggerGui(this);
|
||||||
logger->show();
|
logger->show();
|
||||||
|
|
@ -75,12 +75,12 @@ void ManualWidget::downloadManual(void)
|
||||||
installer->setCache(true);
|
installer->setCache(true);
|
||||||
|
|
||||||
if(ui.radioPdf->isChecked()) {
|
if(ui.radioPdf->isChecked()) {
|
||||||
installer->setUrl(ServerInfo::platformValue(
|
installer->setUrl(ServerInfo::instance()->platformValue(
|
||||||
ServerInfo::ManualPdfUrl, m_platform).toString());
|
ServerInfo::ManualPdfUrl, m_platform).toString());
|
||||||
installer->setLogSection("Manual (PDF)");
|
installer->setLogSection("Manual (PDF)");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
installer->setUrl(ServerInfo::platformValue(
|
installer->setUrl(ServerInfo::instance()->platformValue(
|
||||||
ServerInfo::ManualZipUrl, m_platform).toString());
|
ServerInfo::ManualZipUrl, m_platform).toString());
|
||||||
installer->setLogSection("Manual (HTML)");
|
installer->setLogSection("Manual (HTML)");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ void SelectiveInstallWidget::selectedVersionChanged(int index)
|
||||||
if(current == "development")
|
if(current == "development")
|
||||||
ui.selectedDescription->setText(tr("The development version is "
|
ui.selectedDescription->setText(tr("The development version is "
|
||||||
"updated on every code change. Last update was on %1").arg(
|
"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")
|
if(current == "rc")
|
||||||
ui.selectedDescription->setText(tr("This will eventually become the "
|
ui.selectedDescription->setText(tr("This will eventually become the "
|
||||||
"next Rockbox version. Install it to help testing."));
|
"next Rockbox version. Install it to help testing."));
|
||||||
|
|
@ -91,11 +91,11 @@ void SelectiveInstallWidget::updateVersion(void)
|
||||||
|
|
||||||
// re-populate all version items
|
// re-populate all version items
|
||||||
m_versions.clear();
|
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.
|
// Don't populate RC or development selections if target has been retired.
|
||||||
if (ServerInfo::platformValue(ServerInfo::CurStatus).toInt() != STATUS_RETIRED) {
|
if (ServerInfo::instance()->platformValue(ServerInfo::CurStatus).toInt() != STATUS_RETIRED) {
|
||||||
m_versions.insert("development", ServerInfo::platformValue(ServerInfo::BleedingRevision).toString());
|
m_versions.insert("development", ServerInfo::instance()->platformValue(ServerInfo::BleedingRevision).toString());
|
||||||
m_versions.insert("rc", ServerInfo::platformValue(ServerInfo::RelCandidateVersion).toString());
|
m_versions.insert("rc", ServerInfo::instance()->platformValue(ServerInfo::RelCandidateVersion).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.selectedVersion->clear();
|
ui.selectedVersion->clear();
|
||||||
|
|
@ -385,11 +385,11 @@ void SelectiveInstallWidget::installRockbox(void)
|
||||||
RbSettings::setValue(RbSettings::Build, selected);
|
RbSettings::setValue(RbSettings::Build, selected);
|
||||||
RbSettings::sync();
|
RbSettings::sync();
|
||||||
|
|
||||||
if(selected == "release") url = ServerInfo::platformValue(
|
if(selected == "release") url = ServerInfo::instance()->platformValue(
|
||||||
ServerInfo::CurReleaseUrl, m_target).toString();
|
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();
|
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();
|
ServerInfo::RelCandidateUrl, m_target).toString();
|
||||||
|
|
||||||
//! install build
|
//! install build
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ void RbUtilQt::downloadDone(bool error)
|
||||||
|
|
||||||
// read info into ServerInfo object
|
// read info into ServerInfo object
|
||||||
buildInfo.open();
|
buildInfo.open();
|
||||||
ServerInfo::readBuildInfo(buildInfo.fileName());
|
ServerInfo::instance()->readBuildInfo(buildInfo.fileName());
|
||||||
buildInfo.close();
|
buildInfo.close();
|
||||||
|
|
||||||
ui.statusbar->showMessage(tr("Download build information finished."), 5000);
|
ui.statusbar->showMessage(tr("Download build information finished."), 5000);
|
||||||
|
|
@ -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::statusToString(ServerInfo::platformValue(ServerInfo::CurStatus).toInt()));
|
ServerInfo::instance()->statusAsString());
|
||||||
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();
|
||||||
|
|
@ -789,7 +789,7 @@ void RbUtilQt::changeEvent(QEvent *e)
|
||||||
if(e->type() == QEvent::LanguageChange) {
|
if(e->type() == QEvent::LanguageChange) {
|
||||||
ui.retranslateUi(this);
|
ui.retranslateUi(this);
|
||||||
buildInfo.open();
|
buildInfo.open();
|
||||||
ServerInfo::readBuildInfo(buildInfo.fileName());
|
ServerInfo::instance()->readBuildInfo(buildInfo.fileName());
|
||||||
buildInfo.close();
|
buildInfo.close();
|
||||||
updateDevice();
|
updateDevice();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -110,11 +110,11 @@ void TestServerInfo::testMain()
|
||||||
tf.write(testinfo);
|
tf.write(testinfo);
|
||||||
tf.close();
|
tf.close();
|
||||||
|
|
||||||
ServerInfo::readBuildInfo(filename);
|
ServerInfo::instance()->readBuildInfo(filename);
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); 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));
|
QCOMPARE(result, QString(testdata[i].expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue