moved the old Changelog, which only contained log from the old centericq
[centerim.git] / src / icqmlist.cc
blob8fd7660d92a867e66bc5e56d5c16f14431cb12aa
1 /*
3 * centerim user mode list class
4 * $Id: icqmlist.cc,v 1.17 2002/11/29 15:57:39 konst Exp $
6 * Copyright (C) 2001,2002 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 "icqmlist.h"
26 #include "icqconf.h"
27 #include "abstracthook.h"
29 icqlist::icqlist() {
32 icqlist::~icqlist() {
35 string icqlist::getfname() const {
36 return conf.getconfigfname("modelist");
39 void icqlist::load() {
40 string buf, tok, nick;
41 protocolname pname;
42 ifstream f;
43 int i;
45 f.open(getfname().c_str());
47 if(f.is_open()) {
48 while(!f.eof()) {
49 getstring(f, buf);
50 tok = getword(buf);
52 if(!tok.empty())
53 if(i = atoi(tok.c_str())) {
54 nick = unmime(getword(buf));
56 if(!nick.empty() && !buf.empty()) {
57 pname = conf.getprotocolbyletter(buf[0]);
59 switch(pname) {
60 case icq:
61 lst.push_back(modelistitem(nick, imcontact(strtoul(buf.c_str(),
62 0, 0), icq), (contactstatus) i));
63 break;
64 default:
65 lst.push_back(modelistitem(nick, imcontact(nick,
66 pname), (contactstatus) i));
67 break;
72 f.close();
76 void icqlist::save() {
77 vector<modelistitem>::iterator i;
78 ofstream f;
80 if(conf.enoughdiskspace()) {
81 f.open(getfname().c_str());
83 if(f.is_open()) {
84 for(i = begin(); i != end(); ++i) {
85 f << (int) i->getstatus() << "\t";
86 f << mime(i->getnick()) << "\t";
87 f << conf.getprotocolprefix(i->getdesc().pname);
89 if(i->getdesc().uin)
90 f << i->getdesc().uin;
92 f << endl;
95 f.close();
100 void icqlist::fillmenu(verticalmenu *m, contactstatus ncs) {
101 int capab;
102 vector<modelistitem>::iterator i;
104 m->clear();
105 menucontents.clear();
107 for(i = begin(); i != end(); ++i) {
108 if(i->getstatus() == ncs) {
109 m->additem(conf.getprotcolor(i->getdesc().pname), 0, " " + i->getnick());
110 menucontents.push_back(*i);
115 bool icqlist::inlist(const imcontact &cinfo, contactstatus ncs) const {
116 vector<modelistitem>::const_iterator i;
118 i = begin();
119 while((i = find(i, end(), cinfo)) != end()) {
120 if(i->getstatus() == ncs) return true;
121 i++;
124 return false;
127 void icqlist::del(const imcontact &cinfo, contactstatus ncs) {
128 vector<modelistitem>::iterator i;
130 i = begin();
131 while((i = find(i, end(), cinfo)) != end()) {
132 if(i->getstatus() == ncs) {
133 erase(i);
134 break;
136 i++;
140 modelistitem icqlist::menuat(int pos) const {
141 return menucontents[pos];
144 // ----------------------------------------------------------------------------
146 string modelistitem::getnick() const {
147 return nick;
150 contactstatus modelistitem::getstatus() const {
151 return cs;
154 imcontact modelistitem::getdesc() const {
155 return cdesc;
158 void modelistitem::setstatus(contactstatus ncs) {
159 cs = ncs;
162 bool modelistitem::operator == (const imcontact &cinfo) const {
163 return cdesc == cinfo;
166 bool modelistitem::operator != (const imcontact &cinfo) const {
167 return !(*this == cinfo);