Added an Out for Lunch status
[centerim.git] / src / accountmanager.cc
blob49390a9a662d263625cd79f7df8ffb10ccdb040e
1 /*
3 * centerim account manager dialog implementation
4 * $Id: accountmanager.cc,v 1.43 2005/01/26 23:52:46 konst Exp $
6 * Copyright (C) 2001-2004 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 "accountmanager.h"
26 #include "icqface.h"
27 #include "icqhook.h"
28 #include "yahoohook.h"
29 #include "imcontroller.h"
30 #include "icqcontacts.h"
31 #include "impgp.h"
33 #define getcolor(c) conf.getcolor(c)
35 accountmanager manager;
37 accountmanager::accountmanager() {
38 fopen = false;
41 accountmanager::~accountmanager() {
44 icqconf::imaccount accountmanager::addcontact() {
45 icqconf::imaccount account;
46 return account;
49 void accountmanager::exec() {
50 dialogbox db;
51 int n, b, i, citem, action, pos;
52 set<hookcapab::enumeration> capab;
53 string spname, tmp;
54 bool fin;
55 icqconf::imaccount a;
56 protocolname pname;
58 face.blockmainscreen();
59 fopen = true;
61 db.setwindow(new textwindow(0, 0, face.sizeDlg.width, face.sizeDlg.height,
62 getcolor(cp_dialog_frame), TW_CENTERED,
63 getcolor(cp_dialog_highlight), _(" IM account manager ")));
65 db.settree(new treeview(getcolor(cp_dialog_text), getcolor(cp_dialog_selected),
66 getcolor(cp_dialog_highlight), getcolor(cp_dialog_text)));
68 db.setbar(new horizontalbar(getcolor(cp_dialog_text),
69 getcolor(cp_dialog_selected), _("Change"), _("Done"), 0));
71 db.addautokeys();
72 db.idle = &face.dialogidle;
74 treeview &t = *db.gettree();
76 map<protocolname, bool> mod;
77 for(protocolname pname = icq; pname != protocolname_size; pname++)
78 mod[pname] = false;
80 for(fin = false; !fin; ) {
81 t.clear();
83 for(pname = icq; pname != protocolname_size; pname++) {
84 if(pname != rss && gethook(pname).enabled()) {
85 a = conf.getourid(pname);
87 n = t.addnode(0, 0, 0, " " + conf.getprotocolname(a.pname) + " ");
88 citem = ((int) (a.pname)+1) * 100;
89 capab = gethook(a.pname).getCapabs();
91 if(!a.empty()) {
92 tmp = "";
94 if(!a.server.empty() && a.port)
95 tmp = a.server + ":" + i2str(a.port);
97 t.addleaff(n, 0, citem+9, _(" Server : %s "), tmp.c_str());
99 if(capab.count(hookcapab::ssl))
100 t.addleaff(n, 0, citem+13, _(" Secured : %s "),
101 stryesno(a.additional["ssl"] == "1"));
104 switch(a.pname) {
105 case icq:
106 case gadu:
107 t.addleaff(n, 0, citem+2, _(" UIN : %s "),
108 a.uin ? i2str(a.uin).c_str() : "");
109 break;
111 default:
112 t.addleaff(n, 0, citem+1, _(" Login : %s "),
113 a.nickname.c_str());
114 break;
117 t.addleaff(n, 0, citem+5, capab.count(hookcapab::optionalpassword) ?
118 _(" Password (optional) : %s ") : _(" Password : %s "),
119 string(a.password.size(), '*').c_str());
121 if(!a.empty())
122 switch(a.pname) {
123 case jabber:
124 t.addleaff(n, 0, citem+14, _(" Priority : %s "),
125 a.additional["prio"].c_str());
126 break;
128 case livejournal:
129 t.addleaff(n, 0, citem+11, _(" Import friend list : %s "),
130 stryesno(a.additional["importfriends"] == "1"));
131 break;
133 case irc:
134 t.addleaff(n, 0, citem+12, _(" NickServ password (optional) : %s "),
135 string(a.additional["nickpass"].size(), '*').c_str());
136 break;
139 if(a.empty()) {
140 t.addnode(n, 0, citem+6, _(" Register "));
142 } else {
143 #ifdef HAVE_GPGME
144 if(capab.count(hookcapab::pgp)) {
145 t.addleaff(n, 0, citem+15, _(" OpenPGP key: %s "),
146 a.additional["pgpkey"].empty() ? "none"
147 : a.additional["pgpkey"].c_str());
149 if(!a.additional["pgpkey"].empty())
150 t.addleaff(n, 0, citem+16, _(" Key passphrase: %s "),
151 string(a.additional["pgppass"].size(), '*').c_str());
153 #endif
155 if(capab.count(hookcapab::changedetails))
156 t.addnode(n, 0, citem+7,
157 a.pname == msn ?
158 _(" Change nickname ") :
159 _(" Update user details "));
161 if(capab.count(hookcapab::setaway))
162 t.addnode(n, 0, citem+10, _(" Set away message "));
164 t.addnode(n, 0, citem+8, _(" Drop "));
170 fin = !db.open(n, b, (void **) &citem) || (b == 1);
172 if(!fin && citem) {
173 action = citem-(citem/100)*100;
174 pname = (protocolname) (citem/100-1);
176 a = conf.getourid(pname);
177 spname = conf.getprotocolname(pname);
178 abstracthook &hook = gethook(pname);
180 switch(action) {
181 case 1:
182 tmp = face.inputstr(spname + _(" user name: "), a.nickname);
183 if(face.getlastinputkey() != KEY_ESC && !tmp.empty()) a.nickname = tmp;
184 break;
186 case 2:
187 i = strtoul(face.inputstr(spname + _(" uin: "), i2str(a.uin)).c_str(), 0, 0);
188 if(face.getlastinputkey() != KEY_ESC && i) a.uin = i;
189 break;
191 case 5:
192 tmp = face.inputstr(spname + _(" password: "), a.password, '*');
193 if(face.getlastinputkey() != KEY_ESC &&
194 (!tmp.empty() || capab.count(hookcapab::optionalpassword)))
195 a.password = tmp;
196 break;
198 case 6:
199 if(!a.empty()) {
200 face.status(_("Drop the account information first!"));
201 } else {
202 imcontrol.registration(a);
204 break;
206 case 7:
207 imcontrol.updateinfo(a);
208 break;
210 case 8:
211 if(!hook.online()) {
212 a = icqconf::imaccount(a.pname);
213 } else {
214 face.status(_("You have to disconnect the service first!"));
216 break;
218 case 9:
219 tmp = "";
220 if(!a.server.empty())
221 tmp = a.server + ":" + i2str(a.port);
223 tmp = face.inputstr(spname + _(" server address: "), tmp);
225 if(face.getlastinputkey() != KEY_ESC && !tmp.empty()) {
226 if((pos = tmp.find(":")) != -1) {
227 a.server = tmp.substr(0, pos);
228 a.port = strtoul(tmp.substr(pos+1).c_str(), 0, 0);
229 } else {
230 a.server = tmp;
231 a.port = 0;
234 break;
236 case 10:
237 if(face.edit(tmp = conf.getawaymsg(a.pname), spname + ": " + _("away message"))) {
238 conf.setawaymsg(a.pname, tmp);
240 break;
242 case 11:
243 a.additional["importfriends"] =
244 (a.additional["importfriends"] == "") ? "1" : "0";
245 break;
247 case 12:
248 tmp = face.inputstr(spname + _(" password: "), a.additional["nickpass"], '*');
249 if(face.getlastinputkey() != KEY_ESC)
250 a.additional["nickpass"] = tmp;
251 break;
253 case 13:
254 a.additional["ssl"] =
255 (a.additional["ssl"] == "") ? "1" : "";
257 if(a.additional["ssl"] == "1") {
258 if(a.port == icqconf::defservers[a.pname].port)
259 a.port = icqconf::defservers[a.pname].secureport;
260 } else {
261 if(a.port == icqconf::defservers[a.pname].secureport)
262 a.port = icqconf::defservers[a.pname].port;
264 break;
266 case 14:
267 tmp = leadcut(trailcut(face.inputstr(spname + _(" priority: "),
268 a.additional["prio"])));
270 if(face.getlastinputkey() != KEY_ESC)
271 if(i2str(atoi(tmp.c_str())) == tmp)
272 a.additional["prio"] = tmp;
274 break;
276 case 15:
277 face.selectpgpkey(a.additional["pgpkey"], true);
278 break;
280 case 16:
281 tmp = face.inputstr(_("PGP key passphrase: "), a.additional["pgppass"], '*');
282 if(face.getlastinputkey() != KEY_ESC)
283 a.additional["pgppass"] = tmp;
284 break;
287 if(action != 7) {
288 conf.setourid(a);
289 mod[a.pname] = true;
294 db.close();
295 face.unblockmainscreen();
297 for(pname = icq; pname != protocolname_size; pname++)
298 if(mod[pname])
299 gethook(pname).ouridchanged(conf.getourid(pname));
301 conf.save();
302 face.relaxedupdate();
303 fopen = false;
306 bool accountmanager::isopen() const {
307 return fopen;