2
This file is part of Icecream.
4
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
QValueVector<QColor> HostInfo::mColorTable;
28
QMap<int,QString> HostInfo::mColorNameMap;
30
void HostInfo::initColorTable()
32
initColor( "#A5080B", i18n("cherry") );
33
initColor( "#76d26f", i18n("pistachio"));
34
initColor( "#664a08", i18n("chocolate"));
35
initColor( "#4c9dff", i18n("smurf"));
36
initColor( "#6c2ca8", i18n("blueberry"));
37
initColor( "#fa8344", i18n("orange"));
38
initColor( "#55CFBD", i18n("mint"));
39
initColor( "#db1230", i18n("strawberry"));
40
initColor( "#a6ea5e", i18n("apple"));
41
initColor( "#D6A3D8", i18n("bubblegum"));
42
initColor( "#f2aa4d", i18n("peach"));
43
initColor( "#aa1387", i18n("plum"));
44
initColor( "#26c3f7", i18n("polar sea"));
45
initColor( "#b8850e", i18n("nut"));
46
initColor( "#6a188d", i18n("blackberry"));
47
initColor( "#24b063", i18n("woodruff"));
48
initColor( "#ffff0f", i18n("banana"));
49
initColor( "#1e1407", i18n("mocha"));
50
initColor( "#29B450", i18n("kiwi"));
51
initColor( "#F8DD31", i18n("lemon"));
52
initColor( "#fa7e91", i18n("raspberry"));
53
initColor( "#c5a243", i18n("caramel"));
54
initColor( "#b8bcff", i18n("blueberry"));
55
// try to make the count a prime number (reminder: 19, 23, 29, 31)
56
// initColor( "#ffb8c0", i18n("blackcurrant"));
57
// initColor( "#f7d36f", i18n("passionfruit"));
58
// initColor( "#d51013", i18n("pomegranate"));
59
// initColor( "#C2C032", i18n("pumpkin" ) );
62
void HostInfo::initColor( const QString &value , const QString &name )
65
mColorTable.append( c );
67
mColorNameMap.insert( c.red() + c.green() * 256 + c.blue() * 65536, name );
70
QString HostInfo::colorName( const QColor &c )
72
int key = c.red() + c.green() * 256 + c.blue() * 65536;
74
QMap<int,QString>::ConstIterator it = mColorNameMap.find( key );
75
if ( it == mColorNameMap.end() ) return i18n("<unknown>");
79
HostInfo::HostInfo( unsigned int id )
84
unsigned int HostInfo::id() const
89
QColor HostInfo::color() const
94
QString HostInfo::name() const
99
QString HostInfo::ip() const
104
QString HostInfo::platform() const
109
unsigned int HostInfo::maxJobs() const
114
bool HostInfo::isOffline() const
119
float HostInfo::serverSpeed() const
124
unsigned int HostInfo::serverLoad() const
129
void HostInfo::updateFromStatsMap( const StatsMap &stats )
132
kdDebug() << "HostInfo::updateFromStatsMap():" << endl;
133
StatsMap::ConstIterator it;
134
for( it = stats.begin(); it != stats.end(); it++ ) {
135
kdDebug() << " STAT: " << it.key() << ": " << it.data() << endl;
139
QString name = stats["Name"];
141
if ( name != mName ) {
143
mColor = createColor( mName );
145
mPlatform = stats["Platform"];
148
mMaxJobs = stats["MaxJobs"].toUInt();
149
mOffline = ( stats["State"] == "Offline" );
151
mServerSpeed = stats["Speed"].toFloat();
153
mServerLoad = stats["Load"].toUInt();
156
QColor HostInfo::createColor( const QString &name )
162
for( uint i = 0; i < name.length(); ++i ) {
163
ch = name[i].unicode();
165
if ((g = (h & 0xf0000000)) != 0)
172
h += name.length() + ( name.length() << 17 );
175
// kdDebug() << "HostInfo::createColor: " << h % mColorTable.count() << ": " << name << endl;
177
return mColorTable[ h % mColorTable.count() ];
180
QColor HostInfo::createColor()
184
return mColorTable.at( num++ % mColorTable.count() );
187
QColor color( num, 255 - num, ( num * 3 ) % 255 );
196
HostInfoManager::HostInfoManager()
198
HostInfo::initColorTable();
201
HostInfoManager::~HostInfoManager()
203
HostMap::ConstIterator it;
204
for( it = mHostMap.begin(); it != mHostMap.end(); ++it ) {
209
HostInfo *HostInfoManager::find( unsigned int hostid ) const
211
HostMap::ConstIterator it = mHostMap.find( hostid );
212
if ( it == mHostMap.end() ) return 0;
216
HostInfo *HostInfoManager::checkNode( unsigned int hostid,
217
const HostInfo::StatsMap &stats )
219
HostMap::ConstIterator it = mHostMap.find( hostid );
221
if ( it == mHostMap.end() ) {
222
hostInfo = new HostInfo( hostid );
223
mHostMap.insert( hostid, hostInfo );
228
hostInfo->updateFromStatsMap( stats );
233
QString HostInfoManager::nameForHost( unsigned int id ) const
236
kdError() << "Unknown host" << endl;
238
HostInfo *hostInfo = find( id );
239
if ( hostInfo ) return hostInfo->name();
242
return i18n("<unknown>");
245
QColor HostInfoManager::hostColor( unsigned int id ) const
248
HostInfo *hostInfo = find( id );
250
QColor tmp = hostInfo->color();
251
assert( tmp.isValid() && ( tmp.red() + tmp.green() + tmp.blue() ));
256
kdDebug() << "id " << id << " got no color\n";
259
return QColor( 0, 0, 0 );
262
unsigned int HostInfoManager::maxJobs( unsigned int id ) const
265
HostInfo *hostInfo = find( id );
266
if ( hostInfo ) return hostInfo->maxJobs();
272
HostInfoManager::HostMap HostInfoManager::hostMap() const