summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopetechatsessionmanager.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/kopetechatsessionmanager.cpp
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/libkopete/kopetechatsessionmanager.cpp')
-rw-r--r--kopete/libkopete/kopetechatsessionmanager.cpp197
1 files changed, 197 insertions, 0 deletions
diff --git a/kopete/libkopete/kopetechatsessionmanager.cpp b/kopete/libkopete/kopetechatsessionmanager.cpp
new file mode 100644
index 00000000..9b7dd489
--- /dev/null
+++ b/kopete/libkopete/kopetechatsessionmanager.cpp
@@ -0,0 +1,197 @@
+/*
+ kopetechatsessionmanager.cpp - Creates chat sessions
+
+ Copyright (c) 2002-2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
+
+ Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
+
+ *************************************************************************
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2 of the License, or (at your option) any later version. *
+ * *
+ *************************************************************************
+*/
+
+#include "kopetechatsessionmanager.h"
+#include "kopeteviewmanager.h"
+
+#include <kapplication.h>
+#include <kdebug.h>
+
+#include "ui/kopeteview.h"
+#include "kopetecontact.h"
+
+namespace Kopete {
+
+class ChatSessionManager::Private
+{
+ public:
+ QValueList <ChatSession*> sessions;
+// UI::ChatView *activeView;
+};
+
+ChatSessionManager* ChatSessionManager::s_self = 0L;
+
+ChatSessionManager* ChatSessionManager::self()
+{
+ if( !s_self )
+ s_self = new ChatSessionManager( kapp );
+
+ return s_self;
+}
+
+ChatSessionManager::ChatSessionManager( QObject* parent,
+ const char* name )
+ : QObject( parent, name )
+{
+ d=new Private;
+ s_self = this;
+}
+
+ChatSessionManager::~ChatSessionManager()
+{
+ s_self = 0L;
+ QValueListIterator<ChatSession*> it;
+ for ( it=d->sessions.begin() ; it!=d->sessions.end() ; ++it )
+ {
+ kdDebug( 14010 ) << k_funcinfo << "Unloading KMM: Why this KMM isn't yet unloaded?" << endl;
+ (*it)->deleteLater();
+ }
+ delete d;
+}
+
+ChatSession* ChatSessionManager::findChatSession(const Contact *user,
+ ContactPtrList chatContacts, Protocol *protocol)
+{
+ ChatSession *result = 0L;
+ QValueList<ChatSession*>::Iterator it;
+ for ( it= d->sessions.begin(); it!=d->sessions.end() && !result ; ++it )
+ {
+ ChatSession* cs=(*it);
+ if ( cs->protocol() == protocol && user == cs->myself() )
+ {
+ QPtrList<Contact> contactlist = cs->members();
+
+ // set this to false if chatContacts doesn't contain current cs's contactlist
+ bool halfMatch = true;
+
+ Contact *tmpContact;
+ for (tmpContact = contactlist.first(); tmpContact && halfMatch; tmpContact = contactlist.next())
+ {
+ if ( !chatContacts.containsRef( tmpContact ) )
+ halfMatch = false;
+ }
+
+ // If chatContacts contains current cs's contactlist, try the other way around
+ if (halfMatch)
+ {
+ bool fullMatch = true;
+ for (tmpContact = chatContacts.first(); tmpContact && fullMatch; tmpContact = chatContacts.next())
+ {
+ if ( !contactlist.containsRef( tmpContact ) )
+ fullMatch = false;
+ }
+ // We have a winner
+ if (fullMatch)
+ result = cs;
+ }
+ }
+ }
+ return result;
+}
+
+ChatSession *ChatSessionManager::create(
+ const Contact *user, ContactPtrList chatContacts, Protocol *protocol)
+{
+ ChatSession *result=findChatSession( user, chatContacts, protocol);
+ if (!result)
+ {
+ result = new ChatSession(user, chatContacts, protocol );
+ registerChatSession(result);
+ }
+ return (result);
+}
+
+void ChatSessionManager::slotReadMessage()
+{
+ emit readMessage();
+}
+
+void ChatSessionManager::registerChatSession(ChatSession * result)
+{
+ d->sessions.append( result );
+
+ /*
+ * There's no need for a slot here... just add a public remove()
+ * method and call from KMM's destructor
+ */
+ connect( result, SIGNAL( messageAppended( Kopete::Message &, Kopete::ChatSession * ) ),
+ SIGNAL( aboutToDisplay( Kopete::Message & ) ) );
+ connect( result, SIGNAL( messageSent( Kopete::Message &, Kopete::ChatSession * ) ),
+ SIGNAL( aboutToSend(Kopete::Message & ) ) );
+ connect( result, SIGNAL( messageReceived( Kopete::Message &, Kopete::ChatSession * ) ),
+ SIGNAL( aboutToReceive(Kopete::Message & ) ) );
+
+ connect( result, SIGNAL(messageAppended( Kopete::Message &, Kopete::ChatSession *) ),
+ SIGNAL( display( Kopete::Message &, Kopete::ChatSession *) ) );
+
+ emit chatSessionCreated(result);
+}
+
+
+void ChatSessionManager::removeSession( ChatSession *session)
+{
+ kdDebug(14010) << k_funcinfo << endl;
+ d->sessions.remove( session );
+}
+
+QValueList<ChatSession*> ChatSessionManager::sessions( )
+{
+ return d->sessions;
+}
+
+KopeteView * ChatSessionManager::createView( ChatSession *kmm , const QString &requestedPlugin )
+{
+ KopeteView *newView = KopeteViewManager::viewManager()->view(kmm,requestedPlugin);
+ if(!newView)
+ {
+ kdDebug(14010) << k_funcinfo << "View not successfuly created" << endl;
+ return 0L;
+ }
+
+ QObject *viewObject = dynamic_cast<QObject *>(newView);
+ if(viewObject)
+ {
+ connect(viewObject, SIGNAL(activated(KopeteView *)),
+ this, SIGNAL(viewActivated(KopeteView *)));
+ connect(viewObject, SIGNAL(closing(KopeteView *)),
+ this, SIGNAL(viewClosing(KopeteView *)));
+ }
+ else
+ {
+ kdWarning(14010) << "Failed to cast view to QObject *" << endl;
+ }
+
+ emit viewCreated( newView ) ;
+ return newView;
+}
+
+void ChatSessionManager::postNewEvent(MessageEvent *e)
+{
+ emit newEvent(e);
+}
+
+KopeteView *ChatSessionManager::activeView()
+{
+ return KopeteViewManager::viewManager()->activeView();
+}
+
+} //END namespace Kopete
+
+#include "kopetechatsessionmanager.moc"
+
+// vim: set noet ts=4 sts=4 sw=4:
+