2 kopetegroup.cpp - Kopete (Meta)Contact Group
4 Copyright (c) 2002-2005 by Olivier Goffart <ogoffart@kde.org>
5 Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
7 Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
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. *
16 *************************************************************************
19 #include "kopetegroup.h"
20 #include "kopetegroup_p.h"
22 #include "kopetecontactlist.h"
23 #include "kopetemetacontact.h"
24 #include "kopetecontact.h"
25 #include "kopetechatsession.h"
31 Group
*Group::s_topLevel
= 0L;
32 Group
*Group::s_temporary
= 0L;
33 Group
* Group::topLevel()
36 s_topLevel
= new Group( i18n( "Top Level" ), Group::TopLevel
);
41 Group
* Group::temporary()
44 s_temporary
= new Group( i18n( "Not in your contact list" ), Group::Temporary
);
49 uint
Group::Private::uniqueGroupId
= 0;
51 Group::Group( const QString
&_name
, GroupType _type
)
52 : ContactListElement( ContactList::self() )
55 d
->displayName
= _name
;
62 : ContactListElement( ContactList::self() )
72 if(d
->type
== TopLevel
)
74 if(d
->type
== Temporary
)
79 QList
<MetaContact
*> Group::members() const
81 QList
<MetaContact
*> groupMembers
;
82 foreach(MetaContact
*mc
, ContactList::self()->metaContacts())
84 if( mc
->groups().contains( const_cast<Group
*>(this) ) )
85 groupMembers
.append(mc
);
91 void Group::setDisplayName( const QString
&s
)
93 if ( d
->displayName
!= s
)
95 QString oldname
= d
->displayName
;
97 // Don't emit the signal in loading state
99 emit
displayNameChanged( this, oldname
);
103 QString
Group::displayName() const
105 return d
->displayName
;
108 Group::GroupType
Group::type() const
113 void Group::setType( GroupType t
)
118 void Group::setExpanded( bool isExpanded
)
120 d
->expanded
= isExpanded
;
123 bool Group::isExpanded() const
128 uint
Group::groupId() const
130 if ( d
->groupId
== 0 )
131 d
->groupId
= ++d
->uniqueGroupId
;
136 void Group::setGroupId(uint groupId
)
138 d
->groupId
= groupId
;
141 uint
Group::uniqueGroupId() const
143 return d
->uniqueGroupId
;
146 void Group::setUniqueGroupId(uint uniqueGroupId
)
148 d
->uniqueGroupId
= uniqueGroupId
;
151 void Group::sendMessage()
155 if(onlineMembers().isEmpty())
157 c
= onlineMembers().first()->preferredContact();
159 if( c
->manager( Contact::CanCreate
) )
161 connect( c
->manager(), SIGNAL( messageSent( Kopete::Message
&, Kopete::ChatSession
* ) ), this, SLOT( sendMessage( Kopete::Message
& ) ));
165 void Group::sendMessage( Message
& msg
)
167 QList
<MetaContact
*> list
= onlineMembers();
168 ChatSession
*cs
=msg
.manager();
171 disconnect( cs
, SIGNAL( messageSent( Kopete::Message
&, Kopete::ChatSession
* ) ), this, SLOT( sendMessage( Kopete::Message
& ) ) );
178 list
.removeAll( msg
.to().first()->metaContact() );
179 QListIterator
<MetaContact
*> it(list
);
180 while ( it
.hasNext() )
182 MetaContact
*mc
= it
.next();
183 if(mc
->isReachable())
185 Contact
*kcontact
=mc
->preferredContact();
186 if( kcontact
->manager( Contact::CanCreate
) )
188 //This is hack and stupid. send message to group should never exist anyway - Olivier 2005-09-11
189 // changing the "to" is require, because jabber use it to send the messgae. Cf BUG 111514
190 Message
msg2(cs
->myself() , kcontact
);
191 msg2
.setPlainBody( msg
.plainBody() );
192 msg2
.setDirection( msg
.direction() );
193 msg2
.setRequestedPlugin( msg
.requestedPlugin() );
195 kcontact
->manager( Contact::CanCreate
)->sendMessage( msg2
);
201 QList
<MetaContact
*> Group::onlineMembers() const
203 QList
<MetaContact
*> list
= members();
204 QList
<MetaContact
*>::iterator it
=list
.begin();
205 while ( it
!=list
.end() )
207 if( (*it
)->isReachable() && (*it
)->isOnline() )
215 } //END namespace Kopete
218 #include "kopetegroup.moc"