make webinterface translatable. there are around 20 short strings, all with context...
[kdenetwork.git] / kopete / libkopete / kopetechatsessionmanager.cpp
blob6bcc458e95cde8af88c954e402822ed1397cc483
1 /*
2 kopetechatsessionmanager.cpp - Creates chat sessions
4 Copyright (c) 2002-2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
9 * *
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
14 * *
15 *************************************************************************
18 #include "kopetechatsessionmanager.h"
19 #include "kopeteviewmanager.h"
21 #include <kapplication.h>
22 #include <kdebug.h>
24 #include "ui/kopeteview.h"
25 #include "kopetecontact.h"
26 #include <QList>
28 namespace Kopete {
30 class ChatSessionManager::Private
32 public:
33 QList <ChatSession*> sessions;
34 // UI::ChatView *activeView;
37 ChatSessionManager* ChatSessionManager::s_self = 0L;
39 ChatSessionManager* ChatSessionManager::self()
41 if( !s_self )
42 s_self = new ChatSessionManager( kapp );
44 return s_self;
47 ChatSessionManager::ChatSessionManager( QObject* parent )
48 : QObject( parent )
50 d=new Private;
51 s_self = this;
54 ChatSessionManager::~ChatSessionManager()
56 s_self = 0L;
57 QList<ChatSession*>::Iterator it;
58 for ( it=d->sessions.begin() ; it!=d->sessions.end() ; ++it )
60 kDebug( 14010 ) << "Unloading KMM: Why this KMM isn't yet unloaded?";
61 (*it)->deleteLater();
63 delete d;
66 ChatSession* ChatSessionManager::findChatSession(const Contact *user,
67 ContactPtrList chatContacts, Protocol *protocol)
69 ChatSession *result = 0L;
70 QList<ChatSession*>::Iterator it;
71 int i;
73 for ( it= d->sessions.begin(); it!=d->sessions.end() && !result ; ++it )
75 ChatSession* cs=(*it);
76 if ( cs->protocol() == protocol && user == cs->myself() )
78 QList<Contact*> contactlist = cs->members();
80 // set this to false if chatContacts doesn't contain current cs's contact list
81 bool halfMatch = true;
83 for ( i = 0; i != contactlist.size() && halfMatch; i++ )
85 if ( !chatContacts.contains( contactlist[i] ) )
86 halfMatch = false;
89 // If chatContacts contains current cs's contactlist, try the other way around
90 if (halfMatch)
92 bool fullMatch = true;
93 for ( i = 0; i != chatContacts.size() && fullMatch; i++ )
95 if ( !contactlist.contains( chatContacts[i] ) )
96 fullMatch = false;
98 // We have a winner
99 if (fullMatch)
100 result = cs;
104 return result;
107 ChatSession *ChatSessionManager::create(
108 const Contact *user, ContactPtrList chatContacts, Protocol *protocol, Kopete::ChatSession::Form form )
110 ChatSession *result=findChatSession( user, chatContacts, protocol);
111 if (!result)
113 result = new ChatSession(user, chatContacts, protocol, form );
114 registerChatSession(result);
116 return (result);
119 void ChatSessionManager::slotReadMessage()
121 emit readMessage();
124 void ChatSessionManager::registerChatSession(ChatSession * result)
126 d->sessions.append( result );
129 * There's no need for a slot here... just add a public remove()
130 * method and call from KMM's destructor
132 connect( result, SIGNAL( messageAppended( Kopete::Message &, Kopete::ChatSession * ) ),
133 SIGNAL( aboutToDisplay( Kopete::Message & ) ) );
134 connect( result, SIGNAL( messageSent( Kopete::Message &, Kopete::ChatSession * ) ),
135 SIGNAL( aboutToSend(Kopete::Message & ) ) );
136 connect( result, SIGNAL( messageReceived( Kopete::Message &, Kopete::ChatSession * ) ),
137 SIGNAL( aboutToReceive(Kopete::Message & ) ) );
139 connect( result, SIGNAL(messageAppended( Kopete::Message &, Kopete::ChatSession *) ),
140 SIGNAL( display( Kopete::Message &, Kopete::ChatSession *) ) );
142 emit chatSessionCreated(result);
146 void ChatSessionManager::removeSession( ChatSession *session)
148 kDebug(14010) ;
149 d->sessions.removeAll( session );
152 QList<ChatSession*> ChatSessionManager::sessions( )
154 return d->sessions;
157 KopeteView * ChatSessionManager::createView( ChatSession *kmm , const QString &requestedPlugin )
159 KopeteView *newView = KopeteViewManager::viewManager()->view(kmm,requestedPlugin);
160 if(!newView)
162 kDebug(14010) << "View not successfuly created";
163 return 0L;
166 QObject *viewObject = dynamic_cast<QObject *>(newView);
167 if(viewObject)
169 connect(viewObject, SIGNAL(activated(KopeteView *)),
170 this, SIGNAL(viewActivated(KopeteView *)));
171 connect(viewObject, SIGNAL(closing(KopeteView *)),
172 this, SIGNAL(viewClosing(KopeteView *)));
174 else
176 kWarning(14010) << "Failed to cast view to QObject *";
179 emit viewCreated( newView ) ;
180 return newView;
183 void ChatSessionManager::postNewEvent(MessageEvent *e)
185 emit newEvent(e);
188 KopeteView *ChatSessionManager::activeView()
190 return KopeteViewManager::viewManager()->activeView();
193 } //END namespace Kopete
195 #include "kopetechatsessionmanager.moc"
197 // vim: set noet ts=4 sts=4 sw=4: