1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2010 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "serverinfo.h"
21 #include "rbsettings.h"
22 #include "systeminfo.h"
24 #if defined(Q_OS_LINUX)
30 ServerInfo::ServerInfos info
;
33 } ServerInfoList
[] = {
34 { ServerInfo::CurReleaseVersion
, ":platform:/releaseversion", "" },
35 { ServerInfo::CurStatus
, ":platform:/status", "Unknown" },
36 { ServerInfo::DailyRevision
, "dailyrev", "" },
37 { ServerInfo::DailyDate
, "dailydate", "" },
38 { ServerInfo::BleedingRevision
, "bleedingrev", "" },
39 { ServerInfo::BleedingDate
, "bleedingdate", "" },
42 QMap
<QString
, QVariant
> ServerInfo::serverInfos
;
44 void ServerInfo::readBuildInfo(QString file
)
46 QSettings
info(file
, QSettings::IniFormat
);
48 setValue(ServerInfo::DailyRevision
,info
.value("dailies/rev"));
49 QDate date
= QDate::fromString(info
.value("dailies/date").toString(), "yyyyMMdd");
50 setValue(ServerInfo::DailyDate
,date
.toString(Qt::ISODate
));
52 info
.beginGroup("release");
53 QStringList keys
= info
.allKeys();
56 // get base platforms, handle variants with platforms in the loop
57 QStringList platforms
= SystemInfo::platforms(SystemInfo::PlatformBaseDisabled
);
58 for(int i
= 0; i
< platforms
.size(); i
++)
60 // check if there are rbutil-variants of the current platform and handle
61 // them the same time.
63 variants
= SystemInfo::platforms(SystemInfo::PlatformVariantDisabled
, platforms
.at(i
));
65 info
.beginGroup("release");
66 if(keys
.contains(platforms
.at(i
))) {
67 release
= info
.value(platforms
.at(i
));
71 info
.beginGroup("status");
72 QString status
= tr("Unknown");
73 switch(info
.value(platforms
.at(i
)).toInt())
76 status
= tr("Unusable");
79 status
= tr("Unstable");
82 status
= tr("Stable");
88 // set variants (if any)
89 for(int j
= 0; j
< variants
.size(); ++j
) {
90 setPlatformValue(variants
.at(j
), ServerInfo::CurStatus
, status
);
91 setPlatformValue(variants
.at(j
), ServerInfo::CurReleaseVersion
, release
);
97 void ServerInfo::readBleedingInfo(QString file
)
99 QSettings
info(file
, QSettings::IniFormat
);
101 setValue(ServerInfo::BleedingRevision
,info
.value("bleeding/rev"));
102 QDateTime date
= QDateTime::fromString(info
.value("bleeding/timestamp").toString(), "yyyyMMddThhmmssZ");
103 setValue(ServerInfo::BleedingDate
,date
.toString(Qt::ISODate
));
106 QVariant
ServerInfo::value(enum ServerInfos info
)
110 while(ServerInfoList
[i
].info
!= info
)
113 QString s
= ServerInfoList
[i
].name
;
114 s
.replace(":platform:", RbSettings::value(RbSettings::CurrentPlatform
).toString());
115 qDebug() << "[ServerInfo] GET:" << s
<< serverInfos
.value(s
, ServerInfoList
[i
].def
).toString();
116 return serverInfos
.value(s
, ServerInfoList
[i
].def
);
119 void ServerInfo::setValue(enum ServerInfos setting
, QVariant value
)
122 return setPlatformValue(empty
, setting
, value
);
125 void ServerInfo::setPlatformValue(QString platform
, enum ServerInfos info
, QVariant value
)
127 // locate setting item
129 while(ServerInfoList
[i
].info
!= info
)
132 QString s
= ServerInfoList
[i
].name
;
133 s
.replace(":platform:", platform
);
134 serverInfos
.insert(s
, value
);
135 qDebug() << "[ServerInfo] SET:" << s
<< serverInfos
.value(s
).toString();
138 QVariant
ServerInfo::platformValue(QString platform
, enum ServerInfos info
)
140 // locate setting item
142 while(ServerInfoList
[i
].info
!= info
)
145 QString s
= ServerInfoList
[i
].name
;
146 s
.replace(":platform:", platform
);
147 QString d
= ServerInfoList
[i
].def
;
148 d
.replace(":platform:", platform
);
149 qDebug() << "[ServerInfo] GET" << s
<< serverInfos
.value(s
, d
).toString();
150 return serverInfos
.value(s
, d
);