]> git.0d.be Git - empathy.git/blob - src/empathy-new-chatroom-dialog.c
Renamed empathy_account_chooser_get_account to empathy_account_chooser_dup_account...
[empathy.git] / src / empathy-new-chatroom-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2006-2007 Imendio AB
4  * Copyright (C) 2007-2008 Collabora Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  * 
21  * Authors: Martyn Russell <martyn@imendio.com>
22  *          Xavier Claessens <xclaesse@gmail.com>
23  */
24
25 #include <config.h>
26
27 #include <string.h>
28 #include <stdio.h>
29
30 #include <gtk/gtk.h>
31 #include <glib.h>
32 #include <glib/gi18n.h>
33
34 #include <libmissioncontrol/mission-control.h>
35 #include <libmissioncontrol/mc-account.h>
36 #include <libmissioncontrol/mc-profile.h>
37
38 #include <libempathy/empathy-tp-roomlist.h>
39 #include <libempathy/empathy-chatroom.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy/empathy-dispatcher.h>
42
43 #include <libempathy-gtk/empathy-account-chooser.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45
46 #include "empathy-new-chatroom-dialog.h"
47 #include "ephy-spinner.h"
48
49 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
50 #include <libempathy/empathy-debug.h>
51
52 typedef struct {
53         EmpathyTpRoomlist *room_list;
54
55         GtkWidget         *window;
56         GtkWidget         *vbox_widgets;
57         GtkWidget         *table_info;
58         GtkWidget         *label_account;
59         GtkWidget         *account_chooser;
60         GtkWidget         *label_server;
61         GtkWidget         *entry_server;
62         GtkWidget         *label_room;
63         GtkWidget         *entry_room;
64         GtkWidget         *expander_browse;
65         GtkWidget         *throbber;
66         GtkWidget         *treeview;
67         GtkTreeModel      *model;
68         GtkWidget         *button_join;
69         GtkWidget         *button_close;
70 } EmpathyNewChatroomDialog;
71
72 enum {
73         COL_NEED_PASSWORD,
74         COL_INVITE_ONLY,
75         COL_NAME,
76         COL_ROOM,
77         COL_MEMBERS,
78         COL_TOOLTIP,
79         COL_COUNT
80 };
81
82 static void     new_chatroom_dialog_response_cb                     (GtkWidget               *widget,
83                                                                      gint                     response,
84                                                                      EmpathyNewChatroomDialog *dialog);
85 static void     new_chatroom_dialog_destroy_cb                      (GtkWidget               *widget,
86                                                                      EmpathyNewChatroomDialog *dialog);
87 static void     new_chatroom_dialog_model_setup                     (EmpathyNewChatroomDialog *dialog);
88 static void     new_chatroom_dialog_model_add_columns               (EmpathyNewChatroomDialog *dialog);
89 static void     new_chatroom_dialog_update_widgets                  (EmpathyNewChatroomDialog *dialog);
90 static void     new_chatroom_dialog_account_changed_cb              (GtkComboBox              *combobox,
91                                                                      EmpathyNewChatroomDialog *dialog);
92 static void     new_chatroom_dialog_roomlist_destroy_cb             (EmpathyTpRoomlist        *room_list,
93                                                                      EmpathyNewChatroomDialog *dialog);
94 static void     new_chatroom_dialog_new_room_cb                     (EmpathyTpRoomlist        *room_list,
95                                                                      EmpathyChatroom          *chatroom,
96                                                                      EmpathyNewChatroomDialog *dialog);
97 static void     new_chatroom_dialog_listing_cb                      (EmpathyTpRoomlist        *room_list,
98                                                                      gpointer                  unused,
99                                                                      EmpathyNewChatroomDialog *dialog);
100 static void     new_chatroom_dialog_model_clear                     (EmpathyNewChatroomDialog *dialog);
101 static void     new_chatroom_dialog_model_row_activated_cb          (GtkTreeView             *tree_view,
102                                                                      GtkTreePath             *path,
103                                                                      GtkTreeViewColumn       *column,
104                                                                      EmpathyNewChatroomDialog *dialog);
105 static void     new_chatroom_dialog_model_selection_changed         (GtkTreeSelection        *selection,
106                                                                      EmpathyNewChatroomDialog *dialog);
107 static void     new_chatroom_dialog_join                            (EmpathyNewChatroomDialog *dialog);
108 static void     new_chatroom_dialog_entry_changed_cb                (GtkWidget               *entry,
109                                                                      EmpathyNewChatroomDialog *dialog);
110 static void     new_chatroom_dialog_browse_start                    (EmpathyNewChatroomDialog *dialog);
111 static void     new_chatroom_dialog_browse_stop                     (EmpathyNewChatroomDialog *dialog);
112 static void     new_chatroom_dialog_entry_server_activate_cb        (GtkWidget               *widget,
113                                                                      EmpathyNewChatroomDialog *dialog);
114 static void     new_chatroom_dialog_expander_browse_activate_cb     (GtkWidget               *widget,
115                                                                      EmpathyNewChatroomDialog *dialog);
116 static gboolean new_chatroom_dialog_entry_server_focus_out_cb       (GtkWidget               *widget,
117                                                                      GdkEventFocus           *event,
118                                                                      EmpathyNewChatroomDialog *dialog);
119
120 static EmpathyNewChatroomDialog *dialog_p = NULL;
121
122 void
123 empathy_new_chatroom_dialog_show (GtkWindow *parent)
124 {
125         EmpathyNewChatroomDialog *dialog;
126         GtkBuilder               *gui;
127         GtkSizeGroup             *size_group;
128         gchar                    *filename;
129
130         if (dialog_p) {
131                 gtk_window_present (GTK_WINDOW (dialog_p->window));
132                 return;
133         }
134
135         dialog_p = dialog = g_new0 (EmpathyNewChatroomDialog, 1);
136
137         filename = empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src");
138         gui = empathy_builder_get_file (filename,
139                                        "new_chatroom_dialog", &dialog->window,
140                                        "table_info", &dialog->table_info,
141                                        "label_account", &dialog->label_account,
142                                        "label_server", &dialog->label_server,
143                                        "label_room", &dialog->label_room,
144                                        "entry_server", &dialog->entry_server,
145                                        "entry_room", &dialog->entry_room,
146                                        "treeview", &dialog->treeview,
147                                        "button_join", &dialog->button_join,
148                                        "expander_browse", &dialog->expander_browse,
149                                        NULL);
150         g_free (filename);
151
152         empathy_builder_connect (gui, dialog,
153                               "new_chatroom_dialog", "response", new_chatroom_dialog_response_cb,
154                               "new_chatroom_dialog", "destroy", new_chatroom_dialog_destroy_cb,
155                               "entry_server", "changed", new_chatroom_dialog_entry_changed_cb,
156                               "entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb,
157                               "entry_server", "focus-out-event", new_chatroom_dialog_entry_server_focus_out_cb,
158                               "entry_room", "changed", new_chatroom_dialog_entry_changed_cb,
159                               "expander_browse", "activate", new_chatroom_dialog_expander_browse_activate_cb,
160                               NULL);
161
162         g_object_unref (gui);
163
164         g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog_p);
165
166         /* Label alignment */
167         size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
168
169         gtk_size_group_add_widget (size_group, dialog->label_account);
170         gtk_size_group_add_widget (size_group, dialog->label_server);
171         gtk_size_group_add_widget (size_group, dialog->label_room);
172
173         g_object_unref (size_group);
174
175         /* Set up chatrooms treeview */
176         new_chatroom_dialog_model_setup (dialog);
177
178         /* Add throbber */
179         dialog->throbber = ephy_spinner_new ();
180         ephy_spinner_set_size (EPHY_SPINNER (dialog->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
181         gtk_widget_show (dialog->throbber);
182         gtk_table_attach (GTK_TABLE (dialog->table_info),
183                           dialog->throbber,
184                           2, 3, 0, 1,
185                           0, 0, 0, 0);
186
187         /* Account chooser for custom */
188         dialog->account_chooser = empathy_account_chooser_new ();
189         empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
190                                             empathy_account_chooser_filter_is_connected,
191                                             NULL);
192         gtk_table_attach_defaults (GTK_TABLE (dialog->table_info),
193                                    dialog->account_chooser,
194                                    1, 2, 0, 1);
195         gtk_widget_show (dialog->account_chooser);
196
197         g_signal_connect (GTK_COMBO_BOX (dialog->account_chooser), "changed",
198                           G_CALLBACK (new_chatroom_dialog_account_changed_cb),
199                           dialog);
200         new_chatroom_dialog_account_changed_cb (GTK_COMBO_BOX (dialog->account_chooser),
201                                                 dialog);
202
203         if (parent) {
204                 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
205                                               GTK_WINDOW (parent));
206         }
207
208         gtk_widget_show (dialog->window);
209 }
210
211 static void
212 new_chatroom_dialog_response_cb (GtkWidget               *widget,
213                                  gint                     response,
214                                  EmpathyNewChatroomDialog *dialog)
215 {
216         if (response == GTK_RESPONSE_OK) {
217                 new_chatroom_dialog_join (dialog);
218         }
219
220         gtk_widget_destroy (widget);
221 }
222
223 static void
224 new_chatroom_dialog_destroy_cb (GtkWidget               *widget,
225                                 EmpathyNewChatroomDialog *dialog)
226 {
227         if (dialog->room_list) {
228                 g_object_unref (dialog->room_list);
229         }
230         g_object_unref (dialog->model);  
231
232         g_free (dialog);
233 }
234
235 static void
236 new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog *dialog)
237 {
238         GtkTreeView      *view;
239         GtkListStore     *store;
240         GtkTreeSelection *selection;
241
242         /* View */
243         view = GTK_TREE_VIEW (dialog->treeview);
244
245         g_signal_connect (view, "row-activated",
246                           G_CALLBACK (new_chatroom_dialog_model_row_activated_cb),
247                           dialog);
248
249         /* Store/Model */
250         store = gtk_list_store_new (COL_COUNT,
251                                     G_TYPE_STRING,       /* Invite */
252                                     G_TYPE_STRING,       /* Password */
253                                     G_TYPE_STRING,       /* Name */
254                                     G_TYPE_STRING,       /* Room */
255                                     G_TYPE_STRING,       /* Member count */
256                                     G_TYPE_STRING);      /* Tool tip */
257
258         dialog->model = GTK_TREE_MODEL (store);
259         gtk_tree_view_set_model (view, dialog->model);
260         gtk_tree_view_set_tooltip_column (view, COL_TOOLTIP);
261         gtk_tree_view_set_search_column (view, COL_NAME);
262
263         /* Selection */
264         selection = gtk_tree_view_get_selection (view);
265         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
266                                               COL_NAME, GTK_SORT_ASCENDING);
267
268         g_signal_connect (selection, "changed",
269                           G_CALLBACK (new_chatroom_dialog_model_selection_changed),
270                           dialog);
271
272         /* Columns */
273         new_chatroom_dialog_model_add_columns (dialog);
274 }
275
276 static void
277 new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *dialog)
278 {
279         GtkTreeView       *view;
280         GtkTreeViewColumn *column;
281         GtkCellRenderer   *cell;
282         gint               width, height;
283
284         gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
285
286         view = GTK_TREE_VIEW (dialog->treeview);
287
288         cell = gtk_cell_renderer_pixbuf_new ();
289         g_object_set (cell,
290                       "width", width,
291                       "height", height,
292                       "stock-size", GTK_ICON_SIZE_MENU,
293                       NULL);
294         column = gtk_tree_view_column_new_with_attributes (NULL,
295                                                            cell,
296                                                            "stock-id", COL_INVITE_ONLY,
297                                                            NULL);
298         gtk_tree_view_append_column (view, column);
299
300         column = gtk_tree_view_column_new_with_attributes (NULL,
301                                                            cell,
302                                                            "stock-id", COL_NEED_PASSWORD,
303                                                            NULL);
304         gtk_tree_view_append_column (view, column);
305
306         cell = gtk_cell_renderer_text_new ();
307         g_object_set (cell,
308                       "xpad", (guint) 4,
309                       "ypad", (guint) 2,
310                       "ellipsize", PANGO_ELLIPSIZE_END,
311                       NULL);
312
313         column = gtk_tree_view_column_new_with_attributes (_("Chat Room"),
314                                                            cell,
315                                                            "text", COL_NAME,
316                                                            NULL);
317
318         gtk_tree_view_column_set_expand (column, TRUE);
319         gtk_tree_view_append_column (view, column);
320
321         cell = gtk_cell_renderer_text_new ();
322         g_object_set (cell,
323                       "xpad", (guint) 4,
324                       "ypad", (guint) 2,
325                       "ellipsize", PANGO_ELLIPSIZE_END,
326                       "alignment", PANGO_ALIGN_RIGHT,
327                       NULL);
328         column = gtk_tree_view_column_new_with_attributes (_("Members"),
329                                                            cell,
330                                                            "text", COL_MEMBERS,
331                                                            NULL);
332         gtk_tree_view_append_column (view, column);
333 }
334
335 static void
336 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
337 {
338         EmpathyAccountChooser *account_chooser;
339         McAccount             *account;
340         McProfile             *profile;
341         const gchar           *protocol;
342         const gchar           *room;
343         
344         account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
345         account = empathy_account_chooser_dup_account (account_chooser);
346         profile = mc_account_get_profile (account);
347         protocol = mc_profile_get_protocol_name (profile);
348
349         gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
350
351         /* hardcode here known protocols */
352         if (strcmp (protocol, "jabber") == 0) {
353                 gtk_widget_set_sensitive (dialog->entry_server, TRUE);
354         }
355         else if (strcmp (protocol, "local-xmpp") == 0) {
356                 gtk_widget_set_sensitive (dialog->entry_server, FALSE);
357         }
358         else if (strcmp (protocol, "irc") == 0) {
359                 gtk_widget_set_sensitive (dialog->entry_server, FALSE);
360         }
361         else {
362                 gtk_widget_set_sensitive (dialog->entry_server, TRUE);
363         }
364
365         room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
366         gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
367
368         /* Final set up of the dialog */
369         gtk_widget_grab_focus (dialog->entry_room);
370
371         g_object_unref (account);
372         g_object_unref (profile);
373 }
374
375 static void
376 new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
377                                         EmpathyNewChatroomDialog *dialog)
378 {
379         EmpathyAccountChooser *account_chooser;
380         McAccount             *account;
381         gboolean               listing = FALSE;
382
383         if (dialog->room_list) {
384                 g_object_unref (dialog->room_list);
385         }
386
387         ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
388         new_chatroom_dialog_model_clear (dialog);
389
390         account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
391         account = empathy_account_chooser_dup_account (account_chooser);
392         dialog->room_list = empathy_tp_roomlist_new (account);
393
394         if (dialog->room_list) {
395                 g_signal_connect (dialog->room_list, "destroy",
396                                   G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb),
397                                   dialog);
398                 g_signal_connect (dialog->room_list, "new-room",
399                                   G_CALLBACK (new_chatroom_dialog_new_room_cb),
400                                   dialog);
401                 g_signal_connect (dialog->room_list, "notify::is-listing",
402                                   G_CALLBACK (new_chatroom_dialog_listing_cb),
403                                   dialog);
404
405                 listing = empathy_tp_roomlist_is_listing (dialog->room_list);
406                 if (listing) {
407                         ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
408                 }
409         }
410
411         new_chatroom_dialog_update_widgets (dialog);
412
413         g_object_unref (account);
414 }
415
416 static void
417 new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist        *room_list,
418                                          EmpathyNewChatroomDialog *dialog)
419 {
420         g_object_unref (dialog->room_list);
421         dialog->room_list = NULL;
422 }
423
424 static void
425 new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
426                                  EmpathyChatroom          *chatroom,
427                                  EmpathyNewChatroomDialog *dialog)
428 {
429         GtkTreeView      *view;
430         GtkTreeSelection *selection;
431         GtkListStore     *store;
432         GtkTreeIter       iter;
433         gchar            *members;
434         gchar            *tooltip;
435         const gchar      *need_password;
436         const gchar      *invite_only;
437
438         DEBUG ("New chatroom listed: %s (%s)",
439                 empathy_chatroom_get_name (chatroom),
440                 empathy_chatroom_get_room (chatroom));
441
442         /* Add to model */
443         view = GTK_TREE_VIEW (dialog->treeview);
444         selection = gtk_tree_view_get_selection (view);
445         store = GTK_LIST_STORE (dialog->model);
446         members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
447         tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
448                 "are a channel name, yes/no, yes/no and a number.",
449                 "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
450                 empathy_chatroom_get_name (chatroom),
451                 empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
452                 empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
453                 members);
454         invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
455                 GTK_STOCK_INDEX : NULL);
456         need_password = (empathy_chatroom_get_need_password (chatroom) ?
457                 GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
458
459         gtk_list_store_append (store, &iter);
460         gtk_list_store_set (store, &iter,
461                             COL_NEED_PASSWORD, need_password,
462                             COL_INVITE_ONLY, invite_only,
463                             COL_NAME, empathy_chatroom_get_name (chatroom),
464                             COL_ROOM, empathy_chatroom_get_room (chatroom),
465                             COL_MEMBERS, members,
466                             COL_TOOLTIP, tooltip,
467                             -1);
468
469         g_free (members);
470         g_free (tooltip);
471 }
472
473 static void
474 new_chatroom_dialog_listing_cb (EmpathyTpRoomlist        *room_list,
475                                 gpointer                  unused,
476                                 EmpathyNewChatroomDialog *dialog)
477 {
478         gboolean listing;
479
480         listing = empathy_tp_roomlist_is_listing (room_list);
481
482         /* Update the throbber */
483         if (listing) {
484                 ephy_spinner_start (EPHY_SPINNER (dialog->throbber));           
485         } else {
486                 ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
487         }
488 }
489
490 static void
491 new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *dialog)
492 {
493         GtkListStore *store;
494
495         store = GTK_LIST_STORE (dialog->model);
496         gtk_list_store_clear (store);
497 }
498
499 static void
500 new_chatroom_dialog_model_row_activated_cb (GtkTreeView             *tree_view,
501                                             GtkTreePath             *path,
502                                             GtkTreeViewColumn       *column,
503                                             EmpathyNewChatroomDialog *dialog)
504 {
505         gtk_widget_activate (dialog->button_join);
506 }
507
508 static void
509 new_chatroom_dialog_model_selection_changed (GtkTreeSelection         *selection,
510                                              EmpathyNewChatroomDialog *dialog)
511 {       
512         GtkTreeModel *model;
513         GtkTreeIter   iter;
514         gchar        *room = NULL;
515         gchar        *server = NULL;
516
517         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
518                 return;
519         }
520
521         gtk_tree_model_get (model, &iter, COL_ROOM, &room, -1);
522         server = strstr (room, "@");
523         if (server) {
524                 *server = '\0';
525                 server++;
526         }
527
528         gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), server ? server : "");
529         gtk_entry_set_text (GTK_ENTRY (dialog->entry_room), room ? room : "");
530
531         g_free (room);
532 }
533
534 static void
535 new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
536 {
537         EmpathyAccountChooser *account_chooser;
538         TpConnection          *connection;
539         const gchar           *room;
540         const gchar           *server = NULL;
541         gchar                 *room_name = NULL;
542
543         room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
544         server = gtk_entry_get_text (GTK_ENTRY (dialog->entry_server));
545
546         account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
547         connection = empathy_account_chooser_get_connection (account_chooser);
548
549         if (!EMP_STR_EMPTY (server)) {
550                 room_name = g_strconcat (room, "@", server, NULL);
551         } else {
552                 room_name = g_strdup (room);
553         }
554
555         DEBUG ("Requesting channel for '%s'", room_name);
556         empathy_dispatcher_join_muc (connection, room_name, NULL, NULL);
557
558         g_free (room_name);
559 }
560
561 static void
562 new_chatroom_dialog_entry_changed_cb (GtkWidget                *entry,
563                                       EmpathyNewChatroomDialog *dialog)
564 {
565         if (entry == dialog->entry_room) {
566                 const gchar *room;
567
568                 room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
569                 gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
570                 /* FIXME: Select the room in the list */
571         }
572 }
573
574 static void
575 new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *dialog)
576 {
577         new_chatroom_dialog_model_clear (dialog);
578         if (dialog->room_list) {
579                 empathy_tp_roomlist_start (dialog->room_list);
580         }
581 }
582
583 static void
584 new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog *dialog)
585 {
586         if (dialog->room_list) {
587                 empathy_tp_roomlist_stop (dialog->room_list);
588         }
589 }
590
591 static void
592 new_chatroom_dialog_entry_server_activate_cb (GtkWidget                *widget,
593                                               EmpathyNewChatroomDialog  *dialog)
594 {
595         new_chatroom_dialog_browse_start (dialog);
596 }
597
598 static void
599 new_chatroom_dialog_expander_browse_activate_cb (GtkWidget               *widget,
600                                                  EmpathyNewChatroomDialog *dialog)
601 {
602         gboolean expanded;
603
604         expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
605         if (expanded) {
606                 new_chatroom_dialog_browse_stop (dialog);
607                 gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
608         } else {
609                 new_chatroom_dialog_browse_start (dialog);
610                 gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
611         }
612 }
613
614 static gboolean
615 new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget               *widget,
616                                                GdkEventFocus           *event,
617                                                EmpathyNewChatroomDialog *dialog)
618 {
619         gboolean expanded;
620
621         expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
622         if (expanded) {
623                 new_chatroom_dialog_browse_start (dialog);
624         }
625         return FALSE;
626 }