Mercurial > pidgin
annotate src/protocols/icq/gaim_icq.c @ 2210:3a6fd1e8f00a
[gaim-migrate @ 2220]
i haven't even tested this.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Wed, 05 Sep 2001 05:25:13 +0000 |
| parents | c24595d3c364 |
| children | 8c4ff1a368bd |
| rev | line source |
|---|---|
| 2086 | 1 #include <gtk/gtk.h> |
| 2 #include <string.h> | |
| 3 #include <stdlib.h> | |
| 4 #include "icq.h" /* well, we're doing ICQ, right? */ | |
| 5 #include "multi.h" /* needed for gaim_connection */ | |
| 6 #include "prpl.h" /* needed for prpl */ | |
| 7 #include "gaim.h" /* needed for every other damn thing */ | |
| 8 #include "proxy.h" | |
| 9 | |
| 10 #include "pixmaps/gnomeicu-online.xpm" | |
| 11 #include "pixmaps/gnomeicu-away.xpm" | |
| 12 #include "pixmaps/gnomeicu-dnd.xpm" | |
| 13 #include "pixmaps/gnomeicu-na.xpm" | |
| 14 #include "pixmaps/gnomeicu-occ.xpm" | |
| 15 #include "pixmaps/gnomeicu-ffc.xpm" | |
| 16 | |
| 17 #define USEROPT_NICK 0 | |
| 18 | |
| 19 struct icq_data { | |
| 20 icq_Link *link; | |
| 21 int cur_status; | |
| 22 GSList *thru_serv; | |
| 23 }; | |
| 24 | |
| 25 static guint ack_timer = 0; | |
| 26 | |
| 27 static char *icq_name() { | |
| 28 return "ICQ"; | |
| 29 } | |
| 30 | |
| 31 static void icq_do_log(icq_Link *link, time_t time, unsigned char level, const char *log) { | |
| 32 debug_printf("ICQ debug %d: %s", level, log); | |
| 33 } | |
| 34 | |
| 35 GList *sockets = NULL; | |
| 36 struct gaim_sock { | |
| 37 int socket; | |
| 38 int type; | |
| 39 gint inpa; | |
| 40 }; | |
| 41 | |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
42 static void gaim_icq_handler(gpointer data, gint source, GaimInputCondition cond) { |
|
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
43 if (cond & GAIM_INPUT_READ) |
| 2086 | 44 icq_HandleReadySocket(source, ICQ_SOCKET_READ); |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
45 if (cond & GAIM_INPUT_WRITE) |
| 2086 | 46 icq_HandleReadySocket(source, ICQ_SOCKET_WRITE); |
| 47 } | |
| 48 | |
| 49 static void icq_sock_notify(int socket, int type, int status) { | |
| 50 struct gaim_sock *gs = NULL; | |
| 51 if (status) { | |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
52 GaimInputCondition cond; |
| 2086 | 53 if (type == ICQ_SOCKET_READ) |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
54 cond = GAIM_INPUT_READ; |
| 2086 | 55 else |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
56 cond = GAIM_INPUT_WRITE; |
| 2086 | 57 gs = g_new0(struct gaim_sock, 1); |
| 58 gs->socket = socket; | |
| 59 gs->type = type; | |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
60 gs->inpa = gaim_input_add(socket, cond, gaim_icq_handler, NULL); |
| 2086 | 61 sockets = g_list_append(sockets, gs); |
| 62 debug_printf("Adding socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
| 63 } else { | |
| 64 GList *m = sockets; | |
| 65 while (m) { | |
| 66 gs = m->data; | |
| 67 if ((gs->socket == socket) && (gs->type == type)) | |
| 68 break; | |
| 69 m = g_list_next(m); | |
| 70 } | |
| 71 if (m) { | |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 gaim_input_remove(gs->inpa); |
| 2086 | 73 sockets = g_list_remove(sockets, gs); |
| 74 debug_printf("Removing socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
| 75 g_free(gs); | |
| 76 } | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 static void icq_online(icq_Link *link) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
81 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 82 struct icq_data *id = (struct icq_data *)gc->proto_data; |
| 83 debug_printf("%s is now online.\n", gc->username); | |
| 84 account_online(gc); | |
| 85 /*gc->options |= OPT_USR_KEEPALV; this is always-on now */ | |
| 86 serv_finish_login(gc); | |
| 87 | |
| 88 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
| 89 } | |
| 90 | |
| 91 static void icq_logged_off(icq_Link *link) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
92 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 93 struct icq_data *id = (struct icq_data *)gc->proto_data; |
| 94 | |
| 95 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
| 96 hide_login_progress(gc, "Unable to connect"); | |
| 97 signoff(gc); | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 icq_Login(link, STATUS_ONLINE); | |
| 102 id->cur_status = STATUS_ONLINE; | |
| 103 } | |
| 104 | |
| 105 void strip_linefeed(gchar *text) | |
| 106 { | |
| 107 int i, j; | |
| 108 gchar *text2 = g_malloc(strlen(text) + 1); | |
| 109 | |
| 110 for (i = 0, j = 0; text[i]; i++) | |
| 111 if (text[i] != '\r') | |
| 112 text2[j++] = text[i]; | |
| 113 text2[j] = '\0'; | |
| 114 | |
| 115 strcpy(text, text2); | |
| 116 g_free(text2); | |
| 117 } | |
| 118 | |
| 119 static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
| 120 unsigned char day, unsigned char month, unsigned short year, const char *data) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
121 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 122 char buf[256], *tmp = g_malloc(BUF_LONG); |
| 123 g_snprintf(tmp, BUF_LONG, "%s", data); | |
| 124 g_snprintf(buf, sizeof buf, "%lu", uin); | |
| 125 strip_linefeed(tmp); | |
| 126 serv_got_im(gc, buf, tmp, 0, time((time_t)NULL)); | |
| 127 g_free(tmp); | |
| 128 } | |
| 129 | |
| 130 static void icq_user_online(icq_Link *link, unsigned long uin, unsigned long st, | |
| 131 unsigned long ip, unsigned short port, unsigned long real_ip, | |
| 132 unsigned char tcp_flags) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
133 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 134 guint status; |
| 135 char buf[256]; | |
| 136 | |
| 137 g_snprintf(buf, sizeof buf, "%lu", uin); | |
| 138 status = (st == STATUS_ONLINE) ? UC_NORMAL : UC_UNAVAILABLE | (st << 5); | |
| 139 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); | |
| 140 } | |
| 141 | |
| 142 static void icq_user_offline(icq_Link *link, unsigned long uin) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
143 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 144 char buf[256]; g_snprintf(buf, sizeof buf, "%lu", uin); |
| 145 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
| 146 } | |
| 147 | |
| 148 static void icq_user_status(icq_Link *link, unsigned long uin, unsigned long st) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
149 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 150 guint status; |
| 151 char buf[256]; | |
| 152 | |
| 153 g_snprintf(buf, sizeof buf, "%lu", uin); | |
| 154 status = (st == STATUS_ONLINE) ? UC_NORMAL : UC_UNAVAILABLE | (st << 5); | |
| 155 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); | |
| 156 } | |
| 157 | |
|
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
158 static gboolean icq_set_timeout_cb(gpointer data) { |
| 2086 | 159 icq_HandleTimeout(); |
| 160 ack_timer = 0; | |
| 161 return FALSE; | |
| 162 } | |
| 163 | |
| 164 static void icq_set_timeout(long interval) { | |
| 165 debug_printf("icq_SetTimeout: %ld\n", interval); | |
| 166 if (interval > 0 && ack_timer == 0) | |
|
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
167 ack_timer = g_timeout_add(interval * 1000, icq_set_timeout_cb, NULL); |
| 2086 | 168 else if (ack_timer > 0) { |
|
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
169 g_source_remove(ack_timer); |
| 2086 | 170 ack_timer = 0; |
| 171 } | |
| 172 } | |
| 173 | |
| 174 static void icq_url_incoming(icq_Link *link, unsigned long uin, unsigned char hour, | |
| 175 unsigned char minute, unsigned char day, unsigned char month, | |
| 176 unsigned short year, const char *url, const char *descr) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
177 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 178 char *msg = g_malloc(BUF_LONG), buf[256]; |
| 179 g_snprintf(msg, BUF_LONG, "<A HREF=\"%s\">%s</A>", url, descr); | |
| 180 g_snprintf(buf, 256, "%lu", uin); | |
| 181 serv_got_im(gc, buf, msg, 0, time((time_t)NULL)); | |
| 182 g_free(msg); | |
| 183 } | |
| 184 | |
| 185 static void icq_wrong_passwd(icq_Link *link) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
186 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 187 hide_login_progress(gc, "Invalid password."); |
| 188 signoff(gc); | |
| 189 } | |
| 190 | |
| 191 static void icq_invalid_uin(icq_Link *link) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
192 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 193 hide_login_progress(gc, "Invalid UIN."); |
| 194 signoff(gc); | |
| 195 } | |
| 196 | |
| 197 static void icq_info_reply(icq_Link *link, unsigned long uin, const char *nick, | |
| 198 const char *first, const char *last, const char *email, char auth) { | |
| 199 char buf[16 * 1024]; | |
| 200 | |
| 201 g_snprintf(buf, sizeof buf, | |
| 202 "<B>UIN:</B> %lu<BR>" | |
| 203 "<B>Nick:</B> %s<BR>" | |
| 204 "<B>Name:</B> %s %s<BR>" | |
| 205 "<B>Email:</B> %s\n", | |
| 206 uin, | |
| 207 nick, | |
| 208 first, last, | |
| 209 email); | |
|
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
210 g_show_info_text(buf, NULL); |
| 2086 | 211 } |
| 212 | |
| 213 static void icq_web_pager(icq_Link *link, unsigned char hour, unsigned char minute, | |
| 214 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
| 215 const char *email, const char *msg) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
216 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 217 char *who = g_strdup_printf("ICQ Web Pager: %s (%s)", nick, email); |
| 218 char *what = g_malloc(BUF_LONG); | |
| 219 g_snprintf(what, BUF_LONG, "%s", msg); | |
| 220 serv_got_im(gc, who, what, 0, time((time_t)NULL)); | |
| 221 g_free(who); | |
| 222 g_free(what); | |
| 223 } | |
| 224 | |
| 225 static void icq_mail_express(icq_Link *link, unsigned char hour, unsigned char minute, | |
| 226 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
| 227 const char *email, const char *msg) { | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
228 struct gaim_connection *gc = link->icq_UserData; |
| 2086 | 229 char *who = g_strdup_printf("ICQ Mail Express: %s (%s)", nick, email); |
| 230 char *what = g_malloc(BUF_LONG); | |
| 231 g_snprintf(what, BUF_LONG, "%s", msg); | |
| 232 serv_got_im(gc, who, what, 0, time((time_t)NULL)); | |
| 233 g_free(who); | |
| 234 g_free(what); | |
| 235 } | |
| 236 | |
| 237 static void icq_req_not(icq_Link *link, unsigned long id, int type, int arg, void *data) { | |
| 238 if (type == ICQ_NOTIFY_FAILED) | |
| 239 do_error_dialog("Failure in sending packet", "ICQ error"); | |
| 240 return; | |
| 241 } | |
| 242 | |
| 243 struct icq_auth { | |
| 244 icq_Link *link; | |
| 245 unsigned long uin; | |
| 246 }; | |
| 247 | |
| 248 static void icq_den_auth(gpointer x, struct icq_auth *iq) | |
| 249 { | |
| 250 g_free(iq); | |
| 251 } | |
| 252 | |
| 253 static void icq_acc_auth(gpointer x, struct icq_auth *iq) | |
| 254 { | |
| 255 icq_SendAuthMsg(iq->link, iq->uin); | |
| 256 } | |
| 257 | |
| 258 static void icq_auth_req(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
| 259 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
| 260 const char *first, const char *last, const char *email, const char *reason) | |
| 261 { | |
| 262 char msg[8192]; | |
| 263 struct icq_auth *iq = g_new0(struct icq_auth, 1); | |
| 264 iq->link = link; | |
| 265 iq->uin = uin; | |
| 266 | |
| 267 g_snprintf(msg, sizeof(msg), "The user %s (%s%s%s%s%s) wants you to authorize them.", | |
| 268 nick, first ? first : "", first && last ? " " : "", last ? last : "", | |
| 269 (first || last) && email ? ", " : "", email ? email : ""); | |
| 270 do_ask_dialog(msg, iq, icq_acc_auth, icq_den_auth); | |
| 271 } | |
| 272 | |
| 273 static void icq_login(struct aim_user *user) { | |
| 274 struct gaim_connection *gc = new_gaim_conn(user); | |
| 275 struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1); | |
| 276 icq_Link *link; | |
| 277 char ps[9]; | |
| 278 | |
| 279 icq_LogLevel = ICQ_LOG_MESSAGE; | |
| 280 | |
| 281 g_snprintf(ps, sizeof(ps), "%s", user->password); | |
| 282 link = id->link = icq_ICQLINKNew(atol(user->username), ps, | |
| 283 user->proto_opt[USEROPT_NICK][0] ? user->proto_opt[USEROPT_NICK] : "gaim user", | |
| 284 TRUE); | |
|
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
285 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", user->proto_opt[USEROPT_NICK]); |
| 2086 | 286 |
| 287 link->icq_Logged = icq_online; | |
| 288 link->icq_Disconnected = icq_logged_off; | |
| 289 link->icq_RecvMessage = icq_msg_incoming; | |
| 290 link->icq_RecvURL = icq_url_incoming; | |
| 291 link->icq_RecvWebPager = icq_web_pager; | |
| 292 link->icq_RecvMailExpress = icq_mail_express; | |
| 293 link->icq_RecvAuthReq = icq_auth_req; | |
| 294 link->icq_UserOnline = icq_user_online; | |
| 295 link->icq_UserOffline = icq_user_offline; | |
| 296 link->icq_UserStatusUpdate = icq_user_status; | |
| 297 link->icq_InfoReply = icq_info_reply; | |
| 298 link->icq_WrongPassword = icq_wrong_passwd; | |
| 299 link->icq_InvalidUIN = icq_invalid_uin; | |
| 300 link->icq_Log = icq_do_log; | |
| 301 link->icq_RequestNotify = icq_req_not; | |
|
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
302 link->icq_UserData = gc; |
| 2086 | 303 |
| 304 if (proxytype == PROXY_SOCKS5) | |
| 305 icq_SetProxy(link, proxyhost, proxyport, proxyuser[0], proxyuser, proxypass); | |
| 306 | |
| 307 icq_ContactClear(id->link); | |
| 308 if (bud_list_cache_exists(gc)) | |
| 309 do_import(NULL, gc); | |
| 310 | |
| 311 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
| 312 hide_login_progress(gc, "Unable to connect"); | |
| 313 signoff(gc); | |
| 314 return; | |
| 315 } | |
| 316 | |
| 317 icq_Login(link, STATUS_ONLINE); | |
| 318 id->cur_status = STATUS_ONLINE; | |
| 319 | |
| 320 set_login_progress(gc, 0, "Connecting..."); | |
| 321 } | |
| 322 | |
| 323 static void icq_close(struct gaim_connection *gc) { | |
| 324 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 325 | |
| 326 icq_Logout(id->link); | |
| 327 icq_Disconnect(id->link); | |
| 328 icq_ICQLINKDelete(id->link); | |
| 329 g_slist_free(id->thru_serv); | |
| 330 g_free(id); | |
| 331 } | |
| 332 | |
|
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
333 static int icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int away) { |
| 2086 | 334 if (!away && (strlen(msg) > 0)) { |
| 335 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 336 GSList *l = id->thru_serv; | |
| 337 long w = atol(who); | |
| 338 while (l) { | |
| 339 if (w == (long)l->data) | |
| 340 break; | |
| 341 l = l->next; | |
| 342 } | |
| 343 icq_SendMessage(id->link, w, msg, l ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY); | |
| 344 } | |
|
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
345 return 0; |
| 2086 | 346 } |
| 347 | |
| 348 static void icq_keepalive(struct gaim_connection *gc) { | |
| 349 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 350 icq_KeepAlive(id->link); | |
| 351 } | |
| 352 | |
| 353 static void icq_add_buddy(struct gaim_connection *gc, char *who) { | |
| 354 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 355 icq_ContactAdd(id->link, atol(who)); | |
| 356 icq_ContactSetVis(id->link, atol(who), TRUE); | |
| 357 } | |
| 358 | |
| 359 static void icq_add_buddies(struct gaim_connection *gc, GList *whos) { | |
| 360 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 361 while (whos) { | |
| 362 icq_ContactAdd(id->link, atol(whos->data)); | |
| 363 icq_ContactSetVis(id->link, atol(whos->data), TRUE); | |
| 364 whos = whos->next; | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 static void icq_rem_buddy(struct gaim_connection *gc, char *who) { | |
| 369 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 370 icq_ContactRemove(id->link, atol(who)); | |
| 371 } | |
| 372 | |
| 373 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
| 374 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 375 | |
| 376 if (gc->away) | |
| 377 gc->away = NULL; | |
| 378 | |
| 379 if (!strcmp(state, "Online")) | |
| 380 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
| 381 else if (!strcmp(state, "Away")) { | |
| 382 icq_ChangeStatus(id->link, STATUS_AWAY); | |
| 383 gc->away = ""; | |
| 384 } else if (!strcmp(state, "Do Not Disturb")) { | |
| 385 icq_ChangeStatus(id->link, STATUS_DND); | |
| 386 gc->away = ""; | |
| 387 } else if (!strcmp(state, "Not Available")) { | |
| 388 icq_ChangeStatus(id->link, STATUS_NA); | |
| 389 gc->away = ""; | |
| 390 } else if (!strcmp(state, "Occupied")) { | |
| 391 icq_ChangeStatus(id->link, STATUS_OCCUPIED); | |
| 392 gc->away = ""; | |
| 393 } else if (!strcmp(state, "Free For Chat")) { | |
| 394 icq_ChangeStatus(id->link, STATUS_FREE_CHAT); | |
| 395 gc->away = ""; | |
| 396 } else if (!strcmp(state, "Invisible")) { | |
| 397 icq_ChangeStatus(id->link, STATUS_INVISIBLE); | |
| 398 gc->away = ""; | |
| 399 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
| 400 if (msg) { | |
| 401 icq_ChangeStatus(id->link, STATUS_NA); | |
| 402 gc->away = ""; | |
| 403 } else { | |
| 404 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
| 405 } | |
| 406 } | |
| 407 } | |
| 408 | |
| 409 static char **icq_list_icon(int uc) { | |
| 410 guint status; | |
| 411 if (uc == UC_NORMAL) | |
| 412 return icon_online_xpm; | |
| 413 status = uc >> 5; | |
| 414 if (status & STATUS_NA) | |
| 415 return icon_na_xpm; | |
| 416 if (status & STATUS_DND) | |
| 417 return icon_dnd_xpm; | |
| 418 if (status & STATUS_OCCUPIED) | |
| 419 return icon_occ_xpm; | |
| 420 if (status & STATUS_AWAY) | |
| 421 return icon_away_xpm; | |
| 422 if (status & STATUS_FREE_CHAT) | |
| 423 return icon_ffc_xpm; | |
| 424 if (status & STATUS_INVISIBLE) | |
| 425 return NULL; | |
| 426 return icon_online_xpm; | |
| 427 } | |
| 428 | |
| 429 static void icq_get_info(struct gaim_connection *gc, char *who) { | |
| 430 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
| 431 icq_SendInfoReq(id->link, atol(who)); | |
| 432 } | |
| 433 | |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
434 static void icq_info(struct gaim_connection *gc, char *who) { |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
435 serv_get_info(gc, who); |
| 2086 | 436 } |
| 437 | |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
438 static GList *icq_buddy_menu(struct gaim_connection *gc, char *who) { |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
439 GList *m = NULL; |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
440 struct proto_buddy_menu *pbm; |
| 2086 | 441 |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
442 pbm = g_new0(struct proto_buddy_menu, 1); |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
443 pbm->label = _("Get Info"); |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
444 pbm->callback = icq_info; |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
445 pbm->gc = gc; |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
446 m = g_list_append(m, pbm); |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
447 |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
448 return m; |
| 2086 | 449 } |
| 450 | |
|
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
451 static GList *icq_user_opts() { |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
452 GList *m = NULL; |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
453 struct proto_user_opt *puo; |
| 2086 | 454 |
|
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
455 puo = g_new0(struct proto_user_opt, 1); |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
456 puo->label = "Nick:"; |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
457 puo->def = "Gaim User"; |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
458 puo->pos = USEROPT_NICK; |
|
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
459 m = g_list_append(m, puo); |
| 2086 | 460 |
|
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
461 return m; |
| 2086 | 462 } |
| 463 | |
| 464 static GList *icq_away_states() { | |
| 465 GList *m = NULL; | |
| 466 | |
| 467 m = g_list_append(m, "Online"); | |
| 468 m = g_list_append(m, "Away"); | |
| 469 m = g_list_append(m, "Do Not Disturb"); | |
| 470 m = g_list_append(m, "Not Available"); | |
| 471 m = g_list_append(m, "Occupied"); | |
| 472 m = g_list_append(m, "Free For Chat"); | |
| 473 m = g_list_append(m, "Invisible"); | |
| 474 | |
| 475 return m; | |
| 476 } | |
| 477 | |
| 478 static void toggle_thru_serv(GtkToggleButton *button, struct conversation *c) | |
| 479 { | |
| 480 struct gaim_connection *gc = gtk_object_get_user_data(GTK_OBJECT(button)); | |
| 481 struct icq_data *id = gc->proto_data; | |
| 482 GSList *l = id->thru_serv; | |
| 483 long who = atol(c->name); | |
| 484 | |
| 485 while (l) { | |
| 486 if (who == (long)l->data) | |
| 487 break; | |
| 488 l = l->next; | |
| 489 } | |
| 490 if (l) | |
| 491 id->thru_serv = g_slist_remove(id->thru_serv, (void *)who); | |
| 492 else | |
| 493 id->thru_serv = g_slist_append(id->thru_serv, (void *)who); | |
| 494 } | |
| 495 | |
| 496 static void icq_insert_convo(struct gaim_connection *gc, struct conversation *c) | |
| 497 { | |
| 498 GtkWidget *button; | |
| 499 struct icq_data *id = gc->proto_data; | |
| 500 GSList *l = id->thru_serv; | |
| 501 long who = atol(c->name); | |
| 502 | |
| 503 button = gtk_check_button_new_with_label("Send message through server"); | |
| 504 gtk_box_pack_start(GTK_BOX(c->lbox), button, FALSE, FALSE, 5); | |
| 505 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_thru_serv), c); | |
| 506 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 507 while (l) { | |
| 508 if (who == (long)l->data) | |
| 509 break; | |
| 510 l = l->next; | |
| 511 } | |
| 512 if (l) | |
| 513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 514 gtk_widget_show(button); | |
| 515 } | |
| 516 | |
| 517 static void icq_remove_convo(struct gaim_connection *gc, struct conversation *c) | |
| 518 { | |
| 519 while (GTK_BOX(c->lbox)->children) | |
| 520 gtk_container_remove(GTK_CONTAINER(c->lbox), | |
| 521 ((GtkBoxChild *)GTK_BOX(c->lbox)->children->data)->widget); | |
| 522 } | |
| 523 | |
| 524 static struct prpl *my_protocol = NULL; | |
| 525 | |
| 526 void icq_init(struct prpl *ret) { | |
| 527 ret->protocol = PROTO_ICQ; | |
| 528 ret->name = icq_name; | |
| 529 ret->list_icon = icq_list_icon; | |
| 530 ret->away_states = icq_away_states; | |
| 531 ret->buddy_menu = icq_buddy_menu; | |
| 532 ret->user_opts = icq_user_opts; | |
| 533 ret->insert_convo = icq_insert_convo; | |
| 534 ret->remove_convo = icq_remove_convo; | |
| 535 ret->login = icq_login; | |
| 536 ret->close = icq_close; | |
| 537 ret->send_im = icq_send_msg; | |
| 538 ret->add_buddy = icq_add_buddy; | |
| 539 ret->add_buddies = icq_add_buddies; | |
| 540 ret->remove_buddy = icq_rem_buddy; | |
| 541 ret->get_info = icq_get_info; | |
| 542 ret->set_away = icq_set_away; | |
| 543 ret->keepalive = icq_keepalive; | |
| 544 | |
| 545 my_protocol = ret; | |
| 546 | |
| 547 icq_SocketNotify = icq_sock_notify; | |
| 548 icq_SetTimeout = icq_set_timeout; | |
| 549 } | |
| 550 | |
| 551 #ifndef STATIC | |
| 552 | |
| 553 char *gaim_plugin_init(GModule *handle) | |
| 554 { | |
| 555 load_protocol(icq_init, sizeof(struct prpl)); | |
| 556 return NULL; | |
| 557 } | |
| 558 | |
| 559 void gaim_plugin_remove() | |
| 560 { | |
| 561 struct prpl *p = find_prpl(PROTO_ICQ); | |
| 562 if (p == my_protocol) | |
| 563 unload_protocol(p); | |
| 564 } | |
| 565 | |
| 566 char *name() | |
| 567 { | |
| 568 return "ICQ"; | |
| 569 } | |
| 570 | |
| 571 char *description() | |
| 572 { | |
|
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
573 return PRPL_DESC("ICQ"); |
| 2086 | 574 } |
| 575 | |
| 576 #endif |
