summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/serverinfo.cpp
blob: 2f73d96beb538c75aa00fca9adc80b22a260e687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/***************************************************************************
 *             __________               __   ___.
 *   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"
#include "Logger.h"

ServerInfo* ServerInfo::infoInstance = nullptr;

ServerInfo* ServerInfo::instance()
{
    if (infoInstance == nullptr) {
        infoInstance = new ServerInfo();
    }
    return infoInstance;
}

// server infos
const static struct {
    ServerInfo::ServerInfos info;
    const char* name;
    const char* def;
} ServerInfoList[] = {
    { ServerInfo::CurReleaseVersion,    "release/:platform:",           "" },
    { ServerInfo::CurReleaseUrl,        "release/:platform:",           "" },
    { ServerInfo::RelCandidateVersion,  "release-candidate/:platform:", "" },
    { ServerInfo::RelCandidateUrl,      "release-candidate/:platform:", "" },
    { ServerInfo::CurStatus,            "status/:platform:",            "-1" },
    { ServerInfo::ManualPdfUrl,         "",                             "" },
    { ServerInfo::ManualHtmlUrl,        "",                             "" },
    { ServerInfo::ManualZipUrl,         "",                             "" },
    { ServerInfo::BleedingRevision,     "bleeding/rev",                 "" },
    { ServerInfo::BleedingDate,         "bleeding/timestamp",           "" },
    { ServerInfo::CurDevelUrl,          "",                             "" },
};

void ServerInfo::readBuildInfo(QString file)
{
    if (serverSettings)
        delete serverSettings;
    serverSettings = new QSettings(file, QSettings::IniFormat);
}


QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
{
    // locate setting item in server info file
    int i = 0;
    while(ServerInfoList[i].info != info)
        i++;

    // replace setting name
    if(platform.isEmpty())
        platform = RbSettings::value(RbSettings::CurrentPlatform).toString();

    // 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);

    QString s = ServerInfoList[i].name;
    s.replace(":platform:", platform);

    // get value
    QVariant value = QString();
    if(!s.isEmpty() && serverSettings)
        value = serverSettings->value(s, ServerInfoList[i].def);

    // depending on the actual value we need more replacements.
    switch(info) {
    case CurReleaseVersion:
    case RelCandidateVersion:
        value = value.toStringList().at(0);
        break;
    case CurReleaseUrl:
    case RelCandidateUrl:
        {
            QString version = value.toStringList().at(0);
            if(value.toStringList().size() > 1)
                value = value.toStringList().at(1);
            else if(!version.isEmpty() && info == CurReleaseUrl)
                value = SystemInfo::value(SystemInfo::BuildUrl,
                                          SystemInfo::BuildRelease).toString()
                    .replace("%MODEL%", platform)
                    .replace("%RELVERSION%", version);
            else if(!version.isEmpty() && info == RelCandidateUrl)
                value = SystemInfo::value(SystemInfo::BuildUrl,
                                          SystemInfo::BuildCandidate).toString()
                    .replace("%MODEL%", platform)
                    .replace("%RELVERSION%", version);
        }
        break;
    case CurDevelUrl:
        value = SystemInfo::value(SystemInfo::BuildUrl,
                                  SystemInfo::BuildCurrent).toString()
                .replace("%MODEL%", platform);
        break;
    case ManualPdfUrl:
    case ManualZipUrl:
    case ManualHtmlUrl:
        {
            QString url = SystemInfo::value(SystemInfo::ManualUrl).toString();
            QString modelman = SystemInfo::platformValue(
                    SystemInfo::Manual, platform).toString();
            url.replace("%MODEL%", modelman.isEmpty() ? platform : modelman);
            if(info == ManualPdfUrl)
                url.replace("%FORMAT%", ".pdf");
            else if(info == ManualZipUrl)
                url.replace("%FORMAT%", "-html.zip");
            else if(info == ManualHtmlUrl)
                url.replace("%FORMAT%", "/rockbox-build.html");
            value = url;
        }
        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;
}

QString ServerInfo::statusAsString(QString platform)
{
    QString value;
    switch(platformValue(CurStatus, platform).toInt())
    {
    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;
}