Mercurial > pidgin
annotate src/gtkroomlist.c @ 8420:c25c697525b7
[gaim-migrate @ 9150]
Phase II. If anyone finds anything problematic here that can't be attributed
to GtkIMHtml itself, please let me know (I'll probably tell you it can be
attributed to GtkIMHtml itself ;)).
Love, Sean.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 10 Mar 2004 06:10:00 +0000 |
parents | c1ca19c8f749 |
children | 6d8ec773a485 |
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; | |
274 GaimRoomlistRoom *catagory; | |
275 GValue val = { 0, }; | |
276 | |
277 gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val); | |
278 catagory = g_value_get_pointer(&val); | |
279 | |
280 if (!catagory->expanded_once) { | |
281 gaim_roomlist_expand_catagory(list, catagory); | |
282 catagory->expanded_once = TRUE; | |
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 GaimAccount *first_account = NULL; | |
306 | |
307 if (!account) { | |
308 GList *c; | |
309 GaimConnection *gc; | |
310 | |
311 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { | |
312 gc = c->data; | |
313 | |
314 if (gaim_roomlist_is_possible(gc)) { | |
315 first_account = gaim_connection_get_account(gc); | |
316 break; | |
317 } | |
318 } | |
319 | |
320 if (first_account == NULL) { | |
321 gaim_notify_error(NULL, NULL, | |
322 _("You are not currently signed on with any " | |
323 "protocols that have the ability to list rooms."), | |
324 NULL); | |
325 | |
326 return NULL; | |
327 } | |
328 } | |
329 | |
330 dialog = g_new0(GaimGtkRoomlistDialog, 1); | |
331 | |
332 /* Create the window. */ | |
333 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
334 gtk_window_set_role(GTK_WINDOW(window), "room list"); | |
335 gtk_window_set_title(GTK_WINDOW(window), _("Room List")); | |
336 | |
337 gtk_container_set_border_width(GTK_CONTAINER(window), 12); | |
338 gtk_widget_realize(window); | |
339 | |
340 g_signal_connect(G_OBJECT(window), "delete_event", | |
341 G_CALLBACK(delete_win_cb), dialog); | |
342 | |
343 /* Create the parent vbox for everything. */ | |
8199 | 344 vbox = gtk_vbox_new(FALSE, 12); |
345 gtk_container_add(GTK_CONTAINER(window), vbox); | |
346 gtk_widget_show(vbox); | |
8113 | 347 |
8199 | 348 vbox2 = gtk_vbox_new(FALSE, 12); |
349 gtk_container_add(GTK_CONTAINER(vbox), vbox2); | |
8113 | 350 gtk_widget_show(vbox2); |
351 | |
8199 | 352 |
8352 | 353 if (!account) |
8113 | 354 dialog->account = first_account; |
8352 | 355 else |
356 dialog->account = account; | |
357 /* accounts dropdown list */ | |
358 account_hbox = gtk_hbox_new(FALSE, 0); | |
359 gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); | |
360 gtk_widget_show(account_hbox); | |
8113 | 361 |
8352 | 362 label = gtk_label_new(NULL); |
363 gtk_box_pack_start(GTK_BOX(account_hbox), label, TRUE, TRUE, 0); | |
364 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); | |
365 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
366 gtk_widget_show(label); | |
8113 | 367 |
8352 | 368 dialog->account_widget = gaim_gtk_account_option_menu_new(dialog->account, FALSE, |
369 G_CALLBACK(dialog_select_account_cb), accounts_filter_func, dialog); | |
8199 | 370 |
8352 | 371 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
372 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
373 gtk_widget_show(dialog->account_widget); | |
8113 | 374 |
8199 | 375 /* scrolled window */ |
8113 | 376 dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
377 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
378 GTK_SHADOW_IN); | |
379 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
380 GTK_POLICY_AUTOMATIC, | |
381 GTK_POLICY_AUTOMATIC); | |
8199 | 382 gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
383 gtk_widget_set_size_request(dialog->sw, -1, 250); | |
8113 | 384 gtk_widget_show(dialog->sw); |
385 | |
8199 | 386 /* progress bar */ |
387 dialog->progress = gtk_progress_bar_new(); | |
388 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
389 gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
390 gtk_widget_show(dialog->progress); | |
391 | |
392 | |
393 /* button box */ | |
394 bbox = gtk_hbutton_box_new(); | |
395 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
396 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
397 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
398 gtk_widget_show(bbox); | |
399 | |
400 /* stop button */ | |
401 dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
402 gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
403 g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
404 G_CALLBACK(stop_button_cb), dialog); | |
405 gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
406 gtk_widget_show(dialog->stop_button); | |
407 | |
408 /* list button */ | |
409 dialog->list_button = gtk_button_new_with_mnemonic(_("_Get List")); | |
410 gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); | |
411 g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
412 G_CALLBACK(list_button_cb), dialog); | |
413 gtk_widget_show(dialog->list_button); | |
414 | |
415 /* join button */ | |
416 dialog->join_button = gaim_pixbuf_button_from_stock(_("_Join"), GAIM_STOCK_CHAT, | |
417 GAIM_BUTTON_HORIZONTAL); | |
418 gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); | |
419 g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
420 G_CALLBACK(join_button_cb), dialog); | |
421 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
422 gtk_widget_show(dialog->join_button); | |
423 | |
424 /* close button */ | |
425 dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
426 gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
427 g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
428 G_CALLBACK(close_button_cb), dialog); | |
429 gtk_widget_show(dialog->close_button); | |
430 | |
431 /* show the dialog window and return the dialog */ | |
432 gtk_widget_show(dialog->window); | |
433 | |
8113 | 434 return dialog; |
435 } | |
436 | |
437 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new(void) | |
438 { | |
439 return gaim_gtk_roomlist_dialog_new_with_account(NULL); | |
440 } | |
441 | |
8352 | 442 static void gaim_gtk_roomlist_dialog_show_with_account(GaimAccount *account) |
443 { | |
444 GaimGtkRoomlistDialog *dialog; | |
445 | |
446 dialog = gaim_gtk_roomlist_dialog_new_with_account(account); | |
447 if (!dialog) | |
448 return; | |
449 | |
450 list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
451 } | |
452 | |
8113 | 453 void gaim_gtk_roomlist_dialog_show(void) |
454 { | |
455 gaim_gtk_roomlist_dialog_new(); | |
456 } | |
457 | |
458 static void gaim_gtk_roomlist_new(GaimRoomlist *list) | |
459 { | |
460 GaimGtkRoomlist *rl; | |
461 | |
462 rl = g_new0(GaimGtkRoomlist, 1); | |
463 | |
464 list->ui_data = rl; | |
465 | |
466 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
467 | |
468 roomlists = g_list_append(roomlists, list); | |
469 } | |
470 | |
471 static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
472 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
473 { | |
474 gchar buf[16]; | |
475 int myint; | |
476 | |
477 gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
478 | |
479 if (myint) | |
480 g_snprintf(buf, sizeof(buf), "%d", myint); | |
481 else | |
482 buf[0] = '\0'; | |
483 | |
484 g_object_set(renderer, "text", buf, NULL); | |
485 } | |
486 | |
487 /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
488 infinity-0. you can still click again to reverse it on any of them. */ | |
489 static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
490 { | |
491 int c, d; | |
492 | |
493 c = d = 0; | |
494 | |
495 gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
496 gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
497 | |
498 if (c == d) | |
499 return 0; | |
500 else if (c > d) | |
501 return -1; | |
502 else | |
503 return 1; | |
504 } | |
505 | |
506 static void gaim_gtk_roomlist_set_fields(GaimRoomlist *list, GList *fields) | |
507 { | |
508 GaimGtkRoomlist *grl = list->ui_data; | |
509 gint columns = NUM_OF_COLUMNS; | |
510 int j; | |
511 GtkTreeStore *model; | |
512 GtkWidget *tree; | |
513 GtkCellRenderer *renderer; | |
514 GtkTreeViewColumn *column; | |
8199 | 515 GtkTreeSelection *selection; |
8113 | 516 GList *l; |
517 GType *types; | |
518 | |
519 g_return_if_fail(grl != NULL); | |
520 | |
521 columns += g_list_length(fields); | |
522 types = g_new(GType, columns); | |
523 | |
524 types[NAME_COLUMN] = G_TYPE_STRING; | |
525 types[ROOM_COLUMN] = G_TYPE_POINTER; | |
526 | |
527 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
528 GaimRoomlistField *f = l->data; | |
529 | |
530 switch (f->type) { | |
531 case GAIM_ROOMLIST_FIELD_BOOL: | |
532 types[j] = G_TYPE_BOOLEAN; | |
533 break; | |
534 case GAIM_ROOMLIST_FIELD_INT: | |
535 types[j] = G_TYPE_INT; | |
536 break; | |
537 case GAIM_ROOMLIST_FIELD_STRING: | |
538 types[j] = G_TYPE_STRING; | |
539 break; | |
540 } | |
541 } | |
542 | |
543 model = gtk_tree_store_newv(columns, types); | |
544 g_free(types); | |
545 | |
546 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
547 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
548 | |
8199 | 549 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
550 g_signal_connect(G_OBJECT(selection), "changed", | |
551 G_CALLBACK(selection_changed_cb), grl); | |
552 | |
8113 | 553 g_object_unref(model); |
554 | |
555 grl->model = model; | |
556 grl->tree = tree; | |
557 gtk_widget_show(grl->tree); | |
558 | |
559 renderer = gtk_cell_renderer_text_new(); | |
560 column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
561 "text", NAME_COLUMN, NULL); | |
562 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
563 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
564 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
565 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
566 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
567 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
568 | |
569 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
570 GaimRoomlistField *f = l->data; | |
571 | |
572 if (f->hidden) | |
573 continue; | |
574 | |
575 renderer = gtk_cell_renderer_text_new(); | |
576 column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
577 "text", j, NULL); | |
578 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
579 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
580 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
581 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
582 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
583 if (f->type == GAIM_ROOMLIST_FIELD_INT) { | |
584 gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, | |
585 GINT_TO_POINTER(j), NULL); | |
586 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
587 GINT_TO_POINTER(j), NULL); | |
588 } | |
589 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
590 } | |
591 | |
592 g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
593 g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
594 g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list); | |
595 } | |
596 | |
8230 | 597 static gboolean gaim_gtk_progress_bar_pulse(gpointer data) |
598 { | |
599 GaimRoomlist *list = data; | |
600 GaimGtkRoomlist *rl = list->ui_data; | |
601 | |
602 if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
603 rl->dialog->pg_to_active = FALSE; | |
604 gaim_roomlist_unref(list); | |
605 return FALSE; | |
606 } | |
607 | |
608 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
609 rl->dialog->pg_needs_pulse = FALSE; | |
610 return TRUE; | |
611 } | |
612 | |
8113 | 613 static void gaim_gtk_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room) |
614 { | |
615 GaimGtkRoomlist *rl= list->ui_data; | |
616 GtkTreeRowReference *rr, *parentrr = NULL; | |
617 GtkTreePath *path; | |
618 GtkTreeIter iter, parent, child; | |
619 GList *l, *k; | |
620 int j; | |
621 gboolean append = TRUE; | |
622 | |
623 rl->total_rooms++; | |
624 if (room->type == GAIM_ROOMLIST_ROOMTYPE_ROOM) | |
625 rl->num_rooms++; | |
626 | |
627 if (rl->dialog) { | |
8230 | 628 if (!rl->dialog->pg_to_active) { |
629 rl->dialog->pg_to_active = TRUE; | |
630 gaim_roomlist_ref(list); | |
631 rl->dialog->pg_update_to = g_timeout_add(100, gaim_gtk_progress_bar_pulse, list); | |
632 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
633 } else { | |
634 rl->dialog->pg_needs_pulse = TRUE; | |
635 } | |
8113 | 636 } |
637 if (room->parent) { | |
638 parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
639 path = gtk_tree_row_reference_get_path(parentrr); | |
640 if (path) { | |
641 GaimRoomlistRoom *tmproom = NULL; | |
642 | |
643 gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
644 gtk_tree_path_free(path); | |
645 | |
646 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
647 gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
648 if (!tmproom) | |
649 append = FALSE; | |
650 } | |
651 } | |
652 } | |
653 | |
654 if (append) | |
655 gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
656 else | |
657 iter = child; | |
658 | |
659 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY) | |
660 gtk_tree_store_append(rl->model, &child, &iter); | |
661 | |
662 path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
663 | |
664 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY) { | |
665 rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); | |
666 g_hash_table_insert(rl->cats, room, rr); | |
667 } | |
668 | |
669 gtk_tree_path_free(path); | |
670 | |
671 gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
672 gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
673 | |
674 for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
675 GaimRoomlistField *f = k->data; | |
676 if (f->hidden) | |
677 continue; | |
678 gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
679 } | |
680 } | |
681 | |
682 static void gaim_gtk_roomlist_in_progress(GaimRoomlist *list, gboolean flag) | |
683 { | |
684 GaimGtkRoomlist *rl = list->ui_data; | |
685 | |
686 if (!rl || !rl->dialog) | |
687 return; | |
688 | |
689 if (flag) { | |
8199 | 690 if (rl->dialog->account_widget) |
691 gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
692 gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
693 gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
8113 | 694 } else { |
8230 | 695 rl->dialog->pg_needs_pulse = FALSE; |
8113 | 696 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
8199 | 697 if (rl->dialog->account_widget) |
698 gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
699 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
700 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
8113 | 701 } |
702 } | |
703 | |
704 static void gaim_gtk_roomlist_destroy(GaimRoomlist *list) | |
705 { | |
706 GaimGtkRoomlist *rl; | |
707 | |
708 roomlists = g_list_remove(roomlists, list); | |
709 | |
710 rl = list->ui_data; | |
711 | |
712 g_return_if_fail(rl != NULL); | |
713 | |
714 g_hash_table_destroy(rl->cats); | |
715 g_free(rl); | |
716 list->ui_data = NULL; | |
717 } | |
718 | |
719 static GaimRoomlistUiOps ops = { | |
8352 | 720 gaim_gtk_roomlist_dialog_show_with_account, |
8113 | 721 gaim_gtk_roomlist_new, |
722 gaim_gtk_roomlist_set_fields, | |
723 gaim_gtk_roomlist_add_room, | |
724 gaim_gtk_roomlist_in_progress, | |
725 gaim_gtk_roomlist_destroy | |
726 }; | |
727 | |
728 | |
729 void gaim_gtk_roomlist_init(void) | |
730 { | |
731 gaim_roomlist_set_ui_ops(&ops); | |
732 } |