Wed, 21 Mar 2007 09:00:54 +0000
Re-sed the copyright notices so they don't all talk about Purple.
| 8113 | 1 | /** |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
2 | * @file gtkroomlist.c GTK+ Room List UI |
| 8113 | 3 | * @ingroup gtkui |
| 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 | { |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
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. */ | |
| 374 | dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 375 | gtk_window_set_role(GTK_WINDOW(window), "room list"); | |
| 376 | gtk_window_set_title(GTK_WINDOW(window), _("Room List")); | |
| 377 | ||
| 15882 | 378 | gtk_container_set_border_width(GTK_CONTAINER(window), PIDGIN_HIG_BORDER); |
| 8113 | 379 | |
| 380 | g_signal_connect(G_OBJECT(window), "delete_event", | |
| 381 | G_CALLBACK(delete_win_cb), dialog); | |
| 382 | ||
| 383 | /* Create the parent vbox for everything. */ | |
| 15882 | 384 | vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 385 | gtk_container_add(GTK_CONTAINER(window), vbox); |
| 386 | gtk_widget_show(vbox); | |
| 8113 | 387 | |
| 15882 | 388 | vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 389 | gtk_container_add(GTK_CONTAINER(vbox), vbox2); |
| 8113 | 390 | gtk_widget_show(vbox2); |
| 391 | ||
| 8352 | 392 | /* accounts dropdown list */ |
| 15882 | 393 | account_hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| 8352 | 394 | gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); |
| 395 | gtk_widget_show(account_hbox); | |
| 8113 | 396 | |
| 8352 | 397 | label = gtk_label_new(NULL); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
398 | gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); |
| 8352 | 399 | gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
400 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
| 8352 | 401 | gtk_widget_show(label); |
| 8113 | 402 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
403 | 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
|
404 | G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog); |
| 8199 | 405 | |
| 9067 | 406 | 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
|
407 | dialog->account = pidgin_account_option_menu_get_selected(dialog->account_widget); |
| 9067 | 408 | |
| 8352 | 409 | gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
| 410 | gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
| 411 | gtk_widget_show(dialog->account_widget); | |
| 8113 | 412 | |
| 8199 | 413 | /* scrolled window */ |
| 8113 | 414 | dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
| 415 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 416 | GTK_SHADOW_IN); | |
| 417 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 418 | GTK_POLICY_AUTOMATIC, | |
| 419 | GTK_POLICY_AUTOMATIC); | |
| 8199 | 420 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
| 421 | gtk_widget_set_size_request(dialog->sw, -1, 250); | |
| 8113 | 422 | gtk_widget_show(dialog->sw); |
| 423 | ||
| 8199 | 424 | /* progress bar */ |
| 425 | dialog->progress = gtk_progress_bar_new(); | |
| 426 | gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
| 427 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
| 428 | gtk_widget_show(dialog->progress); | |
| 429 | ||
| 430 | /* button box */ | |
| 431 | bbox = gtk_hbutton_box_new(); | |
| 15882 | 432 | gtk_box_set_spacing(GTK_BOX(bbox), PIDGIN_HIG_BOX_SPACE); |
| 8199 | 433 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
| 434 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
| 435 | gtk_widget_show(bbox); | |
| 436 | ||
| 437 | /* stop button */ | |
| 438 | dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
| 439 | gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
| 440 | g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
| 441 | G_CALLBACK(stop_button_cb), dialog); | |
| 442 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 443 | gtk_widget_show(dialog->stop_button); | |
| 444 | ||
| 445 | /* list button */ | |
| 15568 | 446 | dialog->list_button = pidgin_pixbuf_button_from_stock(_("_Get List"), GTK_STOCK_REFRESH, |
| 447 | PIDGIN_BUTTON_HORIZONTAL); | |
| 8199 | 448 | gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); |
| 449 | g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
| 450 | G_CALLBACK(list_button_cb), dialog); | |
| 451 | gtk_widget_show(dialog->list_button); | |
| 452 | ||
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
453 | /* add button */ |
| 15568 | 454 | dialog->add_button = pidgin_pixbuf_button_from_stock(_("_Add Chat"), GTK_STOCK_ADD, |
| 455 | PIDGIN_BUTTON_HORIZONTAL); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
456 | 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
|
457 | g_signal_connect(G_OBJECT(dialog->add_button), "clicked", |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
458 | G_CALLBACK(add_room_to_blist_cb), dialog); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
459 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
460 | gtk_widget_show(dialog->add_button); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
461 | |
| 8199 | 462 | /* join button */ |
| 15570 | 463 | dialog->join_button = pidgin_pixbuf_button_from_stock(_("_Join"), PIDGIN_STOCK_CHAT, |
| 15568 | 464 | PIDGIN_BUTTON_HORIZONTAL); |
| 8199 | 465 | gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); |
| 466 | g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
| 467 | G_CALLBACK(join_button_cb), dialog); | |
| 468 | gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
| 469 | gtk_widget_show(dialog->join_button); | |
| 470 | ||
| 471 | /* close button */ | |
| 472 | dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 473 | gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
| 474 | g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
| 475 | G_CALLBACK(close_button_cb), dialog); | |
| 476 | gtk_widget_show(dialog->close_button); | |
| 477 | ||
| 478 | /* show the dialog window and return the dialog */ | |
| 479 | gtk_widget_show(dialog->window); | |
| 480 | ||
| 8113 | 481 | return dialog; |
| 482 | } | |
| 483 | ||
| 15884 | 484 | void pidgin_roomlist_dialog_show_with_account(PurpleAccount *account) |
| 8352 | 485 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
486 | PidginRoomlistDialog *dialog; |
| 8352 | 487 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
488 | dialog = pidgin_roomlist_dialog_new_with_account(account); |
| 8352 | 489 | if (!dialog) |
| 490 | return; | |
| 491 | ||
| 492 | list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
| 493 | } | |
| 494 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
495 | void pidgin_roomlist_dialog_show(void) |
| 8113 | 496 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
497 | pidgin_roomlist_dialog_new_with_account(NULL); |
| 8113 | 498 | } |
| 499 | ||
| 15884 | 500 | static void pidgin_roomlist_new(PurpleRoomlist *list) |
| 8113 | 501 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
502 | PidginRoomlist *rl; |
| 8113 | 503 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
504 | rl = g_new0(PidginRoomlist, 1); |
| 8113 | 505 | |
| 506 | list->ui_data = rl; | |
| 507 | ||
| 508 | rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
| 509 | ||
| 510 | roomlists = g_list_append(roomlists, list); | |
| 511 | } | |
| 512 | ||
| 513 | static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
| 514 | GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
| 515 | { | |
| 516 | gchar buf[16]; | |
| 517 | int myint; | |
| 518 | ||
| 519 | gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
| 520 | ||
| 521 | if (myint) | |
| 522 | g_snprintf(buf, sizeof(buf), "%d", myint); | |
| 523 | else | |
| 524 | buf[0] = '\0'; | |
| 525 | ||
| 526 | g_object_set(renderer, "text", buf, NULL); | |
| 527 | } | |
| 528 | ||
| 529 | /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
| 530 | infinity-0. you can still click again to reverse it on any of them. */ | |
| 531 | static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
| 532 | { | |
| 533 | int c, d; | |
| 534 | ||
| 535 | c = d = 0; | |
| 536 | ||
| 537 | gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
| 538 | gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
| 539 | ||
| 540 | if (c == d) | |
| 541 | return 0; | |
| 542 | else if (c > d) | |
| 543 | return -1; | |
| 544 | else | |
| 545 | return 1; | |
| 546 | } | |
| 547 | ||
|
11490
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
548 | static gboolean |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
549 | _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
|
550 | { |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
551 | gboolean result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
552 | gchar *name, *fold, *fkey; |
|
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 | gtk_tree_model_get(model, iter, column, &name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
555 | fold = g_utf8_casefold(name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
556 | fkey = g_utf8_casefold(key, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
557 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
558 | result = (g_strstr_len(fold, strlen(fold), fkey) == NULL); |
|
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 | g_free(fold); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
561 | g_free(fkey); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
562 | g_free(name); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
563 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
564 | return result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
565 | } |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
566 | |
| 15884 | 567 | static void pidgin_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
| 8113 | 568 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
569 | PidginRoomlist *grl = list->ui_data; |
| 8113 | 570 | gint columns = NUM_OF_COLUMNS; |
| 571 | int j; | |
| 572 | GtkTreeStore *model; | |
| 573 | GtkWidget *tree; | |
| 574 | GtkCellRenderer *renderer; | |
| 575 | GtkTreeViewColumn *column; | |
| 8199 | 576 | GtkTreeSelection *selection; |
| 8113 | 577 | GList *l; |
| 578 | GType *types; | |
| 579 | ||
| 580 | g_return_if_fail(grl != NULL); | |
| 581 | ||
| 582 | columns += g_list_length(fields); | |
| 583 | types = g_new(GType, columns); | |
| 584 | ||
| 585 | types[NAME_COLUMN] = G_TYPE_STRING; | |
| 586 | types[ROOM_COLUMN] = G_TYPE_POINTER; | |
| 587 | ||
| 588 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 589 | PurpleRoomlistField *f = l->data; |
| 8113 | 590 | |
| 591 | switch (f->type) { | |
| 15884 | 592 | case PURPLE_ROOMLIST_FIELD_BOOL: |
| 8113 | 593 | types[j] = G_TYPE_BOOLEAN; |
| 594 | break; | |
| 15884 | 595 | case PURPLE_ROOMLIST_FIELD_INT: |
| 8113 | 596 | types[j] = G_TYPE_INT; |
| 597 | break; | |
| 15884 | 598 | case PURPLE_ROOMLIST_FIELD_STRING: |
| 8113 | 599 | types[j] = G_TYPE_STRING; |
| 600 | break; | |
| 601 | } | |
| 602 | } | |
| 603 | ||
| 604 | model = gtk_tree_store_newv(columns, types); | |
| 605 | g_free(types); | |
| 606 | ||
| 607 | tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
| 608 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
| 609 | ||
| 8199 | 610 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
| 611 | g_signal_connect(G_OBJECT(selection), "changed", | |
| 612 | G_CALLBACK(selection_changed_cb), grl); | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13448
diff
changeset
|
613 | |
| 8113 | 614 | g_object_unref(model); |
| 615 | ||
| 616 | grl->model = model; | |
| 617 | grl->tree = tree; | |
| 618 | gtk_widget_show(grl->tree); | |
| 619 | ||
| 620 | renderer = gtk_cell_renderer_text_new(); | |
| 621 | column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
| 622 | "text", NAME_COLUMN, NULL); | |
| 623 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 624 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 625 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 626 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
| 627 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 628 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 629 | ||
| 630 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 631 | PurpleRoomlistField *f = l->data; |
| 8113 | 632 | |
| 633 | if (f->hidden) | |
| 634 | continue; | |
| 635 | ||
| 636 | renderer = gtk_cell_renderer_text_new(); | |
| 637 | column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
| 638 | "text", j, NULL); | |
| 639 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 640 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 641 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 642 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
| 643 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 15884 | 644 | if (f->type == PURPLE_ROOMLIST_FIELD_INT) { |
| 8113 | 645 | gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, |
| 646 | GINT_TO_POINTER(j), NULL); | |
| 647 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
| 648 | GINT_TO_POINTER(j), NULL); | |
| 649 | } | |
| 650 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 651 | } | |
| 652 | ||
| 653 | g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
| 654 | g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
| 655 | 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
|
656 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
657 | /* Enable CTRL+F searching */ |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
658 | 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
|
659 | 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
|
660 | |
| 8113 | 661 | } |
| 662 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
663 | static gboolean pidgin_progress_bar_pulse(gpointer data) |
| 8230 | 664 | { |
| 15884 | 665 | PurpleRoomlist *list = data; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
666 | PidginRoomlist *rl = list->ui_data; |
| 8230 | 667 | |
| 668 | if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
|
13448
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
669 | if (rl && rl->dialog) |
|
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
670 | rl->dialog->pg_to_active = FALSE; |
| 15884 | 671 | purple_roomlist_unref(list); |
| 8230 | 672 | return FALSE; |
| 673 | } | |
| 674 | ||
| 675 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
| 676 | rl->dialog->pg_needs_pulse = FALSE; | |
| 677 | return TRUE; | |
| 678 | } | |
| 679 | ||
| 15884 | 680 | static void pidgin_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8113 | 681 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
682 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 683 | GtkTreeRowReference *rr, *parentrr = NULL; |
| 684 | GtkTreePath *path; | |
| 685 | GtkTreeIter iter, parent, child; | |
| 686 | GList *l, *k; | |
| 687 | int j; | |
| 688 | gboolean append = TRUE; | |
| 689 | ||
| 690 | rl->total_rooms++; | |
| 15884 | 691 | if (room->type == PURPLE_ROOMLIST_ROOMTYPE_ROOM) |
| 8113 | 692 | rl->num_rooms++; |
| 693 | ||
| 694 | if (rl->dialog) { | |
| 8230 | 695 | if (!rl->dialog->pg_to_active) { |
| 696 | rl->dialog->pg_to_active = TRUE; | |
| 15884 | 697 | purple_roomlist_ref(list); |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
698 | rl->dialog->pg_update_to = g_timeout_add(100, pidgin_progress_bar_pulse, list); |
| 8230 | 699 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); |
| 700 | } else { | |
| 701 | rl->dialog->pg_needs_pulse = TRUE; | |
| 702 | } | |
| 8113 | 703 | } |
| 704 | if (room->parent) { | |
| 705 | parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
| 706 | path = gtk_tree_row_reference_get_path(parentrr); | |
| 707 | if (path) { | |
| 15884 | 708 | PurpleRoomlistRoom *tmproom = NULL; |
| 8113 | 709 | |
| 710 | gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
| 711 | gtk_tree_path_free(path); | |
| 712 | ||
| 713 | if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
| 714 | gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
| 715 | if (!tmproom) | |
| 716 | append = FALSE; | |
| 717 | } | |
| 718 | } | |
| 719 | } | |
| 720 | ||
| 721 | if (append) | |
| 722 | gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
| 723 | else | |
| 724 | iter = child; | |
| 725 | ||
| 15884 | 726 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) |
| 8113 | 727 | gtk_tree_store_append(rl->model, &child, &iter); |
| 728 | ||
| 729 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
| 730 | ||
| 15884 | 731 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) { |
| 8113 | 732 | rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); |
| 733 | g_hash_table_insert(rl->cats, room, rr); | |
| 734 | } | |
| 735 | ||
| 736 | gtk_tree_path_free(path); | |
| 737 | ||
| 738 | gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
| 739 | gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
| 740 | ||
| 741 | for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
| 15884 | 742 | PurpleRoomlistField *f = k->data; |
| 8113 | 743 | if (f->hidden) |
| 744 | continue; | |
| 745 | gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
| 746 | } | |
| 747 | } | |
| 748 | ||
| 15884 | 749 | static void pidgin_roomlist_in_progress(PurpleRoomlist *list, gboolean flag) |
| 8113 | 750 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
751 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 752 | |
| 753 | if (!rl || !rl->dialog) | |
| 754 | return; | |
| 755 | ||
| 756 | if (flag) { | |
| 8199 | 757 | if (rl->dialog->account_widget) |
| 758 | gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
| 759 | gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
| 760 | gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
| 8113 | 761 | } else { |
| 8230 | 762 | rl->dialog->pg_needs_pulse = FALSE; |
| 8113 | 763 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
| 8199 | 764 | if (rl->dialog->account_widget) |
| 765 | gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
| 766 | gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
| 767 | gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
| 8113 | 768 | } |
| 769 | } | |
| 770 | ||
| 15884 | 771 | static void pidgin_roomlist_destroy(PurpleRoomlist *list) |
| 8113 | 772 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
773 | PidginRoomlist *rl; |
| 8113 | 774 | |
| 775 | roomlists = g_list_remove(roomlists, list); | |
| 776 | ||
| 777 | rl = list->ui_data; | |
| 778 | ||
| 779 | g_return_if_fail(rl != NULL); | |
| 780 | ||
| 781 | g_hash_table_destroy(rl->cats); | |
| 782 | g_free(rl); | |
| 783 | list->ui_data = NULL; | |
| 784 | } | |
| 785 | ||
| 15884 | 786 | static PurpleRoomlistUiOps ops = { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
787 | pidgin_roomlist_dialog_show_with_account, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
788 | pidgin_roomlist_new, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
789 | pidgin_roomlist_set_fields, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
790 | pidgin_roomlist_add_room, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
791 | pidgin_roomlist_in_progress, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
792 | pidgin_roomlist_destroy |
| 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 | } |