Added an Out for Lunch status
[centerim.git] / src / icqgroup.cc
blobdd939d6fabcda2340a1b9b9f4b643b2dea224314
1 /*
3 * centerim IM contacts group class
4 * $Id: icqgroup.cc,v 1.9 2005/01/30 22:21:34 konst Exp $
6 * Copyright (C) 2001 by Konstantin Klyagin <k@thekonst.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
25 #include "icqgroup.h"
26 #include "icqgroups.h"
27 #include "abstracthook.h"
29 icqgroup::icqgroup(int aid, const string &aname) {
30 id = aid;
31 name = aname;
32 collapsed = false;
35 icqgroup::~icqgroup() {
38 int icqgroup::getcount(bool countonline, bool countoffline) {
39 int i, counter;
41 for(i = counter = 0; i < clist.count; i++) {
42 icqcontact *c = (icqcontact *) clist.at(i);
44 if(c->getgroupid() == id) {
45 if(countoffline && c->getstatus() == offline) counter++;
46 if(countonline && c->getstatus() != offline) counter++;
50 return counter;
53 void icqgroup::moveup() {
54 int nid = id-1;
56 while(nid > 0) {
57 if(find(groups.begin(), groups.end(), nid) != groups.end()) break;
58 nid--;
61 if(nid > 0) exchange(nid);
64 void icqgroup::movedown() {
65 int nid = id+1;
66 int fid = (groups.end()-1)->id;
68 while(nid <= fid) {
69 if(find(groups.begin(), groups.end(), nid) != groups.end()) break;
70 nid++;
73 if(nid <= fid) exchange(nid);
76 void icqgroup::exchange(int nid) {
77 int i;
78 icqcontact *c;
79 vector<icqgroup>::iterator ig;
81 ig = find(groups.begin(), groups.end(), nid);
83 if(ig != groups.end()) {
84 for(i = 0; i < clist.count; i++) {
85 c = (icqcontact *) clist.at(i);
87 if(c->getgroupid() == id) c->setgroupid(nid, false); else
88 if(c->getgroupid() == nid) c->setgroupid(id, false);
91 ig->id = id;
92 id = nid;
96 void icqgroup::rename(const string &aname) {
97 string oldname = name;
98 name = aname;
100 for(protocolname pname = icq; pname != protocolname_size; pname++)
101 gethook(pname).renamegroup(oldname, name);