]> git.0d.be Git - empathy.git/blob - src/empathy-new-chatroom-dialog.c
abfdcf0acefa32de6f5d5a5817f61f6eeeb33add
[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_get_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_get_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
414 static void
415 new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist        *room_list,
416                                          EmpathyNewChatroomDialog *dialog)
417 {
418         g_object_unref (dialog->room_list);
419         dialog->room_list = NULL;
420 }
421
422 static void
423 new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
424                                  EmpathyChatroom          *chatroom,
425                                  EmpathyNewChatroomDialog *dialog)
426 {
427         GtkTreeView      *view;
428         GtkTreeSelection *selection;
429         GtkListStore     *store;
430         GtkTreeIter       iter;
431         gchar            *members;
432         gchar            *tooltip;
433         const gchar      *need_password;
434         const gchar      *invite_only;
435
436         DEBUG ("New chatroom listed: %s (%s)",
437                 empathy_chatroom_get_name (chatroom),
438                 empathy_chatroom_get_room (chatroom));
439
440         /* Add to model */
441         view = GTK_TREE_VIEW (dialog->treeview);
442         selection = gtk_tree_view_get_selection (view);
443         store = GTK_LIST_STORE (dialog->model);
444         members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
445         tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
446                 "are a channel name, yes/no, yes/no and a number.",
447                 "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
448                 empathy_chatroom_get_name (chatroom),
449                 empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
450                 empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
451                 members);
452         invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
453                 GTK_STOCK_INDEX : NULL);
454         need_password = (empathy_chatroom_get_need_password (chatroom) ?
455                 GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
456
457         gtk_list_store_append (store, &iter);
458         gtk_list_store_set (store, &iter,
459                             COL_NEED_PASSWORD, need_password,
460                             COL_INVITE_ONLY, invite_only,
461                             COL_NAME, empathy_chatroom_get_name (chatroom),
462                             COL_ROOM, empathy_chatroom_get_room (chatroom),
463                             COL_MEMBERS, members,
464                             COL_TOOLTIP, tooltip,
465                             -1);
466
467         g_free (members);
468         g_free (tooltip);
469 }
470
471 static void
472 new_chatroom_dialog_listing_cb (EmpathyTpRoomlist        *room_list,
473                                 gpointer                  unused,
474                                 EmpathyNewChatroomDialog *dialog)
475 {
476         gboolean listing;
477
478         listing = empathy_tp_roomlist_is_listing (room_list);
479
480         /* Update the throbber */
481         if (listing) {
482                 ephy_spinner_start (EPHY_SPINNER (dialog->throbber));           
483         } else {
484                 ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
485         }
486 }
487
488 static void
489 new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *dialog)
490 {
491         GtkListStore *store;
492
493         store = GTK_LIST_STORE (dialog->model);
494         gtk_list_store_clear (store);
495 }
496
497 static void
498 new_chatroom_dialog_model_row_activated_cb (GtkTreeView             *tree_view,
499                                             GtkTreePath             *path,
500                                             GtkTreeViewColumn       *column,
501                                             EmpathyNewChatroomDialog *dialog)
502 {
503         gtk_widget_activate (dialog->button_join);
504 }
505
506 static void
507 new_chatroom_dialog_model_selection_changed (GtkTreeSelection         *selection,
508                                              EmpathyNewChatroomDialog *dialog)
509 {       
510         GtkTreeModel *model;
511         GtkTreeIter   iter;
512         gchar        *room = NULL;
513         gchar        *server = NULL;
514
515         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
516                 return;
517         }
518
519         gtk_tree_model_get (model, &iter, COL_ROOM, &room, -1);
520         server = strstr (room, "@");
521         if (server) {
522                 *server = '\0';
523                 server++;
524         }
525
526         gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), server ? server : "");
527         gtk_entry_set_text (GTK_ENTRY (dialog->entry_room), room ? room : "");
528
529         g_free (room);
530 }
531
532 static void
533 new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
534 {
535         EmpathyAccountChooser *account_chooser;
536         TpConnection          *connection;
537         const gchar           *room;
538         const gchar           *server = NULL;
539         gchar                 *room_name = NULL;
540
541         room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
542         server = gtk_entry_get_text (GTK_ENTRY (dialog->entry_server));
543
544         account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
545         connection = empathy_account_chooser_get_connection (account_chooser);
546
547         if (!EMP_STR_EMPTY (server)) {
548                 room_name = g_strconcat (room, "@", server, NULL);
549         } else {
550                 room_name = g_strdup (room);
551         }
552
553         DEBUG ("Requesting channel for '%s'", room_name);
554         empathy_dispatcher_join_muc (connection, room_name, NULL, NULL);
555
556         g_free (room_name);
557 }
558
559 static void
560 new_chatroom_dialog_entry_changed_cb (GtkWidget                *entry,
561                                       EmpathyNewChatroomDialog *dialog)
562 {
563         if (entry == dialog->entry_room) {
564                 const gchar *room;
565
566                 room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
567                 gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
568                 /* FIXME: Select the room in the list */
569         }
570 }
571
572 static void
573 new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *dialog)
574 {
575         new_chatroom_dialog_model_clear (dialog);
576         if (dialog->room_list) {
577                 empathy_tp_roomlist_start (dialog->room_list);
578         }
579 }
580
581 static void
582 new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog *dialog)
583 {
584         if (dialog->room_list) {
585                 empathy_tp_roomlist_stop (dialog->room_list);
586         }
587 }
588
589 static void
590 new_chatroom_dialog_entry_server_activate_cb (GtkWidget                *widget,
591                                               EmpathyNewChatroomDialog  *dialog)
592 {
593         new_chatroom_dialog_browse_start (dialog);
594 }
595
596 static void
597 new_chatroom_dialog_expander_browse_activate_cb (GtkWidget               *widget,
598                                                  EmpathyNewChatroomDialog *dialog)
599 {
600         gboolean expanded;
601
602         expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
603         if (expanded) {
604                 new_chatroom_dialog_browse_stop (dialog);
605                 gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
606         } else {
607                 new_chatroom_dialog_browse_start (dialog);
608                 gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
609         }
610 }
611
612 static gboolean
613 new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget               *widget,
614                                                GdkEventFocus           *event,
615                                                EmpathyNewChatroomDialog *dialog)
616 {
617         gboolean expanded;
618
619         expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
620         if (expanded) {
621                 new_chatroom_dialog_browse_start (dialog);
622         }
623         return FALSE;
624 }