Mercurial > pidgin.yaz
annotate src/gtkroomlist.c @ 8937:fd1a4ff1f7ed
[gaim-migrate @ 9707]
Tools->Room List will now be grayed out when you're not signed on
with an account that supports listing rooms.
This involved 2 big changes:
-Change when the sign_on_off_cb function in gtkblist gets called...
it used to get called when the signing-on and signing-off signal
was emitted, but I changed it to signed-on and signed-off. This
makes more sense to me, and it makes my code work :-) Let me know
if you notice any side-effects
-Add functions to the roomlist API for determining if any online
accounts support chatting or not. This involved extracting a
function from gtkroomlist.c and putting it in roomlist.c, and
adding a little helper TRUE/FALSE function
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 15 May 2004 21:56:17 +0000 |
parents | 058efd3cb86f |
children | 19885cb8a24c |
rev | line source |
---|---|
8113 | 1 /** |
2 * @file gtkroomlist.c Gtk Room List UI | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
8146 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
8113 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 | |
26 #include "gtkinternal.h" | |
27 #include "gtkutils.h" | |
28 #include "stock.h" | |
29 #include "debug.h" | |
30 #include "account.h" | |
31 #include "connection.h" | |
32 #include "notify.h" | |
33 | |
34 #include "gtkroomlist.h" | |
35 | |
36 typedef struct _GaimGtkRoomlist { | |
37 GaimGtkRoomlistDialog *dialog; | |
38 GtkTreeStore *model; | |
39 GtkWidget *tree; | |
40 GHashTable *cats; /**< Meow. */ | |
41 gint num_rooms, total_rooms; | |
42 } GaimGtkRoomlist; | |
43 | |
44 struct _GaimGtkRoomlistDialog { | |
45 GtkWidget *window; | |
46 GtkWidget *account_widget; | |
47 GtkWidget *progress; | |
48 GtkWidget *sw; | |
49 | |
8199 | 50 GtkWidget *stop_button; |
8113 | 51 GtkWidget *list_button; |
8199 | 52 GtkWidget *join_button; |
8113 | 53 GtkWidget *close_button; |
54 | |
55 GaimAccount *account; | |
56 GaimRoomlist *roomlist; | |
8230 | 57 |
58 gboolean pg_needs_pulse; | |
59 gboolean pg_to_active; | |
60 guint pg_update_to; | |
8113 | 61 }; |
62 | |
63 enum { | |
64 NAME_COLUMN = 0, | |
65 ROOM_COLUMN, | |
66 NUM_OF_COLUMNS, | |
67 }; | |
68 | |
69 static GList *roomlists = NULL; | |
70 | |
71 static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) | |
72 { | |
73 GaimGtkRoomlistDialog *dialog; | |
74 | |
75 dialog = (GaimGtkRoomlistDialog *) d; | |
76 | |
8199 | 77 if (dialog->roomlist && gaim_roomlist_get_in_progress(dialog->roomlist)) |
78 gaim_roomlist_cancel_get_list(dialog->roomlist); | |
79 | |
8230 | 80 if (dialog->roomlist) { |
81 if (dialog->pg_to_active) { | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8230
diff
changeset
|
82 gaim_timeout_remove(dialog->pg_update_to); |
8230 | 83 dialog->pg_to_active = FALSE; |
84 /* yes, that's right, unref it twice. */ | |
85 gaim_roomlist_unref(dialog->roomlist); | |
86 } | |
87 } | |
88 | |
8113 | 89 /* free stuff here */ |
90 if (dialog->roomlist) | |
91 gaim_roomlist_unref(dialog->roomlist); | |
92 g_free(dialog); | |
93 | |
94 return FALSE; | |
95 } | |
96 | |
97 static void dialog_select_account_cb(GObject *w, GaimAccount *account, | |
98 GaimGtkRoomlistDialog *dialog) | |
99 { | |
100 dialog->account = account; | |
101 } | |
102 | |
103 static void list_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) | |
104 { | |
105 GaimConnection *gc; | |
106 GaimGtkRoomlist *rl; | |
107 | |
108 gc = gaim_account_get_connection(dialog->account); | |
109 if (!gc) | |
110 return; | |
111 | |
8199 | 112 if (dialog->roomlist != NULL) { |
113 rl = dialog->roomlist->ui_data; | |
114 gtk_widget_destroy(rl->tree); | |
115 gaim_roomlist_unref(dialog->roomlist); | |
116 } | |
117 | |
8113 | 118 dialog->roomlist = gaim_roomlist_get_list(gc); |
119 gaim_roomlist_ref(dialog->roomlist); | |
120 rl = dialog->roomlist->ui_data; | |
121 rl->dialog = dialog; | |
8199 | 122 |
8113 | 123 if (dialog->account_widget) |
124 gtk_widget_set_sensitive(dialog->account_widget, FALSE); | |
8199 | 125 |
126 gtk_container_add(GTK_CONTAINER(dialog->sw), rl->tree); | |
127 | |
128 gtk_widget_set_sensitive(dialog->stop_button, TRUE); | |
8113 | 129 gtk_widget_set_sensitive(dialog->list_button, FALSE); |
8199 | 130 gtk_widget_set_sensitive(dialog->join_button, FALSE); |
8113 | 131 } |
132 | |
133 static void stop_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) | |
134 { | |
135 gaim_roomlist_cancel_get_list(dialog->roomlist); | |
8199 | 136 |
137 if (dialog->account_widget) | |
138 gtk_widget_set_sensitive(dialog->account_widget, TRUE); | |
139 | |
140 gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
141 gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
142 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
8113 | 143 } |
144 | |
145 static void close_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) | |
146 { | |
147 GtkWidget *window = dialog->window; | |
148 | |
149 delete_win_cb(NULL, NULL, dialog); | |
150 gtk_widget_destroy(window); | |
151 } | |
152 | |
153 struct _menu_cb_info { | |
154 GaimRoomlist *list; | |
155 GaimRoomlistRoom *room; | |
156 }; | |
157 | |
8199 | 158 static void |
8377 | 159 join_button_data_change_cb(gpointer data) { |
160 g_free(data); | |
161 } | |
162 | |
163 static void | |
8199 | 164 selection_changed_cb(GtkTreeSelection *selection, GaimGtkRoomlist *grl) { |
165 GtkTreeIter iter; | |
166 GValue val = { 0, }; | |
167 GaimRoomlistRoom *room; | |
168 static struct _menu_cb_info *info; | |
169 GaimGtkRoomlistDialog *dialog; | |
170 | |
171 dialog = grl->dialog; | |
172 | |
173 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { | |
174 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
175 room = g_value_get_pointer(&val); | |
176 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) { | |
177 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
178 return; | |
179 } | |
180 | |
181 info = g_new0(struct _menu_cb_info, 1); | |
182 info->list = dialog->roomlist; | |
183 info->room = room; | |
184 | |
8377 | 185 g_object_set_data_full(G_OBJECT(dialog->join_button), "room-info", |
186 info, join_button_data_change_cb); | |
8199 | 187 |
188 gtk_widget_set_sensitive(dialog->join_button, TRUE); | |
189 } else { | |
190 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
191 } | |
192 } | |
193 | |
8113 | 194 static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info) |
195 { | |
8199 | 196 gaim_roomlist_room_join(info->list, info->room); |
197 } | |
8113 | 198 |
8199 | 199 static void join_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) |
200 { | |
201 GaimRoomlist *rl = dialog->roomlist; | |
202 GaimGtkRoomlist *grl = rl->ui_data; | |
203 struct _menu_cb_info *info; | |
204 | |
205 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); | |
206 | |
8377 | 207 if(info != NULL) |
208 do_join_cb(grl->tree, info); | |
8113 | 209 } |
210 | |
211 static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2, | |
212 GaimRoomlist *list) | |
213 { | |
214 GaimGtkRoomlist *grl = list->ui_data; | |
215 GtkTreeIter iter; | |
216 GaimRoomlistRoom *room; | |
217 GValue val = { 0, }; | |
218 struct _menu_cb_info info; | |
219 | |
220 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
221 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
222 room = g_value_get_pointer(&val); | |
223 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) | |
224 return; | |
225 | |
226 info.list = list; | |
227 info.room = room; | |
228 | |
229 do_join_cb(GTK_WIDGET(tv), &info); | |
230 } | |
231 | |
232 static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, GaimRoomlist *list) | |
233 { | |
234 GtkTreePath *path; | |
235 GaimGtkRoomlist *grl = list->ui_data; | |
236 GValue val = { 0, }; | |
237 GaimRoomlistRoom *room; | |
238 GtkTreeIter iter; | |
239 GtkWidget *menu; | |
240 static struct _menu_cb_info info; /* XXX? */ | |
241 | |
242 if (event->button != 3 || event->type != GDK_BUTTON_PRESS) | |
243 return FALSE; | |
244 | |
245 /* Here we figure out which room was clicked */ | |
246 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
247 return FALSE; | |
248 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
249 gtk_tree_path_free(path); | |
250 gtk_tree_model_get_value (GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
251 room = g_value_get_pointer(&val); | |
252 | |
253 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) | |
254 return FALSE; | |
255 | |
256 info.list = list; | |
257 info.room = room; | |
258 | |
259 | |
260 menu = gtk_menu_new(); | |
261 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT, | |
262 G_CALLBACK(do_join_cb), &info, 0, 0, NULL); | |
263 | |
264 | |
265 gtk_widget_show_all(menu); | |
266 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
267 | |
268 return FALSE; | |
269 } | |
270 | |
271 static void row_expanded_cb(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer user_data) | |
272 { | |
273 GaimRoomlist *list = user_data; | |
8584 | 274 GaimRoomlistRoom *category; |
8113 | 275 GValue val = { 0, }; |
276 | |
277 gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val); | |
8584 | 278 category = g_value_get_pointer(&val); |
8113 | 279 |
8584 | 280 if (!category->expanded_once) { |
281 gaim_roomlist_expand_category(list, category); | |
282 category->expanded_once = TRUE; | |
8113 | 283 } |
284 } | |
285 | |
286 static gboolean accounts_filter_func(GaimAccount *account) | |
287 { | |
288 GaimConnection *gc; | |
289 | |
290 gc = gaim_account_get_connection(account); | |
291 if (!gc) | |
292 return FALSE; | |
293 return gaim_roomlist_is_possible(gc); | |
294 } | |
295 | |
296 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new_with_account(GaimAccount *account) | |
297 { | |
298 GaimGtkRoomlistDialog *dialog; | |
299 GtkWidget *window; | |
8199 | 300 GtkWidget *vbox; |
301 GtkWidget *vbox2; | |
8113 | 302 GtkWidget *account_hbox; |
303 GtkWidget *bbox; | |
304 GtkWidget *label; | |
305 | |
8937 | 306 if (account == NULL) { |
307 account = gaim_roomlist_get_first_valid_account(); | |
8113 | 308 |
8937 | 309 if (account == NULL) { |
8113 | 310 gaim_notify_error(NULL, NULL, |
311 _("You are not currently signed on with any " | |
312 "protocols that have the ability to list rooms."), | |
313 NULL); | |
314 | |
315 return NULL; | |
316 } | |
317 } | |
318 | |
319 dialog = g_new0(GaimGtkRoomlistDialog, 1); | |
8937 | 320 dialog->account = account; |
8113 | 321 |
322 /* Create the window. */ | |
323 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
324 gtk_window_set_role(GTK_WINDOW(window), "room list"); | |
325 gtk_window_set_title(GTK_WINDOW(window), _("Room List")); | |
326 | |
327 gtk_container_set_border_width(GTK_CONTAINER(window), 12); | |
328 gtk_widget_realize(window); | |
329 | |
330 g_signal_connect(G_OBJECT(window), "delete_event", | |
331 G_CALLBACK(delete_win_cb), dialog); | |
332 | |
333 /* Create the parent vbox for everything. */ | |
8199 | 334 vbox = gtk_vbox_new(FALSE, 12); |
335 gtk_container_add(GTK_CONTAINER(window), vbox); | |
336 gtk_widget_show(vbox); | |
8113 | 337 |
8199 | 338 vbox2 = gtk_vbox_new(FALSE, 12); |
339 gtk_container_add(GTK_CONTAINER(vbox), vbox2); | |
8113 | 340 gtk_widget_show(vbox2); |
341 | |
8352 | 342 /* accounts dropdown list */ |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
343 account_hbox = gtk_hbox_new(FALSE, 6); |
8352 | 344 gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); |
345 gtk_widget_show(account_hbox); | |
8113 | 346 |
8352 | 347 label = gtk_label_new(NULL); |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
348 gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); |
8352 | 349 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
350 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
8352 | 351 gtk_widget_show(label); |
8113 | 352 |
8352 | 353 dialog->account_widget = gaim_gtk_account_option_menu_new(dialog->account, FALSE, |
354 G_CALLBACK(dialog_select_account_cb), accounts_filter_func, dialog); | |
8199 | 355 |
8352 | 356 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
357 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
358 gtk_widget_show(dialog->account_widget); | |
8113 | 359 |
8199 | 360 /* scrolled window */ |
8113 | 361 dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
362 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
363 GTK_SHADOW_IN); | |
364 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
365 GTK_POLICY_AUTOMATIC, | |
366 GTK_POLICY_AUTOMATIC); | |
8199 | 367 gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
368 gtk_widget_set_size_request(dialog->sw, -1, 250); | |
8113 | 369 gtk_widget_show(dialog->sw); |
370 | |
8199 | 371 /* progress bar */ |
372 dialog->progress = gtk_progress_bar_new(); | |
373 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
374 gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
375 gtk_widget_show(dialog->progress); | |
376 | |
377 | |
378 /* button box */ | |
379 bbox = gtk_hbutton_box_new(); | |
380 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
381 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
382 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
383 gtk_widget_show(bbox); | |
384 | |
385 /* stop button */ | |
386 dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
387 gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
388 g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
389 G_CALLBACK(stop_button_cb), dialog); | |
390 gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
391 gtk_widget_show(dialog->stop_button); | |
392 | |
393 /* list button */ | |
394 dialog->list_button = gtk_button_new_with_mnemonic(_("_Get List")); | |
395 gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); | |
396 g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
397 G_CALLBACK(list_button_cb), dialog); | |
398 gtk_widget_show(dialog->list_button); | |
399 | |
400 /* join button */ | |
401 dialog->join_button = gaim_pixbuf_button_from_stock(_("_Join"), GAIM_STOCK_CHAT, | |
402 GAIM_BUTTON_HORIZONTAL); | |
403 gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); | |
404 g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
405 G_CALLBACK(join_button_cb), dialog); | |
406 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
407 gtk_widget_show(dialog->join_button); | |
408 | |
409 /* close button */ | |
410 dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
411 gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
412 g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
413 G_CALLBACK(close_button_cb), dialog); | |
414 gtk_widget_show(dialog->close_button); | |
415 | |
416 /* show the dialog window and return the dialog */ | |
417 gtk_widget_show(dialog->window); | |
418 | |
8113 | 419 return dialog; |
420 } | |
421 | |
422 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new(void) | |
423 { | |
424 return gaim_gtk_roomlist_dialog_new_with_account(NULL); | |
425 } | |
426 | |
8352 | 427 static void gaim_gtk_roomlist_dialog_show_with_account(GaimAccount *account) |
428 { | |
429 GaimGtkRoomlistDialog *dialog; | |
430 | |
431 dialog = gaim_gtk_roomlist_dialog_new_with_account(account); | |
432 if (!dialog) | |
433 return; | |
434 | |
435 list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
436 } | |
437 | |
8113 | 438 void gaim_gtk_roomlist_dialog_show(void) |
439 { | |
440 gaim_gtk_roomlist_dialog_new(); | |
441 } | |
442 | |
443 static void gaim_gtk_roomlist_new(GaimRoomlist *list) | |
444 { | |
445 GaimGtkRoomlist *rl; | |
446 | |
447 rl = g_new0(GaimGtkRoomlist, 1); | |
448 | |
449 list->ui_data = rl; | |
450 | |
451 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
452 | |
453 roomlists = g_list_append(roomlists, list); | |
454 } | |
455 | |
456 static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
457 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
458 { | |
459 gchar buf[16]; | |
460 int myint; | |
461 | |
462 gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
463 | |
464 if (myint) | |
465 g_snprintf(buf, sizeof(buf), "%d", myint); | |
466 else | |
467 buf[0] = '\0'; | |
468 | |
469 g_object_set(renderer, "text", buf, NULL); | |
470 } | |
471 | |
472 /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
473 infinity-0. you can still click again to reverse it on any of them. */ | |
474 static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
475 { | |
476 int c, d; | |
477 | |
478 c = d = 0; | |
479 | |
480 gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
481 gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
482 | |
483 if (c == d) | |
484 return 0; | |
485 else if (c > d) | |
486 return -1; | |
487 else | |
488 return 1; | |
489 } | |
490 | |
491 static void gaim_gtk_roomlist_set_fields(GaimRoomlist *list, GList *fields) | |
492 { | |
493 GaimGtkRoomlist *grl = list->ui_data; | |
494 gint columns = NUM_OF_COLUMNS; | |
495 int j; | |
496 GtkTreeStore *model; | |
497 GtkWidget *tree; | |
498 GtkCellRenderer *renderer; | |
499 GtkTreeViewColumn *column; | |
8199 | 500 GtkTreeSelection *selection; |
8113 | 501 GList *l; |
502 GType *types; | |
503 | |
504 g_return_if_fail(grl != NULL); | |
505 | |
506 columns += g_list_length(fields); | |
507 types = g_new(GType, columns); | |
508 | |
509 types[NAME_COLUMN] = G_TYPE_STRING; | |
510 types[ROOM_COLUMN] = G_TYPE_POINTER; | |
511 | |
512 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
513 GaimRoomlistField *f = l->data; | |
514 | |
515 switch (f->type) { | |
516 case GAIM_ROOMLIST_FIELD_BOOL: | |
517 types[j] = G_TYPE_BOOLEAN; | |
518 break; | |
519 case GAIM_ROOMLIST_FIELD_INT: | |
520 types[j] = G_TYPE_INT; | |
521 break; | |
522 case GAIM_ROOMLIST_FIELD_STRING: | |
523 types[j] = G_TYPE_STRING; | |
524 break; | |
525 } | |
526 } | |
527 | |
528 model = gtk_tree_store_newv(columns, types); | |
529 g_free(types); | |
530 | |
531 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
532 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
533 | |
8199 | 534 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
535 g_signal_connect(G_OBJECT(selection), "changed", | |
536 G_CALLBACK(selection_changed_cb), grl); | |
537 | |
8113 | 538 g_object_unref(model); |
539 | |
540 grl->model = model; | |
541 grl->tree = tree; | |
542 gtk_widget_show(grl->tree); | |
543 | |
544 renderer = gtk_cell_renderer_text_new(); | |
545 column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
546 "text", NAME_COLUMN, NULL); | |
547 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
548 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
549 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
550 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
551 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
552 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
553 | |
554 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
555 GaimRoomlistField *f = l->data; | |
556 | |
557 if (f->hidden) | |
558 continue; | |
559 | |
560 renderer = gtk_cell_renderer_text_new(); | |
561 column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
562 "text", j, NULL); | |
563 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
564 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
565 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
566 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
567 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
568 if (f->type == GAIM_ROOMLIST_FIELD_INT) { | |
569 gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, | |
570 GINT_TO_POINTER(j), NULL); | |
571 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
572 GINT_TO_POINTER(j), NULL); | |
573 } | |
574 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
575 } | |
576 | |
577 g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
578 g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
579 g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list); | |
580 } | |
581 | |
8230 | 582 static gboolean gaim_gtk_progress_bar_pulse(gpointer data) |
583 { | |
584 GaimRoomlist *list = data; | |
585 GaimGtkRoomlist *rl = list->ui_data; | |
586 | |
587 if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
588 rl->dialog->pg_to_active = FALSE; | |
589 gaim_roomlist_unref(list); | |
590 return FALSE; | |
591 } | |
592 | |
593 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
594 rl->dialog->pg_needs_pulse = FALSE; | |
595 return TRUE; | |
596 } | |
597 | |
8113 | 598 static void gaim_gtk_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room) |
599 { | |
600 GaimGtkRoomlist *rl= list->ui_data; | |
601 GtkTreeRowReference *rr, *parentrr = NULL; | |
602 GtkTreePath *path; | |
603 GtkTreeIter iter, parent, child; | |
604 GList *l, *k; | |
605 int j; | |
606 gboolean append = TRUE; | |
607 | |
608 rl->total_rooms++; | |
609 if (room->type == GAIM_ROOMLIST_ROOMTYPE_ROOM) | |
610 rl->num_rooms++; | |
611 | |
612 if (rl->dialog) { | |
8230 | 613 if (!rl->dialog->pg_to_active) { |
614 rl->dialog->pg_to_active = TRUE; | |
615 gaim_roomlist_ref(list); | |
616 rl->dialog->pg_update_to = g_timeout_add(100, gaim_gtk_progress_bar_pulse, list); | |
617 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
618 } else { | |
619 rl->dialog->pg_needs_pulse = TRUE; | |
620 } | |
8113 | 621 } |
622 if (room->parent) { | |
623 parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
624 path = gtk_tree_row_reference_get_path(parentrr); | |
625 if (path) { | |
626 GaimRoomlistRoom *tmproom = NULL; | |
627 | |
628 gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
629 gtk_tree_path_free(path); | |
630 | |
631 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
632 gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
633 if (!tmproom) | |
634 append = FALSE; | |
635 } | |
636 } | |
637 } | |
638 | |
639 if (append) | |
640 gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
641 else | |
642 iter = child; | |
643 | |
8584 | 644 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY) |
8113 | 645 gtk_tree_store_append(rl->model, &child, &iter); |
646 | |
647 path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
648 | |
8584 | 649 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY) { |
8113 | 650 rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); |
651 g_hash_table_insert(rl->cats, room, rr); | |
652 } | |
653 | |
654 gtk_tree_path_free(path); | |
655 | |
656 gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
657 gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
658 | |
659 for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
660 GaimRoomlistField *f = k->data; | |
661 if (f->hidden) | |
662 continue; | |
663 gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
664 } | |
665 } | |
666 | |
667 static void gaim_gtk_roomlist_in_progress(GaimRoomlist *list, gboolean flag) | |
668 { | |
669 GaimGtkRoomlist *rl = list->ui_data; | |
670 | |
671 if (!rl || !rl->dialog) | |
672 return; | |
673 | |
674 if (flag) { | |
8199 | 675 if (rl->dialog->account_widget) |
676 gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
677 gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
678 gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
8113 | 679 } else { |
8230 | 680 rl->dialog->pg_needs_pulse = FALSE; |
8113 | 681 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
8199 | 682 if (rl->dialog->account_widget) |
683 gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
684 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
685 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
8113 | 686 } |
687 } | |
688 | |
689 static void gaim_gtk_roomlist_destroy(GaimRoomlist *list) | |
690 { | |
691 GaimGtkRoomlist *rl; | |
692 | |
693 roomlists = g_list_remove(roomlists, list); | |
694 | |
695 rl = list->ui_data; | |
696 | |
697 g_return_if_fail(rl != NULL); | |
698 | |
699 g_hash_table_destroy(rl->cats); | |
700 g_free(rl); | |
701 list->ui_data = NULL; | |
702 } | |
703 | |
704 static GaimRoomlistUiOps ops = { | |
8352 | 705 gaim_gtk_roomlist_dialog_show_with_account, |
8113 | 706 gaim_gtk_roomlist_new, |
707 gaim_gtk_roomlist_set_fields, | |
708 gaim_gtk_roomlist_add_room, | |
709 gaim_gtk_roomlist_in_progress, | |
710 gaim_gtk_roomlist_destroy | |
711 }; | |
712 | |
713 | |
714 void gaim_gtk_roomlist_init(void) | |
715 { | |
716 gaim_roomlist_set_ui_ops(&ops); | |
717 } |