• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • libkopete
kopetecontact.cpp
Go to the documentation of this file.
1 /*
2  kopetecontact.cpp - Kopete Contact
3 
4  Copyright (c) 2002-2004 by Duncan Mac-Vicar Prett <duncan@kde.org>
5  Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
6  Copyright (c) 2002-2004 by Olivier Goffart <ogoffart @ kde.org>
7 
8  Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
9 
10  *************************************************************************
11  * *
12  * This library is free software; you can redistribute it and/or *
13  * modify it under the terms of the GNU Lesser General Public *
14  * License as published by the Free Software Foundation; either *
15  * version 2 of the License, or (at your option) any later version. *
16  * *
17  *************************************************************************
18 */
19 
20 #include "kopetecontact.h"
21 
22 #include <QApplication>
23 #include <QTextDocument>
24 #include <QTimer>
25 
26 #include <KDebug>
27 
28 #include <kdeversion.h>
29 #include <kinputdialog.h>
30 
31 #include <kabcpersistence.h>
32 #include <kdialog.h>
33 #include <klocale.h>
34 #include <kicon.h>
35 #include <kmenu.h>
36 #include <kmessagebox.h>
37 #include <k3listviewsearchline.h>
38 
39 #include "kopetecontactlist.h"
40 #include "kopeteglobal.h"
41 #include "kopeteuiglobal.h"
42 #include "kopeteprotocol.h"
43 #include "kopeteaccount.h"
44 #include "kopetestdaction.h"
45 #include "kopetechatsession.h"
46 #include "kopeteview.h"
47 #include "kopetemetacontact.h"
48 #include "kopeteappearancesettings.h"
49 #include "kopetebehaviorsettings.h"
50 #include "metacontactselectorwidget.h"
51 #include "kopeteemoticons.h"
52 #include "kopetestatusmessage.h"
53 #include "kopeteinfodialog.h"
54 #include "kopetedeletecontacttask.h"
55 
56 //For the moving to another metacontact dialog
57 #include <qlabel.h>
58 #include <qimage.h>
59 #include <qmime.h>
60 #include <kvbox.h>
61 #include <k3listview.h>
62 #include <qcheckbox.h>
63 
64 
65 namespace Kopete {
66 
67 class Contact::Private
68 {
69 public:
70  bool fileCapable;
71 
72  OnlineStatus onlineStatus;
73  Account *account;
74 
75  MetaContact *metaContact;
76 
77  QString contactId;
78  QString icon;
79 
80  QTime idleTimer;
81  unsigned long int idleTime;
82 
83  Kopete::StatusMessage statusMessage;
84  KToggleAction* toggleAlwaysVisibleAction;
85 };
86 
87 Contact::Contact( Account *account, const QString &contactId,
88  MetaContact *parent, const QString &icon )
89  : ContactListElement( parent ), d(new Private())
90 {
91  //kDebug( 14010 ) << "Creating contact with id " << contactId;
92 
93  d->contactId = contactId;
94  d->metaContact = parent;
95  connect( d->metaContact, SIGNAL(destroyed(QObject*)), this, SLOT(slotMetaContactDestroyed(QObject*)) );
96 
97  d->fileCapable = false;
98  d->account = account;
99  d->idleTime = 0;
100  d->icon = icon;
101 
102  bool duplicate = false;
103  // If can happend that a MetaContact may be used without a account
104  // (ex: for unit tests or chat window style preview)
105  if ( account )
106  {
107  // Don't register myself contacts because otherwise we can't have own contact in contact list.
108  if ( d->metaContact != Kopete::ContactList::self()->myself() )
109  duplicate = !account->registerContact( this );
110 
111  connect( account, SIGNAL(isConnectedChanged()), SLOT(slotAccountIsConnectedChanged()) );
112  }
113 
114  // Need to check this because myself() may have no parent
115  // Maybe too the metaContact doesn't have a valid protocol()
116  // (ex: for unit tests or chat window style preview)
117 
118  // if alreadyRegistered is true (which mean that this is duplicate contact) we will not add
119  // parent and the contact will die out on next Kopete restart.
120  if( !duplicate && parent && protocol() )
121  parent->addContact( this );
122 }
123 
124 Contact::~Contact()
125 {
126  //kDebug(14010) ;
127  emit( contactDestroyed( this ) );
128  delete d;
129 }
130 
131 
132 
133 OnlineStatus Contact::onlineStatus() const
134 {
135  if ( this == account()->myself() || account()->isConnected() )
136  return d->onlineStatus;
137  else
138  return protocol()->accountOfflineStatus();
139 }
140 
141 void Contact::setOnlineStatus( const OnlineStatus &status )
142 {
143  if( status == d->onlineStatus )
144  return;
145 
146  const bool oldCanAcceptFiles = canAcceptFiles();
147  OnlineStatus oldStatus = d->onlineStatus;
148  d->onlineStatus = status;
149 
150  Kopete::Global::Properties *globalProps = Kopete::Global::Properties::self();
151 
152  // Contact changed from Offline to another known online status
153  if( oldStatus.status() == OnlineStatus::Offline &&
154  status.status() != OnlineStatus::Unknown &&
155  status.status() != OnlineStatus::Offline )
156  {
157  if ( !hasProperty( globalProps->onlineSince().key() ) )
158  setProperty( globalProps->onlineSince(), QDateTime::currentDateTime() );
159  // kDebug(14010) << "REMOVING lastSeen property for " << nickName();
160  removeProperty( globalProps->lastSeen() );
161  }
162  else if( oldStatus.status() != OnlineStatus::Offline &&
163  oldStatus.status() != OnlineStatus::Unknown &&
164  status.status() == OnlineStatus::Offline ) // Contact went back offline
165  {
166  removeProperty( globalProps->onlineSince() );
167  // kDebug(14010) << "SETTING lastSeen property for " << nickName();
168  setProperty( globalProps->lastSeen(), QDateTime::currentDateTime() );
169  }
170 
171  if ( this == account()->myself() || account()->isConnected() )
172  emit onlineStatusChanged( this, status, oldStatus );
173 
174  if ( oldCanAcceptFiles != canAcceptFiles() )
175  emit canAcceptFilesChanged();
176 }
177 
178 Kopete::StatusMessage Contact::statusMessage() const
179 {
180  return d->statusMessage;
181 }
182 
183 void Contact::setStatusMessage( const Kopete::StatusMessage &statusMessage )
184 {
185  bool emitUpdate = true;
186 
187  if ( d->statusMessage.title() == statusMessage.title() && d->statusMessage.message() == statusMessage.message() )
188  emitUpdate = false;
189 
190  d->statusMessage = statusMessage;
191 
192  kDebug(14010) << "Setting up the status title property with this: " << statusMessage.title();
193  if( !statusMessage.title().isEmpty() )
194  setProperty( Kopete::Global::Properties::self()->statusTitle(), statusMessage.title() );
195  else
196  removeProperty( Kopete::Global::Properties::self()->statusTitle() );
197 
198  kDebug(14010) << "Setting up the status message property with this: " << statusMessage.message();
199  if( !statusMessage.message().isEmpty() )
200  setProperty( Kopete::Global::Properties::self()->statusMessage(), statusMessage.message() );
201  else
202  removeProperty( Kopete::Global::Properties::self()->statusMessage() );
203 
204  if ( emitUpdate )
205  emit statusMessageChanged( this );
206 }
207 
208 void Contact::slotAccountIsConnectedChanged()
209 {
210  if ( this == account()->myself() )
211  return;
212 
213  if ( account()->isConnected() )
214  emit onlineStatusChanged( this, d->onlineStatus, protocol()->accountOfflineStatus() );
215  else
216  emit onlineStatusChanged( this, protocol()->accountOfflineStatus(), d->onlineStatus );
217 }
218 
219 
220 void Contact::sendFile( const KUrl &, const QString &, uint )
221 {
222  kWarning( 14010 ) << "Plugin "
223  << protocol()->pluginId() << " has enabled file sending, "
224  << "but didn't implement it!" << endl;
225 }
226 
227 void Contact::slotAddContact()
228 {
229  if( metaContact() )
230  {
231  metaContact()->setTemporary( false );
232  ContactList::self()->addMetaContact( metaContact() );
233  }
234 }
235 
236 KMenu* Contact::popupMenu( ChatSession * )
237 {
238  return popupMenu();
239 }
240 
241 KMenu* Contact::popupMenu()
242 {
243  KMenu *menu = new KMenu();
244 
245  QString titleText;
246  const QString nick = nickName();
247  if( nick == contactId() )
248  titleText = QString::fromLatin1( "%1 (%2)" ).arg( contactId(), onlineStatus().description() );
249  else
250  titleText = QString::fromLatin1( "%1 <%2> (%3)" ).arg( nick, contactId(), onlineStatus().description() );
251  menu->addTitle( titleText );
252 
253  if( metaContact() && metaContact()->isTemporary() && contactId() != account()->myself()->contactId() )
254  {
255  KAction *actionAddContact = new KAction( KIcon("list-add-user"), i18n( "&Add to Your Contact List" ), menu );
256  connect( actionAddContact, SIGNAL(triggered(bool)), this, SLOT(slotAddContact()) );
257 
258  menu->addAction(actionAddContact);
259  menu->addSeparator();
260  }
261 
262  // FIXME: After KDE 3.2 we should make isReachable do the isConnected call so it can be removed here - Martijn
263  const bool reach = account()->isConnected() && isReachable();
264  const bool myself = (this == account()->myself());
265 
266  KAction *actionSendMessage = KopeteStdAction::sendMessage( this, SLOT(sendMessage()), menu );
267  actionSendMessage->setEnabled( reach && !myself );
268  menu->addAction( actionSendMessage );
269 
270  KAction *actionChat = KopeteStdAction::chat( this, SLOT(startChat()), menu );
271  actionChat->setEnabled( reach && !myself );
272  menu->addAction( actionChat );
273 
274  KAction *actionSendFile = KopeteStdAction::sendFile( this, SLOT(sendFile()), menu );
275  actionSendFile->setEnabled( reach && d->fileCapable && !myself );
276  menu->addAction( actionSendFile );
277 
278  // Protocol specific options will go below this separator
279  // through the use of the customContextMenuActions() function
280 
281  // Get the custom actions from the protocols ( pure virtual function )
282  QList<KAction*> *customActions = customContextMenuActions();
283  if( customActions && !customActions->isEmpty() )
284  {
285  menu->addSeparator();
286  QList<KAction*>::iterator it, itEnd = customActions->end();
287  for( it = customActions->begin(); it != itEnd; ++it )
288  menu->addAction( (*it) );
289  }
290  delete customActions;
291 
292  menu->addSeparator();
293 
294  if( metaContact() && !metaContact()->isTemporary() )
295  {
296  KAction* changeMetaContact = KopeteStdAction::changeMetaContact( this, SLOT(changeMetaContact()), menu );
297  menu->addAction( changeMetaContact );
298 
299  d->toggleAlwaysVisibleAction = new KToggleAction( i18n( "Visible when offline" ), menu );
300  d->toggleAlwaysVisibleAction->setChecked( property( Kopete::Global::Properties::self()->isAlwaysVisible() ).value().toBool() );
301  menu->addAction( d->toggleAlwaysVisibleAction );
302  connect( d->toggleAlwaysVisibleAction, SIGNAL(toggled(bool)), this, SLOT(toggleAlwaysVisible()) );
303  }
304 
305  menu->addAction( KopeteStdAction::contactInfo( this, SLOT(slotUserInfo()), menu ) );
306 
307 #if 0 //this is not fully implemented yet (and doesn't work). disable for now - Olivier 2005-01-11
308  if ( account()->isBlocked( d->contactId ) )
309  KopeteStdAction::unblockContact( this, SLOT(slotUnblock()), menu, "actionUnblockContact" )->plug( menu );
310  else
311  KopeteStdAction::blockContact( this, SLOT(slotBlock()), menu, "actionBlockContact" )->plug( menu );
312 #endif
313 
314  if( metaContact() && !metaContact()->isTemporary() )
315  menu->addAction( KopeteStdAction::deleteContact( this, SLOT(slotDelete()), menu ) );
316 
317  return menu;
318 }
319 
320 void Contact::toggleAlwaysVisible()
321 {
322  bool alwaysVisible = property( Kopete::Global::Properties::self()->isAlwaysVisible() ).value().toBool();
323  setProperty( Kopete::Global::Properties::self()->isAlwaysVisible(), !alwaysVisible );
324  d->toggleAlwaysVisibleAction->setChecked( !alwaysVisible );
325 }
326 
327 void Contact::changeMetaContact()
328 {
329  QPointer <KDialog> moveDialog = new KDialog( Kopete::UI::Global::mainWidget() );
330  moveDialog->setCaption( i18n( "Move Contact" ) );
331  moveDialog->setButtons( KDialog::Ok | KDialog::Cancel );
332  moveDialog->setDefaultButton( KDialog::Ok );
333  moveDialog->showButtonSeparator( true );
334 
335  KVBox *w = new KVBox( moveDialog );
336  w->setSpacing( KDialog::spacingHint() );
337  Kopete::UI::MetaContactSelectorWidget *selector = new Kopete::UI::MetaContactSelectorWidget(w);
338  selector->setLabelMessage(i18n( "Select the meta contact to which you want to move this contact:" ));
339  // exclude this metacontact as a target metacontact for the move
340  selector->excludeMetaContact( metaContact() );
341  QCheckBox *chkCreateNew = new QCheckBox( i18n( "Create a new metacontact for this contact" ), w );
342  chkCreateNew ->setWhatsThis( i18n( "If you select this option, a new metacontact will be created in the top-level group "
343  "with the name of this contact and the contact will be moved to it." ) );
344  QObject::connect( chkCreateNew , SIGNAL(toggled(bool)) , selector , SLOT (setDisabled(bool)) ) ;
345 
346  moveDialog->setMainWidget(w);
347  if( moveDialog->exec() == QDialog::Accepted )
348  {
349  Kopete::MetaContact *mc = selector->metaContact();
350  if(chkCreateNew->isChecked())
351  {
352  mc=new Kopete::MetaContact();
353 
354  if ( metaContact() )
355  { // Add new metaContact to old groups so we don't move it to Top Level group
356  foreach ( Kopete::Group* group, metaContact()->groups() )
357  mc->addToGroup( group );
358  }
359 
360  Kopete::ContactList::self()->addMetaContact(mc);
361  }
362  if( mc )
363  {
364  setMetaContact( mc );
365  }
366  }
367 
368  if ( moveDialog )
369  moveDialog->deleteLater();
370 }
371 
372 void Contact::slotMetaContactDestroyed( QObject* mc )
373 {
374  if (mc != d->metaContact)
375  return;
376 
377  d->metaContact = 0;
378 }
379 
380 void Contact::setMetaContact( MetaContact *m )
381 {
382  MetaContact *old = d->metaContact;
383  if(old==m) //that make no sens
384  return;
385 
386  if( old )
387  {
388  old->removeContact( this );
389  disconnect( old, SIGNAL(destroyed(QObject*)), this, SLOT(slotMetaContactDestroyed(QObject*)) );
390 
391  if(old->contacts().isEmpty())
392  {
393  //remove the old metacontact. (this delete the MC)
394  ContactList::self()->removeMetaContact(old);
395  }
396  else
397  {
398  d->metaContact = m; //i am forced to do that now if i want the next line works
399  //remove cached data for this protocol which will not be removed since we disconnected
400  protocol()->serialize( old );
401  }
402  }
403 
404  d->metaContact = m;
405  setParent( m );
406 
407  if( m )
408  {
409  m->addContact( this );
410  connect( m, SIGNAL(destroyed(QObject*)), this, SLOT(slotMetaContactDestroyed(QObject*)) );
411  // it is necessary to call this write here, because MetaContact::addContact() does not differentiate
412  // between adding completely new contacts (which should be written to kabc) and restoring upon restart
413  // (where no write is needed).
414  KABCPersistence::self()->write( m );
415  }
416  sync();
417 }
418 
419 void Contact::serialize( QMap<QString, QString> &/*serializedData*/,
420  QMap<QString, QString> & /* addressBookData */ )
421 {
422 }
423 
424 bool Contact::isReachable()
425 {
426  // The default implementation returns false when offline and true
427  // otherwise. Subclass if you need more control over the process.
428  return onlineStatus().status() != OnlineStatus::Offline;
429 }
430 
431 
432 void Contact::startChat()
433 {
434  KopeteView *v=manager( CanCreate )->view(true, QString::fromLatin1("kopete_chatwindow") );
435  if(v)
436  v->raise(true);
437 }
438 
439 void Contact::sendMessage()
440 {
441  KopeteView *v=manager( CanCreate )->view(true, QString::fromLatin1("kopete_emailwindow") );
442  if(v)
443  v->raise(true);
444 }
445 
446 void Contact::execute()
447 {
448  // FIXME: After KDE 3.2 remove the isConnected check and move it to isReachable - Martijn
449  if ( account()->isConnected() && isReachable() )
450  {
451  KopeteView *v=manager( CanCreate )->view(true, Kopete::BehaviorSettings::self()->viewPlugin() );
452  if(v)
453  v->raise(true);
454  }
455  else
456  {
457  KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry,
458  i18n( "This user is not reachable at the moment. Please try a protocol that supports offline sending, or wait "
459  "until this user comes online." ), i18n( "User is Not Reachable" ) );
460  }
461 }
462 
463 void Contact::slotDelete()
464 {
465  if ( KMessageBox::warningContinueCancel( Kopete::UI::Global::mainWidget(),
466  i18n( "Are you sure you want to remove the contact '%1' from your contact list?" ,
467  d->contactId ), i18n( "Remove Contact" ), KGuiItem(i18n("Remove"), QString::fromLatin1("list-remove-user") ), KStandardGuiItem::cancel(),
468  QString::fromLatin1("askRemoveContact"), KMessageBox::Notify | KMessageBox::Dangerous )
469  == KMessageBox::Continue )
470  {
471  Kopete::DeleteContactTask *deleteTask = new Kopete::DeleteContactTask(this);
472  deleteTask->start();
473  }
474 }
475 
476 void Contact::deleteContact()
477 {
478  // Default implementation simply deletes the contact
479  deleteLater();
480 }
481 
482 
483 MetaContact * Contact::metaContact() const
484 {
485  return d->metaContact;
486 }
487 
488 QString Contact::contactId() const
489 {
490  return d->contactId;
491 }
492 
493 Protocol * Contact::protocol() const
494 {
495  return d->account ? d->account->protocol() : 0L;
496 }
497 
498 Account * Contact::account() const
499 {
500  return d->account;
501 }
502 
503 
504 
505 void Contact::sync(unsigned int)
506 {
507  /* Default implementation does nothing */
508 }
509 
510 QString& Contact::icon() const
511 {
512  return d->icon;
513 }
514 
515 void Contact::setIcon( const QString& icon )
516 {
517  d->icon = icon;
518  return;
519 }
520 
521 QList<KAction *> *Contact::customContextMenuActions()
522 {
523  return 0L;
524 }
525 
526 QList<KAction*> *Contact::customContextMenuActions( ChatSession * /* manager */ )
527 {
528  return customContextMenuActions();
529 }
530 
531 bool Contact::isOnline() const
532 {
533  return onlineStatus().isDefinitelyOnline();
534 }
535 
536 bool Contact::isFileCapable() const
537 {
538  return d->fileCapable;
539 }
540 
541 void Contact::setFileCapable( bool filecap )
542 {
543  if ( d->fileCapable != filecap )
544  {
545  d->fileCapable = filecap;
546  emit canAcceptFilesChanged();
547  }
548 }
549 
550 bool Contact::canAcceptFiles() const
551 {
552  return isOnline() && d->fileCapable;
553 }
554 
555 unsigned long int Contact::idleTime() const
556 {
557  if(d->idleTime==0)
558  return 0;
559 
560  return d->idleTime+(d->idleTimer.elapsed()/1000);
561 }
562 
563 void Contact::setIdleTime( unsigned long int t )
564 {
565  bool idleChanged = false;
566  if(d->idleTime != t)
567  idleChanged = true;
568  d->idleTime=t;
569  if(t > 0)
570  d->idleTimer.start();
571 //FIXME: if t == 0, idleTime() will now return garbage
572 // else
573 // d->idleTimer.stop();
574  if(idleChanged)
575  emit idleStateChanged(this);
576 }
577 
578 QString Contact::toolTip() const
579 {
580  Kopete::Property p;
581  QString tip;
582  const QStringList shownProps = Kopete::AppearanceSettings::self()->toolTipContents();
583 
584  // --------------------------------------------------------------------------
585  // Fixed part of tooltip
586 
587  QString iconName;
588  if ( this == account()->myself() )
589  {
590  iconName = QString::fromLatin1("kopete-account-icon:%1:%2")
591  .arg( QString(QUrl::toPercentEncoding( protocol()->pluginId() )),
592  QString(QUrl::toPercentEncoding( account()->accountId() )) );
593 
594  }
595  else
596  {
597  iconName = QString::fromLatin1("kopete-contact-icon:%1:%2:%3")
598  .arg( QString(QUrl::toPercentEncoding( protocol()->pluginId() )),
599  QString(QUrl::toPercentEncoding( account()->accountId() )),
600  QString(QUrl::toPercentEncoding( contactId() )) );
601  }
602 
603  // TODO: the nickname should be a configurable properties, like others. -Olivier
604  QString nick = nickName();
605  if ( nick == contactId() )
606  {
607  tip = i18nc( "@label:textbox %3 is contact-display-name, %1 is its status",
608  "<b><nobr>%3</nobr></b><br /><img src=\"%2\">&nbsp;%1",
609  Kopete::Message::escape( onlineStatus().description() ), iconName,
610  Kopete::Message::escape( d->contactId ) );
611  }
612  else
613  {
614  tip = i18nc( "@label:textbox %4 is contact-display-name, %3 is contact-id, %1 is its status",
615  "<nobr><b>%4</b> (%3)</nobr><br /><img src=\"%2\">&nbsp;%1",
616  Kopete::Message::escape( onlineStatus().description() ), iconName,
617  Kopete::Message::escape( contactId() ),
618  Kopete::Emoticons::parseEmoticons( Kopete::Message::escape( nick ) ) );
619  }
620 
621  // --------------------------------------------------------------------------
622  // Configurable part of tooltip
623 
624  // FIXME: It shouldn't use QString to identity the properties. Instead it should use PropertyTmpl::key()
625  for(QStringList::ConstIterator it=shownProps.constBegin(); it!=shownProps.constEnd(); ++it)
626  {
627  if((*it) == Kopete::Global::Properties::self()->fullName().key())
628  {
629  const QString name = formattedName();
630  if(!name.isEmpty())
631  {
632  tip += i18nc("@label:textbox formatted name",
633  "<br /><b>Full Name:</b>&nbsp;<nobr>%1</nobr>", Qt::escape(name));
634  }
635  }
636  else if ((*it) == Kopete::Global::Properties::self()->idleTime().key())
637  {
638  const QString time = formattedIdleTime();
639  if(!time.isEmpty())
640  {
641  tip += i18nc("@label:textbox formatted idle time",
642  "<br /><b>Idle:</b>&nbsp;<nobr>%1</nobr>", time);
643  }
644  }
645  else if ((*it) == QString::fromLatin1("homePage"))
646  {
647  const QString url = property(*it).value().toString();
648  if(!url.isEmpty())
649  {
650  tip += i18nc("@label:textbox formatted url",
651  "<br /><b>Home Page:</b>&nbsp;<a href=\"%1\"><nobr>%2</nobr></a>",
652  QString(QUrl::toPercentEncoding( url )), Kopete::Message::escape( Qt::escape(url) ) );
653  }
654  }
655  else if ((*it) == Kopete::Global::Properties::self()->statusTitle().key() )
656  {
657  const QString statusTitle = property(*it).value().toString();
658  if(!statusTitle.isEmpty())
659  {
660  tip += i18nc("@label:textbox formatted status title",
661  "<br /><b>Status&nbsp;Title:</b>&nbsp;%1", Kopete::Emoticons::parseEmoticons( Kopete::Message::escape(statusTitle) ) );
662  }
663  }
664  else if ((*it) == Kopete::Global::Properties::self()->statusMessage().key() )
665  {
666  const QString statusmsg = property(*it).value().toString();
667  if(!statusmsg.isEmpty())
668  {
669  tip += i18nc("@label:textbox formatted status message",
670  "<br /><b>Status&nbsp;Message:</b>&nbsp;%1", Kopete::Emoticons::parseEmoticons( Kopete::Message::escape(statusmsg) ) );
671  }
672  }
673  else
674  {
675  p = property(*it);
676  if(!p.isNull())
677  {
678  QVariant val = p.value();
679  QString valueText;
680 
681  switch(val.type())
682  {
683  case QVariant::DateTime:
684  valueText = KGlobal::locale()->formatDateTime(val.toDateTime());
685  valueText = Kopete::Message::escape( valueText );
686  break;
687  case QVariant::Date:
688  valueText = KGlobal::locale()->formatDate(val.toDate());
689  valueText = Kopete::Message::escape( valueText );
690  break;
691  case QVariant::Time:
692  valueText = KGlobal::locale()->formatTime(val.toTime());
693  valueText = Kopete::Message::escape( valueText );
694  break;
695  default:
696  if( p.isRichText() )
697  {
698  valueText = val.toString();
699  }
700  else
701  {
702  valueText = Kopete::Message::escape( val.toString() );
703  }
704  }
705 
706  if (valueText.size() > 1000) {
707  valueText.truncate(997);
708  valueText += "...";
709  }
710 
711  tip += i18nc("@label:textbox property label %2 is name, %1 is value",
712  "<br /><nobr><b>%2:</b></nobr>&nbsp;%1",
713  valueText, Qt::escape(p.tmpl().label()) );
714  }
715  }
716  }
717 
718  return tip;
719 }
720 
721 QString Kopete::Contact::formattedName() const
722 {
723  if( hasProperty( Kopete::Global::Properties::self()->fullName().key() ) )
724  return property( Kopete::Global::Properties::self()->fullName() ).value().toString();
725 
726  QString ret;
727  Kopete::Property first, last;
728 
729  first = property( Kopete::Global::Properties::self()->firstName() );
730  last = property( Kopete::Global::Properties::self()->lastName() );
731  if(!first.isNull())
732  {
733  if(!last.isNull()) // contact has both first and last name
734  {
735  ret = i18nc("firstName lastName", "%2 %1",
736  last.value().toString(),
737  first.value().toString());
738  }
739  else // only first name set
740  {
741  ret = first.value().toString();
742  }
743  }
744  else if(!last.isNull()) // only last name set
745  {
746  ret = last.value().toString();
747  }
748 
749  return ret;
750 }
751 
752 QString Kopete::Contact::formattedIdleTime() const
753 {
754  QString ret;
755  unsigned long int leftTime = idleTime();
756 
757  if ( leftTime > 0 )
758  { // FIXME: duplicated from code in kopetecontact listview.cpp
759  unsigned long int days, hours, mins, secs;
760 
761  days = leftTime / ( 60*60*24 );
762  leftTime = leftTime % ( 60*60*24 );
763  hours = leftTime / ( 60*60 );
764  leftTime = leftTime % ( 60*60 );
765  mins = leftTime / 60;
766  secs = leftTime % 60;
767 
768  if ( days != 0 )
769  {
770  ret = i18nc( "<days>d <hours>h <minutes>m <seconds>s",
771  "%4d %3h %2m %1s" ,
772  secs ,
773  mins ,
774  hours ,
775  days );
776  }
777  else if ( hours != 0 )
778  {
779  ret = i18nc( "<hours>h <minutes>m <seconds>s", "%3h %2m %1s" ,
780  secs ,
781  mins ,
782  hours );
783  }
784  else
785  {
786  // xgettext: no-c-format
787  ret = i18nc( "<minutes>m <seconds>s", "%2m %1s" ,
788  secs ,
789  mins );
790  }
791  }
792  return ret;
793 }
794 
795 void Kopete::Contact::slotBlock()
796 {
797  account()->block( d->contactId );
798 }
799 
800 void Kopete::Contact::slotUnblock()
801 {
802  account()->unblock( d->contactId );
803 }
804 
805 void Kopete::Contact::setNickName( const QString &name )
806 {
807  setProperty( Kopete::Global::Properties::self()->nickName(), name );
808 }
809 
810 QString Kopete::Contact::nickName() const
811 {
812  const QString nick = property( Kopete::Global::Properties::self()->nickName() ).value().toString();
813  if( !nick.isEmpty() )
814  return nick;
815 
816  return contactId();
817 }
818 
819 void Kopete::Contact::setPhoto(const QString &photoPath)
820 {
821  setProperty( Kopete::Global::Properties::self()->photo(), photoPath );
822 }
823 
824 
825 } //END namespace Kopete
826 
827 #include "kopetecontact.moc"
Kopete::Contact::isReachable
virtual bool isReachable()
Get whether this contact can receive messages.
Definition: kopetecontact.cpp:424
Kopete::Contact::setStatusMessage
void setStatusMessage(const Kopete::StatusMessage &statusMessage)
Set the contact's status message.
Definition: kopetecontact.cpp:183
Kopete::ContactList::myself
MetaContact * myself()
return the metacontact that represent the user itself.
Definition: kopetecontactlist.cpp:349
kopetemetacontact.h
Kopete::ContactList::self
static ContactList * self()
The contact list is a singleton object.
Definition: kopetecontactlist.cpp:71
Kopete::OnlineStatus
Definition: kopeteonlinestatus.h:68
status
OnlineStatus::StatusType status
Definition: kopeteonlinestatus.cpp:103
Kopete::DeleteContactTask::start
virtual void start()
Begin the task.
Definition: kopetedeletecontacttask.cpp:52
KopeteStdAction::changeMetaContact
static KAction * changeMetaContact(const QObject *recvr, const char *slot, QObject *parent)
Standard action to change a contacts Kopete::MetaContact.
Definition: kopetestdaction.cpp:116
Kopete::Account::myself
Contact * myself() const
Retrieve the 'myself' contact.
Definition: kopeteaccount.cpp:535
Kopete::MetaContact::addToGroup
void addToGroup(Kopete::Group *to)
Add a contact to another group.
Definition: kopetemetacontact.cpp:1037
kopeteappearancesettings.h
Kopete::MetaContact::setTemporary
void setTemporary(bool b=true, Kopete::Group *group=0L)
Set if this is a temporary contact.
Definition: kopetemetacontact.cpp:1142
Kopete::Emoticons::parseEmoticons
static QString parseEmoticons(const QString &text, KEmoticonsTheme::ParseMode mode=KEmoticonsTheme::DefaultParse, const QStringList &exclude=QStringList())
Definition: kopeteemoticons.cpp:36
Kopete::Global::Properties::self
static Properties * self()
Singleton accessor for this class.
Definition: kopeteglobal.cpp:49
Kopete::Contact::toggleAlwaysVisible
void toggleAlwaysVisible()
Toggle the visibility of this contact even if offline.
Definition: kopetecontact.cpp:320
Kopete::Contact::execute
void execute()
The user clicked on the contact, do the default action.
Definition: kopetecontact.cpp:446
Kopete::Contact::canAcceptFilesChanged
void canAcceptFilesChanged()
Emitted when the file transfer capability of this contact has changed.
kopeteaccount.h
Kopete::UI::MetaContactSelectorWidget::excludeMetaContact
void excludeMetaContact(Kopete::MetaContact *mc)
excludes a metacontact from being shown in the list if the metacontact is already excluded...
Definition: metacontactselectorwidget.cpp:261
metacontactselectorwidget.h
Kopete::Contact::onlineStatusChanged
void onlineStatusChanged(Kopete::Contact *contact, const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus)
The contact's online status changed.
Kopete::Contact::icon
QString & icon() const
Returns the name of the icon to use for this contact If null, the protocol icon need to be used...
KopeteView::raise
virtual void raise(bool activate=false)=0
Raises the view above other windows.
Kopete::Contact::setMetaContact
void setMetaContact(MetaContact *m)
Move this contact to a new MetaContact.
Definition: kopetecontact.cpp:380
Kopete::StatusMessage
This class encapsulate a status message.
Definition: kopetestatusmessage.h:48
KopeteStdAction::unblockContact
static KAction * unblockContact(const QObject *recvr, const char *slot, QObject *parent)
Standard action to unblock a contact.
Definition: kopetestdaction.cpp:139
Kopete::KABCPersistence::write
void write(MetaContact *mc)
Change the KABC data associated with this metacontact.
Definition: kabcpersistence.cpp:102
Kopete::Protocol
base class of every protocol.
Definition: kopeteprotocol.h:62
kabcpersistence.h
Kopete::Contact::idleStateChanged
void idleStateChanged(Kopete::Contact *contact)
The contact's idle state changed.
Kopete::Account::isConnected
bool isConnected
Definition: kopeteaccount.h:81
Kopete::DeleteContactTask
Delete a contact in Kopete.
Definition: kopetedeletecontacttask.h:52
Kopete::OnlineStatus::Unknown
Refers to protocols where state cannot be determined.
Definition: kopeteonlinestatus.h:90
Kopete::PropertyContainer::property
const Kopete::Property & property(const QString &key) const
Get the value of a property with key "key".
Definition: kopetepropertycontainer.cpp:111
Kopete::OnlineStatus::Offline
State where you really cannot be contacted.
Definition: kopeteonlinestatus.h:98
Kopete::Contact::account
Account * account() const
Get the account that this contact belongs to.
Definition: kopetecontact.cpp:498
KDialog
Kopete::MetaContact::removeContact
void removeContact(Contact *c, bool deleted=false)
remove the contact from this metacontact
Definition: kopetemetacontact.cpp:161
Kopete::OnlineStatus::status
StatusType status() const
Return the status.
Definition: kopeteonlinestatus.cpp:242
Kopete::OnlineStatus::isDefinitelyOnline
bool isDefinitelyOnline() const
Definition: kopeteonlinestatus.cpp:287
QObject
Kopete::Property::isRichText
bool isRichText() const
Returns true if this property is HTML formatted.
Definition: kopeteproperty.cpp:244
Kopete::Global::Properties
Global facility to query/store templates that are needed by KopeteProperty.
Definition: kopeteglobal.h:45
Kopete::ChatSession
Definition: kopetechatsession.h:74
Kopete::Contact::canAcceptFiles
bool canAcceptFiles() const
Get whether or not this contact can accept file transfers.
Kopete::Contact::nickName
QString nickName() const
Convenience method to retrieve the nickName property.
Kopete::Contact::statusMessageChanged
void statusMessageChanged(Kopete::Contact *contact)
The contact's status message changed.
kopeteuiglobal.h
Kopete::Contact::formattedName
QString formattedName() const
Returns a formatted string of "firstName" and/or "lastName" properties if present.
Kopete::Contact::contactDestroyed
void contactDestroyed(Kopete::Contact *contact)
The contact is about to be destroyed.
kopeteinfodialog.h
Kopete::Global::Properties::fullName
const PropertyTmpl & fullName() const
Definition: kopeteglobal.cpp:127
Kopete::UI::MetaContactSelectorWidget::setLabelMessage
void setLabelMessage(const QString &msg)
sets the widget label message example: Please select a contact or, Choose a contact to delete ...
Definition: metacontactselectorwidget.cpp:295
KopeteStdAction::sendFile
static KAction * sendFile(const QObject *recvr, const char *slot, QObject *parent)
Standard action to initiate sending a file to a contact.
Definition: kopetestdaction.cpp:96
Kopete::Contact::onlineStatus
OnlineStatus onlineStatus() const
Get the online status of the contact.
Definition: kopetecontact.cpp:133
Kopete::Contact::slotUserInfo
virtual void slotUserInfo()
Method to retrieve user information.
Definition: kopetecontact.h:411
Kopete::Contact::protocol
Protocol * protocol() const
Get the protocol that the contact belongs to.
Definition: kopetecontact.cpp:493
Kopete::Message::escape
static QString escape(const QString &)
Transform a plaintext message into HTML.
Definition: kopetemessage.cpp:350
Kopete::ContactListElement
Definition: kopetecontactlistelement.h:46
Kopete::Property::tmpl
const PropertyTmpl & tmpl() const
Getter for this properties template.
Definition: kopeteproperty.cpp:234
kopeteemoticons.h
kopetedeletecontacttask.h
Kopete::Plugin::pluginId
QString pluginId() const
Get the plugin id.
Definition: kopeteplugin.cpp:46
kopetestatusmessage.h
Kopete::Contact::popupMenu
KMenu * popupMenu()
Get the Context Menu for this contact.
Definition: kopetecontact.cpp:241
kopeteprotocol.h
Kopete::Contact::sendFile
virtual void sendFile(const KUrl &sourceURL=KUrl(), const QString &fileName=QString(), uint fileSize=0L)
This is the Contact level slot for sending files.
Definition: kopetecontact.cpp:220
Kopete::StatusMessage::message
QString message() const
Return the current status message.
Definition: kopetestatusmessage.cpp:75
Kopete::Contact::setPhoto
void setPhoto(const QString &photoPath)
Convience method to set the photo property.
Definition: kopetecontact.cpp:819
KopeteStdAction::sendMessage
static KAction * sendMessage(const QObject *recvr, const char *slot, QObject *parent)
Standard action to send a single message.
Definition: kopetestdaction.cpp:86
Kopete::Contact::manager
virtual ChatSession * manager(CanCreateFlags canCreate=CannotCreate)=0
Returns the primary message manager affiliated with this contact Although a contact can have more tha...
kopetechatsession.h
KopeteStdAction::blockContact
static KAction * blockContact(const QObject *recvr, const char *slot, QObject *parent)
Standard action to block a contact.
Definition: kopetestdaction.cpp:134
kopetecontactlist.h
KopeteStdAction::contactInfo
static KAction * contactInfo(const QObject *recvr, const char *slot, QObject *parent)
Standard action to open a user info dialog.
Definition: kopetestdaction.cpp:91
Kopete::MetaContact::contacts
QList< Contact * > contacts() const
Retrieve the list of contacts that are part of the meta contact.
Definition: kopetemetacontact.cpp:1270
Kopete::PropertyContainer::hasProperty
bool hasProperty(const QString &key) const
Check for existence of a certain property stored using "key".
Definition: kopetepropertycontainer.cpp:106
Kopete::Contact::startChat
void startChat()
This should typically pop up a KopeteChatWindow.
Definition: kopetecontact.cpp:432
Kopete::Contact::formattedIdleTime
QString formattedIdleTime() const
Returns a formatted string of idleTime().
KopeteStdAction::chat
static KAction * chat(const QObject *recvr, const char *slot, QObject *parent)
Standard action to start a chat.
Definition: kopetestdaction.cpp:81
Kopete::Contact::changeMetaContact
void changeMetaContact()
Changes the MetaContact that this contact is a part of.
Definition: kopetecontact.cpp:327
Kopete::Contact::statusMessage
Kopete::StatusMessage statusMessage() const
Get the current status message of the contact.
Definition: kopetecontact.cpp:178
Kopete::AppearanceSettings::self
static AppearanceSettings * self()
Definition: kopeteappearancesettings.cpp:23
Kopete::Account::registerContact
bool registerContact(Contact *c)
Definition: kopeteaccount.cpp:308
Kopete::Global::Properties::lastSeen
const PropertyTmpl & lastSeen() const
Definition: kopeteglobal.cpp:145
Kopete::PropertyContainer::removeProperty
void removeProperty(const Kopete::PropertyTmpl &tmpl)
Remove a property if it exists.
Definition: kopetepropertycontainer.cpp:158
Kopete::UI::Global::mainWidget
KOPETE_EXPORT QWidget * mainWidget()
Returns the main widget - this is the widget that message boxes and KNotify stuff should use as a par...
Definition: kopeteuiglobal.cpp:37
Kopete::ContactList::addMetaContact
void addMetaContact(Kopete::MetaContact *c)
Add the metacontact into the contact list When calling this method, the contact has to be already pla...
Definition: kopetecontactlist.cpp:235
Kopete::Contact::deleteContact
virtual KDE_DEPRECATED void deleteContact()
Definition: kopetecontact.cpp:476
Kopete::Global::Properties::statusMessage
const PropertyTmpl & statusMessage() const
Definition: kopeteglobal.cpp:157
Kopete::UI::MetaContactSelectorWidget
Definition: metacontactselectorwidget.h:38
Kopete::Contact::isOnline
bool isOnline() const
Get whether this contact is online.
Kopete::Contact::metaContact
MetaContact * metaContact() const
Get the metacontact for this contact.
Definition: kopetecontact.cpp:483
Kopete::MetaContact::addContact
void addContact(Contact *c)
Add a contact which has just been deserialised to the meta contact.
Definition: kopetemetacontact.cpp:90
Kopete::Protocol::serialize
void serialize(Kopete::MetaContact *metaContact)
Serialize meta contact into the metacontact's plugin data Call serialize() for all contained contacts...
Definition: kopeteprotocol.cpp:175
Kopete::Property
Definition: kopeteproperty.h:150
Kopete::Global::Properties::onlineSince
const PropertyTmpl & onlineSince() const
Return default template for a contact's online-since time (i.e.
Definition: kopeteglobal.cpp:139
Kopete::Contact::setFileCapable
void setFileCapable(bool filecap)
Set the file transfer capability of this contact.
Definition: kopetecontact.cpp:541
Kopete::BehaviorSettings::self
static BehaviorSettings * self()
Definition: kopetebehaviorsettings.cpp:23
KAction
Kopete::Group
Class which represents the Group.
Definition: kopetegroup.h:44
Kopete::ContactList::removeMetaContact
void removeMetaContact(Kopete::MetaContact *contact)
Remove a metacontact from the contact list.
Definition: kopetecontactlist.cpp:251
Kopete::Contact::toolTip
QString toolTip() const
Get the tooltip for this contact Makes use of formattedName() and formattedIdleTime().
Kopete::Contact::Contact
Contact(Account *account, const QString &id, MetaContact *parent, const QString &icon=QString())
Create new contact.
Definition: kopetecontact.cpp:87
Kopete::Contact::sendMessage
void sendMessage()
Pops up an email type window.
Definition: kopetecontact.cpp:439
Kopete::Property::value
const QVariant & value() const
Getter for this properties value.
Definition: kopeteproperty.cpp:229
Kopete::PropertyContainer::setProperty
void setProperty(const Kopete::PropertyTmpl &tmpl, const QVariant &value)
Add or Set a property for this contact.
Definition: kopetepropertycontainer.cpp:129
Kopete::Contact::sync
virtual void sync(unsigned int changed=0xFF)
Syncronise the server and the metacontact.
Definition: kopetecontact.cpp:505
Kopete::MetaContact
Definition: kopetemetacontact.h:54
Kopete::PropertyTmpl::label
const QString & label() const
Getter for i18ned label.
Definition: kopeteproperty.cpp:142
Kopete::Contact::customContextMenuActions
virtual QList< KAction * > * customContextMenuActions()
Get the set of custom menu items for this contact.
Definition: kopetecontact.cpp:521
Kopete::Contact::isFileCapable
bool isFileCapable() const
Get whether or not this contact is capable of file transfers.
Definition: kopetecontact.cpp:536
Kopete::Protocol::accountOfflineStatus
Kopete::OnlineStatus accountOfflineStatus() const
Returns the status used for contacts when accounts of this protocol are offline.
Definition: kopeteprotocol.cpp:94
Kopete::Contact::CanCreate
Definition: kopetecontact.h:283
kopeteview.h
Kopete::Contact::setNickName
void setNickName(const QString &name)
Convenience method to set the nickName property to the specified value.
Definition: kopetecontact.cpp:805
Kopete::Property::isNull
bool isNull() const
Returns true if this object is an empty Property (i.e.
Definition: kopeteproperty.cpp:239
Kopete::Contact::setIcon
void setIcon(const QString &icon)
Change the icon to use for this contact If you don't want to have the protocol icon as icon for this ...
Definition: kopetecontact.cpp:515
Kopete::Contact::idleTime
virtual unsigned long int idleTime() const
Get the time (in seconds) this contact has been idle It will return the time set in setIdleTime() wit...
Definition: kopetecontact.cpp:555
Kopete::Contact::contactId
QString contactId() const
Get the unique id that identifies a contact.
Kopete::PropertyTmpl::key
const QString & key() const
Getter for the unique key.
Definition: kopeteproperty.cpp:137
Kopete::ChatSession::view
KopeteView * view(bool canCreate=false, const QString &requestedPlugin=QString())
the manager's view
Definition: kopetechatsession.cpp:641
KopeteView
Definition: kopeteview.h:40
Kopete::KABCPersistence::self
static KABCPersistence * self()
Retrieve the instance of AccountManager.
Definition: kabcpersistence.cpp:86
kopetebehaviorsettings.h
Kopete::Contact::serialize
virtual void serialize(QMap< QString, QString > &serializedData, QMap< QString, QString > &addressBookData)
Serialize the contact for storage in the contact list.
Definition: kopetecontact.cpp:419
Kopete::Account
The Kopete::Account class handles one account.
Definition: kopeteaccount.h:72
Kopete::Contact::setOnlineStatus
void setOnlineStatus(const OnlineStatus &status)
Set the contact's online status.
Definition: kopetecontact.cpp:141
Kopete::AppearanceSettings::toolTipContents
static QStringList toolTipContents()
Get Contact properties that contact tooltip will show.
Definition: kopeteappearancesettings.h:384
Kopete::Contact::~Contact
~Contact()
Definition: kopetecontact.cpp:124
Kopete::UI::MetaContactSelectorWidget::metaContact
Kopete::MetaContact * metaContact()
Definition: metacontactselectorwidget.cpp:230
kopetestdaction.h
kopetecontact.h
kopeteglobal.h
Kopete::StatusMessage::title
QString title() const
Return the current status title.
Definition: kopetestatusmessage.cpp:109
Kopete::Contact::setIdleTime
void setIdleTime(unsigned long int)
Set the current idle time in seconds.
Definition: kopetecontact.cpp:563
Kopete::Global::Properties::statusTitle
const PropertyTmpl & statusTitle() const
Definition: kopeteglobal.cpp:151
name
const char * name
Definition: kopeteonlinestatus.cpp:104
KopeteStdAction::deleteContact
static KAction * deleteContact(const QObject *recvr, const char *slot, QObject *parent)
Standard action to delete a contact.
Definition: kopetestdaction.cpp:121
Kopete::Contact::fileCapable
bool fileCapable
Definition: kopetecontact.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal