• 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.14
  • kdenetwork
  • kopete
  • libkopete
kopetechatsession.cpp
Go to the documentation of this file.
1 /*
2  kopetechatsession.cpp - Manages all chats
3 
4  Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org>
5  Copyright (c) 2002 by Daniel Stone <dstone@kde.org>
6  Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
7  Copyright (c) 2002-2004 by Olivier Goffart <ogoffart@kde.org>
8  Copyright (c) 2003 by Jason Keirstead <jason@keirstead.org>
9  Copyright (c) 2005 by MichaĆ«l Larouche <larouche@kde.org>
10 
11  Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
12 
13  *************************************************************************
14  * *
15  * This library is free software; you can redistribute it and/or *
16  * modify it under the terms of the GNU Lesser General Public *
17  * License as published by the Free Software Foundation; either *
18  * version 2 of the License, or (at your option) any later version. *
19  * *
20  *************************************************************************
21 */
22 
23 #include "kopetechatsession.h"
24 
25 #include <qapplication.h>
26 #include <qfile.h>
27 #include <qregexp.h>
28 #include <qpointer.h>
29 
30 #include <kdebug.h>
31 #include <kdeversion.h>
32 #include <kglobal.h>
33 #include <klocale.h>
34 #include <kmessagebox.h>
35 #include <knotification.h>
36 #include <kstandarddirs.h>
37 
38 #include "kopeteaccount.h"
39 #include "kopetebehaviorsettings.h"
40 #include "kopetecommandhandler.h"
41 #include "kopetechatsessionmanager.h"
42 #include "kopetemessagehandlerchain.h"
43 #include "kopetemetacontact.h"
44 #include "kopetegroup.h"
45 #include "kopeteuiglobal.h"
46 #include "kopeteglobal.h"
47 #include "kopeteview.h"
48 #include "kopetecontact.h"
49 #include "kopetepluginmanager.h"
50 #include "kopeteprotocol.h"
51 #include "kopetepicture.h"
52 #include "kopeteactivenotification.h"
53 
54 const int CHAIN_COUNT = 3;
55 
56 class KMMPrivate
57 {
58 public:
59  Kopete::ContactPtrList contacts;
60  const Kopete::Contact *mUser;
61  QMap<const Kopete::Contact *, Kopete::OnlineStatus> contactStatus;
62  Kopete::ActiveNotifications typingNotifications;
63  Kopete::Protocol *mProtocol;
64  bool isEmpty;
65  bool mCanBeDeleted;
66  unsigned int refcount;
67  bool customDisplayName;
68  QDateTime awayTime;
69  QString displayName;
70  QString lastUrl;
71  KopeteView *view;
72  bool mayInvite;
73  Kopete::MessageHandlerChain::Ptr chains[CHAIN_COUNT];
74  Kopete::ChatSession::Form form;
75  bool warnGroupChat;
76 };
77 
78 Kopete::ChatSession::ChatSession( const Kopete::Contact *user,
79  Kopete::ContactPtrList others, Kopete::Protocol *protocol, Kopete::ChatSession::Form form )
80 : QObject( user->account())
81 {
82  d = new KMMPrivate;
83  d->mUser = user;
84  d->mProtocol = protocol;
85  d->isEmpty = others.isEmpty();
86  d->mCanBeDeleted = true;
87  d->refcount = 0;
88  d->view = 0L;
89  d->customDisplayName = false;
90  d->mayInvite = false;
91  d->form = form;
92  d->warnGroupChat = true;
93  if ( !others.isEmpty() ) {
94  d->lastUrl = initLastUrl( others.first() );
95  }
96 
97  for ( int i = 0; others.size() != i; ++i )
98  addContact( others[i], true );
99 
100  connect( Kopete::PluginManager::self(), SIGNAL(pluginLoaded(Kopete::Plugin*)), this, SLOT(clearChains()) );
101  connect( Kopete::PluginManager::self(), SIGNAL(pluginUnloaded(QString)), this, SLOT(clearChains()) );
102 
103  connect( user, SIGNAL(contactDestroyed(Kopete::Contact*)), this, SLOT(slotMyselfDestroyed(Kopete::Contact*)) );
104  connect( user, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)), this,
105  SLOT(slotOnlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)) );
106 
107  if( user->metaContact() )
108  connect( user->metaContact(), SIGNAL(photoChanged()), this, SIGNAL(photoChanged()) );
109 
110  slotUpdateDisplayName();
111 }
112 
113 Kopete::ChatSession::~ChatSession()
114 {
115  //for ( Kopete::Contact *c = d->contacts.first(); c; c = d->contacts.next() )
116  // c->setConversations( c->conversations() - 1 );
117 
118  if ( !d )
119  return;
120  d->mCanBeDeleted = false; //prevent double deletion
121  Kopete::ChatSessionManager::self()->removeSession( this );
122  emit closing( this );
123  delete d;
124 }
125 
126 void Kopete::ChatSession::slotOnlineStatusChanged( Kopete::Contact *c, const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus )
127 {
128  slotUpdateDisplayName();
129  emit onlineStatusChanged((Kopete::Contact*)c, status, oldStatus);
130 }
131 
132 void Kopete::ChatSession::setContactOnlineStatus( const Kopete::Contact *contact, const Kopete::OnlineStatus &status )
133 {
134  Kopete::OnlineStatus oldStatus = d->contactStatus[ contact ];
135  d->contactStatus[ contact ] = status;
136  disconnect( contact, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
137  this, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)) );
138  emit onlineStatusChanged( (Kopete::Contact*)contact, status, oldStatus );
139 }
140 
141 const Kopete::OnlineStatus Kopete::ChatSession::contactOnlineStatus( const Kopete::Contact *contact ) const
142 {
143  if ( d->contactStatus.contains( contact ) )
144  return d->contactStatus[ contact ];
145 
146  return contact->onlineStatus();
147 }
148 
149 void Kopete::ChatSession::setLastUrl( const QString &verylastUrl )
150 {
151  d->lastUrl = verylastUrl;
152 }
153 
154 const QString Kopete::ChatSession::lastUrl()
155 {
156  return d->lastUrl;
157 }
158 
159 const QString Kopete::ChatSession::displayName()
160 {
161  if ( d->displayName.isNull() )
162  {
163  slotUpdateDisplayName();
164  }
165 
166  return d->displayName;
167 }
168 
169 void Kopete::ChatSession::setDisplayName( const QString &newName )
170 {
171  d->displayName = newName;
172  d->customDisplayName = true;
173  emit displayNameChanged();
174 }
175 
176 void Kopete::ChatSession::slotUpdateDisplayName()
177 {
178  if( d->customDisplayName )
179  return;
180 
181 
182  //If there is no member yet, don't try to update the display name
183  if ( d->contacts.isEmpty() )
184  return;
185 
186  d->displayName.clear();
187  for(int i = 0; i != d->contacts.size(); i++ )
188  {
189  Kopete::Contact * c = d->contacts[i];
190  if(! d->displayName.isNull() )
191  d->displayName.append( QString::fromLatin1( ", " ) ) ;
192 
193  if ( c->metaContact() )
194  d->displayName.append( c->metaContact()->displayName() );
195  else
196  {
197  d->displayName.append( c->displayName() );
198  }
199  }
200 
201  //If we have only 1 contact, add the status of him
202  if ( d->contacts.count() == 1 )
203  {
204  d->displayName.append( QString::fromLatin1( " (%1)" ).arg( d->contacts.first()->onlineStatus().description() ) );
205  }
206 
207  emit displayNameChanged();
208 }
209 
210 const Kopete::ContactPtrList& Kopete::ChatSession::members() const
211 {
212  return d->contacts;
213 }
214 
215 const Kopete::Contact* Kopete::ChatSession::myself() const
216 {
217  return d->mUser;
218 }
219 
220 Kopete::Protocol* Kopete::ChatSession::protocol() const
221 {
222  return d->mProtocol;
223 }
224 
225 
226 #include "kopetemessagehandler.h"
227 #include "kopetemessageevent.h"
228 
229 // FIXME: remove this and the friend decl in KMM
230 class Kopete::TemporaryKMMCallbackAppendMessageHandler : public Kopete::MessageHandler
231 {
232  QPointer<Kopete::ChatSession> manager;
233 public:
234  TemporaryKMMCallbackAppendMessageHandler( Kopete::ChatSession *manager )
235  : manager(manager)
236  {
237  }
238  void handleMessage( Kopete::MessageEvent *event )
239  {
240  Kopete::Message message = event->message();
241 
242  if ( manager )
243  emit manager->messageAppended( message, manager );
244 
245  delete event;
246  }
247 };
248 
249 class TempFactory : public Kopete::MessageHandlerFactory
250 {
251 public:
252  Kopete::MessageHandler *create( Kopete::ChatSession *manager, Kopete::Message::MessageDirection )
253  {
254  return new Kopete::TemporaryKMMCallbackAppendMessageHandler( manager );
255  }
256  int filterPosition( Kopete::ChatSession *, Kopete::Message::MessageDirection )
257  {
258  // FIXME: somewhere after everyone else.
259  return 100000;
260  }
261 };
262 
263 void Kopete::ChatSession::clearChains()
264 {
265  for (int i = 0; i < CHAIN_COUNT; i++)
266  d->chains[i] = 0;
267 }
268 
269 Kopete::MessageHandlerChain::Ptr Kopete::ChatSession::chainForDirection( Kopete::Message::MessageDirection dir )
270 {
271  if( dir < 0 || dir >= CHAIN_COUNT)
272  kFatal(14000) << "invalid message direction " << dir;
273  if( !d->chains[dir] )
274  {
275  TempFactory theTempFactory;
276  d->chains[dir] = Kopete::MessageHandlerChain::create( this, dir );
277  }
278  return d->chains[dir];
279 }
280 
281 void Kopete::ChatSession::sendMessage( Kopete::Message &message )
282 {
283  message.setManager( this );
284  Kopete::Message sentMessage = message;
285  if ( !Kopete::CommandHandler::commandHandler()->processMessage( message, this ) )
286  {
287  emit messageSent( sentMessage, this );
288  if ( ( !account()->isAway() || Kopete::BehaviorSettings::self()->enableEventsWhileAway() ) && !account()->isBusy() )
289  {
290  KNotification::event(QString::fromLatin1( "kopete_outgoing" ), i18n( "Outgoing Message Sent" ) );
291  }
292  }
293  else
294  {
295  messageSucceeded();
296  }
297 }
298 
299 void Kopete::ChatSession::messageSucceeded()
300 {
301  emit messageSuccess();
302 }
303 
304 void Kopete::ChatSession::emitNudgeNotification()
305 {
306  if ( !account()->isBusy() )
307  KNotification::event( QString::fromLatin1("buzz_nudge"), i18n("A contact sent you a buzz/nudge.") );
308 }
309 
310 void Kopete::ChatSession::appendMessage( Kopete::Message &msg )
311 {
312  msg.setManager( this );
313 
314  if ( msg.direction() == Kopete::Message::Inbound )
315  {
316  const QString nick = myself()->displayName();
317  if ( Kopete::BehaviorSettings::self()->highlightEnabled() && !nick.isEmpty() )
318  {
319  const QString nickNameRegExp = QString::fromLatin1( "(^|[\\W])(%1)([\\W]|$)" ).arg( QRegExp::escape( nick ) );
320  if ( msg.plainBody().contains( QRegExp( nickNameRegExp, Qt::CaseInsensitive ) ) )
321  {
322  msg.setImportance( Kopete::Message::Highlight );
323  }
324  }
325 
326  emit messageReceived( msg, this );
327  }
328 
329  // outbound messages here are ones the user has sent that are now
330  // getting reflected back to the chatwindow. they should go down
331  // the incoming chain.
332  Kopete::Message::MessageDirection chainDirection = msg.direction();
333  if( chainDirection == Kopete::Message::Outbound )
334  chainDirection = Kopete::Message::Inbound;
335 
336  chainForDirection( chainDirection )->processMessage( msg );
337 
338  //looking for urls in the message
339  urlSearch( msg );
340 // emit messageAppended( msg, this );
341 }
342 
343 void Kopete::ChatSession::urlSearch( const Kopete::Message &msg )
344 {
345  //if there are any urls in the message
346  QStringList lasturls = findUrls(msg);
347  if ( !lasturls.empty() ) {
348  //set lasturl for message's chatsession
349  msg.manager()->setLastUrl( lasturls.last() );
350  //saving new url(s) found in message //file named contactId.lasturls.txt in proper folder
351  QString urlfilename = Kopete::ChatSession::getUrlsFileName( msg.manager()->members().first() );
352  QFile file( urlfilename );
353  file.open( QIODevice::Append );
354  QTextStream stream( &file );
355 
356  for (int i = 0; i < lasturls.size(); ++i)
357  stream << lasturls.at(i) << "\n";
358  file.close();
359  }
360 }
361 
362 QStringList Kopete::ChatSession::findUrls(const Kopete::Message &msg )
363 {
364  Kopete::Message message = msg;
365  //we check the message for every pattern
366  QString tempstr = message.plainBody();
367  QStringList regexppatterns = message.regexpPatterns();
368  QRegExp linkregexp;
369  QMap<int,QString> mapUrl;
370 
371  for (int i = 0; i < regexppatterns.size(); ++i) {
372  linkregexp.setPattern(regexppatterns[i]);
373  int pos = 0;
374  while ((pos = linkregexp.indexIn(tempstr, pos)) != -1) {
375  mapUrl.insert(pos,linkregexp.cap(0));
376  pos += linkregexp.matchedLength(); }
377  }
378  //we use QMap to sort links as they are in the message (if there are many links in one message)
379  //lasturllist[0] - is the earliest
380  QStringList lasturllist;
381  QMapIterator< int, QString > i(mapUrl);
382  while (i.hasNext()) { i.next(); lasturllist << i.value(); }
383  lasturllist.replaceInStrings(" ", "");
384  //add "http://" to link if needed to open it with a browser
385  lasturllist.replaceInStrings(QRegExp( regexppatterns[1] ), QLatin1String("\\1http://\\2\\3" ));
386 
387  return lasturllist;
388 }
389 
390 QString Kopete::ChatSession::initLastUrl( const Kopete::Contact* c )
391 {
392  QString urlfilename = getUrlsFileName(c);
393  if ( !urlfilename.isEmpty() )
394  {
395  QFile file( urlfilename );
396  QString lastUrl;
397  if ( file.exists() ) {
398  if ( file.open(QIODevice::ReadOnly) ) {
399  QTextStream stream( &file );
400  while ( !stream.atEnd() )
401  lastUrl = stream.readLine();
402  file.close(); }
403  else {
404  kDebug(14310) << "cant open lasturls file for " << c->contactId();
405  }
406  }
407  if ( !lastUrl.isEmpty() )
408  return lastUrl;
409  else return "";
410  }
411  else
412  {
413  kDebug(14310) << "cant find lasturls file for " << c->contactId();
414  return "";
415  }
416 }
417 
418 QString Kopete::ChatSession::getUrlsFileName(const Kopete::Contact* c)
419 {
420  QString name = c->protocol()->pluginId().replace( QRegExp( QString::fromLatin1( "[./~?*]" ) ), QString::fromLatin1( "-" ) ) +
421  QString::fromLatin1( "/" ) +
422  c->account()->accountId().replace( QRegExp( QString::fromLatin1( "[./~?*]" ) ), QString::fromLatin1( "-" ) ) +
423  QString::fromLatin1( "/" ) +
424  c->contactId().replace( QRegExp( QString::fromLatin1( "[./~?*]" ) ), QString::fromLatin1( "-" ) ) +
425  QString::fromLatin1( ".lasturls" );
426 
427  QString filename = KStandardDirs::locateLocal( "data", QString::fromLatin1( "kopete/urls/" ) + name + QString::fromLatin1( ".txt" ) ) ;
428 
429  return filename;
430 }
431 
432 void Kopete::ChatSession::addContact( const Kopete::Contact *c, const Kopete::OnlineStatus &initialStatus, bool suppress )
433 {
434  if( !d->contactStatus.contains(c) )
435  d->contactStatus[ c ] = initialStatus;
436  addContact( c, suppress );
437 }
438 
439 void Kopete::ChatSession::addContact( const Kopete::Contact *c, bool suppress )
440 {
441  //kDebug( 14010 ) ;
442  if ( d->contacts.contains( (Kopete::Contact*)c ) )
443  {
444  kDebug( 14010 ) << "Contact already exists";
445 // emit contactAdded( c, suppress );
446  }
447  else
448  {
449  if ( d->contacts.count() == 1 && d->isEmpty )
450  {
451  kDebug( 14010 ) << " FUCKER ZONE ";
452  /* We have only 1 contact before, so the status of the
453  message manager was given from that contact status */
454  Kopete::Contact *old = d->contacts.first();
455  d->contacts.removeAll( old );
456  d->contacts.append( (Kopete::Contact*)c );
457 
458  disconnect( old, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
459  this, SLOT(slotOnlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)) );
460  disconnect( old, SIGNAL(statusMessageChanged(Kopete::Contact*)), this, SIGNAL(statusMessageChanged(Kopete::Contact*)) );
461 
462  if ( old->metaContact() )
463  {
464  disconnect( old->metaContact(), SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
465  disconnect( old->metaContact(), SIGNAL(photoChanged()), this, SIGNAL(photoChanged()) );
466  }
467  else
468  disconnect( old, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
469 
470  disconnect( old, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotDisplayNameChanged(QString,QString)) );
471 
472  emit contactAdded( c, suppress );
473  emit contactRemoved( old, QString() );
474  }
475  else
476  {
477  d->contacts.append( (Kopete::Contact*)c );
478  emit contactAdded( c, suppress );
479  }
480 
481  connect( c, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
482  this, SLOT(slotOnlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)) );
483  connect( c, SIGNAL(statusMessageChanged(Kopete::Contact*)), this, SIGNAL(statusMessageChanged(Kopete::Contact*)) );
484 
485  if ( c->metaContact() )
486  {
487  connect( c->metaContact(), SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
488  connect( c->metaContact(), SIGNAL(photoChanged()), this, SIGNAL(photoChanged()) );
489  }
490  else
491  connect( c, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
492  connect( c, SIGNAL(contactDestroyed(Kopete::Contact*)), this, SLOT(slotContactDestroyed(Kopete::Contact*)) );
493  connect( c, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotDisplayNameChanged(QString,QString)) );
494 
495  slotUpdateDisplayName();
496  }
497  d->isEmpty = false;
498 }
499 
500 void Kopete::ChatSession::removeContact( const Kopete::Contact *c, const QString& reason, Qt::TextFormat format, bool suppressNotification )
501 {
502  kDebug( 14010 ) ;
503  if ( !c || !d->contacts.contains( (Kopete::Contact*)c ) )
504  return;
505 
506  if ( d->contacts.count() == 1 )
507  {
508  kDebug( 14010 ) << "Contact not removed. Keep always one contact";
509  d->isEmpty = true;
510  }
511  else
512  {
513  d->contacts.removeAll( (Kopete::Contact*)c );
514 
515  disconnect( c, SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
516  this, SLOT(slotOnlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)) );
517 
518  if ( c->metaContact() )
519  {
520  disconnect( c->metaContact(), SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
521  disconnect( c->metaContact(), SIGNAL(photoChanged()), this, SIGNAL(photoChanged()) );
522  }
523  else
524  disconnect( c, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotUpdateDisplayName()) );
525  disconnect( c, SIGNAL(contactDestroyed(Kopete::Contact*)), this, SLOT(slotContactDestroyed(Kopete::Contact*)) );
526 
527  disconnect( c, SIGNAL(displayNameChanged(QString,QString)), this, SLOT(slotDisplayNameChanged(QString,QString)) );
528 
529  slotUpdateDisplayName();
530  }
531 
532  d->contactStatus.remove( c );
533 
534  emit contactRemoved( c, reason, format, suppressNotification );
535 }
536 
537 void Kopete::ChatSession::receivedTypingMsg( const Kopete::Contact *c, bool t )
538 {
539  emit remoteTyping( c, t );
540 
541  if ( ( account()->isAway() && ! Kopete::BehaviorSettings::self()->enableEventsWhileAway() ) || account()->isBusy() )
542  return;
543 
544  QWidget * viewWidget = dynamic_cast<QWidget*>(view(false));
545  bool isActiveWindow = view(false) && ( viewWidget && viewWidget->isActiveWindow() );
546 
547  // We aren't interested in notification from current window
548  // or 'user stopped typing' notifications
549  if ( isActiveWindow || !t )
550  {
551  return;
552  }
553 
554  // If there is a notification in d->typingNotifications, then we should show it and quit
555  Kopete::ActiveNotifications::iterator notifyIt =
556  d->typingNotifications.find( c->account()->accountLabel() + c->contactId() );
557  if (notifyIt != d->typingNotifications.end())
558  {
559  ( *notifyIt )->showNotification();
560  return;
561  }
562 
563  KNotification *notification = new KNotification( "user_is_typing_message", viewWidget );
564  const QString msgBody = i18n( "User <i>%1</i> is typing a message", c->displayName() );
565  notification->setText( msgBody );
566  notification->setPixmap( QPixmap::fromImage( c->metaContact()->picture().image() ) );
567  notification->setActions( QStringList( i18nc("@action", "Chat") ) );
568 
569  new Kopete::ActiveNotification( notification,
570  c->account()->accountLabel() + c->contactId(),
571  d->typingNotifications,
572  "",
573  msgBody );
574 
575  Kopete::MetaContact *mc = c->metaContact();
576  if ( mc )
577  {
578  notification->addContext( qMakePair( QString::fromLatin1("contact"), mc->metaContactId().toString() ) );
579  foreach( Kopete::Group *g , mc->groups() )
580  {
581  notification->addContext( qMakePair( QString::fromLatin1("group") , QString::number( g->groupId() ) ) );
582  }
583  }
584  connect( notification, SIGNAL(activated(uint)) , c, SLOT(execute()) );
585  // User don't need this notification when view is activate
586  connect( this, SIGNAL(viewActivated(KopeteView*)), notification, SLOT(close()) );
587 
588  notification->sendEvent();
589 }
590 
591 
592 void Kopete::ChatSession::receivedTypingMsg( const QString &contactId, bool t )
593 {
594  int i;
595 
596  // FIXME: this needs better design. We can't iterate through List to find out who got what ID
597  // hash will be better for that, right ?
598  for ( i=0; i != d->contacts.size(); i++ )
599  {
600  if ( (d->contacts[i])->contactId() == contactId )
601  {
602  receivedTypingMsg( d->contacts[i], t );
603  return;
604  }
605  }
606 }
607 
608 void Kopete::ChatSession::typing( bool t )
609 {
610  emit myselfTyping( t );
611 }
612 
613 void Kopete::ChatSession::receivedEventNotification( const QString& notificationText)
614 {
615  emit eventNotification( notificationText );
616 }
617 
618 void Kopete::ChatSession::receivedMessageState( uint messageId, Kopete::Message::MessageState state )
619 {
620  emit messageStateChanged( messageId, state );
621 }
622 
623 void Kopete::ChatSession::setCanBeDeleted ( bool b )
624 {
625  d->mCanBeDeleted = b;
626  if (d->refcount < (b?1:0) && !d->view )
627  deleteLater();
628 }
629 
630 void Kopete::ChatSession::ref ()
631 {
632  d->refcount++;
633 }
634 void Kopete::ChatSession::deref ()
635 {
636  d->refcount--;
637  if ( d->refcount < 1 && d->mCanBeDeleted && !d->view )
638  deleteLater();
639 }
640 
641 KopeteView* Kopete::ChatSession::view( bool canCreate, const QString &requestedPlugin )
642 {
643  if ( !d->view && canCreate )
644  {
645  d->view = Kopete::ChatSessionManager::self()->createView( this, requestedPlugin );
646  if ( d->view )
647  {
648  connect( d->view->mainWidget(), SIGNAL(activated(KopeteView*)), this, SIGNAL(viewActivated(KopeteView*)) );
649  connect( d->view->mainWidget(), SIGNAL(closing(KopeteView*)), this, SLOT(slotViewDestroyed()) );
650  }
651  else
652  {
653  KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Error,
654  i18n( "<qt>An error has occurred while creating a new chat window. The chat window has not been created.</qt>" ),
655  i18n( "Error While Creating Chat Window" ) );
656  }
657  }
658  return d->view;
659 }
660 
661 void Kopete::ChatSession::slotViewDestroyed()
662 {
663  d->view = 0L;
664  if ( d->mCanBeDeleted && d->refcount < 1)
665  deleteLater();
666 }
667 
668 Kopete::Account *Kopete::ChatSession::account() const
669 {
670  if ( !myself() )
671  return 0;
672 
673  return myself()->account();
674 }
675 
676 void Kopete::ChatSession::slotContactDestroyed( Kopete::Contact *contact )
677 {
678  if( !contact || !d->contacts.contains( contact ) )
679  return;
680 
681  //This is a workaround to prevent crash if the contact get deleted.
682  // in the best case, we should ask the protocol to recreate a temporary contact.
683  // (remember: the contact may be deleted when the users removes it from the contact list, or when closing kopete )
684  d->contacts.removeAll( contact );
685  emit contactRemoved( contact, QString() );
686 
687  if ( d->contacts.isEmpty() )
688  deleteLater();
689 }
690 
691 void Kopete::ChatSession::slotMyselfDestroyed( Kopete::Contact *contact )
692 {
693  Q_UNUSED(contact);
694  d->mUser = 0;
695  deleteLater();
696 }
697 
698 bool Kopete::ChatSession::mayInvite() const
699 {
700  return d->mayInvite;
701 }
702 
703 void Kopete::ChatSession::inviteContact(const QString& )
704 {
705  //default implementation do nothing
706 }
707 
708 void Kopete::ChatSession::setMayInvite( bool b )
709 {
710  d->mayInvite=b;
711 }
712 
713 void Kopete::ChatSession::raiseView()
714 {
715  KopeteView *v=view(true, Kopete::BehaviorSettings::self()->viewPlugin() );
716  if(v)
717  v->raise(true);
718 }
719 
720 Kopete::ChatSession::Form Kopete::ChatSession::form() const
721 {
722  return d->form;
723 }
724 bool Kopete::ChatSession::warnGroupChat() const
725 {
726  return d->warnGroupChat;
727 }
728 
729 void Kopete::ChatSession::setWarnGroupChat( bool b )
730 {
731  d->warnGroupChat=b;
732 }
733 
734 void Kopete::ChatSession::slotDisplayNameChanged(const QString &oldName, const QString &)
735 {
736  Kopete::Contact *c = static_cast<Kopete::Contact *>(sender());
737  emit nickNameChanged(c, oldName);
738 }
739 
740 #include "kopetechatsession.moc"
741 
742 
743 
744 // vim: set noet ts=4 sts=4 sw=4:
745 
Kopete::Account::accountLabel
QString accountLabel() const
The label for this account.
Definition: kopeteaccount.cpp:292
kopetemetacontact.h
Kopete::OnlineStatus
Definition: kopeteonlinestatus.h:68
Kopete::ChatSession::receivedEventNotification
void receivedEventNotification(const QString &notificationText)
Got an event notification from a user.
Definition: kopetechatsession.cpp:613
Kopete::MessageEvent
Definition: kopetemessageevent.h:41
status
OnlineStatus::StatusType status
Definition: kopeteonlinestatus.cpp:103
QWidget
Kopete::ChatSession::setCanBeDeleted
void setCanBeDeleted(bool canBeDeleted)
Set if the KMM will be deleted when the chatwindow is deleted.
Definition: kopetechatsession.cpp:623
QRegExp::cap
QString cap(int nth) const
kopetechatsessionmanager.h
QString::append
QString & append(QChar ch)
Kopete::ChatSession::receivedMessageState
void receivedMessageState(uint messageId, Kopete::Message::MessageState state)
Change state of message.
Definition: kopetechatsession.cpp:618
Kopete::Message::setImportance
void setImportance(MessageImportance importance)
Set the importance.
Definition: kopetemessage.cpp:281
QTextStream::readLine
QString readLine(qint64 maxlen)
kopeteaccount.h
Kopete::ChatSession::ref
void ref()
reference count the chat session.
Definition: kopetechatsession.cpp:630
KopeteView::raise
virtual void raise(bool activate=false)=0
Raises the view above other windows.
Kopete::Contact::contactId
QString contactId
Definition: kopetecontact.h:70
Kopete::Protocol
base class of every protocol.
Definition: kopeteprotocol.h:62
Kopete::ChatSessionManager::createView
KopeteView * createView(Kopete::ChatSession *, const QString &requestedPlugin=QString())
create a new view for the manager.
Definition: kopetechatsessionmanager.cpp:156
Kopete::ChatSession::form
Form form() const
Get the form of this chatsession.
Definition: kopetechatsession.cpp:720
QRegExp::escape
QString escape(const QString &str)
QList::at
const T & at(int i) const
QMap< const Kopete::Contact *, Kopete::OnlineStatus >
Kopete::ChatSession::contactOnlineStatus
const OnlineStatus contactOnlineStatus(const Contact *contact) const
get the status of a contact.
Definition: kopetechatsession.cpp:141
QPointer< Kopete::ChatSession >
Kopete::ChatSession::~ChatSession
~ChatSession()
Delete a chat manager instance You shouldn't delete the KMM yourself.
Definition: kopetechatsession.cpp:113
kopetecommandhandler.h
kopetegroup.h
Kopete::Contact::account
Account * account() const
Get the account that this contact belongs to.
Definition: kopetecontact.cpp:538
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
Kopete::Message::MessageState
MessageState
Definition: kopetemessage.h:116
Kopete::ChatSession::chainForDirection
MessageHandlerChain::Ptr chainForDirection(Message::MessageDirection dir)
Returns the message handler chain for the message direction dir.
Definition: kopetechatsession.cpp:269
Kopete::MessageHandlerFactory
Definition: kopetemessagehandler.h:109
Kopete::ChatSession::findUrls
QStringList findUrls(const Kopete::Message &msg)
finds all urls in the current message (if there are many) sorts them as they are in the meassage QStr...
Definition: kopetechatsession.cpp:362
QFile::exists
bool exists() const
Kopete::ChatSession::getUrlsFileName
static QString getUrlsFileName(const Kopete::Contact *)
returns file name where urls for this contact supposed to be
Definition: kopetechatsession.cpp:418
Kopete::ChatSession::setMayInvite
void setMayInvite(bool)
Set whether or not contact from this account may be invited in this chat.
Definition: kopetechatsession.cpp:708
Kopete::ChatSession
Definition: kopetechatsession.h:74
Kopete::Message::Outbound
Message sent by the user.
Definition: kopetemessage.h:91
QFile
QTextStream
kopeteuiglobal.h
QList::size
int size() const
Kopete::ChatSession::appendMessage
void appendMessage(Kopete::Message &msg)
Show a message to the chatwindow, or append it to the queue.
Definition: kopetechatsession.cpp:310
Kopete::Picture::image
QImage image()
Return the current picture as QImage.
Definition: kopetepicture.cpp:78
QObject::event
virtual bool event(QEvent *e)
QRegExp::setPattern
void setPattern(const QString &pattern)
QRegExp::matchedLength
int matchedLength() const
Kopete::Message::direction
MessageDirection direction() const
Accessor method for the direction of the message.
Definition: kopetemessage.cpp:580
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
Kopete::Contact::onlineStatus
OnlineStatus onlineStatus() const
Get the online status of the contact.
Definition: kopetecontact.cpp:173
QString::number
QString number(int n, int base)
Kopete::Contact::protocol
Protocol * protocol() const
Get the protocol that the contact belongs to.
Definition: kopetecontact.cpp:533
Kopete::ChatSession::initLastUrl
QString initLastUrl(const Kopete::Contact *c)
finds proper file with lasturls for current contact ChatSession->members().first() then sets lasturl ...
Definition: kopetechatsession.cpp:390
QMapIterator
QTextStream::atEnd
bool atEnd() const
Kopete::MessageHandlerChain::create
static Ptr create(ChatSession *manager, Message::MessageDirection direction)
Create a new MessageHandlerChain object with the appropriate handlers for processing messages enterin...
Definition: kopetemessagehandlerchain.cpp:55
QList::empty
bool empty() const
Kopete::MetaContact::picture
Picture & picture() const
Return the correct Kopete::Picture object depending of the metacontact photo source.
Definition: kopetemetacontact.cpp:750
Kopete::ChatSession::setLastUrl
void setLastUrl(const QString &verylastUrl)
sets lastUrl for current ChatSession
Definition: kopetechatsession.cpp:149
QHash< QString, ActiveNotification * >
Kopete::Group::groupId
uint groupId
Definition: kopetegroup.h:47
QMapIterator::next
Item next()
QObject
Kopete::ChatSession::ChatSession
ChatSession(const Contact *user, ContactPtrList others, Protocol *protocol, Form form=Small)
Create a message manager.
Definition: kopetechatsession.cpp:78
Kopete::Account::accountId
QString accountId
Definition: kopeteaccount.h:77
kopetepicture.h
Kopete::Plugin::pluginId
QString pluginId() const
Get the plugin id.
Definition: kopeteplugin.cpp:46
Kopete::Message::setManager
void setManager(ChatSession *manager)
Set the messagemanager for this message.
Definition: kopetemessage.cpp:610
kopeteprotocol.h
QList::isEmpty
bool isEmpty() const
Kopete::Message::MessageDirection
MessageDirection
Direction of a message.
Definition: kopetemessage.h:88
QString::isEmpty
bool isEmpty() const
kopetechatsession.h
Kopete::MetaContact::displayName
QString displayName
Definition: kopetemetacontact.h:58
Kopete::ChatSession::sendMessage
void sendMessage(Kopete::Message &message)
Send a message to the user.
Definition: kopetechatsession.cpp:281
Kopete::ChatSession::messageSucceeded
void messageSucceeded()
Protocols have to call this method when the last message sent has been correctly sent This will emit ...
Definition: kopetechatsession.cpp:299
Kopete::ChatSession::typing
void typing(bool t)
Tell the KMM that the user is typing This method should be called only by a chatwindow.
Definition: kopetechatsession.cpp:608
Kopete::Message::Inbound
Message is from the chat partner.
Definition: kopetemessage.h:90
QStringList::replaceInStrings
QStringList & replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
QList::first
T & first()
QString
Kopete::MessageHandler::handleMessage
virtual void handleMessage(MessageEvent *event)
Performs any processing necessary on the message.
Definition: kopetemessagehandler.cpp:63
QList< Contact * >
QWidget::isActiveWindow
isActiveWindow
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QMapIterator::value
const T & value() const
Kopete::Contact
Definition: kopetecontact.h:58
QStringList
Kopete::ChatSession::photoChanged
void photoChanged()
A contact within the chat session changed his photo.
Kopete::Plugin
Base class for all plugins or protocols.
Definition: kopeteplugin.h:84
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
Kopete::ChatSession::mayInvite
bool mayInvite() const
says if you may invite contact from the same account to this chat with inviteContact ...
Definition: kopetechatsession.cpp:698
kopetemessagehandlerchain.h
QFile::close
virtual void close()
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::PluginManager::self
static PluginManager * self()
Retrieve the plugin loader instance.
Definition: kopetepluginmanager.cpp:104
Kopete::ChatSessionManager::self
static ChatSessionManager * self()
Definition: kopetechatsessionmanager.cpp:39
QString::replace
QString & replace(int position, int n, QChar after)
Kopete::ChatSession::setContactOnlineStatus
void setContactOnlineStatus(const Contact *contact, const OnlineStatus &newStatus)
set a specified KOS for specified contact in this KMM
Definition: kopetechatsession.cpp:132
Kopete::ChatSession::addContact
void addContact(const Kopete::Contact *c, bool suppress=false)
Add a contact to the session.
Definition: kopetechatsession.cpp:439
Kopete::Contact::metaContact
MetaContact * metaContact() const
Get the metacontact for this contact.
Definition: kopetecontact.cpp:523
Kopete::ChatSession::account
Account * account() const
get the account
Definition: kopetechatsession.cpp:668
Kopete::MessageHandlerChain::Ptr
KSharedPtr< MessageHandlerChain > Ptr
Definition: kopetemessagehandlerchain.h:50
Kopete::ChatSession::myself
const Contact * myself() const
Get the local user in the session.
Definition: kopetechatsession.cpp:215
QLatin1String
QWidget::find
QWidget * find(WId id)
Kopete::BehaviorSettings::self
static BehaviorSettings * self()
Definition: kopetebehaviorsettings.cpp:23
Kopete::ChatSession::members
const ContactPtrList & members() const
Get a list of all contacts in the session.
Definition: kopetechatsession.cpp:210
kopetemessageevent.h
Kopete::ChatSession::onlineStatusChanged
void onlineStatusChanged(Kopete::Contact *, const Kopete::OnlineStatus &, const Kopete::OnlineStatus &)
a contact in this chat has changed his status
QList::last
T & last()
Kopete::ChatSession::receivedTypingMsg
void receivedTypingMsg(const Kopete::Contact *contact, bool isTyping=true)
Got a typing notification from a user.
Definition: kopetechatsession.cpp:537
CHAIN_COUNT
const int CHAIN_COUNT
Definition: kopetechatsession.cpp:54
Kopete::Group
Class which represents the Group.
Definition: kopetegroup.h:44
Kopete::ChatSession::deref
void deref()
dereference count the chat session if the reference counter reach 0 and there is no chat window open...
Definition: kopetechatsession.cpp:634
Kopete::Contact::displayName
QString displayName() const
Returns display name of contact.
Definition: kopetecontact.cpp:913
Kopete::MessageHandler
Definition: kopetemessagehandler.h:44
Kopete::ChatSession::urlSearch
void urlSearch(const Kopete::Message &msg)
prosesses every sent/appended message looks for urls, if found: sets current lastUrl and save it to p...
Definition: kopetechatsession.cpp:343
Kopete::ChatSession::lastUrl
const QString lastUrl()
returns lastUrl for current ChatSession can be empty
Definition: kopetechatsession.cpp:154
Kopete::MetaContact
Definition: kopetemetacontact.h:54
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Kopete::ChatSession::displayName
const QString displayName()
The caption of the chat.
Definition: kopetechatsession.cpp:159
kopeteview.h
QMap::insert
iterator insert(const Key &key, const T &value)
Kopete::ChatSession::setDisplayName
void setDisplayName(const QString &displayName)
change the displayname
Definition: kopetechatsession.cpp:169
Kopete::ChatSession::setWarnGroupChat
void setWarnGroupChat(bool)
set if kopete show warning message, when you closing window of group chat By default, it is set to true
Definition: kopetechatsession.cpp:729
kopetemessagehandler.h
Kopete::ChatSession::protocol
Protocol * protocol() const
Get the protocol being used.
Definition: kopetechatsession.cpp:220
Kopete::ChatSession::Form
Form
Describes the form of this chat session.
Definition: kopetechatsession.h:85
Kopete::Message::plainBody
QString plainBody() const
Get the message body back as plain text.
Definition: kopetemessage.cpp:366
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::ActiveNotification
Definition: kopeteactivenotification.h:30
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
kopetebehaviorsettings.h
Kopete::ChatSession::removeContact
void removeContact(const Kopete::Contact *contact, const QString &reason=QString(), Qt::TextFormat format=Qt::PlainText, bool suppressNotification=false)
Remove a contact from the session.
Definition: kopetechatsession.cpp:500
Kopete::Message::manager
ChatSession * manager() const
Get the related message manager.
Definition: kopetemessage.cpp:605
Kopete::ChatSession::emitNudgeNotification
void emitNudgeNotification()
Protocols have to call this method if they want to emit a notification when a nudge/buzz is received...
Definition: kopetechatsession.cpp:304
Kopete::Account
The Kopete::Account class handles one account.
Definition: kopeteaccount.h:72
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Kopete::CommandHandler::commandHandler
static CommandHandler * commandHandler()
Returns a pointer to the command handler.
Definition: kopetecommandhandler.cpp:164
Kopete::Message
Representation of a message in Kopete.
Definition: kopetemessage.h:82
Kopete::ChatSessionManager::removeSession
void removeSession(Kopete::ChatSession *session)
Definition: kopetechatsessionmanager.cpp:145
Kopete::Message::regexpPatterns
const QStringList regexpPatterns()
returns QStringList with regexp patterns will be used to look for links in the message ...
Definition: kopetemessage.cpp:420
kopetepluginmanager.h
Kopete::Message::Highlight
Highlight notification, for most important messages, which require particular attentions.
Definition: kopetemessage.h:113
kopetecontact.h
kopeteglobal.h
kopeteactivenotification.h
QMapIterator::hasNext
bool hasNext() const
QDateTime
Kopete::ChatSession::inviteContact
virtual void inviteContact(const QString &contactId)
this method is called when a contact is dragged to the contact list.
Definition: kopetechatsession.cpp:703
Kopete::ChatSession::warnGroupChat
bool warnGroupChat() const
say if kopete show warning message, when you closing window of group chat
Definition: kopetechatsession.cpp:724
name
const char * name
Definition: kopeteonlinestatus.cpp:104
Kopete::ChatSession::raiseView
void raiseView()
Raise the chat window and give him the focus It's used when the user wanted to activated (by clicking...
Definition: kopetechatsession.cpp:713
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 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