Mercurial > pidgin
annotate plugins/chatlist.c @ 4207:bda7855fa32f
[gaim-migrate @ 4443]
So, I figured, "Hey, it's 7am on a Sunday. Why don't I take the legend out
of OSCAR Info windows."
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 05 Jan 2003 12:09:34 +0000 |
parents | 59751fe608c5 |
children | da5e1b57adb0 |
rev | line source |
---|---|
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
1 #include "config.h" |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
2 |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
3 #ifndef GAIM_PLUGINS |
2241 | 4 #define GAIM_PLUGINS |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
5 #endif |
2241 | 6 |
7 #include "pixmaps/refresh.xpm" | |
8 #include "pixmaps/gnome_add.xpm" | |
9 #include "pixmaps/gnome_remove.xpm" | |
10 | |
11 #include "proxy.h" | |
12 #include "gaim.h" | |
13 | |
14 #include <stdlib.h> | |
2272
4ecc9a9a75d8
[gaim-migrate @ 2282]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2241
diff
changeset
|
15 #include <string.h> |
3630 | 16 #ifdef _WIN32 |
17 #include "win32dep.h" | |
18 #endif | |
2241 | 19 |
2993 | 20 #define AOL_SRCHSTR "aim:GoChat?RoomName=" |
2417
5473c8c5378d
[gaim-migrate @ 2430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2356
diff
changeset
|
21 |
2241 | 22 struct chat_page { |
23 GtkWidget *list1; | |
24 GtkWidget *list2; | |
25 }; | |
26 | |
27 struct chat_room { | |
28 char name[80]; | |
29 int exchange; | |
30 }; | |
31 | |
32 static GtkWidget *item = NULL; /* this is the parent tree */ | |
33 static GList *chat_rooms = NULL; | |
34 | |
35 static struct chat_page *cp = NULL; | |
36 | |
37 static void des_item() | |
38 { | |
39 if (item) | |
40 gtk_widget_destroy(item); | |
41 item = NULL; | |
42 } | |
43 | |
44 static void handle_click_chat(GtkWidget *widget, GdkEventButton * event, struct chat_room *cr) | |
45 { | |
46 if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { | |
47 GList *m = g_list_append(NULL, cr->name); | |
48 int *x = g_new0(int, 1); | |
49 *x = cr->exchange; | |
50 m = g_list_append(m, x); | |
51 serv_join_chat(connections->data, m); | |
52 g_free(x); | |
53 g_list_free(m); | |
54 } | |
55 } | |
56 | |
57 static void setup_buddy_chats() | |
58 { | |
59 GList *crs = chat_rooms; | |
60 GtkWidget *tree; | |
61 | |
62 if (!blist) | |
63 return; | |
64 | |
65 if (item) | |
66 gtk_tree_remove_item(GTK_TREE(buddies), item); | |
67 item = NULL; | |
68 | |
69 if (!chat_rooms) | |
70 return; | |
71 | |
72 item = gtk_tree_item_new_with_label(_("Buddy Chat")); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
73 g_signal_connect(GTK_OBJECT(item), "destroy", G_CALLBACK(des_item), NULL); |
2241 | 74 gtk_tree_append(GTK_TREE(buddies), item); |
75 gtk_tree_item_expand(GTK_TREE_ITEM(item)); | |
76 gtk_widget_show(item); | |
77 | |
78 tree = gtk_tree_new(); | |
79 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree); | |
80 gtk_widget_show(tree); | |
81 | |
82 while (crs) { | |
83 struct chat_room *cr = (struct chat_room *)crs->data; | |
84 GtkWidget *titem = gtk_tree_item_new_with_label(cr->name); | |
85 gtk_object_set_user_data(GTK_OBJECT(titem), cr); | |
86 gtk_tree_append(GTK_TREE(tree), titem); | |
87 gtk_widget_show(titem); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
88 g_signal_connect(GTK_OBJECT(titem), "button_press_event", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
89 G_CALLBACK(handle_click_chat), cr); |
2241 | 90 crs = crs->next; |
91 } | |
2900
aaaca46b507b
[gaim-migrate @ 2913]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2892
diff
changeset
|
92 |
aaaca46b507b
[gaim-migrate @ 2913]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2892
diff
changeset
|
93 gtk_tree_item_expand(GTK_TREE_ITEM(item)); |
2241 | 94 } |
95 | |
96 static void save_chat_prefs() | |
97 { | |
98 FILE *f; | |
99 char path[1024]; | |
100 char *x = gaim_user_dir(); | |
101 GList *crs = chat_rooms; | |
102 | |
103 g_snprintf(path, sizeof(path), "%s/%s", x, "chats"); | |
104 f = fopen(path, "w"); | |
3930 | 105 if (!f) |
2241 | 106 return; |
107 while (crs) { | |
108 struct chat_room *cr = crs->data; | |
109 crs = crs->next; | |
110 fprintf(f, "%s\n%d\n", cr->name, cr->exchange); | |
111 } | |
112 fclose(f); | |
113 } | |
114 | |
115 static void restore_chat_prefs() | |
116 { | |
117 FILE *f; | |
118 char path[1024]; | |
119 char *x = gaim_user_dir(); | |
120 char buf[1024]; | |
121 | |
122 g_snprintf(path, sizeof(path), "%s/%s", x, "chats"); | |
123 f = fopen(path, "r"); | |
3930 | 124 if (!f) |
2241 | 125 return; |
126 while (fgets(buf, 1024, f)) { | |
127 struct chat_room *cr = g_new0(struct chat_room, 1); | |
2356
ddf404cd9757
[gaim-migrate @ 2369]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2272
diff
changeset
|
128 g_snprintf(cr->name, sizeof(cr->name), "%s", g_strchomp(buf)); |
2241 | 129 if (!fgets(buf, 1024, f)) { |
130 g_free(cr); | |
131 break; | |
132 } | |
133 cr->exchange = atoi(buf); | |
134 chat_rooms = g_list_append(chat_rooms, cr); | |
135 } | |
136 fclose(f); | |
137 setup_buddy_chats(); | |
138 } | |
139 | |
140 static void ref_list_callback(gpointer data, char *text) | |
141 { | |
142 char *c; | |
143 int len; | |
144 GtkWidget *item; | |
145 GList *items = GTK_LIST(cp->list1)->children; | |
146 struct chat_room *cr; | |
147 c = text; | |
148 | |
149 if (!text) | |
150 return; | |
151 | |
152 len = strlen(text); | |
153 | |
154 while (items) { | |
155 g_free(gtk_object_get_user_data(GTK_OBJECT(items->data))); | |
156 items = items->next; | |
157 } | |
158 | |
159 items = NULL; | |
160 | |
161 gtk_list_clear_items(GTK_LIST(cp->list1), 0, -1); | |
162 | |
163 item = gtk_list_item_new_with_label(_("Gaim Chat")); | |
164 cr = g_new0(struct chat_room, 1); | |
165 strcpy(cr->name, _("Gaim Chat")); | |
166 cr->exchange = 4; | |
167 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
168 gtk_widget_show(item); | |
169 | |
170 items = g_list_append(NULL, item); | |
171 | |
172 while (c) { | |
173 if (c - text > len - 30) | |
174 break; /* assume no chat rooms 30 from end, padding */ | |
175 if (!g_strncasecmp(AOL_SRCHSTR, c, strlen(AOL_SRCHSTR))) { | |
176 char *t; | |
177 int len = 0; | |
3000 | 178 int exchange = 5; |
2241 | 179 char *name = NULL; |
180 | |
181 c += strlen(AOL_SRCHSTR); | |
182 t = c; | |
183 while (t) { | |
184 len++; | |
185 name = g_realloc(name, len); | |
186 if (*t == '+') | |
187 name[len - 1] = ' '; | |
188 else if (*t == '&') { | |
189 name[len - 1] = 0; | |
3000 | 190 sscanf(t, "&Exchange=%d", &exchange); |
191 c = t + strlen("&Exchange=x"); | |
2241 | 192 break; |
193 } else | |
194 name[len - 1] = *t; | |
195 t++; | |
196 } | |
197 cr = g_new0(struct chat_room, 1); | |
198 strcpy(cr->name, name); | |
199 cr->exchange = exchange; | |
4164
a55c2a0ddcd4
[gaim-migrate @ 4393]
Christian Hammond <chipx86@chipx86.com>
parents:
3930
diff
changeset
|
200 printf("Adding '%s'\n", name); |
2241 | 201 item = gtk_list_item_new_with_label(name); |
202 gtk_widget_show(item); | |
203 items = g_list_append(items, item); | |
204 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
205 g_free(name); | |
206 } | |
207 c++; | |
208 } | |
209 gtk_list_append_items(GTK_LIST(cp->list1), items); | |
210 } | |
211 | |
212 static void refresh_list(GtkWidget *w, gpointer *m) | |
213 { | |
2872
30828b83143d
[gaim-migrate @ 2885]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2692
diff
changeset
|
214 grab_url("http://www.aim.com/community/chats.adp", FALSE, ref_list_callback, NULL); |
2241 | 215 } |
216 | |
217 static void add_chat(GtkWidget *w, gpointer *m) | |
218 { | |
219 GList *sel = GTK_LIST(cp->list1)->selection; | |
220 struct chat_room *cr, *cr2; | |
221 GList *crs = chat_rooms; | |
222 GtkWidget *item; | |
223 | |
224 if (sel) { | |
225 cr = (struct chat_room *)gtk_object_get_user_data(GTK_OBJECT(sel->data)); | |
226 } else | |
227 return; | |
228 | |
229 while (crs) { | |
230 cr2 = (struct chat_room *)crs->data; | |
231 if (!g_strcasecmp(cr->name, cr2->name)) | |
232 return; | |
233 crs = crs->next; | |
234 } | |
235 item = gtk_list_item_new_with_label(cr->name); | |
236 cr2 = g_new0(struct chat_room, 1); | |
237 strcpy(cr2->name, cr->name); | |
238 cr2->exchange = cr->exchange; | |
239 gtk_object_set_user_data(GTK_OBJECT(item), cr2); | |
240 gtk_widget_show(item); | |
241 sel = g_list_append(NULL, item); | |
242 gtk_list_append_items(GTK_LIST(cp->list2), sel); | |
243 chat_rooms = g_list_append(chat_rooms, cr2); | |
244 | |
245 setup_buddy_chats(); | |
246 save_chat_prefs(); | |
247 } | |
248 | |
249 static void remove_chat(GtkWidget *w, gpointer *m) | |
250 { | |
251 GList *sel = GTK_LIST(cp->list2)->selection; | |
252 struct chat_room *cr; | |
253 GList *crs; | |
254 GtkWidget *item; | |
255 | |
256 if (sel) { | |
257 item = (GtkWidget *)sel->data; | |
258 cr = (struct chat_room *)gtk_object_get_user_data(GTK_OBJECT(item)); | |
259 } else | |
260 return; | |
261 | |
262 chat_rooms = g_list_remove(chat_rooms, cr); | |
263 | |
264 | |
265 gtk_list_clear_items(GTK_LIST(cp->list2), 0, -1); | |
266 | |
267 if (g_list_length(chat_rooms) == 0) | |
268 chat_rooms = NULL; | |
269 | |
270 crs = chat_rooms; | |
271 | |
272 while (crs) { | |
273 cr = (struct chat_room *)crs->data; | |
274 item = gtk_list_item_new_with_label(cr->name); | |
275 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
276 gtk_widget_show(item); | |
277 gtk_list_append_items(GTK_LIST(cp->list2), g_list_append(NULL, item)); | |
278 | |
279 | |
280 crs = crs->next; | |
281 } | |
282 | |
283 setup_buddy_chats(); | |
284 save_chat_prefs(); | |
285 } | |
286 | |
3630 | 287 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() |
2241 | 288 { |
3565 | 289 GtkWidget *ret, *vbox; |
2241 | 290 GtkWidget *list1, *list2; |
291 GtkWidget *sw1, *sw2; | |
3565 | 292 GtkWidget *ref_button, *add_button, *rem_button; |
293 GtkWidget *table, *label; | |
294 struct chat_room *cr = NULL; | |
2241 | 295 GList *items = NULL; |
3565 | 296 GList *crs = chat_rooms; |
297 | |
2241 | 298 if (cp) |
3565 | 299 g_free(cp); |
300 cp = g_new0(struct chat_page, 1); | |
2241 | 301 |
302 | |
3565 | 303 ret = gtk_vbox_new(FALSE, 18); |
304 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
2241 | 305 |
3565 | 306 vbox = make_frame(ret, _("Chat Rooms")); |
2241 | 307 |
308 table = gtk_table_new(4, 2, FALSE); | |
309 gtk_widget_show(table); | |
310 | |
3565 | 311 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); |
2241 | 312 |
313 list1 = gtk_list_new(); | |
314 list2 = gtk_list_new(); | |
315 sw1 = gtk_scrolled_window_new(NULL, NULL); | |
316 sw2 = gtk_scrolled_window_new(NULL, NULL); | |
317 | |
3565 | 318 ref_button = picture_button(prefs, _("Refresh"), refresh_xpm); |
319 add_button = picture_button(prefs, _("Add"), gnome_add_xpm); | |
320 rem_button = picture_button(prefs, _("Remove"), gnome_remove_xpm); | |
2241 | 321 gtk_widget_show(list1); |
322 gtk_widget_show(sw1); | |
323 gtk_widget_show(list2); | |
324 gtk_widget_show(sw2); | |
325 | |
326 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw1), list1); | |
327 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list2); | |
328 | |
329 cp->list1 = list1; | |
330 cp->list2 = list2; | |
331 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
332 g_signal_connect(GTK_OBJECT(ref_button), "clicked", G_CALLBACK(refresh_list), cp); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
333 g_signal_connect(GTK_OBJECT(rem_button), "clicked", G_CALLBACK(remove_chat), cp); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4164
diff
changeset
|
334 g_signal_connect(GTK_OBJECT(add_button), "clicked", G_CALLBACK(add_chat), cp); |
2241 | 335 |
336 label = gtk_label_new(_("List of available chats")); | |
337 gtk_widget_show(label); | |
338 | |
339 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
340 gtk_table_attach(GTK_TABLE(table), ref_button, 0, 1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
341 gtk_table_attach(GTK_TABLE(table), sw1, 0, 1, 2, 3, | |
342 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5); | |
343 gtk_table_attach(GTK_TABLE(table), add_button, 0, 1, 3, 4, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
344 | |
345 | |
346 label = gtk_label_new(_("List of subscribed chats")); | |
347 gtk_widget_show(label); | |
348 | |
349 gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
350 gtk_table_attach(GTK_TABLE(table), sw2, 1, 2, 2, 3, | |
351 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5); | |
352 gtk_table_attach(GTK_TABLE(table), rem_button, 1, 2, 3, 4, GTK_SHRINK, GTK_SHRINK, 0, 0); | |
353 | |
354 | |
355 item = gtk_list_item_new_with_label(_("Gaim Chat")); | |
356 cr = g_new0(struct chat_room, 1); | |
357 strcpy(cr->name, _("Gaim Chat")); | |
358 cr->exchange = 4; | |
359 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
360 gtk_widget_show(item); | |
361 gtk_list_append_items(GTK_LIST(list1), g_list_append(NULL, item)); | |
362 | |
363 | |
364 while (crs) { | |
365 cr = (struct chat_room *)crs->data; | |
366 item = gtk_list_item_new_with_label(cr->name); | |
367 gtk_object_set_user_data(GTK_OBJECT(item), cr); | |
368 gtk_widget_show(item); | |
369 items = g_list_append(items, item); | |
370 | |
371 crs = crs->next; | |
372 } | |
373 | |
374 gtk_list_append_items(GTK_LIST(list2), items); | |
3565 | 375 gtk_widget_show_all(ret); |
376 return ret; | |
2241 | 377 } |
378 | |
379 static void handle_signon(struct gaim_connection *gc) | |
380 { | |
381 setup_buddy_chats(); | |
382 } | |
383 | |
3630 | 384 G_MODULE_EXPORT char *gaim_plugin_init(GModule *m) |
2241 | 385 { |
386 restore_chat_prefs(); | |
387 gaim_signal_connect(m, event_signon, handle_signon, NULL); | |
388 return NULL; | |
389 } | |
390 | |
3630 | 391 G_MODULE_EXPORT void gaim_plugin_remove() |
2241 | 392 { |
393 if (item) | |
394 gtk_tree_remove_item(GTK_TREE(buddies), item); | |
395 item = NULL; | |
396 | |
397 while (chat_rooms) { | |
398 g_free(chat_rooms->data); | |
399 chat_rooms = g_list_remove(chat_rooms, chat_rooms->data); | |
400 } | |
401 | |
402 if (cp) | |
403 g_free(cp); | |
404 cp = NULL; | |
405 } | |
406 | |
3551 | 407 struct gaim_plugin_description desc; |
408 struct gaim_plugin_description *gaim_plugin_desc() { | |
409 desc.api_version = PLUGIN_API_VERSION; | |
410 desc.name = g_strdup("Chat List"); | |
411 desc.version = g_strdup(VERSION); | |
412 desc.description = g_strdup("Allows you to add chat rooms to your buddy list."); | |
413 desc.authors = g_strdup("Eric Warmenhoven <eric@warmenhoven.org>"); | |
414 desc.url = g_strdup(WEBSITE); | |
415 return &desc; | |
416 } | |
417 | |
3630 | 418 G_MODULE_EXPORT char *name() |
2241 | 419 { |
420 return "Chat List"; | |
421 } | |
422 | |
3630 | 423 G_MODULE_EXPORT char *description() |
2241 | 424 { |
425 return "Allows you to add chat rooms to your buddy list. Click the configure button to choose" | |
426 " which rooms."; | |
427 } |