Mercurial > pidgin
annotate plugins/chatlist.c @ 2583:ce3df2c43f46
[gaim-migrate @ 2596]
thanks to Dennis Lambe Jr. (malsyned).
Several of you will probably wonder why I put it in gtkimhtml.c instead of conversation.c like the rest of the smilies. (Dennis also put it in gtkimhtml.c.)
gtkimhtml.c strives to be more or less compatible and identical with winaim (though fewer bugs ;) ). winaim parses out :-d. winaim doesn't parse any of the ones in conversation.c though. So if winaim parses it, it goes in gtkimhtml.c.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 23 Oct 2001 04:59:46 +0000 |
parents | 5473c8c5378d |
children | 34812d648f72 |
rev | line source |
---|---|
2241 | 1 #define GAIM_PLUGINS |
2 | |
3 #include "pixmaps/cancel.xpm" | |
4 #include "pixmaps/refresh.xpm" | |
5 #include "pixmaps/gnome_add.xpm" | |
6 #include "pixmaps/gnome_remove.xpm" | |
7 | |
8 #include "proxy.h" | |
9 #include "gaim.h" | |
10 | |
11 #include <stdlib.h> | |
2272
4ecc9a9a75d8
[gaim-migrate @ 2282]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2241
diff
changeset
|
12 #include <string.h> |
2241 | 13 |
2417
5473c8c5378d
[gaim-migrate @ 2430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2356
diff
changeset
|
14 #define AOL_SRCHSTR "/community/aimcheck.adp/url=" |
5473c8c5378d
[gaim-migrate @ 2430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2356
diff
changeset
|
15 |
2241 | 16 struct chat_page { |
17 GtkWidget *list1; | |
18 GtkWidget *list2; | |
19 }; | |
20 | |
21 struct chat_room { | |
22 char name[80]; | |
23 int exchange; | |
24 }; | |
25 | |
26 static GtkWidget *item = NULL; /* this is the parent tree */ | |
27 static GList *chat_rooms = NULL; | |
28 | |
29 static GtkWidget *parent = NULL; /* this is the config thing where you can see the list */ | |
30 static struct chat_page *cp = NULL; | |
31 | |
32 static void des_item() | |
33 { | |
34 if (item) | |
35 gtk_widget_destroy(item); | |
36 item = NULL; | |
37 } | |
38 | |
39 static void handle_click_chat(GtkWidget *widget, GdkEventButton * event, struct chat_room *cr) | |
40 { | |
41 if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { | |
42 GList *m = g_list_append(NULL, cr->name); | |
43 int *x = g_new0(int, 1); | |
44 *x = cr->exchange; | |
45 m = g_list_append(m, x); | |
46 serv_join_chat(connections->data, m); | |
47 g_free(x); | |
48 g_list_free(m); | |
49 } | |
50 } | |
51 | |
52 static void setup_buddy_chats() | |
53 { | |
54 GList *crs = chat_rooms; | |
55 GtkWidget *tree; | |
56 | |
57 if (!blist) | |
58 return; | |
59 | |
60 if (item) | |
61 gtk_tree_remove_item(GTK_TREE(buddies), item); | |
62 item = NULL; | |
63 | |
64 if (!chat_rooms) | |
65 return; | |
66 | |
67 item = gtk_tree_item_new_with_label(_("Buddy Chat")); | |
68 gtk_signal_connect(GTK_OBJECT(item), "destroy", GTK_SIGNAL_FUNC(des_item), NULL); | |
69 gtk_tree_append(GTK_TREE(buddies), item); | |
70 gtk_tree_item_expand(GTK_TREE_ITEM(item)); | |
71 gtk_widget_show(item); | |
72 | |
73 tree = gtk_tree_new(); | |
74 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree); | |
75 gtk_widget_show(tree); | |
76 | |
77 while (crs) { | |
78 struct chat_room *cr = (struct chat_room *)crs->data; | |
79 GtkWidget *titem = gtk_tree_item_new_with_label(cr->name); | |
80 gtk_object_set_user_data(GTK_OBJECT(titem), cr); | |
81 gtk_tree_append(GTK_TREE(tree), titem); | |
82 gtk_widget_show(titem); | |
83 gtk_signal_connect(GTK_OBJECT(titem), "button_press_event", | |
84 GTK_SIGNAL_FUNC(handle_click_chat), cr); | |
85 crs = crs->next; | |
86 } | |
87 } | |
88 | |
89 static void save_chat_prefs() | |
90 { | |
91 FILE *f; | |
92 char path[1024]; | |
93 char *x = gaim_user_dir(); | |
94 GList *crs = chat_rooms; | |
95 | |
96 g_snprintf(path, sizeof(path), "%s/%s", x, "chats"); | |
97 f = fopen(path, "w"); | |
98 if (!f) { | |
99 g_free(x); | |
100 return; | |
101 } | |
102 while (crs) { | |
103 struct chat_room *cr = crs->data; | |
104 crs = crs->next; | |
105 fprintf(f, "%s\n%d\n", cr->name, cr->exchange); | |
106 } | |
107 fclose(f); | |
108 } | |
109 | |
110 static void restore_chat_prefs() | |
111 { | |
112 FILE *f; | |
113 char path[1024]; | |
114 char *x = gaim_user_dir(); | |
115 char buf[1024]; | |
116 | |
117 g_snprintf(path, sizeof(path), "%s/%s", x, "chats"); | |
118 f = fopen(path, "r"); | |
119 if (!f) { | |
120 g_free(x); | |
121 return; | |
122 } | |
123 while (fgets(buf, 1024, f)) { | |
124 struct chat_room *cr = g_new0(struct chat_room, 1); | |
2356
ddf404cd9757
[gaim-migrate @ 2369]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2272
diff
changeset
|
125 g_snprintf(cr->name, sizeof(cr->name), "%s", g_strchomp(buf)); |
2241 | 126 if (!fgets(buf, 1024, f)) { |
127 g_free(cr); | |
128 break; | |
129 } | |
130 cr->exchange = atoi(buf); | |
131 chat_rooms = g_list_append(chat_rooms, cr); | |
132 } | |
133 fclose(f); | |
134 setup_buddy_chats(); | |
135 } | |
136 | |
137 static void ref_list_callback(gpointer data, char *text) | |
138 { | |
139 char *c; | |
140 int len; | |
141 GtkWidget *item; | |
142 GList *items = GTK_LIST(cp->list1)->children; | |
143 struct chat_room *cr; | |
144 c = text; | |
145 | |
146 if (!text) | |
147 return; | |
148 | |
149 len = strlen(text); | |
150 | |
151 while (items) { | |
152 g_free(gtk_object_get_user_data(GTK_OBJECT(items->data))); | |
153 items = items->next; | |
154 } | |
155 | |
156 items = NULL; | |
157 | |
158 gtk_list_clear_items(GTK_LIST(cp->list1), 0, -1); | |
159 | |
160 item = gtk_list_item_new_with_label(_("Gaim Chat")); | |
161 cr = g_new0(struct chat_room, 1); | |
162 strcpy(cr->name, _("Gaim Chat")); | |
163 cr->exchange = 4; | |
164 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
165 gtk_widget_show(item); | |
166 | |
167 items = g_list_append(NULL, item); | |
168 | |
169 while (c) { | |
170 if (c - text > len - 30) | |
171 break; /* assume no chat rooms 30 from end, padding */ | |
172 if (!g_strncasecmp(AOL_SRCHSTR, c, strlen(AOL_SRCHSTR))) { | |
173 char *t; | |
174 int len = 0; | |
175 int exchange; | |
176 char *name = NULL; | |
177 | |
178 c += strlen(AOL_SRCHSTR); | |
179 t = c; | |
180 while (t) { | |
181 len++; | |
182 name = g_realloc(name, len); | |
183 if (*t == '+') | |
184 name[len - 1] = ' '; | |
185 else if (*t == '&') { | |
186 name[len - 1] = 0; | |
187 sscanf(t, "&Exchange=%d", &exchange); | |
188 c = t + strlen("&Exchange=x"); | |
189 break; | |
190 } else | |
191 name[len - 1] = *t; | |
192 t++; | |
193 } | |
194 cr = g_new0(struct chat_room, 1); | |
195 strcpy(cr->name, name); | |
196 cr->exchange = exchange; | |
197 item = gtk_list_item_new_with_label(name); | |
198 gtk_widget_show(item); | |
199 items = g_list_append(items, item); | |
200 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
201 g_free(name); | |
202 } | |
203 c++; | |
204 } | |
205 gtk_list_append_items(GTK_LIST(cp->list1), items); | |
206 g_free(text); | |
207 } | |
208 | |
209 static void refresh_list(GtkWidget *w, gpointer *m) | |
210 { | |
211 grab_url("http://www.aol.com/community/chat/allchats.html", ref_list_callback, NULL); | |
212 } | |
213 | |
214 static void add_chat(GtkWidget *w, gpointer *m) | |
215 { | |
216 GList *sel = GTK_LIST(cp->list1)->selection; | |
217 struct chat_room *cr, *cr2; | |
218 GList *crs = chat_rooms; | |
219 GtkWidget *item; | |
220 | |
221 if (sel) { | |
222 cr = (struct chat_room *)gtk_object_get_user_data(GTK_OBJECT(sel->data)); | |
223 } else | |
224 return; | |
225 | |
226 while (crs) { | |
227 cr2 = (struct chat_room *)crs->data; | |
228 if (!g_strcasecmp(cr->name, cr2->name)) | |
229 return; | |
230 crs = crs->next; | |
231 } | |
232 item = gtk_list_item_new_with_label(cr->name); | |
233 cr2 = g_new0(struct chat_room, 1); | |
234 strcpy(cr2->name, cr->name); | |
235 cr2->exchange = cr->exchange; | |
236 gtk_object_set_user_data(GTK_OBJECT(item), cr2); | |
237 gtk_widget_show(item); | |
238 sel = g_list_append(NULL, item); | |
239 gtk_list_append_items(GTK_LIST(cp->list2), sel); | |
240 chat_rooms = g_list_append(chat_rooms, cr2); | |
241 | |
242 setup_buddy_chats(); | |
243 save_chat_prefs(); | |
244 } | |
245 | |
246 static void remove_chat(GtkWidget *w, gpointer *m) | |
247 { | |
248 GList *sel = GTK_LIST(cp->list2)->selection; | |
249 struct chat_room *cr; | |
250 GList *crs; | |
251 GtkWidget *item; | |
252 | |
253 if (sel) { | |
254 item = (GtkWidget *)sel->data; | |
255 cr = (struct chat_room *)gtk_object_get_user_data(GTK_OBJECT(item)); | |
256 } else | |
257 return; | |
258 | |
259 chat_rooms = g_list_remove(chat_rooms, cr); | |
260 | |
261 | |
262 gtk_list_clear_items(GTK_LIST(cp->list2), 0, -1); | |
263 | |
264 if (g_list_length(chat_rooms) == 0) | |
265 chat_rooms = NULL; | |
266 | |
267 crs = chat_rooms; | |
268 | |
269 while (crs) { | |
270 cr = (struct chat_room *)crs->data; | |
271 item = gtk_list_item_new_with_label(cr->name); | |
272 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
273 gtk_widget_show(item); | |
274 gtk_list_append_items(GTK_LIST(cp->list2), g_list_append(NULL, item)); | |
275 | |
276 | |
277 crs = crs->next; | |
278 } | |
279 | |
280 setup_buddy_chats(); | |
281 save_chat_prefs(); | |
282 } | |
283 | |
284 static void parent_destroy() | |
285 { | |
286 if (parent) | |
287 gtk_widget_destroy(parent); | |
288 parent = NULL; | |
289 } | |
290 | |
291 void gaim_plugin_config() | |
292 { | |
293 GtkWidget *vbox; | |
294 GtkWidget *frame; | |
295 GtkWidget *box; | |
296 GtkWidget *table; | |
297 GtkWidget *rem_button, *add_button, *ref_button; | |
298 GtkWidget *list1, *list2; | |
299 GtkWidget *label; | |
300 GtkWidget *sw1, *sw2; | |
301 GtkWidget *item; | |
302 GtkWidget *hbox; | |
303 GtkWidget *button; | |
304 GList *crs = chat_rooms; | |
305 GList *items = NULL; | |
306 struct chat_room *cr; | |
307 | |
308 if (parent) { | |
309 gtk_widget_show(parent); | |
310 return; | |
311 } | |
312 | |
313 if (cp) | |
314 g_free(cp); | |
315 cp = g_new0(struct chat_page, 1); | |
316 | |
317 parent = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
318 gtk_widget_set_usize(parent, 300, 400); | |
319 gtk_window_set_title(GTK_WINDOW(parent), "Chat Rooms"); | |
320 gtk_window_set_wmclass(GTK_WINDOW(parent), "chatlist", "Gaim"); | |
321 gtk_widget_realize(parent); | |
322 aol_icon(parent->window); | |
323 gtk_signal_connect(GTK_OBJECT(parent), "destroy", | |
324 GTK_SIGNAL_FUNC(parent_destroy), NULL); | |
325 | |
326 vbox = gtk_vbox_new(FALSE, 0); | |
327 gtk_container_add(GTK_CONTAINER(parent), vbox); | |
328 gtk_widget_show(vbox); | |
329 | |
330 hbox = gtk_hbox_new(FALSE, 0); | |
331 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
332 gtk_widget_show(hbox); | |
333 | |
334 button = picture_button(parent, _("Close"), cancel_xpm); | |
335 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
336 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
337 GTK_SIGNAL_FUNC(parent_destroy), NULL); | |
338 | |
339 frame = gtk_frame_new(_("Chat Rooms")); | |
340 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); | |
341 gtk_widget_show(frame); | |
342 | |
343 box = gtk_vbox_new(FALSE, 5); | |
344 gtk_container_set_border_width(GTK_CONTAINER(box), 5); | |
345 gtk_container_add(GTK_CONTAINER(frame), box); | |
346 gtk_widget_show(box); | |
347 | |
348 table = gtk_table_new(4, 2, FALSE); | |
349 gtk_widget_show(table); | |
350 | |
351 gtk_box_pack_start(GTK_BOX(box), table, TRUE, TRUE, 0); | |
352 | |
353 list1 = gtk_list_new(); | |
354 list2 = gtk_list_new(); | |
355 sw1 = gtk_scrolled_window_new(NULL, NULL); | |
356 sw2 = gtk_scrolled_window_new(NULL, NULL); | |
357 | |
358 ref_button = picture_button(parent, _("Refresh"), refresh_xpm); | |
359 add_button = picture_button(parent, _("Add"), gnome_add_xpm); | |
360 rem_button = picture_button(parent, _("Remove"), gnome_remove_xpm); | |
361 gtk_widget_show(list1); | |
362 gtk_widget_show(sw1); | |
363 gtk_widget_show(list2); | |
364 gtk_widget_show(sw2); | |
365 | |
366 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw1), list1); | |
367 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list2); | |
368 | |
369 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw1), | |
370 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
371 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2), | |
372 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
373 | |
374 cp->list1 = list1; | |
375 cp->list2 = list2; | |
376 | |
377 gtk_signal_connect(GTK_OBJECT(ref_button), "clicked", GTK_SIGNAL_FUNC(refresh_list), cp); | |
378 gtk_signal_connect(GTK_OBJECT(rem_button), "clicked", GTK_SIGNAL_FUNC(remove_chat), cp); | |
379 gtk_signal_connect(GTK_OBJECT(add_button), "clicked", GTK_SIGNAL_FUNC(add_chat), cp); | |
380 | |
381 | |
382 | |
383 label = gtk_label_new(_("List of available chats")); | |
384 gtk_widget_show(label); | |
385 | |
386 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
387 gtk_table_attach(GTK_TABLE(table), ref_button, 0, 1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
388 gtk_table_attach(GTK_TABLE(table), sw1, 0, 1, 2, 3, | |
389 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5); | |
390 gtk_table_attach(GTK_TABLE(table), add_button, 0, 1, 3, 4, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
391 | |
392 | |
393 label = gtk_label_new(_("List of subscribed chats")); | |
394 gtk_widget_show(label); | |
395 | |
396 gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
397 gtk_table_attach(GTK_TABLE(table), sw2, 1, 2, 2, 3, | |
398 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5); | |
399 gtk_table_attach(GTK_TABLE(table), rem_button, 1, 2, 3, 4, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
400 | |
401 | |
402 item = gtk_list_item_new_with_label(_("Gaim Chat")); | |
403 cr = g_new0(struct chat_room, 1); | |
404 strcpy(cr->name, _("Gaim Chat")); | |
405 cr->exchange = 4; | |
406 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
407 gtk_widget_show(item); | |
408 gtk_list_append_items(GTK_LIST(list1), g_list_append(NULL, item)); | |
409 | |
410 | |
411 while (crs) { | |
412 cr = (struct chat_room *)crs->data; | |
413 item = gtk_list_item_new_with_label(cr->name); | |
414 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
415 gtk_widget_show(item); | |
416 items = g_list_append(items, item); | |
417 | |
418 crs = crs->next; | |
419 } | |
420 | |
421 gtk_list_append_items(GTK_LIST(list2), items); | |
422 | |
423 gtk_widget_show(parent); | |
424 } | |
425 | |
426 static void handle_signon(struct gaim_connection *gc) | |
427 { | |
428 setup_buddy_chats(); | |
429 } | |
430 | |
431 char *gaim_plugin_init(GModule *m) | |
432 { | |
433 restore_chat_prefs(); | |
434 gaim_signal_connect(m, event_signon, handle_signon, NULL); | |
435 return NULL; | |
436 } | |
437 | |
438 void gaim_plugin_remove() | |
439 { | |
440 if (parent) | |
441 gtk_widget_destroy(parent); | |
442 parent = NULL; | |
443 | |
444 if (item) | |
445 gtk_tree_remove_item(GTK_TREE(buddies), item); | |
446 item = NULL; | |
447 | |
448 while (chat_rooms) { | |
449 g_free(chat_rooms->data); | |
450 chat_rooms = g_list_remove(chat_rooms, chat_rooms->data); | |
451 } | |
452 | |
453 if (cp) | |
454 g_free(cp); | |
455 cp = NULL; | |
456 } | |
457 | |
458 char *name() | |
459 { | |
460 return "Chat List"; | |
461 } | |
462 | |
463 char *description() | |
464 { | |
465 return "Allows you to add chat rooms to your buddy list. Click the configure button to choose" | |
466 " which rooms."; | |
467 } |