25
25
#include "userlist.h"
26
26
#include "alerticon.h"
27
27
#include "psievent.h"
29
28
#include "psicon.h"
30
30
#include "psiaccount.h"
31
#include "psiiconset.h"
32
#include "iconlabel.h"
33
#include "psioptions.h"
32
35
#include <qapplication.h>
33
36
#include <qlayout.h>
35
//----------------------------------------------------------------------------
37
//----------------------------------------------------------------------------
39
class PsiPopupList : public QObject, public QPtrList<PsiPopup>
56
return QPtrList<PsiPopup>::first();
59
void prepend(const PsiPopup *d)
64
connect(d, SIGNAL(destroyed(QObject *)), SLOT(popupDestroyed(QObject *)));
65
QPtrList<PsiPopup>::prepend(d);
73
void popupDestroyed(QObject *p)
76
remove((PsiPopup *)p);
84
static PsiPopupList *psiPopupList = 0;
39
#include <QVBoxLayout>
40
#include <QHBoxLayout>
44
#include <QTextDocument>
47
* Limits number of popups that could be displayed
48
* simultaneously on screen. Old popups momentally
49
* disappear when new ones appear.
51
static int MaxPopups = 5;
54
* Holds a list of Psi Popups.
56
static QList<PsiPopup *> *psiPopupList = 0;
86
58
//----------------------------------------------------------------------------
87
59
// PsiPopup::Private
94
66
Private(PsiPopup *p);
97
void init(const Icon *titleIcon, QString titleText, PsiAccount *_acc, PopupType type);
69
void init(const PsiIcon *titleIcon, QString titleText, PsiAccount *_acc, PopupType type);
98
70
QString clipText(QString);
99
QBoxLayout *createContactInfo(const Icon *icon, QString text);
71
QBoxLayout *createContactInfo(const PsiIcon *icon, QString text);
102
74
void popupDestroyed();
138
void PsiPopup::Private::init(const Icon *_titleIcon, QString titleText, PsiAccount *acc, PopupType type)
113
void PsiPopup::Private::init(const PsiIcon *_titleIcon, QString titleText, PsiAccount *acc, PopupType type)
140
115
psi = acc->psi();
119
if ( !option.ppIsOn )
144
122
if ( !psiPopupList )
145
psiPopupList = new PsiPopupList();
147
FancyPopup *last = 0;
148
if ( psiPopupList->last() )
149
last = psiPopupList->last()->popup();
123
psiPopupList = new QList<PsiPopup *>();
125
if ( psiPopupList->count() >= MaxPopups && MaxPopups > 0 )
126
delete psiPopupList->first();
128
FancyPopup *lastPopup = 0;
129
if ( psiPopupList->count() && psiPopupList->last() )
130
lastPopup = psiPopupList->last()->popup();
151
132
if ( type != AlertNone )
152
133
titleIcon = new AlertIcon(_titleIcon);
154
titleIcon = new Icon(*_titleIcon);
135
titleIcon = new PsiIcon(*_titleIcon);
156
137
FancyPopup::setHideTimeout( option.ppHideTime );
157
138
FancyPopup::setBorderColor( option.ppBorderColor );
159
popup = new FancyPopup(titleText, titleIcon, last, false);
140
popup = new FancyPopup(titleText, titleIcon, lastPopup, false);
160
141
connect(popup, SIGNAL(clicked(int)), SLOT(popupClicked(int)));
161
142
connect(popup, SIGNAL(destroyed()), SLOT(popupDestroyed()));
184
165
account->actionDefault( j );
192
170
void PsiPopup::Private::eventDestroyed()
194
if ( (popupType == AlertMessage || popupType == AlertHeadline) && !option.popupMsgs )
196
if ( popupType == AlertChat && !option.popupChats /*&& option.alertOpenChats*/ )
198
if ( popupType == AlertHeadline && !option.popupHeadlines)
200
if ( popupType == AlertFile && !option.popupFiles)
172
popup->deleteLater();
226
QBoxLayout *PsiPopup::Private::createContactInfo(const Icon *icon, QString text)
196
QBoxLayout *PsiPopup::Private::createContactInfo(const PsiIcon *icon, QString text)
228
QHBoxLayout *dataBox = new QHBoxLayout(0);
198
QHBoxLayout *dataBox = new QHBoxLayout();
231
201
IconLabel *iconLabel = new IconLabel(popup);
232
202
iconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
233
iconLabel->setIcon(icon);
203
iconLabel->setPsiIcon(icon);
234
204
dataBox->addWidget(iconLabel);
236
206
dataBox->addSpacing(5);
239
IconLabel *textLabel = new IconLabel(popup);
209
QLabel *textLabel = new QLabel(popup);
241
211
font.fromString( option.font[fPopup] );
242
212
textLabel->setFont(font);
214
textLabel->setWordWrap(false);
244
215
textLabel->setText(QString("<qt>%1</qt>").arg(clipText(text)));
245
216
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
246
217
dataBox->addWidget(textLabel);
253
224
//----------------------------------------------------------------------------
255
PsiPopup::PsiPopup(const Icon *titleIcon, QString titleText, PsiAccount *acc)
226
PsiPopup::PsiPopup(const PsiIcon *titleIcon, QString titleText, PsiAccount *acc)
257
228
d = new Private(this);
258
229
d->init(titleIcon, titleText, acc, AlertNone);
268
239
d = new Private(this);
270
241
d->popupType = type;
272
243
QString text = "Psi: ";
273
244
bool doAlertIcon = false;
276
247
case AlertOnline:
277
248
text += PsiPopup::tr("Contact online");
278
icon = (Icon *)IconsetFactory::iconPtr("status/online");
249
icon = (PsiIcon *)IconsetFactory::iconPtr("status/online");
280
251
case AlertOffline:
281
252
text += PsiPopup::tr("Contact offline");
282
icon = (Icon *)IconsetFactory::iconPtr("status/offline");
253
icon = (PsiIcon *)IconsetFactory::iconPtr("status/offline");
284
255
case AlertStatusChange:
285
256
text += PsiPopup::tr("Status change");
286
icon = (Icon *)IconsetFactory::iconPtr("status/online");
257
icon = (PsiIcon *)IconsetFactory::iconPtr("status/online");
288
259
case AlertMessage:
289
260
text += PsiPopup::tr("Incoming message");
290
icon = (Icon *)IconsetFactory::iconPtr("psi/message");
261
icon = (PsiIcon *)IconsetFactory::iconPtr("psi/message");
291
262
doAlertIcon = true;
294
265
text += PsiPopup::tr("Incoming chat message");
295
icon= (Icon *)IconsetFactory::iconPtr("psi/chat");
266
icon= (PsiIcon *)IconsetFactory::iconPtr("psi/chat");
296
267
doAlertIcon = true;
298
269
case AlertHeadline:
299
270
text += PsiPopup::tr("Headline");
300
icon= (Icon *)IconsetFactory::iconPtr("psi/headline");
271
icon= (PsiIcon *)IconsetFactory::iconPtr("psi/headline");
301
272
doAlertIcon = true;
304
275
text += PsiPopup::tr("Incoming file");
305
icon= (Icon *)IconsetFactory::iconPtr("psi/file");
276
icon= (PsiIcon *)IconsetFactory::iconPtr("psi/file");
306
277
doAlertIcon = true;
312
283
d->init(icon, text, acc, doAlertIcon ? type : AlertNone);
315
void PsiPopup::setData(const Icon *icon, QString text)
286
void PsiPopup::setData(const PsiIcon *icon, QString text)
317
288
if ( !d->popup ) {
344
315
connect(event, SIGNAL(destroyed()), d, SLOT(eventDestroyed()));
346
Icon *icon = is->statusPtr(j, r.status());
317
PsiIcon *icon = PsiIconset::instance()->statusPtr(j, r.status());
349
320
QString jid = j.full();
361
332
if ( u && !u->name().isEmpty() ) {
335
else if (event && event->type() == PsiEvent::Auth) {
336
name = ((AuthEvent*) event)->nick();
338
else if (event && event->type() == PsiEvent::Message) {
339
name = ((MessageEvent*) event)->nick();
342
if (!name.isEmpty()) {
362
343
if ( !option.ppJidClip )
363
name = "<nobr>" + u->name() + "</nobr>";
344
name = "<nobr>" + Qt::escape(name) + "</nobr>";
365
name = "<nobr>" + u->name() + " <" + jid + ">" + "</nobr>";
346
name = "<nobr>" + Qt::escape(name) + " <" + Qt::escape(jid) + ">" + "</nobr>";
368
name = "<nobr><" + jid + "></nobr>";
349
name = "<nobr><" + Qt::escape(jid) + "></nobr>";
370
QString statusString = plain2rich(status);
351
QString statusString = TextUtil::plain2rich(status);
371
352
if ( option.useEmoticons )
372
statusString = emoticonify(statusString);
353
statusString = TextUtil::emoticonify(statusString);
354
if( PsiOptions::instance()->getOption("options.ui.chat.legacy-formatting").toBool() )
355
statusString = TextUtil::legacyFormat(statusString);
374
357
if ( !statusString.isEmpty() )
375
358
statusString = "<br>" + statusString;
377
360
QString contactText = "<font size=\"+1\">" + name + "</font>" + statusString;
379
362
// hack for duplicate "Contact Online"/"Status Change" popups
380
PsiPopup *pp = psiPopupList->first();
363
foreach (PsiPopup *pp, *psiPopupList) {
382
364
if ( d->jid.full() == pp->d->jid.full() && d->status.show() == pp->d->status.show() && d->status.status() == d->status.status() ) {
383
365
if ( d->popupType == AlertStatusChange && pp->d->popupType == AlertOnline ) {
384
366
d->display = false;
404
384
if ( !jmessage->subject().isEmpty() )
405
385
message += "<font color=\"red\"><b>" + tr("Subject:") + " " + jmessage->subject() + "</b></font><br>";
406
message += plain2rich( jmessage->body() );
386
message += TextUtil::plain2rich( jmessage->body() );
408
388
QLabel *messageLabel = new QLabel(d->popup);
409
389
QFont font = messageLabel->font();
410
390
font.setPointSize(option.smallFontSize);
411
391
messageLabel->setFont(font);
413
messageLabel->setTextFormat(RichText);
414
messageLabel->setText( d->clipText(linkify( message )) );
393
messageLabel->setWordWrap(true);
394
messageLabel->setTextFormat(Qt::RichText);
395
messageLabel->setText( d->clipText(TextUtil::linkify( message )) );
415
396
messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
416
397
vbox->addWidget(messageLabel);
429
410
void PsiPopup::show()
431
if ( !d->popup || !option.ppIsOn ) {
436
417
if ( !d->id.isEmpty() /*&& option.ppNoDupes*/ ) {
437
PsiPopup *pp = psiPopupList->first();
418
foreach (PsiPopup *pp, *psiPopupList) {
439
419
if ( d->id == pp->id() && pp->popup() ) {
440
420
pp->popup()->restartHideTimer();
442
422
d->display = false;
446
pp = psiPopupList->next();
450
428
if ( d->display ) {
451
psiPopupList->prepend( this );
429
psiPopupList->append( this );
452
430
d->popup->show();