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

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • contactlist
contactlistmodel.cpp
Go to the documentation of this file.
1 /*
2  Kopete Contactlist Model
3 
4  Copyright (c) 2007 by Aleix Pol <aleixpol@gmail.com>
5  Copyright (c) 2008 by Matt Rogers <mattr@kde.org>
6  Copyright (c) 2009 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
7  Copyright 2009 by Roman Jarosz <kedgedev@gmail.com>
8 
9  Kopete (c) 2002-2009 by the Kopete developers <kopete-devel@kde.org>
10 
11  *************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  *************************************************************************
19 */
20 
21 #include "contactlistmodel.h"
22 
23 #include <QMimeData>
24 #include <QFile>
25 #include <QTextDocument>
26 #include <QDomDocument>
27 
28 #include <KDebug>
29 #include <KEmoticonsTheme>
30 #include <KMessageBox>
31 
32 #include "kopeteaccount.h"
33 #include "kopetepicture.h"
34 #include "kopetemetacontact.h"
35 #include "kopeteprotocol.h"
36 #include "kopetecontact.h"
37 #include "kopetecontactlist.h"
38 #include "kopeteitembase.h"
39 #include "kopeteappearancesettings.h"
40 #include "kopeteemoticons.h"
41 #include "kopetemessage.h"
42 #include "kopetechatsession.h"
43 #include "kopeteaccountmanager.h"
44 #include "kopetemessageevent.h"
45 #include "kopetechatsessionmanager.h"
46 #include "kopeteuiglobal.h"
47 
48 namespace Kopete {
49 
50 namespace UI {
51 
52 ContactListModel::ContactListModel( QObject* parent )
53  : QAbstractItemModel( parent )
54 {
55  AppearanceSettings* as = AppearanceSettings::self();
56  m_manualGroupSorting = (as->contactListGroupSorting() == AppearanceSettings::EnumContactListGroupSorting::Manual);
57  m_manualMetaContactSorting = (as->contactListMetaContactSorting() == AppearanceSettings::EnumContactListMetaContactSorting::Manual);
58  connect ( AppearanceSettings::self(), SIGNAL(configChanged()), this, SLOT(appearanceConfigChanged()) );
59 
60  connect( Kopete::ChatSessionManager::self(), SIGNAL(newEvent(Kopete::MessageEvent*)),
61  this, SLOT(newMessageEvent(Kopete::MessageEvent*)) );
62 
63 }
64 
65 // Can't be in constructor because we can't call virtual method loadContactList from constructor
66 void ContactListModel::init()
67 {
68  Kopete::ContactList* kcl = Kopete::ContactList::self();
69 
70  // Wait till whole contact list is loaded so we can apply manual sort.
71  if ( !kcl->loaded() )
72  connect( kcl, SIGNAL(contactListLoaded()), this, SLOT(loadContactList()) );
73  else
74  loadContactList();
75 }
76 
77 int ContactListModel::columnCount ( const QModelIndex& ) const
78 {
79  return 1;
80 }
81 
82 Qt::DropActions ContactListModel::supportedDropActions() const
83 {
84  return (Qt::DropActions)(Qt::CopyAction | Qt::MoveAction);
85 }
86 
87 QStringList ContactListModel::mimeTypes() const
88 {
89  QStringList types;
90 
91  types << "application/kopete.group";
92  types << "application/kopete.metacontacts.list";
93  types << "text/uri-list";
94 
95  return types;
96 }
97 
98 QMimeData* ContactListModel::mimeData(const QModelIndexList &indexes) const
99 {
100  QMimeData *mdata = new QMimeData();
101  QByteArray encodedData;
102 
103  QDataStream stream(&encodedData, QIODevice::WriteOnly);
104 
105  enum DragType { DragNone = 0x0, DragGroup = 0x1, DragMetaContact = 0x2 };
106  int dragType = DragNone;
107  foreach (QModelIndex index, indexes)
108  {
109  if ( !index.isValid() )
110  continue;
111 
112  switch ( data(index, Kopete::Items::TypeRole).toInt() )
113  {
114  case Kopete::Items::MetaContact:
115  {
116  dragType |= DragMetaContact;
117  // each metacontact entry will be encoded as group/uuid to
118  // make sure that when moving a metacontact from one group
119  // to another it will handle the right group
120 
121  // so get the group id
122  QString text = data(index.parent(), Kopete::Items::IdRole).toString();
123 
124  // and the metacontactid
125  text += "/" + data(index, Kopete::Items::UuidRole).toString();
126  stream << text;
127  break;
128  }
129  case Kopete::Items::Group:
130  {
131  dragType |= DragGroup;
132  // so get the group id
133  QString text = data(index, Kopete::Items::IdRole).toString();
134  stream << text;
135  break;
136  }
137  }
138  }
139 
140  if ( (dragType & (DragGroup | DragMetaContact)) == (DragGroup | DragMetaContact) )
141  return 0;
142 
143  if ( (dragType & DragGroup) == DragGroup )
144  mdata->setData("application/kopete.group", encodedData);
145  else if ( (dragType & DragMetaContact) == DragMetaContact )
146  mdata->setData("application/kopete.metacontacts.list", encodedData);
147  else
148  return 0;
149 
150  return mdata;
151 }
152 
153 bool ContactListModel::setData(const QModelIndex &index, const QVariant &value, const int role){
154  if ( !index.isValid() )
155  return false;
156  QObject* metaContactObject = qVariantValue<QObject*>( index.data( Kopete::Items::ObjectRole ) );
157  Kopete::MetaContact* metaContact = qobject_cast<Kopete::MetaContact*>(metaContactObject);
158  if ( metaContact )
159  {
160  metaContact->setDisplayName(value.toString());
161  metaContact->setDisplayNameSource(MetaContact::SourceCustom);
162  emit dataChanged(index,index);
163  return true;
164  }
165  return false;
166  Q_UNUSED(role);
167 }
168 
169 bool ContactListModel::loadModelSettings( const QString& modelType )
170 {
171  QDomDocument doc;
172 
173  QString fileName = KStandardDirs::locateLocal( "appdata", QLatin1String( "contactlistmodel.xml" ) );
174  if ( QFile::exists( fileName ) )
175  {
176  QFile file( fileName );
177  if( !file.open( QIODevice::ReadOnly ) || !doc.setContent( &file ) )
178  {
179  kDebug() << "error opening/parsing file " << fileName;
180  QDomElement dummyElement;
181  loadModelSettingsImpl( dummyElement );
182  return false;
183  }
184  }
185 
186  QDomElement rootElement = doc.firstChildElement( "Models" );
187  if ( !rootElement.isNull() )
188  {
189  QDomElement modelRootElement;
190  QDomNodeList modelRootList = rootElement.elementsByTagName("Model");
191  for ( int index = 0; index < modelRootList.size(); ++index )
192  {
193  QDomElement element = modelRootList.item( index ).toElement();
194  if ( !element.isNull() && element.attribute( "type" ) == modelType )
195  {
196  modelRootElement = element;
197  break;
198  }
199  }
200 
201  if ( !modelRootElement.isNull() )
202  {
203  loadModelSettingsImpl( modelRootElement );
204  return true;
205  }
206  }
207 
208  QDomElement dummyElement;
209  loadModelSettingsImpl( dummyElement );
210  return false;
211 }
212 
213 bool ContactListModel::saveModelSettings( const QString& modelType )
214 {
215  QDomDocument doc;
216 
217  QString fileName = KStandardDirs::locateLocal( "appdata", QLatin1String( "contactlistmodel.xml" ) );
218  if ( QFile::exists( fileName ) )
219  {
220  QFile file( fileName );
221  if( !file.open( QIODevice::ReadOnly ) || !doc.setContent( &file ) )
222  kDebug() << "error opening/parsing file " << fileName;
223 
224  file.close();
225  }
226 
227  QDomElement rootElement = doc.firstChildElement( "Models" );
228  if ( rootElement.isNull() )
229  {
230  rootElement = doc.createElement( "Models" );
231  doc.appendChild( rootElement );
232  }
233 
234  QDomElement modelRootElement;
235  QDomNodeList modelRootList = rootElement.elementsByTagName("Model");
236  for ( int index = 0; index < modelRootList.size(); ++index )
237  {
238  QDomElement element = modelRootList.item( index ).toElement();
239  if ( !element.isNull() && element.attribute( "type" ) == modelType )
240  {
241  modelRootElement = element;
242  break;
243  }
244  }
245 
246  if ( modelRootElement.isNull() )
247  {
248  modelRootElement = doc.createElement( "Model" );
249  rootElement.appendChild( modelRootElement );
250  modelRootElement.setAttribute( "type", modelType );
251  }
252 
253  saveModelSettingsImpl( doc, modelRootElement );
254 
255  QFile file( fileName );
256  if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
257  {
258  kDebug() << "error saving file " << fileName;
259  return false;
260  }
261 
262  QTextStream out( &file );
263  out << doc.toString();
264  file.close();
265  return true;
266 }
267 
268 void ContactListModel::addMetaContact( Kopete::MetaContact* contact )
269 {
270  connect( contact, SIGNAL(onlineStatusChanged(Kopete::MetaContact*,Kopete::OnlineStatus::StatusType)),
271  this, SLOT(handleContactDataChange(Kopete::MetaContact*)) );
272  connect( contact, SIGNAL(statusMessageChanged(Kopete::MetaContact*)),
273  this, SLOT(handleContactDataChange(Kopete::MetaContact*)) );
274  connect( contact, SIGNAL(displayNameChanged(QString,QString)),
275  this, SLOT(handleContactDataChange()) );
276  connect( contact, SIGNAL(photoChanged()),
277  this, SLOT(handleContactDataChange()) );
278 }
279 
280 void ContactListModel::removeMetaContact( Kopete::MetaContact* contact )
281 {
282  disconnect( contact, SIGNAL(onlineStatusChanged(Kopete::MetaContact*,Kopete::OnlineStatus::StatusType)),
283  this, SLOT(handleContactDataChange(Kopete::MetaContact*)));
284  disconnect( contact, SIGNAL(statusMessageChanged(Kopete::MetaContact*)),
285  this, SLOT(handleContactDataChange(Kopete::MetaContact*)) );
286  disconnect( contact, SIGNAL(displayNameChanged(QString,QString)),
287  this, SLOT(handleContactDataChange()) );
288  disconnect( contact, SIGNAL(photoChanged()),
289  this, SLOT(handleContactDataChange()) );
290 
291  m_newMessageMetaContactSet.remove( contact );
292 }
293 
294 void ContactListModel::addGroup( Kopete::Group* group )
295 {
296  Q_UNUSED( group );
297 }
298 
299 void ContactListModel::removeGroup( Kopete::Group* group )
300 {
301  Q_UNUSED( group );
302 }
303 
304 void ContactListModel::addMetaContactToGroup( Kopete::MetaContact *mc, Kopete::Group *group )
305 {
306  Q_UNUSED( mc );
307  Q_UNUSED( group );
308 }
309 
310 void ContactListModel::removeMetaContactFromGroup( Kopete::MetaContact *mc, Kopete::Group *group )
311 {
312  Q_UNUSED( mc );
313  Q_UNUSED( group );
314 }
315 
316 void ContactListModel::moveMetaContactToGroup( Kopete::MetaContact *mc, Kopete::Group *from, Kopete::Group *to)
317 {
318  removeMetaContactFromGroup(mc, from);
319  addMetaContactToGroup(mc, to);
320 }
321 
322 void ContactListModel::loadContactList()
323 {
324  Kopete::ContactList* kcl = Kopete::ContactList::self();
325  disconnect( kcl, SIGNAL(contactListLoaded()), this, SLOT(loadContactList()) );
326 
327  // MetaContact related
328  connect( kcl, SIGNAL(metaContactAdded(Kopete::MetaContact*)),
329  this, SLOT(addMetaContact(Kopete::MetaContact*)) );
330  connect( kcl, SIGNAL(metaContactRemoved(Kopete::MetaContact*)),
331  this, SLOT(removeMetaContact(Kopete::MetaContact*)) );
332 
333  // Group related
334  connect( kcl, SIGNAL(groupAdded(Kopete::Group*)),
335  this, SLOT(addGroup(Kopete::Group*)) );
336  connect( kcl, SIGNAL(groupRemoved(Kopete::Group*)),
337  this, SLOT(removeGroup(Kopete::Group*)) );
338 
339  // MetaContact and Group related
340  connect( kcl, SIGNAL(metaContactAddedToGroup(Kopete::MetaContact*,Kopete::Group*)),
341  this, SLOT(addMetaContactToGroup(Kopete::MetaContact*,Kopete::Group*)) );
342  connect( kcl, SIGNAL(metaContactRemovedFromGroup(Kopete::MetaContact*,Kopete::Group*)),
343  this, SLOT(removeMetaContactFromGroup(Kopete::MetaContact*,Kopete::Group*)) );
344  connect( kcl, SIGNAL(metaContactMovedToGroup(Kopete::MetaContact*,Kopete::Group*,Kopete::Group*)),
345  this, SLOT(moveMetaContactToGroup(Kopete::MetaContact*,Kopete::Group*,Kopete::Group*)));
346 }
347 
348 void ContactListModel::handleContactDataChange()
349 {
350  Kopete::MetaContact* metaContact = qobject_cast<Kopete::MetaContact*>(sender());
351  if ( metaContact )
352  handleContactDataChange( metaContact );
353 }
354 
355 void ContactListModel::newMessageEvent( Kopete::MessageEvent *event )
356 {
357  Kopete::Message msg = event->message();
358 
359  //only for single chat
360  if ( msg.from() && msg.to().count() == 1 )
361  {
362  Kopete::MetaContact *mc = msg.from()->metaContact();
363  if( !mc )
364  return;
365 
366  connect( event, SIGNAL(done(Kopete::MessageEvent*)),
367  this, SLOT(newMessageEventDone(Kopete::MessageEvent*)) );
368 
369  bool firstEvent = m_newMessageMetaContactSet[mc].isEmpty();
370  m_newMessageMetaContactSet[mc].insert( event );
371  if ( firstEvent )
372  handleContactDataChange( mc );
373  }
374 }
375 
376 void ContactListModel::newMessageEventDone( Kopete::MessageEvent *event )
377 {
378  Kopete::Message msg = event->message();
379 
380  Q_ASSERT( msg.from() );
381 
382  Kopete::MetaContact *mc = msg.from()->metaContact();
383  if( !mc )
384  return;
385 
386  m_newMessageMetaContactSet[mc].remove( event );
387  if ( m_newMessageMetaContactSet[mc].isEmpty() )
388  {
389  m_newMessageMetaContactSet.remove( mc );
390  handleContactDataChange( mc );
391  }
392 }
393 
394 bool ContactListModel::dropUrl( const QMimeData *data, int row, const QModelIndex &parent, Qt::DropAction action )
395 {
396  // we don't support dropping things in an empty space
397  if ( !parent.isValid() || parent.data( Kopete::Items::TypeRole ) != Kopete::Items::MetaContact )
398  return false;
399 
400  QObject* metaContactObject = qVariantValue<QObject*>( parent.data( Kopete::Items::ObjectRole ) );
401  Kopete::MetaContact* metaContact = qobject_cast<Kopete::MetaContact*>(metaContactObject);
402 
403  KUrl::List urlList = KUrl::List::fromMimeData( data );
404  for ( KUrl::List::Iterator it = urlList.begin(); it != urlList.end(); ++it )
405  {
406  KUrl url = (*it);
407  if( url.protocol() == QLatin1String( "kopetemessage" ) )
408  {
409  //Add a contact
410  QString protocolId = url.queryItem( "protocolId" );
411  QString accountId = url.queryItem( "accountId" );
412  QString contactId = url.host();
413 
414  kDebug() << "protocolId=" << protocolId << ", accountId=" << accountId << ", contactId=" << contactId;
415  Kopete::Account *account = Kopete::AccountManager::self()->findAccount( protocolId, accountId );
416  if( account && account->contacts().value( contactId ) )
417  {
418  Kopete::Contact *source_contact = account->contacts().value( contactId );
419  if( source_contact )
420  {
421  if( source_contact->metaContact()->isTemporary() )
422  {
423  GroupMetaContactPair pair;
424  pair.first = source_contact->metaContact()->groups().first();
425  pair.second = source_contact->metaContact();
426 
427  QList<GroupMetaContactPair> items;
428  items << pair;
429  return dropMetaContacts( row, parent, action, items );
430  }
431  else
432  {
433  KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Error,
434  i18n( "<qt>This contact is already on your contact list. It is a child contact of <b>%1</b></qt>",
435  source_contact->metaContact()->displayName() )
436  );
437  }
438  }
439  }
440  }
441  else if ( metaContact )
442  {
443  if( url.isLocalFile() )
444  {
445  metaContact->sendFile( url );
446  }
447  else
448  {
449  //this is a URL, send the URL in a message
450  Kopete::Contact *contact = metaContact->execute();
451  Kopete::Message msg( contact->account()->myself(), contact );
452  msg.setPlainBody( url.url() );
453  msg.setDirection( Kopete::Message::Outbound );
454 
455  contact->manager( Kopete::Contact::CanCreate )->sendMessage( msg );
456  }
457  }
458  }
459  return true;
460 }
461 
462 bool ContactListModel::dropMetaContacts( int row, const QModelIndex &parent, Qt::DropAction action, const QList<GroupMetaContactPair> &items )
463 {
464  Q_UNUSED( row );
465  Q_UNUSED( action );
466 
467  if ( items.isEmpty() || !parent.isValid() )
468  return false;
469 
470  if ( parent.data( Kopete::Items::TypeRole ) == Kopete::Items::MetaContact )
471  {
472  QObject* metaContactObject = qVariantValue<QObject*>( parent.data( Kopete::Items::ObjectRole ) );
473  Kopete::MetaContact* destMetaContact = qobject_cast<Kopete::MetaContact*>(metaContactObject);
474  if ( !destMetaContact )
475  return false;
476 
477  QStringList displayNames;
478  displayNames << destMetaContact->displayName();
479 
480  QList<Kopete::MetaContact*> metaContacts;
481  QListIterator<GroupMetaContactPair> it( items );
482  while ( it.hasNext() )
483  {
484  Kopete::MetaContact* mc = it.next().second;
485  metaContacts << mc;
486  displayNames << mc->displayName();
487  }
488 
489  if( KMessageBox::questionYesNo( Kopete::UI::Global::mainWidget(),
490  i18n( "<qt>Are you sure you want to merge meta contacts?\n<b>%1</b>", displayNames.join( ", " ) ),
491  i18n( "Meta Contact Merge" ), KStandardGuiItem::yes(), KStandardGuiItem::no(),
492  "askDDMergeMetaContacts", KMessageBox::Notify | KMessageBox::Dangerous ) != KMessageBox::Yes )
493  {
494  return false;
495  }
496 
497  // Merge the metacontacts from mimedata into this one
498  Kopete::ContactList::self()->mergeMetaContacts( metaContacts, destMetaContact );
499  return true;
500  }
501 
502  return false;
503 }
504 
505 QVariant ContactListModel::metaContactData( const Kopete::MetaContact* mc, int role ) const
506 {
507  switch ( role )
508  {
509  case Qt::DisplayRole:
510  case Qt::EditRole:
511  return mc->displayName();
512  break;
513  case Qt::AccessibleTextRole:
514  return i18nc("%1 is display name, %2 is status (connected/away/etc.)", "%1 (%2)", mc->displayName(), mc->statusString());
515  break;
516  case Qt::AccessibleDescriptionRole:
517  return i18nc("%1 is display name, %2 is status and %3 is status message", "%1 (%2)\n%3", mc->displayName(), mc->statusString(), mc->statusMessage().message());
518  break;
519  case Kopete::Items::MetaContactImageRole:
520  return metaContactImage( mc );
521  break;
522  case Qt::ToolTipRole:
523  return metaContactTooltip( mc );
524  break;
525  case Kopete::Items::TypeRole:
526  return Kopete::Items::MetaContact;
527  break;
528  case Kopete::Items::ObjectRole:
529  return qVariantFromValue( (QObject*)mc );
530  break;
531  case Kopete::Items::UuidRole:
532  return mc->metaContactId().toString();
533  break;
534  case Kopete::Items::OnlineStatusRole:
535  return mc->status();
536  break;
537  case Kopete::Items::StatusMessageRole:
538  return mc->statusMessage().message();
539  break;
540  case Kopete::Items::StatusTitleRole:
541  return mc->statusMessage().title();
542  break;
543  case Kopete::Items::AccountIconsRole:
544  {
545  QList<QVariant> accountIconList;
546  foreach ( Kopete::Contact *contact, mc->contacts() )
547  accountIconList << qVariantFromValue( contact->onlineStatus().iconFor( contact ) );
548 
549  return accountIconList;
550  }
551  case Kopete::Items::HasNewMessageRole:
552  return m_newMessageMetaContactSet.contains( mc );
553  case Kopete::Items::IdleTimeRole:
554  return mc->idleTime();
555  }
556 
557  return QVariant();
558 }
559 
560 QVariant ContactListModel::metaContactImage( const Kopete::MetaContact* mc ) const
561 {
562  using namespace Kopete;
563 
564  int iconMode = AppearanceSettings::self()->contactListIconMode();
565  if ( iconMode == AppearanceSettings::EnumContactListIconMode::IconPhoto )
566  {
567  QImage img = mc->picture().image();
568  if ( !img.isNull() && img.width() > 0 && img.height() > 0 )
569  return img;
570  }
571 
572  switch( mc->status() )
573  {
574  case OnlineStatus::Online:
575  if( mc->useCustomIcon() )
576  return mc->icon( ContactListElement::Online );
577  else
578  return QString::fromUtf8( "user-online" );
579  break;
580  case OnlineStatus::Away:
581  if( mc->useCustomIcon() )
582  return mc->icon( ContactListElement::Away );
583  else
584  return QString::fromUtf8( "user-away" );
585  break;
586  case OnlineStatus::Busy:
587  if( mc->useCustomIcon() )
588  return mc->icon( ContactListElement::Away );
589  else
590  return QString::fromUtf8( "user-busy" );
591  break;
592  case OnlineStatus::Unknown:
593  if( mc->useCustomIcon() )
594  return mc->icon( ContactListElement::Unknown );
595  if ( mc->contacts().isEmpty() )
596  return QString::fromUtf8( "metacontact_unknown" );
597  else
598  return QString::fromUtf8( "user-offline" );
599  break;
600  case OnlineStatus::Offline:
601  default:
602  if( mc->useCustomIcon() )
603  return mc->icon( ContactListElement::Offline );
604  else
605  return QString::fromUtf8( "user-offline" );
606  break;
607  }
608 
609  return QVariant();
610 }
611 
612 QString ContactListModel::metaContactTooltip( const Kopete::MetaContact* metaContact ) const
613 {
614  // We begin with the meta contact display name at the top of the tooltip
615  QString toolTip = QLatin1String("<qt><table>");
616  toolTip += QLatin1String("<tr><td>");
617 
618  if ( !metaContact->picture().isNull() )
619  {
620 #ifdef __GNUC__
621 #warning Currently using metaContact->picture().path() but should use replacement of KopeteMimeSourceFactory
622 #endif
623 #if 0
624  QString photoName = QLatin1String("kopete-metacontact-photo:%1").arg( KUrl::encode_string( metaContact->metaContactId() ));
625  //QMimeSourceFactory::defaultFactory()->setImage( "contactimg", metaContact->photo() );
626  toolTip += QString::fromLatin1("<img src=\"%1\">").arg( photoName );
627 #endif
628  // scale big image to max size 96x96
629  // NOTE: attribute style="max-width:96px; max-height:96px;" not working
630  const QImage &image = metaContact->picture().image();
631  if ( image.width() <= 96 && image.height() <= 96 )
632  toolTip += QString::fromLatin1("<img src=\"%1\">&nbsp;").arg( metaContact->picture().path() );
633  else if ( image.width() > image.height() )
634  toolTip += QString::fromLatin1("<img src=\"%1\" width=\"96\">&nbsp;").arg( metaContact->picture().path() );
635  else
636  toolTip += QString::fromLatin1("<img src=\"%1\" height=\"96\">&nbsp;").arg( metaContact->picture().path() );
637  }
638 
639  toolTip += QLatin1String("</td><td>");
640 
641  QString displayName;
642  QList<KEmoticonsTheme::Token> t = Kopete::Emoticons::tokenize( metaContact->displayName());
643  QList<KEmoticonsTheme::Token>::iterator it;
644  for( it = t.begin(); it != t.end(); ++it )
645  {
646  if( (*it).type == KEmoticonsTheme::Image )
647  displayName += (*it).picHTMLCode;
648  else if( (*it).type == KEmoticonsTheme::Text )
649  displayName += Qt::escape( (*it).text );
650  }
651 
652  toolTip += QString::fromLatin1("<b><font size=\"+1\">%1</font></b><br>").arg( displayName );
653 
654  QList<Contact*> contacts = metaContact->contacts();
655  if ( contacts.count() == 1 )
656  return toolTip + "<br>" + contacts.first()->toolTip() + QLatin1String("</td></tr></table></qt>");
657 
658  toolTip += QLatin1String("<table>");
659 
660  // We are over a metacontact with > 1 child contacts, and not over a specific contact
661  // Iterate through children and display a summary tooltip
662  foreach ( Contact* c, contacts )
663  {
664  QString iconName = QString::fromLatin1("kopete-contact-icon:%1:%2:%3")
665  .arg( QString(QUrl::toPercentEncoding( c->protocol()->pluginId() )),
666  QString(QUrl::toPercentEncoding( c->account()->accountId() )),
667  QString(QUrl::toPercentEncoding( c->contactId() ) )
668  );
669 
670  QString name = Kopete::Emoticons::parseEmoticons(c->nickName());
671 
672  QString message = c->statusMessage().message();
673 
674  // try harder!
675  if(message.isEmpty())
676  message = c->property(Kopete::Global::Properties::self()->statusMessage()).value().toString();
677 
678  toolTip += i18nc("<tr><td>STATUS ICON <b>PROTOCOL NAME</b> (ACCOUNT NAME)</td><td>STATUS DESCRIPTION</td></tr>",
679  "<tr style='white-space:pre'><td>"
680  "<img src=\"%1\">&nbsp;"
681  "</td><td>"
682  "<b>%2</b>&nbsp;(%3)"
683  "</td><td align=\"right\">"
684  "%4"
685  "</td></tr>",
686  iconName, name, c->contactId(), c->onlineStatus().description());
687 
688  if(!message.isEmpty()){
689  toolTip += i18nc("<tr><td><small><i>STATUS MESSAGE</i></small></td></tr>",
690  "<tr><td>&nbsp;</td><td colspan='2'><small><i>%1</i></small></td></tr>",
691  message);
692  }
693  }
694 
695  return toolTip + QLatin1String("</table></td></tr></table></qt>");
696 }
697 
698 }
699 
700 }
701 
702 #include "contactlistmodel.moc"
703 //kate: tab-width 4
Kopete::UI::ContactListModel::metaContactImage
QVariant metaContactImage(const Kopete::MetaContact *mc) const
Definition: contactlistmodel.cpp:560
Kopete::UI::ContactListModel::GroupMetaContactPair
QPair< Kopete::Group *, Kopete::MetaContact * > GroupMetaContactPair
Definition: contactlistmodel.h:82
kopeteitembase.h
Contains definitions common between model items.
Kopete::UI::ContactListModel::metaContactData
QVariant metaContactData(const Kopete::MetaContact *mc, int role) const
Definition: contactlistmodel.cpp:505
Kopete::UI::ContactListModel::init
void init()
Definition: contactlistmodel.cpp:66
Kopete::Items::OnlineStatusRole
const int OnlineStatusRole
Definition: kopeteitembase.h:36
Kopete::Items::IdleTimeRole
const int IdleTimeRole
Definition: kopeteitembase.h:37
contactlistmodel.h
Kopete::UI::ContactListModel::addMetaContactToGroup
virtual void addMetaContactToGroup(Kopete::MetaContact *, Kopete::Group *)
Definition: contactlistmodel.cpp:304
QObject
Kopete::Items::UuidRole
const int UuidRole
Definition: kopeteitembase.h:38
Kopete::UI::ContactListModel::dropUrl
bool dropUrl(const QMimeData *data, int row, const QModelIndex &parent, Qt::DropAction action)
Definition: contactlistmodel.cpp:394
Kopete::UI::ContactListModel::ContactListModel
ContactListModel(QObject *parent=0)
Definition: contactlistmodel.cpp:52
Kopete::Items::AccountIconsRole
const int AccountIconsRole
Definition: kopeteitembase.h:49
Kopete::Items::MetaContact
Definition: kopeteitembase.h:57
Kopete::UI::ContactListModel::moveMetaContactToGroup
virtual void moveMetaContactToGroup(Kopete::MetaContact *, Kopete::Group *, Kopete::Group *)
Definition: contactlistmodel.cpp:316
Kopete::UI::ContactListModel::addMetaContact
virtual void addMetaContact(Kopete::MetaContact *)
Definition: contactlistmodel.cpp:268
Kopete::UI::ContactListModel::addGroup
virtual void addGroup(Kopete::Group *)
Definition: contactlistmodel.cpp:294
Kopete::Items::StatusMessageRole
const int StatusMessageRole
Definition: kopeteitembase.h:48
Kopete::Items::Group
Definition: kopeteitembase.h:57
accountId
QString accountId
Definition: kopete-account-kconf_update.cpp:31
Kopete::UI::ContactListModel::m_manualGroupSorting
bool m_manualGroupSorting
Definition: contactlistmodel.h:92
Kopete::Items::TypeRole
const int TypeRole
Qt Model Role Definitions.
Definition: kopeteitembase.h:34
Kopete::UI::ContactListModel::loadModelSettingsImpl
virtual void loadModelSettingsImpl(QDomElement &rootElement)=0
Kopete::Items::IdRole
const int IdRole
Definition: kopeteitembase.h:41
Kopete::UI::ContactListModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, const int role)
Definition: contactlistmodel.cpp:153
Kopete::UI::ContactListModel::saveModelSettingsImpl
virtual void saveModelSettingsImpl(QDomDocument &doc, QDomElement &rootElement)=0
Kopete::UI::ContactListModel::loadContactList
virtual void loadContactList()
Definition: contactlistmodel.cpp:322
QAbstractItemModel
Kopete::UI::ContactListModel::appearanceConfigChanged
virtual void appearanceConfigChanged()=0
Kopete::UI::ContactListModel::metaContactTooltip
QString metaContactTooltip(const Kopete::MetaContact *metaContact) const
Definition: contactlistmodel.cpp:612
Kopete::UI::ContactListModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Definition: contactlistmodel.cpp:98
Kopete::UI::ContactListModel::removeMetaContactFromGroup
virtual void removeMetaContactFromGroup(Kopete::MetaContact *, Kopete::Group *)
Definition: contactlistmodel.cpp:310
Kopete::UI::ContactListModel::dropMetaContacts
virtual bool dropMetaContacts(int row, const QModelIndex &parent, Qt::DropAction action, const QList< GroupMetaContactPair > &items)
Definition: contactlistmodel.cpp:462
Kopete::UI::ContactListModel::newMessageEvent
void newMessageEvent(Kopete::MessageEvent *event)
Definition: contactlistmodel.cpp:355
Kopete::UI::ContactListModel::mimeTypes
virtual QStringList mimeTypes() const
Definition: contactlistmodel.cpp:87
Kopete::Items::HasNewMessageRole
const int HasNewMessageRole
Definition: kopeteitembase.h:52
Kopete::UI::ContactListModel::saveModelSettings
bool saveModelSettings(const QString &modelType)
Definition: contactlistmodel.cpp:213
Kopete::UI::ContactListModel::removeGroup
virtual void removeGroup(Kopete::Group *)
Definition: contactlistmodel.cpp:299
Kopete::UI::ContactListModel::newMessageEventDone
void newMessageEventDone(Kopete::MessageEvent *event)
Definition: contactlistmodel.cpp:376
Kopete::UI::ContactListModel::supportedDropActions
virtual Qt::DropActions supportedDropActions() const
Definition: contactlistmodel.cpp:82
Kopete::UI::ContactListModel::removeMetaContact
virtual void removeMetaContact(Kopete::MetaContact *)
Definition: contactlistmodel.cpp:280
Kopete::UI::ContactListModel::handleContactDataChange
void handleContactDataChange()
Definition: contactlistmodel.cpp:348
Kopete::UI::ContactListModel::loadModelSettings
bool loadModelSettings(const QString &modelType)
Definition: contactlistmodel.cpp:169
Kopete::Items::ObjectRole
const int ObjectRole
Definition: kopeteitembase.h:50
Kopete::Items::MetaContactImageRole
const int MetaContactImageRole
Definition: kopeteitembase.h:44
Kopete::Items::StatusTitleRole
const int StatusTitleRole
Definition: kopeteitembase.h:47
Kopete::UI::ContactListModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: contactlistmodel.cpp:77
Kopete::UI::ContactListModel::m_manualMetaContactSorting
bool m_manualMetaContactSorting
Definition: contactlistmodel.h:93
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • 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