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
25 #include "accountmanager.h"
28 #include "yahoohook.h"
29 #include "imcontroller.h"
30 #include "icqcontacts.h"
33 #define getcolor(c) conf.getcolor(c)
35 accountmanager manager
;
37 accountmanager::accountmanager() {
41 accountmanager::~accountmanager() {
44 icqconf::imaccount
accountmanager::addcontact() {
45 icqconf::imaccount account
;
49 void accountmanager::exec() {
51 int n
, b
, i
, citem
, action
, pos
;
52 set
<hookcapab::enumeration
> capab
;
58 face
.blockmainscreen();
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));
72 db
.idle
= &face
.dialogidle
;
74 treeview
&t
= *db
.gettree();
76 map
<protocolname
, bool> mod
;
77 for(protocolname pname
= icq
; pname
!= protocolname_size
; pname
++)
80 for(fin
= false; !fin
; ) {
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();
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"));
107 t
.addleaff(n
, 0, citem
+2, _(" UIN : %s "),
108 a
.uin
? i2str(a
.uin
).c_str() : "");
112 t
.addleaff(n
, 0, citem
+1, _(" Login : %s "),
117 t
.addleaff(n
, 0, citem
+5, capab
.count(hookcapab::optionalpassword
) ?
118 _(" Password (optional) : %s ") : _(" Password : %s "),
119 string(a
.password
.size(), '*').c_str());
124 t
.addleaff(n
, 0, citem
+14, _(" Priority : %s "),
125 a
.additional
["prio"].c_str());
129 t
.addleaff(n
, 0, citem
+11, _(" Import friend list : %s "),
130 stryesno(a
.additional
["importfriends"] == "1"));
134 t
.addleaff(n
, 0, citem
+12, _(" NickServ password (optional) : %s "),
135 string(a
.additional
["nickpass"].size(), '*').c_str());
140 t
.addnode(n
, 0, citem
+6, _(" Register "));
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());
155 if(capab
.count(hookcapab::changedetails
))
156 t
.addnode(n
, 0, citem
+7,
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);
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
);
182 tmp
= face
.inputstr(spname
+ _(" user name: "), a
.nickname
);
183 if(face
.getlastinputkey() != KEY_ESC
&& !tmp
.empty()) a
.nickname
= tmp
;
187 i
= strtoul(face
.inputstr(spname
+ _(" uin: "), i2str(a
.uin
)).c_str(), 0, 0);
188 if(face
.getlastinputkey() != KEY_ESC
&& i
) a
.uin
= i
;
192 tmp
= face
.inputstr(spname
+ _(" password: "), a
.password
, '*');
193 if(face
.getlastinputkey() != KEY_ESC
&&
194 (!tmp
.empty() || capab
.count(hookcapab::optionalpassword
)))
200 face
.status(_("Drop the account information first!"));
202 imcontrol
.registration(a
);
207 imcontrol
.updateinfo(a
);
212 a
= icqconf::imaccount(a
.pname
);
214 face
.status(_("You have to disconnect the service first!"));
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);
237 if(face
.edit(tmp
= conf
.getawaymsg(a
.pname
), spname
+ ": " + _("away message"))) {
238 conf
.setawaymsg(a
.pname
, tmp
);
243 a
.additional
["importfriends"] =
244 (a
.additional
["importfriends"] == "1") ? "0" : "1";
248 tmp
= face
.inputstr(spname
+ _(" password: "), a
.additional
["nickpass"], '*');
249 if(face
.getlastinputkey() != KEY_ESC
)
250 a
.additional
["nickpass"] = tmp
;
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
;
261 if(a
.port
== icqconf::defservers
[a
.pname
].secureport
)
262 a
.port
= icqconf::defservers
[a
.pname
].port
;
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
;
277 face
.selectpgpkey(a
.additional
["pgpkey"], true);
281 tmp
= face
.inputstr(_("PGP key passphrase: "), a
.additional
["pgppass"], '*');
282 if(face
.getlastinputkey() != KEY_ESC
)
283 a
.additional
["pgppass"] = tmp
;
295 face
.unblockmainscreen();
297 for(pname
= icq
; pname
!= protocolname_size
; pname
++)
299 gethook(pname
).ouridchanged(conf
.getourid(pname
));
302 face
.relaxedupdate();
306 bool accountmanager::isopen() const {