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