connwrap - initialize gnutls session in cw_connect
[centerim.git] / src / icqgroups.cc
blob8575bf193462e6a650264159bd65bd329027a758
1 /*
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
21 * USA
25 #include "icqgroups.h"
26 #include "icqconf.h"
28 icqgroups::icqgroups() {
31 icqgroups::~icqgroups() {
34 string icqgroups::getfname() const {
35 return conf->getdirname() + "groups";
38 void icqgroups::load() {
39 string buf;
40 ifstream f;
41 int gid;
42 vector<icqgroup>::iterator ig;
44 clear();
45 f.open(getfname().c_str());
47 if(f.is_open()) {
48 while(!f.eof()) {
49 getstring(f, buf);
50 gid = atol(getword(buf).c_str());
52 if(gid) {
53 if(!buf.empty()) {
54 push_back(icqgroup(gid, buf));
55 } else {
56 ig = find(begin(), end(), gid);
57 if(ig != end()) ig->changecollapsed();
62 f.close();
65 if(find(begin(), end(), 1) == end()) {
66 push_back(icqgroup(1, _("General")));
70 void icqgroups::save() {
71 ofstream f;
72 iterator i;
74 if(conf->enoughdiskspace()) {
75 f.open(getfname().c_str());
77 if(f.is_open()) {
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;
83 f.close();
88 int icqgroups::add(const string &aname) {
89 int i;
91 for(i = 1; find(begin(), end(), i) != end(); i++);
92 push_back(icqgroup(i, aname));
94 return i;
97 void icqgroups::remove(int gid) {
98 iterator i = find(begin(), end(), gid);
99 if(i != end()) {
100 erase(i);
104 string icqgroups::getname(int gid) const {
105 string r;
106 const_iterator i = find(vector<icqgroup>::begin(), vector<icqgroup>::end(), gid);
107 if(i != vector<icqgroup>::end()) r = i->getname();
109 return r;