Sun, 22 Jul 2007 08:14:16 +0000
revert 'no visible tabs when only one conversation' as it proved unpopular. Made tabs only fill the entire width of the notebook when there's only one tab to avoid http://pidgin.im/~deryni/that_just_looks_dumb.png
| 8113 | 1 | /** |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
2 | * @file gtkroomlist.c GTK+ Room List UI |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
| 8113 | 4 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
5 | * pidgin |
| 8113 | 6 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
7 | * Pidgin is the legal property of its developers, whose names are too numerous |
|
8146
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8143
diff
changeset
|
8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8143
diff
changeset
|
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 | ||
| 9791 | 26 | #include "internal.h" |
| 15577 | 27 | #include "pidgin.h" |
| 8113 | 28 | #include "gtkutils.h" |
|
15883
969b74a3e27a
According to etags, pidgin/ should be completely clean of references to 'gaim' as a client
Sean Egan <seanegan@pidgin.im>
parents:
15882
diff
changeset
|
29 | #include "pidginstock.h" |
| 8113 | 30 | #include "debug.h" |
| 31 | #include "account.h" | |
| 32 | #include "connection.h" | |
| 33 | #include "notify.h" | |
| 34 | ||
| 35 | #include "gtkroomlist.h" | |
| 36 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
37 | typedef struct _PidginRoomlistDialog { |
| 8113 | 38 | GtkWidget *window; |
| 39 | GtkWidget *account_widget; | |
| 40 | GtkWidget *progress; | |
| 41 | GtkWidget *sw; | |
| 42 | ||
| 8199 | 43 | GtkWidget *stop_button; |
| 8113 | 44 | GtkWidget *list_button; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
45 | GtkWidget *add_button; |
| 8199 | 46 | GtkWidget *join_button; |
| 8113 | 47 | GtkWidget *close_button; |
| 48 | ||
| 15884 | 49 | PurpleAccount *account; |
| 50 | PurpleRoomlist *roomlist; | |
| 8230 | 51 | |
| 52 | gboolean pg_needs_pulse; | |
| 53 | gboolean pg_to_active; | |
| 54 | guint pg_update_to; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
55 | } PidginRoomlistDialog; |
| 14649 | 56 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
57 | typedef struct _PidginRoomlist { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
58 | PidginRoomlistDialog *dialog; |
| 14649 | 59 | GtkTreeStore *model; |
| 60 | GtkWidget *tree; | |
| 61 | GHashTable *cats; /**< Meow. */ | |
| 62 | gint num_rooms, total_rooms; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
63 | } PidginRoomlist; |
| 8113 | 64 | |
| 65 | enum { | |
| 66 | NAME_COLUMN = 0, | |
| 67 | ROOM_COLUMN, | |
| 68 | NUM_OF_COLUMNS, | |
| 69 | }; | |
| 70 | ||
| 71 | static GList *roomlists = NULL; | |
| 72 | ||
| 73 | static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) | |
| 74 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
75 | PidginRoomlistDialog *dialog; |
| 8113 | 76 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
77 | dialog = (PidginRoomlistDialog *) d; |
| 8113 | 78 | |
| 15884 | 79 | if (dialog->roomlist && purple_roomlist_get_in_progress(dialog->roomlist)) |
| 80 | purple_roomlist_cancel_get_list(dialog->roomlist); | |
| 8199 | 81 | |
| 8230 | 82 | if (dialog->roomlist) { |
| 83 | if (dialog->pg_to_active) { | |
| 15884 | 84 | purple_timeout_remove(dialog->pg_update_to); |
| 8230 | 85 | dialog->pg_to_active = FALSE; |
| 86 | /* yes, that's right, unref it twice. */ | |
| 15884 | 87 | purple_roomlist_unref(dialog->roomlist); |
| 8230 | 88 | } |
| 89 | } | |
| 90 | ||
| 8113 | 91 | /* free stuff here */ |
| 92 | if (dialog->roomlist) | |
| 15884 | 93 | purple_roomlist_unref(dialog->roomlist); |
| 8113 | 94 | g_free(dialog); |
| 95 | ||
| 96 | return FALSE; | |
| 97 | } | |
| 98 | ||
| 15884 | 99 | static void dialog_select_account_cb(GObject *w, PurpleAccount *account, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
100 | PidginRoomlistDialog *dialog) |
| 8113 | 101 | { |
| 102 | dialog->account = account; | |
| 103 | } | |
| 104 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
105 | static void list_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 106 | { |
| 15884 | 107 | PurpleConnection *gc; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
108 | PidginRoomlist *rl; |
| 8113 | 109 | |
| 15884 | 110 | gc = purple_account_get_connection(dialog->account); |
| 8113 | 111 | if (!gc) |
| 112 | return; | |
| 113 | ||
| 8199 | 114 | if (dialog->roomlist != NULL) { |
| 115 | rl = dialog->roomlist->ui_data; | |
| 116 | gtk_widget_destroy(rl->tree); | |
| 15884 | 117 | purple_roomlist_unref(dialog->roomlist); |
| 8199 | 118 | } |
| 119 | ||
| 15884 | 120 | dialog->roomlist = purple_roomlist_get_list(gc); |
| 9159 | 121 | if (!dialog->roomlist) |
| 122 | return; | |
| 15884 | 123 | purple_roomlist_ref(dialog->roomlist); |
| 8113 | 124 | rl = dialog->roomlist->ui_data; |
| 125 | rl->dialog = dialog; | |
| 8199 | 126 | |
| 8113 | 127 | if (dialog->account_widget) |
| 128 | gtk_widget_set_sensitive(dialog->account_widget, FALSE); | |
| 8199 | 129 | |
| 130 | gtk_container_add(GTK_CONTAINER(dialog->sw), rl->tree); | |
| 131 | ||
| 15884 | 132 | /* some protocols (not bundled with libpurple) finish getting their |
| 15350 | 133 | * room list immediately */ |
| 15884 | 134 | if(purple_roomlist_get_in_progress(dialog->roomlist)) { |
| 15350 | 135 | gtk_widget_set_sensitive(dialog->stop_button, TRUE); |
| 136 | gtk_widget_set_sensitive(dialog->list_button, FALSE); | |
| 137 | } else { | |
| 138 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 139 | gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
| 140 | } | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
141 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 142 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 8113 | 143 | } |
| 144 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
145 | static void stop_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 146 | { |
| 15884 | 147 | purple_roomlist_cancel_get_list(dialog->roomlist); |
| 8199 | 148 | |
| 149 | if (dialog->account_widget) | |
| 150 | gtk_widget_set_sensitive(dialog->account_widget, TRUE); | |
| 151 | ||
| 152 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 153 | gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
154 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 155 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 8113 | 156 | } |
| 157 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
158 | static void close_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 159 | { |
| 160 | GtkWidget *window = dialog->window; | |
| 161 | ||
| 162 | delete_win_cb(NULL, NULL, dialog); | |
| 163 | gtk_widget_destroy(window); | |
| 164 | } | |
| 165 | ||
| 166 | struct _menu_cb_info { | |
| 15884 | 167 | PurpleRoomlist *list; |
| 168 | PurpleRoomlistRoom *room; | |
| 8113 | 169 | }; |
| 170 | ||
| 8199 | 171 | static void |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
172 | selection_changed_cb(GtkTreeSelection *selection, PidginRoomlist *grl) { |
| 8199 | 173 | GtkTreeIter iter; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
174 | GValue val; |
| 15884 | 175 | PurpleRoomlistRoom *room; |
| 8199 | 176 | static struct _menu_cb_info *info; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
177 | PidginRoomlistDialog *dialog; |
| 8199 | 178 | |
| 179 | dialog = grl->dialog; | |
| 180 | ||
| 181 | if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
182 | val.g_type = 0; |
| 8199 | 183 | gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 184 | room = g_value_get_pointer(&val); | |
| 15884 | 185 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) { |
| 8199 | 186 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
187 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 188 | return; |
| 189 | } | |
| 190 | ||
| 191 | info = g_new0(struct _menu_cb_info, 1); | |
| 192 | info->list = dialog->roomlist; | |
| 193 | info->room = room; | |
| 194 | ||
| 8377 | 195 | g_object_set_data_full(G_OBJECT(dialog->join_button), "room-info", |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
196 | info, g_free); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
197 | g_object_set_data(G_OBJECT(dialog->add_button), "room-info", info); |
| 8199 | 198 | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
199 | gtk_widget_set_sensitive(dialog->add_button, TRUE); |
| 8199 | 200 | gtk_widget_set_sensitive(dialog->join_button, TRUE); |
| 201 | } else { | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
202 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 203 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 204 | } | |
| 205 | } | |
| 206 | ||
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
207 | static void do_add_room_cb(GtkWidget *w, struct _menu_cb_info *info) |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
208 | { |
| 15185 | 209 | char *name; |
| 15884 | 210 | PurpleConnection *gc = purple_account_get_connection(info->list->account); |
| 211 | PurplePluginProtocolInfo *prpl_info = NULL; | |
| 15185 | 212 | |
| 213 | if(gc != NULL) | |
| 15884 | 214 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 15185 | 215 | |
| 216 | if(prpl_info != NULL && prpl_info->roomlist_room_serialize) | |
| 217 | name = prpl_info->roomlist_room_serialize(info->room); | |
| 218 | else | |
| 219 | name = g_strdup(info->room->name); | |
| 220 | ||
| 15884 | 221 | purple_blist_request_add_chat(info->list->account, NULL, NULL, name); |
| 15185 | 222 | |
| 223 | g_free(name); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
224 | } |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
225 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
226 | static void add_room_to_blist_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
227 | { |
| 15884 | 228 | PurpleRoomlist *rl = dialog->roomlist; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
229 | PidginRoomlist *grl = rl->ui_data; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
230 | struct _menu_cb_info *info; |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
231 | |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
232 | info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
233 | |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
234 | if(info != NULL) |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
235 | do_add_room_cb(grl->tree, info); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
236 | } |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
237 | |
| 8113 | 238 | static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info) |
| 239 | { | |
| 15884 | 240 | purple_roomlist_room_join(info->list, info->room); |
| 8199 | 241 | } |
| 8113 | 242 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
243 | static void join_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8199 | 244 | { |
| 15884 | 245 | PurpleRoomlist *rl = dialog->roomlist; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
246 | PidginRoomlist *grl = rl->ui_data; |
| 8199 | 247 | struct _menu_cb_info *info; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
248 | |
| 8199 | 249 | info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
250 | |
| 8377 | 251 | if(info != NULL) |
| 252 | do_join_cb(grl->tree, info); | |
| 8113 | 253 | } |
| 254 | ||
| 255 | static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2, | |
| 15884 | 256 | PurpleRoomlist *list) |
| 8113 | 257 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
258 | PidginRoomlist *grl = list->ui_data; |
| 8113 | 259 | GtkTreeIter iter; |
| 15884 | 260 | PurpleRoomlistRoom *room; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
261 | GValue val; |
| 8113 | 262 | struct _menu_cb_info info; |
| 263 | ||
| 264 | gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
265 | val.g_type = 0; |
| 8113 | 266 | gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 267 | room = g_value_get_pointer(&val); | |
| 15884 | 268 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) |
| 8113 | 269 | return; |
| 270 | ||
| 271 | info.list = list; | |
| 272 | info.room = room; | |
| 273 | ||
| 274 | do_join_cb(GTK_WIDGET(tv), &info); | |
| 275 | } | |
| 276 | ||
| 15884 | 277 | static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, PurpleRoomlist *list) |
| 8113 | 278 | { |
| 279 | GtkTreePath *path; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
280 | PidginRoomlist *grl = list->ui_data; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
281 | GValue val; |
| 15884 | 282 | PurpleRoomlistRoom *room; |
| 8113 | 283 | GtkTreeIter iter; |
| 284 | GtkWidget *menu; | |
| 285 | static struct _menu_cb_info info; /* XXX? */ | |
| 286 | ||
| 287 | if (event->button != 3 || event->type != GDK_BUTTON_PRESS) | |
| 288 | return FALSE; | |
| 289 | ||
| 290 | /* Here we figure out which room was clicked */ | |
| 291 | if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
| 292 | return FALSE; | |
| 293 | gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
| 294 | gtk_tree_path_free(path); | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
295 | val.g_type = 0; |
| 8113 | 296 | gtk_tree_model_get_value (GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 297 | room = g_value_get_pointer(&val); | |
| 298 | ||
| 15884 | 299 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) |
| 8113 | 300 | return FALSE; |
| 301 | ||
| 302 | info.list = list; | |
| 303 | info.room = room; | |
| 304 | ||
| 305 | menu = gtk_menu_new(); | |
| 15570 | 306 | pidgin_new_item_from_stock(menu, _("_Join"), PIDGIN_STOCK_CHAT, |
| 8113 | 307 | G_CALLBACK(do_join_cb), &info, 0, 0, NULL); |
| 15568 | 308 | pidgin_new_item_from_stock(menu, _("_Add"), GTK_STOCK_ADD, |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
309 | G_CALLBACK(do_add_room_cb), &info, 0, 0, NULL); |
| 8113 | 310 | |
| 311 | gtk_widget_show_all(menu); | |
| 312 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
| 313 | ||
| 314 | return FALSE; | |
| 315 | } | |
| 316 | ||
| 317 | static void row_expanded_cb(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer user_data) | |
| 318 | { | |
| 15884 | 319 | PurpleRoomlist *list = user_data; |
| 320 | PurpleRoomlistRoom *category; | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
321 | GValue val; |
| 8113 | 322 | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
323 | val.g_type = 0; |
| 8113 | 324 | gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val); |
| 8584 | 325 | category = g_value_get_pointer(&val); |
| 8113 | 326 | |
| 8584 | 327 | if (!category->expanded_once) { |
| 15884 | 328 | purple_roomlist_expand_category(list, category); |
| 8584 | 329 | category->expanded_once = TRUE; |
| 8113 | 330 | } |
| 331 | } | |
| 332 | ||
| 15884 | 333 | static gboolean account_filter_func(PurpleAccount *account) |
| 8113 | 334 | { |
| 15884 | 335 | PurpleConnection *gc = purple_account_get_connection(account); |
| 336 | PurplePluginProtocolInfo *prpl_info = NULL; | |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
337 | |
| 15884 | 338 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
339 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
340 | return (prpl_info->roomlist_get_list != NULL); |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
341 | } |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
342 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
343 | gboolean |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
344 | pidgin_roomlist_is_showable() |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
345 | { |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
346 | GList *c; |
| 15884 | 347 | PurpleConnection *gc; |
| 8113 | 348 | |
| 15884 | 349 | for (c = purple_connections_get_all(); c != NULL; c = c->next) { |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
350 | gc = c->data; |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
351 | |
| 15884 | 352 | if (account_filter_func(purple_connection_get_account(gc))) |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
353 | return TRUE; |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
354 | } |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
355 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
356 | return FALSE; |
| 8113 | 357 | } |
| 358 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
359 | static PidginRoomlistDialog * |
| 15884 | 360 | pidgin_roomlist_dialog_new_with_account(PurpleAccount *account) |
| 8113 | 361 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
362 | PidginRoomlistDialog *dialog; |
| 8113 | 363 | GtkWidget *window; |
| 8199 | 364 | GtkWidget *vbox; |
| 365 | GtkWidget *vbox2; | |
| 8113 | 366 | GtkWidget *account_hbox; |
| 367 | GtkWidget *bbox; | |
| 368 | GtkWidget *label; | |
| 369 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
370 | dialog = g_new0(PidginRoomlistDialog, 1); |
|
8937
b436e9cbd701
[gaim-migrate @ 9707]
Mark Doliner <markdoliner@pidgin.im>
parents:
8584
diff
changeset
|
371 | dialog->account = account; |
| 8113 | 372 | |
| 373 | /* Create the window. */ | |
| 17213 | 374 | dialog->window = window = pidgin_create_window(_("Room List"), PIDGIN_HIG_BORDER, "room list", TRUE); |
| 8113 | 375 | |
| 376 | g_signal_connect(G_OBJECT(window), "delete_event", | |
| 377 | G_CALLBACK(delete_win_cb), dialog); | |
| 378 | ||
| 379 | /* Create the parent vbox for everything. */ | |
| 15882 | 380 | vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 381 | gtk_container_add(GTK_CONTAINER(window), vbox); |
| 382 | gtk_widget_show(vbox); | |
| 8113 | 383 | |
| 15882 | 384 | vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 385 | gtk_container_add(GTK_CONTAINER(vbox), vbox2); |
| 8113 | 386 | gtk_widget_show(vbox2); |
| 387 | ||
| 8352 | 388 | /* accounts dropdown list */ |
| 15882 | 389 | account_hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| 8352 | 390 | gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); |
| 391 | gtk_widget_show(account_hbox); | |
| 8113 | 392 | |
| 8352 | 393 | label = gtk_label_new(NULL); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
394 | gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); |
| 8352 | 395 | gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
396 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
| 8352 | 397 | gtk_widget_show(label); |
| 8113 | 398 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
399 | dialog->account_widget = pidgin_account_option_menu_new(dialog->account, FALSE, |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
400 | G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog); |
| 8199 | 401 | |
| 9067 | 402 | if (!dialog->account) /* this is normally null, and we normally don't care what the first selected item is */ |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
403 | dialog->account = pidgin_account_option_menu_get_selected(dialog->account_widget); |
| 9067 | 404 | |
| 8352 | 405 | gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
| 406 | gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
| 407 | gtk_widget_show(dialog->account_widget); | |
| 8113 | 408 | |
| 8199 | 409 | /* scrolled window */ |
| 8113 | 410 | dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
| 411 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 412 | GTK_SHADOW_IN); | |
| 413 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 414 | GTK_POLICY_AUTOMATIC, | |
| 415 | GTK_POLICY_AUTOMATIC); | |
| 8199 | 416 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
| 417 | gtk_widget_set_size_request(dialog->sw, -1, 250); | |
| 8113 | 418 | gtk_widget_show(dialog->sw); |
| 419 | ||
| 8199 | 420 | /* progress bar */ |
| 421 | dialog->progress = gtk_progress_bar_new(); | |
| 422 | gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
| 423 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
| 424 | gtk_widget_show(dialog->progress); | |
| 425 | ||
| 426 | /* button box */ | |
| 427 | bbox = gtk_hbutton_box_new(); | |
| 15882 | 428 | gtk_box_set_spacing(GTK_BOX(bbox), PIDGIN_HIG_BOX_SPACE); |
| 8199 | 429 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
| 430 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
| 431 | gtk_widget_show(bbox); | |
| 432 | ||
| 433 | /* stop button */ | |
| 434 | dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
| 435 | gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
| 436 | g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
| 437 | G_CALLBACK(stop_button_cb), dialog); | |
| 438 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 439 | gtk_widget_show(dialog->stop_button); | |
| 440 | ||
| 441 | /* list button */ | |
| 15568 | 442 | dialog->list_button = pidgin_pixbuf_button_from_stock(_("_Get List"), GTK_STOCK_REFRESH, |
| 443 | PIDGIN_BUTTON_HORIZONTAL); | |
| 8199 | 444 | gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); |
| 445 | g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
| 446 | G_CALLBACK(list_button_cb), dialog); | |
| 447 | gtk_widget_show(dialog->list_button); | |
| 448 | ||
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
449 | /* add button */ |
| 15568 | 450 | dialog->add_button = pidgin_pixbuf_button_from_stock(_("_Add Chat"), GTK_STOCK_ADD, |
| 451 | PIDGIN_BUTTON_HORIZONTAL); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
452 | gtk_box_pack_start(GTK_BOX(bbox), dialog->add_button, FALSE, FALSE, 0); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
453 | g_signal_connect(G_OBJECT(dialog->add_button), "clicked", |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
454 | G_CALLBACK(add_room_to_blist_cb), dialog); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
455 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
456 | gtk_widget_show(dialog->add_button); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
457 | |
| 8199 | 458 | /* join button */ |
| 15570 | 459 | dialog->join_button = pidgin_pixbuf_button_from_stock(_("_Join"), PIDGIN_STOCK_CHAT, |
| 15568 | 460 | PIDGIN_BUTTON_HORIZONTAL); |
| 8199 | 461 | gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); |
| 462 | g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
| 463 | G_CALLBACK(join_button_cb), dialog); | |
| 464 | gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
| 465 | gtk_widget_show(dialog->join_button); | |
| 466 | ||
| 467 | /* close button */ | |
| 468 | dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 469 | gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
| 470 | g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
| 471 | G_CALLBACK(close_button_cb), dialog); | |
| 472 | gtk_widget_show(dialog->close_button); | |
| 473 | ||
| 474 | /* show the dialog window and return the dialog */ | |
| 475 | gtk_widget_show(dialog->window); | |
| 476 | ||
| 8113 | 477 | return dialog; |
| 478 | } | |
| 479 | ||
| 15884 | 480 | void pidgin_roomlist_dialog_show_with_account(PurpleAccount *account) |
| 8352 | 481 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
482 | PidginRoomlistDialog *dialog; |
| 8352 | 483 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
484 | dialog = pidgin_roomlist_dialog_new_with_account(account); |
| 8352 | 485 | if (!dialog) |
| 486 | return; | |
| 487 | ||
| 488 | list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
| 489 | } | |
| 490 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
491 | void pidgin_roomlist_dialog_show(void) |
| 8113 | 492 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
493 | pidgin_roomlist_dialog_new_with_account(NULL); |
| 8113 | 494 | } |
| 495 | ||
| 15884 | 496 | static void pidgin_roomlist_new(PurpleRoomlist *list) |
| 8113 | 497 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
498 | PidginRoomlist *rl; |
| 8113 | 499 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
500 | rl = g_new0(PidginRoomlist, 1); |
| 8113 | 501 | |
| 502 | list->ui_data = rl; | |
| 503 | ||
| 504 | rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
| 505 | ||
| 506 | roomlists = g_list_append(roomlists, list); | |
| 507 | } | |
| 508 | ||
| 509 | static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
| 510 | GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
| 511 | { | |
| 512 | gchar buf[16]; | |
| 513 | int myint; | |
| 514 | ||
| 515 | gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
| 516 | ||
| 517 | if (myint) | |
| 518 | g_snprintf(buf, sizeof(buf), "%d", myint); | |
| 519 | else | |
| 520 | buf[0] = '\0'; | |
| 521 | ||
| 522 | g_object_set(renderer, "text", buf, NULL); | |
| 523 | } | |
| 524 | ||
| 525 | /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
| 526 | infinity-0. you can still click again to reverse it on any of them. */ | |
| 527 | static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
| 528 | { | |
| 529 | int c, d; | |
| 530 | ||
| 531 | c = d = 0; | |
| 532 | ||
| 533 | gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
| 534 | gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
| 535 | ||
| 536 | if (c == d) | |
| 537 | return 0; | |
| 538 | else if (c > d) | |
| 539 | return -1; | |
| 540 | else | |
| 541 | return 1; | |
| 542 | } | |
| 543 | ||
|
11490
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
544 | static gboolean |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
545 | _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
546 | { |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
547 | gboolean result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
548 | gchar *name, *fold, *fkey; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
549 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
550 | gtk_tree_model_get(model, iter, column, &name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
551 | fold = g_utf8_casefold(name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
552 | fkey = g_utf8_casefold(key, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
553 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
554 | result = (g_strstr_len(fold, strlen(fold), fkey) == NULL); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
555 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
556 | g_free(fold); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
557 | g_free(fkey); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
558 | g_free(name); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
559 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
560 | return result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
561 | } |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
562 | |
| 15884 | 563 | static void pidgin_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
| 8113 | 564 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
565 | PidginRoomlist *grl = list->ui_data; |
| 8113 | 566 | gint columns = NUM_OF_COLUMNS; |
| 567 | int j; | |
| 568 | GtkTreeStore *model; | |
| 569 | GtkWidget *tree; | |
| 570 | GtkCellRenderer *renderer; | |
| 571 | GtkTreeViewColumn *column; | |
| 8199 | 572 | GtkTreeSelection *selection; |
| 8113 | 573 | GList *l; |
| 574 | GType *types; | |
| 575 | ||
| 576 | g_return_if_fail(grl != NULL); | |
| 577 | ||
| 578 | columns += g_list_length(fields); | |
| 579 | types = g_new(GType, columns); | |
| 580 | ||
| 581 | types[NAME_COLUMN] = G_TYPE_STRING; | |
| 582 | types[ROOM_COLUMN] = G_TYPE_POINTER; | |
| 583 | ||
| 584 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 585 | PurpleRoomlistField *f = l->data; |
| 8113 | 586 | |
| 587 | switch (f->type) { | |
| 15884 | 588 | case PURPLE_ROOMLIST_FIELD_BOOL: |
| 8113 | 589 | types[j] = G_TYPE_BOOLEAN; |
| 590 | break; | |
| 15884 | 591 | case PURPLE_ROOMLIST_FIELD_INT: |
| 8113 | 592 | types[j] = G_TYPE_INT; |
| 593 | break; | |
| 15884 | 594 | case PURPLE_ROOMLIST_FIELD_STRING: |
| 8113 | 595 | types[j] = G_TYPE_STRING; |
| 596 | break; | |
| 597 | } | |
| 598 | } | |
| 599 | ||
| 600 | model = gtk_tree_store_newv(columns, types); | |
| 601 | g_free(types); | |
| 602 | ||
| 603 | tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
| 604 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
| 605 | ||
| 8199 | 606 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
| 607 | g_signal_connect(G_OBJECT(selection), "changed", | |
| 608 | G_CALLBACK(selection_changed_cb), grl); | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13448
diff
changeset
|
609 | |
| 8113 | 610 | g_object_unref(model); |
| 611 | ||
| 612 | grl->model = model; | |
| 613 | grl->tree = tree; | |
| 614 | gtk_widget_show(grl->tree); | |
| 615 | ||
| 616 | renderer = gtk_cell_renderer_text_new(); | |
| 617 | column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
| 618 | "text", NAME_COLUMN, NULL); | |
| 619 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 620 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 621 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 622 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
| 623 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 624 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 625 | ||
| 626 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 627 | PurpleRoomlistField *f = l->data; |
| 8113 | 628 | |
| 629 | if (f->hidden) | |
| 630 | continue; | |
| 631 | ||
| 632 | renderer = gtk_cell_renderer_text_new(); | |
| 633 | column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
| 634 | "text", j, NULL); | |
| 635 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 636 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 637 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 638 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
| 639 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 15884 | 640 | if (f->type == PURPLE_ROOMLIST_FIELD_INT) { |
| 8113 | 641 | gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, |
| 642 | GINT_TO_POINTER(j), NULL); | |
| 643 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
| 644 | GINT_TO_POINTER(j), NULL); | |
| 645 | } | |
| 646 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 647 | } | |
| 648 | ||
| 649 | g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
| 650 | g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
| 651 | g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list); | |
|
11490
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
652 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
653 | /* Enable CTRL+F searching */ |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
654 | gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), NAME_COLUMN); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
655 | gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), _search_func, NULL, NULL); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
656 | |
| 8113 | 657 | } |
| 658 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
659 | static gboolean pidgin_progress_bar_pulse(gpointer data) |
| 8230 | 660 | { |
| 15884 | 661 | PurpleRoomlist *list = data; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
662 | PidginRoomlist *rl = list->ui_data; |
| 8230 | 663 | |
| 664 | if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
|
13448
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
665 | if (rl && rl->dialog) |
|
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
666 | rl->dialog->pg_to_active = FALSE; |
| 15884 | 667 | purple_roomlist_unref(list); |
| 8230 | 668 | return FALSE; |
| 669 | } | |
| 670 | ||
| 671 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
| 672 | rl->dialog->pg_needs_pulse = FALSE; | |
| 673 | return TRUE; | |
| 674 | } | |
| 675 | ||
| 15884 | 676 | static void pidgin_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8113 | 677 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
678 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 679 | GtkTreeRowReference *rr, *parentrr = NULL; |
| 680 | GtkTreePath *path; | |
| 681 | GtkTreeIter iter, parent, child; | |
| 682 | GList *l, *k; | |
| 683 | int j; | |
| 684 | gboolean append = TRUE; | |
| 685 | ||
| 686 | rl->total_rooms++; | |
| 15884 | 687 | if (room->type == PURPLE_ROOMLIST_ROOMTYPE_ROOM) |
| 8113 | 688 | rl->num_rooms++; |
| 689 | ||
| 690 | if (rl->dialog) { | |
| 8230 | 691 | if (!rl->dialog->pg_to_active) { |
| 692 | rl->dialog->pg_to_active = TRUE; | |
| 15884 | 693 | purple_roomlist_ref(list); |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
694 | rl->dialog->pg_update_to = g_timeout_add(100, pidgin_progress_bar_pulse, list); |
| 8230 | 695 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); |
| 696 | } else { | |
| 697 | rl->dialog->pg_needs_pulse = TRUE; | |
| 698 | } | |
| 8113 | 699 | } |
| 700 | if (room->parent) { | |
| 701 | parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
| 702 | path = gtk_tree_row_reference_get_path(parentrr); | |
| 703 | if (path) { | |
| 15884 | 704 | PurpleRoomlistRoom *tmproom = NULL; |
| 8113 | 705 | |
| 706 | gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
| 707 | gtk_tree_path_free(path); | |
| 708 | ||
| 709 | if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
| 710 | gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
| 711 | if (!tmproom) | |
| 712 | append = FALSE; | |
| 713 | } | |
| 714 | } | |
| 715 | } | |
| 716 | ||
| 717 | if (append) | |
| 718 | gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
| 719 | else | |
| 720 | iter = child; | |
| 721 | ||
| 15884 | 722 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) |
| 8113 | 723 | gtk_tree_store_append(rl->model, &child, &iter); |
| 724 | ||
| 725 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
| 726 | ||
| 15884 | 727 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) { |
| 8113 | 728 | rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); |
| 729 | g_hash_table_insert(rl->cats, room, rr); | |
| 730 | } | |
| 731 | ||
| 732 | gtk_tree_path_free(path); | |
| 733 | ||
| 734 | gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
| 735 | gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
| 736 | ||
| 737 | for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
| 15884 | 738 | PurpleRoomlistField *f = k->data; |
| 8113 | 739 | if (f->hidden) |
| 740 | continue; | |
| 741 | gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
| 742 | } | |
| 743 | } | |
| 744 | ||
| 15884 | 745 | static void pidgin_roomlist_in_progress(PurpleRoomlist *list, gboolean flag) |
| 8113 | 746 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
747 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 748 | |
| 749 | if (!rl || !rl->dialog) | |
| 750 | return; | |
| 751 | ||
| 752 | if (flag) { | |
| 8199 | 753 | if (rl->dialog->account_widget) |
| 754 | gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
| 755 | gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
| 756 | gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
| 8113 | 757 | } else { |
| 8230 | 758 | rl->dialog->pg_needs_pulse = FALSE; |
| 8113 | 759 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
| 8199 | 760 | if (rl->dialog->account_widget) |
| 761 | gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
| 762 | gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
| 763 | gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
| 8113 | 764 | } |
| 765 | } | |
| 766 | ||
| 15884 | 767 | static void pidgin_roomlist_destroy(PurpleRoomlist *list) |
| 8113 | 768 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
769 | PidginRoomlist *rl; |
| 8113 | 770 | |
| 771 | roomlists = g_list_remove(roomlists, list); | |
| 772 | ||
| 773 | rl = list->ui_data; | |
| 774 | ||
| 775 | g_return_if_fail(rl != NULL); | |
| 776 | ||
| 777 | g_hash_table_destroy(rl->cats); | |
| 778 | g_free(rl); | |
| 779 | list->ui_data = NULL; | |
| 780 | } | |
| 781 | ||
| 15884 | 782 | static PurpleRoomlistUiOps ops = { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
783 | pidgin_roomlist_dialog_show_with_account, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
784 | pidgin_roomlist_new, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
785 | pidgin_roomlist_set_fields, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
786 | pidgin_roomlist_add_room, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
787 | pidgin_roomlist_in_progress, |
|
16752
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
788 | pidgin_roomlist_destroy, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
789 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
790 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
791 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
792 | NULL |
| 8113 | 793 | }; |
| 794 | ||
| 795 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
796 | void pidgin_roomlist_init(void) |
| 8113 | 797 | { |
| 15884 | 798 | purple_roomlist_set_ui_ops(&ops); |
| 8113 | 799 | } |