make webinterface translatable. there are around 20 short strings, all with context...
[kdenetwork.git] / kopete / libkopete / kopetegroup.cpp
blobaafe5b8786790afcb2887c8ac990630ee3a26f61
1 /*
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 *************************************************************************
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 *************************************************************************
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"
27 #include <klocale.h>
29 namespace Kopete {
31 Group *Group::s_topLevel = 0L;
32 Group *Group::s_temporary = 0L;
33 Group * Group::topLevel()
35 if ( !s_topLevel )
36 s_topLevel = new Group( i18n( "Top Level" ), Group::TopLevel );
38 return s_topLevel;
41 Group * Group::temporary()
43 if ( !s_temporary )
44 s_temporary = new Group( i18n( "Not in your contact list" ), Group::Temporary );
46 return s_temporary;
49 uint Group::Private::uniqueGroupId = 0;
51 Group::Group( const QString &_name, GroupType _type )
52 : ContactListElement( ContactList::self() )
54 d = new Private;
55 d->displayName = _name;
56 d->type = _type;
57 d->expanded = true;
58 d->groupId = 0;
61 Group::Group()
62 : ContactListElement( ContactList::self() )
64 d = new Private;
65 d->expanded = true;
66 d->type = Normal;
67 d->groupId = 0;
70 Group::~Group()
72 if(d->type == TopLevel)
73 s_topLevel=0L;
74 if(d->type == Temporary)
75 s_temporary=0L;
76 delete d;
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);
88 return groupMembers;
91 void Group::setDisplayName( const QString &s )
93 if ( d->displayName != s )
95 QString oldname = d->displayName;
96 d->displayName = s;
97 // Don't emit the signal in loading state
98 if( !loading() )
99 emit displayNameChanged( this, oldname );
103 QString Group::displayName() const
105 return d->displayName;
108 Group::GroupType Group::type() const
110 return d->type;
113 void Group::setType( GroupType t )
115 d->type = t;
118 void Group::setExpanded( bool isExpanded )
120 d->expanded = isExpanded;
123 bool Group::isExpanded() const
125 return d->expanded;
128 uint Group::groupId() const
130 if ( d->groupId == 0 )
131 d->groupId = ++d->uniqueGroupId;
133 return d->groupId;
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()
153 Kopete::Contact *c;
155 if(onlineMembers().isEmpty())
156 return;
157 c = onlineMembers().first()->preferredContact();
158 c->sendMessage();
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();
169 if( cs )
171 disconnect( cs, SIGNAL( messageSent( Kopete::Message&, Kopete::ChatSession* ) ), this, SLOT( sendMessage( Kopete::Message& ) ) );
173 else
174 return;
176 if(list.isEmpty())
177 return;
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() )
208 ++it;
209 else
210 it=list.erase(it);
212 return list;
215 } //END namespace Kopete
218 #include "kopetegroup.moc"