Mercurial > pidgin
annotate src/gtkroomlist.c @ 9479:fababc25f270
[gaim-migrate @ 10304]
a few updates
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 07 Jul 2004 22:06:44 +0000 |
parents | 31be05742be9 |
children | 03be9d653123 |
rev | line source |
---|---|
8113 | 1 /** |
8939 | 2 * @file gtkroomlist.c GTK+ Room List UI |
8113 | 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); |
9159 | 119 if (!dialog->roomlist) |
120 return; | |
8113 | 121 gaim_roomlist_ref(dialog->roomlist); |
122 rl = dialog->roomlist->ui_data; | |
123 rl->dialog = dialog; | |
8199 | 124 |
8113 | 125 if (dialog->account_widget) |
126 gtk_widget_set_sensitive(dialog->account_widget, FALSE); | |
8199 | 127 |
128 gtk_container_add(GTK_CONTAINER(dialog->sw), rl->tree); | |
129 | |
130 gtk_widget_set_sensitive(dialog->stop_button, TRUE); | |
8113 | 131 gtk_widget_set_sensitive(dialog->list_button, FALSE); |
8199 | 132 gtk_widget_set_sensitive(dialog->join_button, FALSE); |
8113 | 133 } |
134 | |
135 static void stop_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) | |
136 { | |
137 gaim_roomlist_cancel_get_list(dialog->roomlist); | |
8199 | 138 |
139 if (dialog->account_widget) | |
140 gtk_widget_set_sensitive(dialog->account_widget, TRUE); | |
141 | |
142 gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
143 gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
144 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
8113 | 145 } |
146 | |
147 static void close_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) | |
148 { | |
149 GtkWidget *window = dialog->window; | |
150 | |
151 delete_win_cb(NULL, NULL, dialog); | |
152 gtk_widget_destroy(window); | |
153 } | |
154 | |
155 struct _menu_cb_info { | |
156 GaimRoomlist *list; | |
157 GaimRoomlistRoom *room; | |
158 }; | |
159 | |
8199 | 160 static void |
8377 | 161 join_button_data_change_cb(gpointer data) { |
162 g_free(data); | |
163 } | |
164 | |
165 static void | |
8199 | 166 selection_changed_cb(GtkTreeSelection *selection, GaimGtkRoomlist *grl) { |
167 GtkTreeIter iter; | |
168 GValue val = { 0, }; | |
169 GaimRoomlistRoom *room; | |
170 static struct _menu_cb_info *info; | |
171 GaimGtkRoomlistDialog *dialog; | |
172 | |
173 dialog = grl->dialog; | |
174 | |
175 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { | |
176 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
177 room = g_value_get_pointer(&val); | |
178 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) { | |
179 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
180 return; | |
181 } | |
182 | |
183 info = g_new0(struct _menu_cb_info, 1); | |
184 info->list = dialog->roomlist; | |
185 info->room = room; | |
186 | |
8377 | 187 g_object_set_data_full(G_OBJECT(dialog->join_button), "room-info", |
188 info, join_button_data_change_cb); | |
8199 | 189 |
190 gtk_widget_set_sensitive(dialog->join_button, TRUE); | |
191 } else { | |
192 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
193 } | |
194 } | |
195 | |
8113 | 196 static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info) |
197 { | |
8199 | 198 gaim_roomlist_room_join(info->list, info->room); |
199 } | |
8113 | 200 |
8199 | 201 static void join_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) |
202 { | |
203 GaimRoomlist *rl = dialog->roomlist; | |
204 GaimGtkRoomlist *grl = rl->ui_data; | |
205 struct _menu_cb_info *info; | |
206 | |
207 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); | |
208 | |
8377 | 209 if(info != NULL) |
210 do_join_cb(grl->tree, info); | |
8113 | 211 } |
212 | |
213 static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2, | |
214 GaimRoomlist *list) | |
215 { | |
216 GaimGtkRoomlist *grl = list->ui_data; | |
217 GtkTreeIter iter; | |
218 GaimRoomlistRoom *room; | |
219 GValue val = { 0, }; | |
220 struct _menu_cb_info info; | |
221 | |
222 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
223 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
224 room = g_value_get_pointer(&val); | |
225 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) | |
226 return; | |
227 | |
228 info.list = list; | |
229 info.room = room; | |
230 | |
231 do_join_cb(GTK_WIDGET(tv), &info); | |
232 } | |
233 | |
234 static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, GaimRoomlist *list) | |
235 { | |
236 GtkTreePath *path; | |
237 GaimGtkRoomlist *grl = list->ui_data; | |
238 GValue val = { 0, }; | |
239 GaimRoomlistRoom *room; | |
240 GtkTreeIter iter; | |
241 GtkWidget *menu; | |
242 static struct _menu_cb_info info; /* XXX? */ | |
243 | |
244 if (event->button != 3 || event->type != GDK_BUTTON_PRESS) | |
245 return FALSE; | |
246 | |
247 /* Here we figure out which room was clicked */ | |
248 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
249 return FALSE; | |
250 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
251 gtk_tree_path_free(path); | |
252 gtk_tree_model_get_value (GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); | |
253 room = g_value_get_pointer(&val); | |
254 | |
255 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) | |
256 return FALSE; | |
257 | |
258 info.list = list; | |
259 info.room = room; | |
260 | |
261 | |
262 menu = gtk_menu_new(); | |
263 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT, | |
264 G_CALLBACK(do_join_cb), &info, 0, 0, NULL); | |
265 | |
266 | |
267 gtk_widget_show_all(menu); | |
268 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
269 | |
270 return FALSE; | |
271 } | |
272 | |
273 static void row_expanded_cb(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer user_data) | |
274 { | |
275 GaimRoomlist *list = user_data; | |
8584 | 276 GaimRoomlistRoom *category; |
8113 | 277 GValue val = { 0, }; |
278 | |
279 gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val); | |
8584 | 280 category = g_value_get_pointer(&val); |
8113 | 281 |
8584 | 282 if (!category->expanded_once) { |
283 gaim_roomlist_expand_category(list, category); | |
284 category->expanded_once = TRUE; | |
8113 | 285 } |
286 } | |
287 | |
8939 | 288 static gboolean account_filter_func(GaimAccount *account) |
8113 | 289 { |
8939 | 290 GaimConnection *gc = gaim_account_get_connection(account); |
291 GaimPluginProtocolInfo *prpl_info = NULL; | |
292 | |
293 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
294 | |
295 return (prpl_info->roomlist_get_list != NULL); | |
296 } | |
297 | |
298 gboolean | |
299 gaim_gtk_roomlist_is_showable() | |
300 { | |
301 GList *c; | |
8113 | 302 GaimConnection *gc; |
303 | |
8939 | 304 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { |
305 gc = c->data; | |
306 | |
307 if (account_filter_func(gaim_connection_get_account(gc))) | |
308 return TRUE; | |
309 } | |
310 | |
311 return FALSE; | |
8113 | 312 } |
313 | |
314 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new_with_account(GaimAccount *account) | |
315 { | |
316 GaimGtkRoomlistDialog *dialog; | |
317 GtkWidget *window; | |
8199 | 318 GtkWidget *vbox; |
319 GtkWidget *vbox2; | |
8113 | 320 GtkWidget *account_hbox; |
321 GtkWidget *bbox; | |
322 GtkWidget *label; | |
323 | |
324 dialog = g_new0(GaimGtkRoomlistDialog, 1); | |
8937 | 325 dialog->account = account; |
8113 | 326 |
327 /* Create the window. */ | |
328 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
329 gtk_window_set_role(GTK_WINDOW(window), "room list"); | |
330 gtk_window_set_title(GTK_WINDOW(window), _("Room List")); | |
331 | |
332 gtk_container_set_border_width(GTK_CONTAINER(window), 12); | |
333 gtk_widget_realize(window); | |
334 | |
335 g_signal_connect(G_OBJECT(window), "delete_event", | |
336 G_CALLBACK(delete_win_cb), dialog); | |
337 | |
338 /* Create the parent vbox for everything. */ | |
8199 | 339 vbox = gtk_vbox_new(FALSE, 12); |
340 gtk_container_add(GTK_CONTAINER(window), vbox); | |
341 gtk_widget_show(vbox); | |
8113 | 342 |
8199 | 343 vbox2 = gtk_vbox_new(FALSE, 12); |
344 gtk_container_add(GTK_CONTAINER(vbox), vbox2); | |
8113 | 345 gtk_widget_show(vbox2); |
346 | |
8352 | 347 /* accounts dropdown list */ |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
348 account_hbox = gtk_hbox_new(FALSE, 6); |
8352 | 349 gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); |
350 gtk_widget_show(account_hbox); | |
8113 | 351 |
8352 | 352 label = gtk_label_new(NULL); |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
353 gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); |
8352 | 354 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); |
8425
6d8ec773a485
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
355 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
8352 | 356 gtk_widget_show(label); |
8113 | 357 |
8352 | 358 dialog->account_widget = gaim_gtk_account_option_menu_new(dialog->account, FALSE, |
8939 | 359 G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog); |
8199 | 360 |
9067 | 361 if (!dialog->account) /* this is normally null, and we normally don't care what the first selected item is */ |
362 dialog->account = gaim_gtk_account_option_menu_get_selected(dialog->account_widget); | |
363 | |
8352 | 364 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
365 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
366 gtk_widget_show(dialog->account_widget); | |
8113 | 367 |
8199 | 368 /* scrolled window */ |
8113 | 369 dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
370 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
371 GTK_SHADOW_IN); | |
372 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
373 GTK_POLICY_AUTOMATIC, | |
374 GTK_POLICY_AUTOMATIC); | |
8199 | 375 gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
376 gtk_widget_set_size_request(dialog->sw, -1, 250); | |
8113 | 377 gtk_widget_show(dialog->sw); |
378 | |
8199 | 379 /* progress bar */ |
380 dialog->progress = gtk_progress_bar_new(); | |
381 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
382 gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
383 gtk_widget_show(dialog->progress); | |
384 | |
385 | |
386 /* button box */ | |
387 bbox = gtk_hbutton_box_new(); | |
388 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
389 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
390 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
391 gtk_widget_show(bbox); | |
392 | |
393 /* stop button */ | |
394 dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
395 gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
396 g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
397 G_CALLBACK(stop_button_cb), dialog); | |
398 gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
399 gtk_widget_show(dialog->stop_button); | |
400 | |
401 /* list button */ | |
402 dialog->list_button = gtk_button_new_with_mnemonic(_("_Get List")); | |
403 gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); | |
404 g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
405 G_CALLBACK(list_button_cb), dialog); | |
406 gtk_widget_show(dialog->list_button); | |
407 | |
408 /* join button */ | |
409 dialog->join_button = gaim_pixbuf_button_from_stock(_("_Join"), GAIM_STOCK_CHAT, | |
410 GAIM_BUTTON_HORIZONTAL); | |
411 gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); | |
412 g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
413 G_CALLBACK(join_button_cb), dialog); | |
414 gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
415 gtk_widget_show(dialog->join_button); | |
416 | |
417 /* close button */ | |
418 dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
419 gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
420 g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
421 G_CALLBACK(close_button_cb), dialog); | |
422 gtk_widget_show(dialog->close_button); | |
423 | |
424 /* show the dialog window and return the dialog */ | |
425 gtk_widget_show(dialog->window); | |
426 | |
8113 | 427 return dialog; |
428 } | |
429 | |
430 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new(void) | |
431 { | |
432 return gaim_gtk_roomlist_dialog_new_with_account(NULL); | |
433 } | |
434 | |
8352 | 435 static void gaim_gtk_roomlist_dialog_show_with_account(GaimAccount *account) |
436 { | |
437 GaimGtkRoomlistDialog *dialog; | |
438 | |
439 dialog = gaim_gtk_roomlist_dialog_new_with_account(account); | |
440 if (!dialog) | |
441 return; | |
442 | |
443 list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
444 } | |
445 | |
8113 | 446 void gaim_gtk_roomlist_dialog_show(void) |
447 { | |
448 gaim_gtk_roomlist_dialog_new(); | |
449 } | |
450 | |
451 static void gaim_gtk_roomlist_new(GaimRoomlist *list) | |
452 { | |
453 GaimGtkRoomlist *rl; | |
454 | |
455 rl = g_new0(GaimGtkRoomlist, 1); | |
456 | |
457 list->ui_data = rl; | |
458 | |
459 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
460 | |
461 roomlists = g_list_append(roomlists, list); | |
462 } | |
463 | |
464 static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
465 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
466 { | |
467 gchar buf[16]; | |
468 int myint; | |
469 | |
470 gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
471 | |
472 if (myint) | |
473 g_snprintf(buf, sizeof(buf), "%d", myint); | |
474 else | |
475 buf[0] = '\0'; | |
476 | |
477 g_object_set(renderer, "text", buf, NULL); | |
478 } | |
479 | |
480 /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
481 infinity-0. you can still click again to reverse it on any of them. */ | |
482 static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
483 { | |
484 int c, d; | |
485 | |
486 c = d = 0; | |
487 | |
488 gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
489 gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
490 | |
491 if (c == d) | |
492 return 0; | |
493 else if (c > d) | |
494 return -1; | |
495 else | |
496 return 1; | |
497 } | |
498 | |
499 static void gaim_gtk_roomlist_set_fields(GaimRoomlist *list, GList *fields) | |
500 { | |
501 GaimGtkRoomlist *grl = list->ui_data; | |
502 gint columns = NUM_OF_COLUMNS; | |
503 int j; | |
504 GtkTreeStore *model; | |
505 GtkWidget *tree; | |
506 GtkCellRenderer *renderer; | |
507 GtkTreeViewColumn *column; | |
8199 | 508 GtkTreeSelection *selection; |
8113 | 509 GList *l; |
510 GType *types; | |
511 | |
512 g_return_if_fail(grl != NULL); | |
513 | |
514 columns += g_list_length(fields); | |
515 types = g_new(GType, columns); | |
516 | |
517 types[NAME_COLUMN] = G_TYPE_STRING; | |
518 types[ROOM_COLUMN] = G_TYPE_POINTER; | |
519 | |
520 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
521 GaimRoomlistField *f = l->data; | |
522 | |
523 switch (f->type) { | |
524 case GAIM_ROOMLIST_FIELD_BOOL: | |
525 types[j] = G_TYPE_BOOLEAN; | |
526 break; | |
527 case GAIM_ROOMLIST_FIELD_INT: | |
528 types[j] = G_TYPE_INT; | |
529 break; | |
530 case GAIM_ROOMLIST_FIELD_STRING: | |
531 types[j] = G_TYPE_STRING; | |
532 break; | |
533 } | |
534 } | |
535 | |
536 model = gtk_tree_store_newv(columns, types); | |
537 g_free(types); | |
538 | |
539 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
540 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
541 | |
8199 | 542 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
543 g_signal_connect(G_OBJECT(selection), "changed", | |
544 G_CALLBACK(selection_changed_cb), grl); | |
545 | |
8113 | 546 g_object_unref(model); |
547 | |
548 grl->model = model; | |
549 grl->tree = tree; | |
550 gtk_widget_show(grl->tree); | |
551 | |
552 renderer = gtk_cell_renderer_text_new(); | |
553 column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
554 "text", NAME_COLUMN, NULL); | |
555 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
556 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
557 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
558 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
559 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
560 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
561 | |
562 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
563 GaimRoomlistField *f = l->data; | |
564 | |
565 if (f->hidden) | |
566 continue; | |
567 | |
568 renderer = gtk_cell_renderer_text_new(); | |
569 column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
570 "text", j, NULL); | |
571 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
572 GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
573 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
574 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
575 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
576 if (f->type == GAIM_ROOMLIST_FIELD_INT) { | |
577 gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, | |
578 GINT_TO_POINTER(j), NULL); | |
579 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
580 GINT_TO_POINTER(j), NULL); | |
581 } | |
582 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
583 } | |
584 | |
585 g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
586 g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
587 g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list); | |
588 } | |
589 | |
8230 | 590 static gboolean gaim_gtk_progress_bar_pulse(gpointer data) |
591 { | |
592 GaimRoomlist *list = data; | |
593 GaimGtkRoomlist *rl = list->ui_data; | |
594 | |
595 if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
596 rl->dialog->pg_to_active = FALSE; | |
597 gaim_roomlist_unref(list); | |
598 return FALSE; | |
599 } | |
600 | |
601 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
602 rl->dialog->pg_needs_pulse = FALSE; | |
603 return TRUE; | |
604 } | |
605 | |
8113 | 606 static void gaim_gtk_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room) |
607 { | |
608 GaimGtkRoomlist *rl= list->ui_data; | |
609 GtkTreeRowReference *rr, *parentrr = NULL; | |
610 GtkTreePath *path; | |
611 GtkTreeIter iter, parent, child; | |
612 GList *l, *k; | |
613 int j; | |
614 gboolean append = TRUE; | |
615 | |
616 rl->total_rooms++; | |
617 if (room->type == GAIM_ROOMLIST_ROOMTYPE_ROOM) | |
618 rl->num_rooms++; | |
619 | |
620 if (rl->dialog) { | |
8230 | 621 if (!rl->dialog->pg_to_active) { |
622 rl->dialog->pg_to_active = TRUE; | |
623 gaim_roomlist_ref(list); | |
624 rl->dialog->pg_update_to = g_timeout_add(100, gaim_gtk_progress_bar_pulse, list); | |
625 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
626 } else { | |
627 rl->dialog->pg_needs_pulse = TRUE; | |
628 } | |
8113 | 629 } |
630 if (room->parent) { | |
631 parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
632 path = gtk_tree_row_reference_get_path(parentrr); | |
633 if (path) { | |
634 GaimRoomlistRoom *tmproom = NULL; | |
635 | |
636 gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
637 gtk_tree_path_free(path); | |
638 | |
639 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
640 gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
641 if (!tmproom) | |
642 append = FALSE; | |
643 } | |
644 } | |
645 } | |
646 | |
647 if (append) | |
648 gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
649 else | |
650 iter = child; | |
651 | |
8584 | 652 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY) |
8113 | 653 gtk_tree_store_append(rl->model, &child, &iter); |
654 | |
655 path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
656 | |
8584 | 657 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY) { |
8113 | 658 rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); |
659 g_hash_table_insert(rl->cats, room, rr); | |
660 } | |
661 | |
662 gtk_tree_path_free(path); | |
663 | |
664 gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
665 gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
666 | |
667 for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
668 GaimRoomlistField *f = k->data; | |
669 if (f->hidden) | |
670 continue; | |
671 gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
672 } | |
673 } | |
674 | |
675 static void gaim_gtk_roomlist_in_progress(GaimRoomlist *list, gboolean flag) | |
676 { | |
677 GaimGtkRoomlist *rl = list->ui_data; | |
678 | |
679 if (!rl || !rl->dialog) | |
680 return; | |
681 | |
682 if (flag) { | |
8199 | 683 if (rl->dialog->account_widget) |
684 gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
685 gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
686 gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
8113 | 687 } else { |
8230 | 688 rl->dialog->pg_needs_pulse = FALSE; |
8113 | 689 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
8199 | 690 if (rl->dialog->account_widget) |
691 gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
692 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
693 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
8113 | 694 } |
695 } | |
696 | |
697 static void gaim_gtk_roomlist_destroy(GaimRoomlist *list) | |
698 { | |
699 GaimGtkRoomlist *rl; | |
700 | |
701 roomlists = g_list_remove(roomlists, list); | |
702 | |
703 rl = list->ui_data; | |
704 | |
705 g_return_if_fail(rl != NULL); | |
706 | |
707 g_hash_table_destroy(rl->cats); | |
708 g_free(rl); | |
709 list->ui_data = NULL; | |
710 } | |
711 | |
712 static GaimRoomlistUiOps ops = { | |
8352 | 713 gaim_gtk_roomlist_dialog_show_with_account, |
8113 | 714 gaim_gtk_roomlist_new, |
715 gaim_gtk_roomlist_set_fields, | |
716 gaim_gtk_roomlist_add_room, | |
717 gaim_gtk_roomlist_in_progress, | |
718 gaim_gtk_roomlist_destroy | |
719 }; | |
720 | |
721 | |
722 void gaim_gtk_roomlist_init(void) | |
723 { | |
724 gaim_roomlist_set_ui_ops(&ops); | |
725 } |