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