3 * centerim IM contacts group listing class
4 * $Id: icqgroups.cc,v 1.12 2003/11/05 14:54:27 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
25 #include "icqgroups.h"
28 icqgroups::icqgroups() {
31 icqgroups::~icqgroups() {
34 string
icqgroups::getfname() const {
35 return conf
->getdirname() + "groups";
38 void icqgroups::load() {
42 vector
<icqgroup
>::iterator ig
;
45 f
.open(getfname().c_str());
50 gid
= atol(getword(buf
).c_str());
54 push_back(icqgroup(gid
, buf
));
56 ig
= find(begin(), end(), gid
);
57 if(ig
!= end()) ig
->changecollapsed();
65 if(find(begin(), end(), 1) == end()) {
66 push_back(icqgroup(1, _("General")));
70 void icqgroups::save() {
74 if(conf
->enoughdiskspace()) {
75 f
.open(getfname().c_str());
78 for(i
= begin(); i
!= end(); ++i
) {
79 f
<< i
->getid() << "\t" << i
->getname() << endl
;
81 for(i
= begin(); i
!= end(); ++i
)
82 if(i
->iscollapsed()) f
<< i
->getid() << endl
;
88 int icqgroups::add(const string
&aname
) {
91 for(i
= 1; find(begin(), end(), i
) != end(); i
++);
92 push_back(icqgroup(i
, aname
));
97 void icqgroups::remove(int gid
) {
98 iterator i
= find(begin(), end(), gid
);
104 string
icqgroups::getname(int gid
) const {
106 const_iterator i
= find(vector
<icqgroup
>::begin(), vector
<icqgroup
>::end(), gid
);
107 if(i
!= vector
<icqgroup
>::end()) r
= i
->getname();