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

kopete/libkopete

kopetechatsessionmanager.cpp

Go to the documentation of this file.
00001 /*
00002     kopetechatsessionmanager.cpp - Creates chat sessions
00003 
00004     Copyright (c) 2002-2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
00005 
00006     Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>
00007 
00008     *************************************************************************
00009     *                                                                       *
00010     * This library is free software; you can redistribute it and/or         *
00011     * modify it under the terms of the GNU Lesser General Public            *
00012     * License as published by the Free Software Foundation; either          *
00013     * version 2 of the License, or (at your option) any later version.      *
00014     *                                                                       *
00015     *************************************************************************
00016 */
00017 
00018 #include "kopetechatsessionmanager.h"
00019 #include "kopeteviewmanager.h"
00020 
00021 #include <kapplication.h>
00022 #include <kdebug.h>
00023 
00024 #include "ui/kopeteview.h"
00025 #include "kopetecontact.h"
00026 #include <QList>
00027 
00028 namespace Kopete {
00029 
00030 class ChatSessionManager::Private
00031 {
00032   public:
00033     QList <ChatSession*> sessions;
00034 //  UI::ChatView *activeView;
00035 };
00036 
00037 ChatSessionManager* ChatSessionManager::s_self = 0L;
00038 
00039 ChatSessionManager* ChatSessionManager::self()
00040 {
00041     if( !s_self )
00042         s_self = new ChatSessionManager( kapp );
00043 
00044     return s_self;
00045 }
00046 
00047 ChatSessionManager::ChatSessionManager( QObject* parent )
00048     : QObject( parent )
00049 {
00050     d=new Private;
00051     s_self = this;
00052 }
00053 
00054 ChatSessionManager::~ChatSessionManager()
00055 {
00056     s_self = 0L;
00057     QList<ChatSession*>::Iterator it;
00058     for ( it=d->sessions.begin() ; it!=d->sessions.end() ; ++it )
00059     {
00060         kDebug( 14010 ) << "Unloading KMM: Why this KMM isn't yet unloaded?";
00061         (*it)->deleteLater();
00062     }
00063     delete d;
00064 }
00065 
00066 ChatSession* ChatSessionManager::findChatSession(const Contact *user,
00067         ContactPtrList chatContacts, Protocol *protocol)
00068 {
00069     ChatSession *result = 0L;
00070     QList<ChatSession*>::Iterator it;
00071     int i;
00072 
00073     for ( it= d->sessions.begin(); it!=d->sessions.end() && !result ; ++it  )
00074     {
00075       ChatSession* cs=(*it);
00076       if ( cs->protocol() == protocol && user == cs->myself() )
00077         {
00078             QList<Contact*> contactlist = cs->members();
00079 
00080             // set this to false if chatContacts doesn't contain current cs's contact list
00081             bool halfMatch = true;
00082 
00083             for ( i = 0; i != contactlist.size() && halfMatch; i++ )
00084             {
00085                 if ( !chatContacts.contains( contactlist[i] ) )
00086                     halfMatch = false;
00087             }
00088 
00089             // If chatContacts contains current cs's contactlist, try the other way around
00090             if (halfMatch)
00091             {
00092                 bool fullMatch = true;
00093                 for ( i = 0; i != chatContacts.size() && fullMatch; i++ )
00094                 {
00095                     if ( !contactlist.contains( chatContacts[i] ) )
00096                         fullMatch = false;
00097                 }
00098                 // We have a winner
00099                 if (fullMatch)
00100                     result = cs;
00101             }
00102         }
00103     }
00104     return result;
00105 }
00106 
00107 ChatSession *ChatSessionManager::create(
00108     const Contact *user, ContactPtrList chatContacts, Protocol *protocol, Kopete::ChatSession::Form form )
00109 {
00110     ChatSession *result=findChatSession( user,  chatContacts, protocol);
00111     if (!result)
00112     {
00113         result = new ChatSession(user,  chatContacts, protocol, form );
00114         registerChatSession(result);
00115     }
00116     return (result);
00117 }
00118 
00119 void ChatSessionManager::slotReadMessage()
00120 {
00121     emit readMessage();
00122 }
00123 
00124 void ChatSessionManager::registerChatSession(ChatSession * result)
00125 {
00126     d->sessions.append( result );
00127 
00128     /*
00129      * There's no need for a slot here... just add a public remove()
00130      * method and call from KMM's destructor
00131      */
00132     connect( result, SIGNAL( messageAppended( Kopete::Message &, Kopete::ChatSession * ) ),
00133         SIGNAL( aboutToDisplay( Kopete::Message & ) ) );
00134     connect( result, SIGNAL( messageSent( Kopete::Message &, Kopete::ChatSession * ) ),
00135         SIGNAL( aboutToSend(Kopete::Message & ) ) );
00136     connect( result, SIGNAL( messageReceived( Kopete::Message &, Kopete::ChatSession * ) ),
00137         SIGNAL( aboutToReceive(Kopete::Message & ) ) );
00138 
00139     connect( result, SIGNAL(messageAppended( Kopete::Message &, Kopete::ChatSession *) ),
00140         SIGNAL( display( Kopete::Message &, Kopete::ChatSession *) ) );
00141 
00142     emit chatSessionCreated(result);
00143 }
00144 
00145 
00146 void ChatSessionManager::removeSession( ChatSession *session)
00147 {
00148     kDebug(14010) ;
00149     d->sessions.removeAll( session );
00150 }
00151 
00152 QList<ChatSession*> ChatSessionManager::sessions( )
00153 {
00154     return d->sessions;
00155 }
00156 
00157 KopeteView * ChatSessionManager::createView( ChatSession *kmm , const QString &requestedPlugin )
00158 {
00159     KopeteView *newView = KopeteViewManager::viewManager()->view(kmm,requestedPlugin);
00160     if(!newView)
00161     {
00162         kDebug(14010) << "View not successfuly created";
00163         return 0L;
00164     }
00165 
00166     QObject *viewObject = dynamic_cast<QObject *>(newView);
00167     if(viewObject)
00168     {
00169         connect(viewObject, SIGNAL(activated(KopeteView *)),
00170             this, SIGNAL(viewActivated(KopeteView *)));
00171         connect(viewObject, SIGNAL(closing(KopeteView *)),
00172             this, SIGNAL(viewClosing(KopeteView *)));
00173     }
00174     else
00175     {
00176         kWarning(14010) << "Failed to cast view to QObject *";
00177     }
00178 
00179     emit viewCreated( newView ) ;
00180     return newView;
00181 }
00182 
00183 void ChatSessionManager::postNewEvent(MessageEvent *e)
00184 {
00185     emit newEvent(e);
00186 }
00187 
00188 KopeteView *ChatSessionManager::activeView()
00189 {
00190     return KopeteViewManager::viewManager()->activeView();
00191 }
00192 
00193 } //END namespace Kopete
00194 
00195 #include "kopetechatsessionmanager.moc"
00196 
00197 // vim: set noet ts=4 sts=4 sw=4:
00198 

kopete/libkopete

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal