2010-01-24 21:12:11 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 by Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "serverinfo.h"
|
|
|
|
#include "rbsettings.h"
|
|
|
|
#include "systeminfo.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2010-01-24 21:12:11 +00:00
|
|
|
|
2020-11-19 18:54:25 +00:00
|
|
|
ServerInfo* ServerInfo::infoInstance = nullptr;
|
|
|
|
|
|
|
|
ServerInfo* ServerInfo::instance()
|
|
|
|
{
|
|
|
|
if (infoInstance == nullptr) {
|
|
|
|
infoInstance = new ServerInfo();
|
|
|
|
}
|
|
|
|
return infoInstance;
|
|
|
|
}
|
2020-11-15 20:01:36 +00:00
|
|
|
|
2010-01-24 21:12:11 +00:00
|
|
|
// server infos
|
|
|
|
const static struct {
|
|
|
|
ServerInfo::ServerInfos info;
|
|
|
|
const char* name;
|
2020-11-15 20:55:34 +00:00
|
|
|
const char* def;
|
2010-01-24 21:12:11 +00:00
|
|
|
} ServerInfoList[] = {
|
2020-11-15 20:55:34 +00:00
|
|
|
{ ServerInfo::CurReleaseVersion, "release/:platform:", "" },
|
|
|
|
{ ServerInfo::CurReleaseUrl, "release/:platform:", "" },
|
|
|
|
{ ServerInfo::RelCandidateVersion, "release-candidate/:platform:", "" },
|
|
|
|
{ ServerInfo::RelCandidateUrl, "release-candidate/:platform:", "" },
|
2020-11-22 15:39:56 +00:00
|
|
|
{ ServerInfo::DailyVersion, "daily/:platform:", "" },
|
|
|
|
{ ServerInfo::DailyUrl, "daily/:platform:", "" },
|
2020-11-15 20:55:34 +00:00
|
|
|
{ ServerInfo::CurStatus, "status/:platform:", "-1" },
|
|
|
|
{ ServerInfo::BleedingRevision, "bleeding/rev", "" },
|
|
|
|
{ ServerInfo::BleedingDate, "bleeding/timestamp", "" },
|
|
|
|
{ ServerInfo::CurDevelUrl, "", "" },
|
2012-06-02 22:50:01 +00:00
|
|
|
};
|
2010-01-24 21:12:11 +00:00
|
|
|
|
|
|
|
void ServerInfo::readBuildInfo(QString file)
|
|
|
|
{
|
2020-11-15 20:01:36 +00:00
|
|
|
if (serverSettings)
|
|
|
|
delete serverSettings;
|
|
|
|
serverSettings = new QSettings(file, QSettings::IniFormat);
|
2010-01-24 21:12:11 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 22:50:01 +00:00
|
|
|
|
2020-11-14 15:23:56 +00:00
|
|
|
QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
|
2010-01-24 21:12:11 +00:00
|
|
|
{
|
2020-11-15 20:01:36 +00:00
|
|
|
// locate setting item in server info file
|
2010-01-24 21:12:11 +00:00
|
|
|
int i = 0;
|
|
|
|
while(ServerInfoList[i].info != info)
|
|
|
|
i++;
|
|
|
|
|
2020-11-15 20:01:36 +00:00
|
|
|
// replace setting name
|
2020-11-14 15:23:56 +00:00
|
|
|
if(platform.isEmpty())
|
|
|
|
platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
|
|
|
|
|
2020-11-15 20:01:36 +00:00
|
|
|
// split of variant for platform.
|
|
|
|
// we can have an optional variant part in the platform string.
|
|
|
|
// For build info we don't use that.
|
|
|
|
platform = platform.split('.').at(0);
|
|
|
|
|
2010-01-24 21:12:11 +00:00
|
|
|
QString s = ServerInfoList[i].name;
|
|
|
|
s.replace(":platform:", platform);
|
2020-11-15 20:01:36 +00:00
|
|
|
|
|
|
|
// get value
|
|
|
|
QVariant value = QString();
|
|
|
|
if(!s.isEmpty() && serverSettings)
|
2020-11-15 20:55:34 +00:00
|
|
|
value = serverSettings->value(s, ServerInfoList[i].def);
|
2020-11-15 20:01:36 +00:00
|
|
|
|
|
|
|
// depending on the actual value we need more replacements.
|
|
|
|
switch(info) {
|
|
|
|
case CurReleaseVersion:
|
|
|
|
case RelCandidateVersion:
|
2020-11-22 15:39:56 +00:00
|
|
|
case DailyVersion:
|
2020-11-15 20:06:33 +00:00
|
|
|
value = value.toStringList().at(0);
|
2020-11-15 20:01:36 +00:00
|
|
|
break;
|
|
|
|
case CurReleaseUrl:
|
2020-11-15 20:23:02 +00:00
|
|
|
case RelCandidateUrl:
|
2020-11-22 15:39:56 +00:00
|
|
|
case DailyUrl:
|
2020-11-15 20:01:36 +00:00
|
|
|
{
|
|
|
|
QString version = value.toStringList().at(0);
|
|
|
|
if(value.toStringList().size() > 1)
|
|
|
|
value = value.toStringList().at(1);
|
2020-11-15 20:23:02 +00:00
|
|
|
else if(!version.isEmpty() && info == CurReleaseUrl)
|
2020-11-13 20:53:53 +00:00
|
|
|
value = SystemInfo::value(SystemInfo::BuildUrl,
|
|
|
|
SystemInfo::BuildRelease).toString()
|
2020-11-15 20:01:36 +00:00
|
|
|
.replace("%MODEL%", platform)
|
|
|
|
.replace("%RELVERSION%", version);
|
2020-11-15 20:23:02 +00:00
|
|
|
else if(!version.isEmpty() && info == RelCandidateUrl)
|
2020-11-13 20:53:53 +00:00
|
|
|
value = SystemInfo::value(SystemInfo::BuildUrl,
|
|
|
|
SystemInfo::BuildCandidate).toString()
|
2020-11-15 20:23:02 +00:00
|
|
|
.replace("%MODEL%", platform)
|
|
|
|
.replace("%RELVERSION%", version);
|
2020-11-23 19:26:05 +00:00
|
|
|
else if(!version.isEmpty() && info == DailyUrl)
|
|
|
|
value = SystemInfo::value(SystemInfo::BuildUrl,
|
|
|
|
SystemInfo::BuildDaily).toString()
|
|
|
|
.replace("%MODEL%", platform)
|
|
|
|
.replace("%RELVERSION%", version);
|
2020-11-15 20:01:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CurDevelUrl:
|
2020-11-13 20:53:53 +00:00
|
|
|
value = SystemInfo::value(SystemInfo::BuildUrl,
|
|
|
|
SystemInfo::BuildCurrent).toString()
|
2020-11-15 20:01:36 +00:00
|
|
|
.replace("%MODEL%", platform);
|
|
|
|
break;
|
|
|
|
case BleedingDate:
|
|
|
|
// TODO: get rid of this, it's location specific.
|
|
|
|
value = QDateTime::fromString(value.toString(),
|
|
|
|
"yyyyMMddThhmmssZ").toString(Qt::ISODate);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_INFO() << "Server:" << value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:54:25 +00:00
|
|
|
QString ServerInfo::statusAsString(QString platform)
|
2020-11-15 20:01:36 +00:00
|
|
|
{
|
|
|
|
QString value;
|
2020-11-19 18:54:25 +00:00
|
|
|
switch(platformValue(CurStatus, platform).toInt())
|
2020-11-15 20:01:36 +00:00
|
|
|
{
|
|
|
|
case STATUS_RETIRED:
|
|
|
|
value = tr("Stable (Retired)");
|
|
|
|
break;
|
|
|
|
case STATUS_UNUSABLE:
|
|
|
|
value = tr("Unusable");
|
|
|
|
break;
|
|
|
|
case STATUS_UNSTABLE:
|
|
|
|
value = tr("Unstable");
|
|
|
|
break;
|
|
|
|
case STATUS_STABLE:
|
|
|
|
value = tr("Stable");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = tr("Unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2010-01-24 21:12:11 +00:00
|
|
|
}
|