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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/*
kopeteonlinestatus.cpp - Kopete Online Status
Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
Copyright (c) 2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
Copyright (c) 2003 by Will Stephenson <lists@stevello.free-online.co.uk>
Copyright (c) 2004 by Olivier Goffart <ogoffart @ tiscalinet.be>
Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "kopeteonlinestatus.h"
#include "kopeteonlinestatusmanager.h"
#include "kopeteprotocol.h"
#include "kopeteaccount.h"
#include "kopetecontact.h"
#include <kiconloader.h>
#include <kiconeffect.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstaticdeleter.h>
#include <kapplication.h>
using namespace Kopete;
class OnlineStatus::Private
: public TDEShared
{
public:
StatusType status;
unsigned weight;
Protocol *protocol;
unsigned internalStatus;
TQStringList overlayIcons;
TQString description;
unsigned refCount;
TQString protocolIcon() const
{
return protocol ? protocol->pluginIcon() : TQString::fromLatin1( "unknown" );
}
};
/**
* This is required by some plugins, when a status need to be stored on
* the disk, to avoid problems.
*/
static struct
{
OnlineStatus::StatusType status;
const char *name;
} statusNames[] = {
{ OnlineStatus::Unknown, "Unknown" },
{ OnlineStatus::Offline, "Offline" },
{ OnlineStatus::Connecting, "Connecting" },
{ OnlineStatus::Invisible, "Invisible" },
{ OnlineStatus::Online, "Online"},
{ OnlineStatus::Away, "Away" } };
OnlineStatus::OnlineStatus( StatusType status, unsigned weight, Protocol *protocol,
unsigned internalStatus, const TQStringList &overlayIcons, const TQString &description )
: d( new Private )
{
d->status = status;
d->internalStatus = internalStatus;
d->weight = weight;
d->overlayIcons = overlayIcons;
d->protocol = protocol;
d->description = description;
}
OnlineStatus::OnlineStatus( StatusType status, unsigned weight, Protocol *protocol, unsigned internalStatus,
const TQStringList &overlayIcons, const TQString &description, const TQString &caption, unsigned int categories , unsigned int options )
: d( new Private )
{
d->status = status;
d->internalStatus = internalStatus;
d->weight = weight;
d->overlayIcons = overlayIcons;
d->protocol = protocol;
d->description = description;
OnlineStatusManager::self()->registerOnlineStatus(*this, caption, categories, options );
}
OnlineStatus::OnlineStatus( StatusType status )
: d( new Private )
{
d->status = status;
d->internalStatus = 0;
d->weight = 0;
d->protocol = 0L;
switch( status )
{
case Online:
d->description = i18n( "Online" );
break;
case Away:
d->description = i18n( "Away" );
break;
case Connecting:
d->description = i18n( "Connecting" );
break;
case Invisible:
d->description = i18n( "Invisible" );
break;
case Offline:
d->description = i18n( "Offline" );
break;
case Unknown:
default:
d->description = i18n( "Unknown" );
d->overlayIcons = TQString::fromLatin1("status_unknown");
break;
}
}
OnlineStatus::OnlineStatus()
: d( new Private )
{
d->status = Unknown;
d->internalStatus = 0;
d->weight = 0;
d->protocol = 0L;
d->overlayIcons = TQString::fromLatin1( "status_unknown" );
}
OnlineStatus::OnlineStatus( const OnlineStatus &other )
: d( other.d )
{
}
bool OnlineStatus::operator==( const OnlineStatus &other ) const
{
if ( d->internalStatus == other.d->internalStatus && d->protocol == other.d->protocol &&
d->weight == other.d->weight && d->overlayIcons == other.d->overlayIcons &&
d->description == other.d->description )
{
return true;
}
return false;
}
bool OnlineStatus::operator!=( const OnlineStatus &other ) const
{
return !(*this == other);
}
bool OnlineStatus::operator>( const OnlineStatus &other ) const
{
if( d->status == other.d->status )
return d->weight > other.d->weight;
else
return d->status > other.d->status;
}
bool OnlineStatus::operator<( const OnlineStatus &other ) const
{
if( d->status == other.d->status )
return d->weight < other.d->weight;
else
return d->status < other.d->status;
}
OnlineStatus & OnlineStatus::operator=( const OnlineStatus &other )
{
d = other.d;
return *this;
}
OnlineStatus::~OnlineStatus()
{
}
OnlineStatus::StatusType OnlineStatus::status() const
{
return d->status;
}
unsigned OnlineStatus::internalStatus() const
{
return d->internalStatus;
}
unsigned OnlineStatus::weight() const
{
return d->weight;
}
TQStringList OnlineStatus::overlayIcons() const
{
return d->overlayIcons;
}
TQString OnlineStatus::description() const
{
return d->description;
}
Protocol* OnlineStatus::protocol() const
{
return d->protocol;
}
bool OnlineStatus::isDefinitelyOnline() const
{
if ( status() == Offline || status() == Connecting || status() == Unknown )
return false;
return true;
}
TQPixmap OnlineStatus::iconFor( const Contact *contact, int size ) const
{
return OnlineStatusManager::self()->cacheLookupByMimeSource( mimeSourceFor( contact, size ) );
}
TQString OnlineStatus::mimeSourceFor( const Contact *contact, int size ) const
{
// figure out what icon we should use for this contact
TQString iconName = contact->icon();
if ( iconName.isNull() )
iconName = contact->account()->customIcon();
if ( iconName.isNull() )
iconName = d->protocolIcon();
return mimeSource( iconName, size, contact->account()->color(),contact->idleTime() >= 10*60 );
}
TQPixmap OnlineStatus::iconFor( const Account *account, int size ) const
{
return OnlineStatusManager::self()->cacheLookupByMimeSource( mimeSourceFor( account, size ) );
}
TQString OnlineStatus::mimeSourceFor( const Account *account, int size ) const
{
TQString iconName = account->customIcon();
if ( iconName.isNull() )
iconName = d->protocolIcon();
return mimeSource( iconName, size, account->color(), false );
}
TQPixmap OnlineStatus::iconFor( const TQString &mimeSource ) const
{
return OnlineStatusManager::self()->cacheLookupByMimeSource( mimeSource );
}
TQPixmap OnlineStatus::protocolIcon() const
{
return OnlineStatusManager::self()->cacheLookupByObject( *this, d->protocolIcon() , 16, TQColor() );
}
TQString OnlineStatus::mimeSource( const TQString& icon, int size, TQColor color, bool idle) const
{
// make sure the item is in the cache
OnlineStatusManager::self()->cacheLookupByObject( *this, icon, size, color, idle );
// now return the fingerprint instead
return OnlineStatusManager::self()->fingerprint( *this, icon, size, color, idle );
}
TQString OnlineStatus::statusTypeToString(OnlineStatus::StatusType statusType)
{
const int size = sizeof(statusNames) / sizeof(statusNames[0]);
for (int i=0; i< size; i++)
if (statusNames[i].status == statusType)
return TQString::fromLatin1(statusNames[i].name);
return TQString::fromLatin1(statusNames[0].name); // Unknown
}
OnlineStatus::StatusType OnlineStatus::statusStringToType(TQString& string)
{
int size = sizeof(statusNames) / sizeof(statusNames[0]);
for (int i=0; i< size; i++)
if (TQString::fromLatin1(statusNames[i].name) == string)
return statusNames[i].status;
return OnlineStatus::Unknown;
}
// vim: set noet ts=4 sts=4 sw=4:
|