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
27 #include "abstracthook.h"
35 string
icqlist::getfname() const {
36 return conf
.getconfigfname("modelist");
39 void icqlist::load() {
40 string buf
, tok
, nick
;
45 f
.open(getfname().c_str());
53 if(i
= atoi(tok
.c_str())) {
54 nick
= unmime(getword(buf
));
56 if(!nick
.empty() && !buf
.empty()) {
57 pname
= conf
.getprotocolbyletter(buf
[0]);
61 lst
.push_back(modelistitem(nick
, imcontact(strtoul(buf
.c_str(),
62 0, 0), icq
), (contactstatus
) i
));
65 lst
.push_back(modelistitem(nick
, imcontact(nick
,
66 pname
), (contactstatus
) i
));
76 void icqlist::save() {
77 vector
<modelistitem
>::iterator i
;
80 if(conf
.enoughdiskspace()) {
81 f
.open(getfname().c_str());
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
);
90 f
<< i
->getdesc().uin
;
100 void icqlist::fillmenu(verticalmenu
*m
, contactstatus ncs
) {
102 vector
<modelistitem
>::iterator i
;
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
;
119 while((i
= find(i
, end(), cinfo
)) != end()) {
120 if(i
->getstatus() == ncs
) return true;
127 void icqlist::del(const imcontact
&cinfo
, contactstatus ncs
) {
128 vector
<modelistitem
>::iterator i
;
131 while((i
= find(i
, end(), cinfo
)) != end()) {
132 if(i
->getstatus() == ncs
) {
140 modelistitem
icqlist::menuat(int pos
) const {
141 return menucontents
[pos
];
144 // ----------------------------------------------------------------------------
146 string
modelistitem::getnick() const {
150 contactstatus
modelistitem::getstatus() const {
154 imcontact
modelistitem::getdesc() const {
158 void modelistitem::setstatus(contactstatus 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
);