• 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
kopetechatsessionmanager.cpp
Go to the documentation of this file.
1 /*
2  kopetechatsessionmanager.cpp - Creates chat sessions
3 
4  Copyright (c) 2002-2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
5 
6  Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
7 
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  *************************************************************************
16 */
17 
18 #include "kopetechatsessionmanager.h"
19 #include "kopeteviewmanager.h"
20 
21 #include <kapplication.h>
22 #include <kdebug.h>
23 
24 #include "ui/kopeteview.h"
25 #include "kopetecontact.h"
26 #include <QList>
27 
28 namespace Kopete {
29 
30 class ChatSessionManager::Private
31 {
32  public:
33  QList <ChatSession*> sessions;
34 // UI::ChatView *activeView;
35 };
36 
37 ChatSessionManager* ChatSessionManager::s_self = 0L;
38 
39 ChatSessionManager* ChatSessionManager::self()
40 {
41  if( !s_self )
42  s_self = new ChatSessionManager( kapp );
43 
44  return s_self;
45 }
46 
47 ChatSessionManager::ChatSessionManager( QObject* parent )
48  : QObject( parent ), d(new Private())
49 {
50  s_self = this;
51 }
52 
53 ChatSessionManager::~ChatSessionManager()
54 {
55  s_self = 0L;
56  QList<ChatSession*>::ConstIterator it;
57  for ( it=d->sessions.constBegin() ; it!=d->sessions.constEnd() ; ++it )
58  {
59  kDebug( 14010 ) << "Unloading KMM: Why this KMM isn't yet unloaded?";
60  (*it)->deleteLater();
61  }
62  delete d;
63 }
64 
65 ChatSession* ChatSessionManager::findChatSession(const Contact *user,
66  ContactPtrList chatContacts, Protocol *protocol)
67 {
68  ChatSession *result = 0L;
69  QList<ChatSession*>::ConstIterator it;
70  int i;
71 
72  for ( it= d->sessions.constBegin(); it!=d->sessions.constEnd() && !result ; ++it )
73  {
74  ChatSession* cs=(*it);
75  if ( cs->protocol() == protocol && user == cs->myself() )
76  {
77  QList<Contact*> contactlist = cs->members();
78 
79  // set this to false if chatContacts doesn't contain current cs's contact list
80  bool halfMatch = true;
81 
82  for ( i = 0; i != contactlist.size() && halfMatch; i++ )
83  {
84  if ( !chatContacts.contains( contactlist[i] ) )
85  halfMatch = false;
86  }
87 
88  // If chatContacts contains current cs's contactlist, try the other way around
89  if (halfMatch)
90  {
91  bool fullMatch = true;
92  for ( i = 0; i != chatContacts.size() && fullMatch; i++ )
93  {
94  if ( !contactlist.contains( chatContacts[i] ) )
95  fullMatch = false;
96  }
97  // We have a winner
98  if (fullMatch)
99  result = cs;
100  }
101  }
102  }
103  return result;
104 }
105 
106 ChatSession *ChatSessionManager::create(
107  const Contact *user, ContactPtrList chatContacts, Protocol *protocol, Kopete::ChatSession::Form form )
108 {
109  ChatSession *result=findChatSession( user, chatContacts, protocol);
110  if (!result)
111  {
112  result = new ChatSession(user, chatContacts, protocol, form );
113  registerChatSession(result);
114  }
115  return (result);
116 }
117 
118 void ChatSessionManager::slotReadMessage()
119 {
120  emit readMessage();
121 }
122 
123 void ChatSessionManager::registerChatSession(ChatSession * result)
124 {
125  d->sessions.append( result );
126 
127  /*
128  * There's no need for a slot here... just add a public remove()
129  * method and call from KMM's destructor
130  */
131  connect( result, SIGNAL(messageAppended(Kopete::Message&,Kopete::ChatSession*)),
132  SIGNAL(aboutToDisplay(Kopete::Message&)) );
133  connect( result, SIGNAL(messageSent(Kopete::Message&,Kopete::ChatSession*)),
134  SIGNAL(aboutToSend(Kopete::Message&)) );
135  connect( result, SIGNAL(messageReceived(Kopete::Message&,Kopete::ChatSession*)),
136  SIGNAL(aboutToReceive(Kopete::Message&)) );
137 
138  connect( result, SIGNAL(messageAppended(Kopete::Message&,Kopete::ChatSession*)),
139  SIGNAL(display(Kopete::Message&,Kopete::ChatSession*)) );
140 
141  emit chatSessionCreated(result);
142 }
143 
144 
145 void ChatSessionManager::removeSession( ChatSession *session)
146 {
147  kDebug(14010) ;
148  d->sessions.removeAll( session );
149 }
150 
151 QList<ChatSession*> ChatSessionManager::sessions( )
152 {
153  return d->sessions;
154 }
155 
156 KopeteView * ChatSessionManager::createView( ChatSession *kmm , const QString &requestedPlugin )
157 {
158  KopeteView *newView = KopeteViewManager::viewManager()->view(kmm,requestedPlugin);
159  if(!newView)
160  {
161  kDebug(14010) << "View not successfuly created";
162  return 0L;
163  }
164 
165  QObject *viewObject = dynamic_cast<QObject *>(newView);
166  if(viewObject)
167  {
168  connect(viewObject, SIGNAL(activated(KopeteView*)),
169  this, SIGNAL(viewActivated(KopeteView*)));
170  connect(viewObject, SIGNAL(closing(KopeteView*)),
171  this, SIGNAL(viewClosing(KopeteView*)));
172  }
173  else
174  {
175  kWarning(14010) << "Failed to cast view to QObject *";
176  }
177 
178  emit viewCreated( newView ) ;
179  return newView;
180 }
181 
182 void ChatSessionManager::postNewEvent(MessageEvent *e)
183 {
184  emit newEvent(e);
185 }
186 
187 KopeteView *ChatSessionManager::activeView()
188 {
189  return KopeteViewManager::viewManager()->activeView();
190 }
191 
192 } //END namespace Kopete
193 
194 #include "kopetechatsessionmanager.moc"
195 
196 // vim: set noet ts=4 sts=4 sw=4:
197 
kopeteviewmanager.h
Kopete::MessageEvent
Definition: kopetemessageevent.h:41
Kopete::ChatSessionManager::activeView
KopeteView * activeView()
Returns the current active Kopete view.
Definition: kopetechatsessionmanager.cpp:187
Kopete::ChatSessionManager::aboutToDisplay
void aboutToDisplay(Kopete::Message &message)
This signal is emitted whenever a message is about to be displayed by the KopeteChatWindow.
kopetechatsessionmanager.h
Kopete::ChatSessionManager::readMessage
void readMessage()
The global shortcut for sending message has been used.
Kopete::ChatSessionManager::create
Kopete::ChatSession * create(const Kopete::Contact *user, Kopete::ContactPtrList chatContacts, Kopete::Protocol *protocol, Kopete::ChatSession::Form form=Kopete::ChatSession::Small)
Create a new chat session.
Definition: kopetechatsessionmanager.cpp:106
Kopete::ChatSessionManager::registerChatSession
void registerChatSession(Kopete::ChatSession *)
Registers a Kopete::ChatSession (or subclass thereof) with the Kopete::ChatSessionManager.
Definition: kopetechatsessionmanager.cpp:123
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::ChatSessionManager::newEvent
void newEvent(Kopete::MessageEvent *)
A new event has been posted.
Kopete::ChatSessionManager
Definition: kopetechatsessionmanager.h:47
Kopete::ChatSessionManager::aboutToReceive
void aboutToReceive(Kopete::Message &message)
Plugins may connect to this signal to manipulate the contents of the message that is being received...
Kopete::ChatSession
Definition: kopetechatsession.h:74
QList::size
int size() const
Kopete::ChatSessionManager::slotReadMessage
void slotReadMessage()
Definition: kopetechatsessionmanager.cpp:118
QObject
Kopete::ChatSessionManager::viewActivated
void viewActivated(KopeteView *view)
A view as been activated(manually only?).
Kopete::ChatSessionManager::~ChatSessionManager
~ChatSessionManager()
Definition: kopetechatsessionmanager.cpp:53
QString
QList
Kopete::Contact
Definition: kopetecontact.h:58
Kopete::ChatSessionManager::chatSessionCreated
void chatSessionCreated(Kopete::ChatSession *)
a new KMM has been created
QList::contains
bool contains(const T &value) const
Kopete::ChatSessionManager::self
static ChatSessionManager * self()
Definition: kopetechatsessionmanager.cpp:39
KopeteViewManager::activeView
KopeteView * activeView() const
Provide access to the list of KopeteChatWindow the class maintains.
Definition: kopeteviewmanager.cpp:566
Kopete::ChatSessionManager::sessions
QList< ChatSession * > sessions()
Get a list of all open sessions.
Definition: kopetechatsessionmanager.cpp:151
Kopete::ChatSessionManager::findChatSession
Kopete::ChatSession * findChatSession(const Kopete::Contact *user, Kopete::ContactPtrList chatContacts, Kopete::Protocol *protocol)
Find a chat session, if one exists, that matches the given list of contacts.
Definition: kopetechatsessionmanager.cpp:65
Kopete::ChatSessionManager::aboutToSend
void aboutToSend(Kopete::Message &message)
Plugins may connect to this signal to manipulate the contents of the message that is being sent...
Kopete::ChatSession::myself
const Contact * myself() const
Get the local user in the session.
Definition: kopetechatsession.cpp:215
Kopete::ChatSessionManager::postNewEvent
void postNewEvent(Kopete::MessageEvent *)
Post a new event.
Definition: kopetechatsessionmanager.cpp:182
Kopete::ChatSession::members
const ContactPtrList & members() const
Get a list of all contacts in the session.
Definition: kopetechatsession.cpp:210
Kopete::ChatSessionManager::viewCreated
void viewCreated(KopeteView *)
A new view has been created.
KopeteViewManager::viewManager
static KopeteViewManager * viewManager()
This is a singleton class.
Definition: kopeteviewmanager.cpp:133
kopeteview.h
Kopete::ChatSessionManager::viewClosing
void viewClosing(KopeteView *view)
Kopete::ChatSession::protocol
Protocol * protocol() const
Get the protocol being used.
Definition: kopetechatsession.cpp:220
Kopete::ChatSessionManager::display
void display(Kopete::Message &message, Kopete::ChatSession *)
the message is ready to be displayed
Kopete::ChatSession::Form
Form
Describes the form of this chat session.
Definition: kopetechatsession.h:85
KopeteView
Definition: kopeteview.h:40
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kopete::Message
Representation of a message in Kopete.
Definition: kopetemessage.h:82
Kopete::ChatSessionManager::removeSession
void removeSession(Kopete::ChatSession *session)
Definition: kopetechatsessionmanager.cpp:145
kopetecontact.h
KopeteViewManager::view
KopeteView * view(Kopete::ChatSession *session, const QString &requestedPlugin=QString())
Return a view for the supplied Kopete::ChatSession.
Definition: kopeteviewmanager.cpp:187
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