• 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
kopetegroup.cpp
Go to the documentation of this file.
1 /*
2  kopetegroup.cpp - Kopete (Meta)Contact Group
3 
4  Copyright (c) 2002-2005 by Olivier Goffart <ogoffart@kde.org>
5  Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
6 
7  Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
8 
9  *************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2 of the License, or (at your option) any later version. *
15  * *
16  *************************************************************************
17 */
18 
19 #include "kopetegroup.h"
20 #include "kopetegroup_p.h"
21 
22 #include "kopetecontactlist.h"
23 #include "kopetemetacontact.h"
24 #include "kopetecontact.h"
25 #include "kopetechatsession.h"
26 
27 #include <KIcon>
28 #include <klocale.h>
29 
30 namespace Kopete {
31 
32 Group *Group::s_topLevel = 0L;
33 Group *Group::s_temporary = 0L;
34 Group *Group::s_offline = 0L;
35 Group * Group::topLevel()
36 {
37  if ( !s_topLevel )
38  s_topLevel = new Group( i18n( "Top Level" ), Group::TopLevel );
39 
40  return s_topLevel;
41 }
42 
43 Group * Group::temporary()
44 {
45  if ( !s_temporary )
46  s_temporary = new Group( i18n( "Not in your contact list" ), Group::Temporary );
47 
48  return s_temporary;
49 }
50 
51 Group * Group::offline()
52 {
53  if ( !s_offline )
54  s_offline = new Group( i18n( "Offline Users" ), Group::Offline );
55 
56  return s_offline;
57 }
58 
59 uint Group::Private::uniqueGroupId = 0;
60 
61 Group::Group( const QString &_name )
62  : ContactListElement( ContactList::self() ), d(new Private())
63 {
64  d->displayName = _name;
65  d->type = Normal;
66  d->expanded = true;
67  d->groupId = 0;
68 }
69 
70 Group::Group( const QString &_name, GroupType _type )
71  : ContactListElement( ContactList::self() ), d(new Private())
72 {
73  d->displayName = _name;
74  d->type = _type;
75  d->expanded = true;
76  d->groupId = 0;
77 }
78 
79 Group::Group()
80  : ContactListElement( ContactList::self() ), d(new Private())
81 {
82  d->expanded = true;
83  d->type = Normal;
84  d->groupId = 0;
85 }
86 
87 Group::~Group()
88 {
89  if(d->type == TopLevel)
90  s_topLevel=0L;
91  if(d->type == Temporary)
92  s_temporary=0L;
93  if(d->type == Offline)
94  s_offline=0L;
95  delete d;
96 }
97 
98 QList<MetaContact *> Group::members() const
99 {
100  QList<MetaContact *> groupMembers;
101  foreach(MetaContact *mc, ContactList::self()->metaContacts())
102  {
103  if( mc->groups().contains( const_cast<Group*>(this) ) )
104  groupMembers.append(mc);
105  }
106 
107  return groupMembers;
108 }
109 
110 void Group::setDisplayName( const QString &s )
111 {
112  if ( d->displayName != s )
113  {
114  QString oldname = d->displayName;
115  d->displayName = s;
116  // Don't emit the signal in loading state
117  if( !loading() )
118  emit displayNameChanged( this, oldname );
119  }
120 }
121 
122 QString Group::displayName() const
123 {
124  return d->displayName;
125 }
126 
127 Group::GroupType Group::type() const
128 {
129  return d->type;
130 }
131 
132 void Group::setExpanded( bool isExpanded )
133 {
134  d->expanded = isExpanded;
135 }
136 
137 bool Group::isExpanded() const
138 {
139  return d->expanded;
140 }
141 
142 uint Group::groupId() const
143 {
144  if ( d->groupId == 0 )
145  d->groupId = ++d->uniqueGroupId;
146 
147  return d->groupId;
148 }
149 
150 void Group::setGroupId(uint groupId)
151 {
152  d->groupId = groupId;
153 }
154 
155 uint Group::uniqueGroupId() const
156 {
157  return d->uniqueGroupId;
158 }
159 
160 void Group::setUniqueGroupId(uint uniqueGroupId)
161 {
162  d->uniqueGroupId = uniqueGroupId;
163 }
164 
165 void Group::sendMessage()
166 {
167  Kopete::Contact *c;
168 
169  if(onlineMembers().isEmpty())
170  return;
171  c = onlineMembers().first()->preferredContact();
172  c->sendMessage();
173  if( c->manager( Contact::CanCreate ) )
174  {
175  connect( c->manager(), SIGNAL(messageSent(Kopete::Message&,Kopete::ChatSession*)), this, SLOT(sendMessage(Kopete::Message&)));
176  }
177 }
178 
179 void Group::sendMessage( Message& msg )
180 {
181  QList<MetaContact *> list = onlineMembers();
182  ChatSession *cs=msg.manager();
183  if( cs )
184  {
185  disconnect( cs, SIGNAL(messageSent(Kopete::Message&,Kopete::ChatSession*)), this, SLOT(sendMessage(Kopete::Message&)) );
186  }
187  else
188  return;
189 
190  if(list.isEmpty())
191  return;
192  list.removeAll( msg.to().first()->metaContact() );
193  QListIterator<MetaContact *> it(list);
194  while ( it.hasNext() )
195  {
196  MetaContact *mc = it.next();
197  if(mc->isReachable())
198  {
199  Contact *kcontact=mc->preferredContact();
200  if( kcontact->manager( Contact::CanCreate ) )
201  {
202  //This is hack and stupid. send message to group should never exist anyway - Olivier 2005-09-11
203  // changing the "to" is require, because jabber use it to send the messgae. Cf BUG 111514
204  Message msg2(cs->myself() , kcontact);
205  msg2.setPlainBody( msg.plainBody() );
206  msg2.setDirection( msg.direction() );
207  msg2.setRequestedPlugin( msg.requestedPlugin() );
208 
209  kcontact->manager( Contact::CanCreate )->sendMessage( msg2 );
210  }
211  }
212  }
213 }
214 
215 QList<MetaContact *> Group::onlineMembers() const
216 {
217  QList<MetaContact *> list = members();
218  QList<MetaContact *>::iterator it=list.begin();
219  while ( it!=list.end() )
220  {
221  if( (*it)->isReachable() && (*it)->isOnline() )
222  ++it;
223  else
224  it=list.erase(it);
225  }
226  return list;
227 }
228 
229 } //END namespace Kopete
230 
231 
232 #include "kopetegroup.moc"
233 
234 
235 
kopetemetacontact.h
Kopete::ContactList::self
static ContactList * self()
The contact list is a singleton object.
Definition: kopetecontactlist.cpp:71
Kopete::ContactList
manage contacts and metacontact
Definition: kopetecontactlist.h:49
Kopete::Group::setUniqueGroupId
void setUniqueGroupId(uint uniqueGroupId)
Definition: kopetegroup.cpp:160
Kopete::Group::offline
static Group * offline()
Definition: kopetegroup.cpp:51
Kopete::Group::displayNameChanged
void displayNameChanged(Kopete::Group *group, const QString &oldName)
Emitted when the group has been renamed.
Kopete::Group::GroupType
GroupType
Kinds of groups.
Definition: kopetegroup.h:56
Kopete::Group::setExpanded
void setExpanded(bool expanded)
Set if the group is expanded.
Definition: kopetegroup.cpp:132
Kopete::Group::members
QList< MetaContact * > members() const
child metacontact This function is not very efficient - it searches through all the metacontacts in t...
Definition: kopetegroup.cpp:98
Kopete::ContactListElement::loading
bool loading() const
Check if we are in loading stage.
Definition: kopetecontactlistelement.cpp:61
Kopete::Group::Private::expanded
bool expanded
Definition: kopetegroup_p.h:31
Kopete::Group::displayName
QString displayName() const
Return the group's display name.
Kopete::Group::Private::type
Group::GroupType type
Definition: kopetegroup_p.h:30
kopetegroup.h
QList::erase
iterator erase(iterator pos)
Kopete::Group::isExpanded
bool isExpanded() const
Definition: kopetegroup.cpp:137
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Kopete::ChatSession
Definition: kopetechatsession.h:74
Kopete::Group::Private
Definition: kopetegroup_p.h:26
Kopete::Group::Private::displayName
QString displayName
Definition: kopetegroup_p.h:29
Kopete::Message::direction
MessageDirection direction() const
Accessor method for the direction of the message.
Definition: kopetemessage.cpp:580
QList::append
void append(const T &value)
Kopete::Group::Private::uniqueGroupId
static uint uniqueGroupId
Definition: kopetegroup_p.h:35
Kopete::ContactListElement
Definition: kopetecontactlistelement.h:46
Kopete::Group::groupId
uint groupId() const
Kopete::Group::setGroupId
void setGroupId(uint groupId)
Definition: kopetegroup.cpp:150
QList::isEmpty
bool isEmpty() const
Kopete::Contact::manager
virtual ChatSession * manager(CanCreateFlags canCreate=CannotCreate)=0
Returns the primary message manager affiliated with this contact Although a contact can have more tha...
QList::removeAll
int removeAll(const T &value)
kopetechatsession.h
Kopete::Group::uniqueGroupId
uint uniqueGroupId() const
Definition: kopetegroup.cpp:155
Kopete::Group::sendMessage
void sendMessage()
Send a message to all contacts in the group.
Definition: kopetegroup.cpp:165
kopetecontactlist.h
QList::first
T & first()
Kopete::Group::Offline
Definition: kopetegroup.h:56
QString
QList< MetaContact * >
Kopete::Contact
Definition: kopetecontact.h:58
Kopete::Group::~Group
~Group()
Definition: kopetegroup.cpp:87
Kopete::Group::Private::groupId
uint groupId
Definition: kopetegroup_p.h:32
Kopete::Group::Normal
Definition: kopetegroup.h:56
QList::end
iterator end()
QList::contains
bool contains(const T &value) const
Kopete::Message::requestedPlugin
QString requestedPlugin() const
Accessor method for the preferred plugin If null, Kopete will use the user's preferred plugin...
Definition: kopetemessage.cpp:530
Kopete::Group::topLevel
static Group * topLevel()
Definition: kopetegroup.cpp:35
Kopete::ChatSession::myself
const Contact * myself() const
Get the local user in the session.
Definition: kopetechatsession.cpp:215
Kopete::Group::Group
Group()
Create an empty group.
Definition: kopetegroup.cpp:79
Kopete::Group::TopLevel
Definition: kopetegroup.h:56
Kopete::MetaContact::groups
QList< Group * > groups() const
The groups the contact is stored in.
Definition: kopetemetacontact.cpp:1069
Kopete::Group
Class which represents the Group.
Definition: kopetegroup.h:44
Kopete::Group::setDisplayName
void setDisplayName(const QString &newName)
Rename the group.
Definition: kopetegroup.cpp:110
Kopete::Contact::sendMessage
void sendMessage()
Pops up an email type window.
Definition: kopetecontact.cpp:479
Kopete::MetaContact
Definition: kopetemetacontact.h:54
Kopete::Group::Temporary
Definition: kopetegroup.h:56
Kopete::Contact::CanCreate
Definition: kopetecontact.h:297
Kopete::Message::to
QList< Contact * > to() const
Accessor method for the Contacts that this message was sent to.
Definition: kopetemessage.cpp:515
QListIterator
Kopete::Group::type
GroupType type() const
Definition: kopetegroup.cpp:127
kopetegroup_p.h
Kopete::Message::plainBody
QString plainBody() const
Get the message body back as plain text.
Definition: kopetemessage.cpp:366
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kopete::Message::manager
ChatSession * manager() const
Get the related message manager.
Definition: kopetemessage.cpp:605
Kopete::Message
Representation of a message in Kopete.
Definition: kopetemessage.h:82
QList::begin
iterator begin()
kopetecontact.h
Kopete::Group::temporary
static Group * temporary()
Definition: kopetegroup.cpp:43
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