Updated German help translation
[empathy/ppotvin.git] / src / empathy-new-chatroom-dialog.c
blobf1ac7c2608f3e926f714200fafea32285d718c00
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.
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.
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.
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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
25 #include <config.h>
27 #include <string.h>
28 #include <stdio.h>
30 #include <gtk/gtk.h>
31 #include <glib.h>
32 #include <glib/gi18n.h>
33 #include <glib/gprintf.h>
35 #include <libempathy/empathy-tp-roomlist.h>
36 #include <libempathy/empathy-chatroom.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-dispatcher.h>
40 #include <libempathy-gtk/empathy-account-chooser.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include "empathy-new-chatroom-dialog.h"
44 #include "ephy-spinner.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
47 #include <libempathy/empathy-debug.h>
49 typedef struct {
50 EmpathyTpRoomlist *room_list;
51 /* Currently selected account */
52 TpAccount *account;
53 /* Signal id of the "status-changed" signal connected on the currently
54 * selected account */
55 gulong status_changed_id;
57 GtkWidget *window;
58 GtkWidget *vbox_widgets;
59 GtkWidget *table_info;
60 GtkWidget *label_account;
61 GtkWidget *account_chooser;
62 GtkWidget *label_server;
63 GtkWidget *entry_server;
64 GtkWidget *label_room;
65 GtkWidget *entry_room;
66 GtkWidget *expander_browse;
67 GtkWidget *throbber;
68 GtkWidget *treeview;
69 GtkTreeModel *model;
70 GtkWidget *button_join;
71 GtkWidget *label_error_message;
72 GtkWidget *viewport_error;
73 } EmpathyNewChatroomDialog;
75 enum {
76 COL_NEED_PASSWORD,
77 COL_INVITE_ONLY,
78 COL_NAME,
79 COL_ROOM,
80 COL_MEMBERS,
81 COL_MEMBERS_INT,
82 COL_TOOLTIP,
83 COL_COUNT
86 static void new_chatroom_dialog_response_cb (GtkWidget *widget,
87 gint response,
88 EmpathyNewChatroomDialog *dialog);
89 static void new_chatroom_dialog_destroy_cb (GtkWidget *widget,
90 EmpathyNewChatroomDialog *dialog);
91 static void new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog *dialog);
92 static void new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *dialog);
93 static void new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog);
94 static void new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox,
95 EmpathyNewChatroomDialog *dialog);
96 static void new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist *room_list,
97 EmpathyNewChatroomDialog *dialog);
98 static void new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist *room_list,
99 EmpathyChatroom *chatroom,
100 EmpathyNewChatroomDialog *dialog);
101 static void new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
102 gpointer unused,
103 EmpathyNewChatroomDialog *dialog);
104 static void start_listing_error_cb (EmpathyTpRoomlist *room_list,
105 GError *error,
106 EmpathyNewChatroomDialog *dialog);
107 static void stop_listing_error_cb (EmpathyTpRoomlist *room_list,
108 GError *error,
109 EmpathyNewChatroomDialog *dialog);
110 static void new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *dialog);
111 static void new_chatroom_dialog_model_row_activated_cb (GtkTreeView *tree_view,
112 GtkTreePath *path,
113 GtkTreeViewColumn *column,
114 EmpathyNewChatroomDialog *dialog);
115 static void new_chatroom_dialog_model_selection_changed (GtkTreeSelection *selection,
116 EmpathyNewChatroomDialog *dialog);
117 static void new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog);
118 static void new_chatroom_dialog_entry_changed_cb (GtkWidget *entry,
119 EmpathyNewChatroomDialog *dialog);
120 static void new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *dialog);
121 static void new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog *dialog);
122 static void new_chatroom_dialog_entry_server_activate_cb (GtkWidget *widget,
123 EmpathyNewChatroomDialog *dialog);
124 static void new_chatroom_dialog_expander_browse_activate_cb (GtkWidget *widget,
125 EmpathyNewChatroomDialog *dialog);
126 static gboolean new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget *widget,
127 GdkEventFocus *event,
128 EmpathyNewChatroomDialog *dialog);
129 static void new_chatroom_dialog_button_close_error_clicked_cb (GtkButton *button,
130 EmpathyNewChatroomDialog *dialog);
132 static EmpathyNewChatroomDialog *dialog_p = NULL;
134 void
135 empathy_new_chatroom_dialog_show (GtkWindow *parent)
137 EmpathyNewChatroomDialog *dialog;
138 GtkBuilder *gui;
139 GtkSizeGroup *size_group;
140 gchar *filename;
142 if (dialog_p) {
143 gtk_window_present (GTK_WINDOW (dialog_p->window));
144 return;
147 dialog_p = dialog = g_new0 (EmpathyNewChatroomDialog, 1);
149 filename = empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src");
150 gui = empathy_builder_get_file (filename,
151 "new_chatroom_dialog", &dialog->window,
152 "table_info", &dialog->table_info,
153 "label_account", &dialog->label_account,
154 "label_server", &dialog->label_server,
155 "label_room", &dialog->label_room,
156 "entry_server", &dialog->entry_server,
157 "entry_room", &dialog->entry_room,
158 "treeview", &dialog->treeview,
159 "button_join", &dialog->button_join,
160 "expander_browse", &dialog->expander_browse,
161 "label_error_message", &dialog->label_error_message,
162 "viewport_error", &dialog->viewport_error,
163 NULL);
164 g_free (filename);
166 empathy_builder_connect (gui, dialog,
167 "new_chatroom_dialog", "response", new_chatroom_dialog_response_cb,
168 "new_chatroom_dialog", "destroy", new_chatroom_dialog_destroy_cb,
169 "entry_server", "changed", new_chatroom_dialog_entry_changed_cb,
170 "entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb,
171 "entry_server", "focus-out-event", new_chatroom_dialog_entry_server_focus_out_cb,
172 "entry_room", "changed", new_chatroom_dialog_entry_changed_cb,
173 "expander_browse", "activate", new_chatroom_dialog_expander_browse_activate_cb,
174 "button_close_error", "clicked", new_chatroom_dialog_button_close_error_clicked_cb,
175 NULL);
177 g_object_unref (gui);
179 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog_p);
181 /* Label alignment */
182 size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
184 gtk_size_group_add_widget (size_group, dialog->label_account);
185 gtk_size_group_add_widget (size_group, dialog->label_server);
186 gtk_size_group_add_widget (size_group, dialog->label_room);
188 g_object_unref (size_group);
190 /* Set up chatrooms treeview */
191 new_chatroom_dialog_model_setup (dialog);
193 /* Add throbber */
194 dialog->throbber = ephy_spinner_new ();
195 ephy_spinner_set_size (EPHY_SPINNER (dialog->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
196 gtk_widget_show (dialog->throbber);
197 gtk_table_attach (GTK_TABLE (dialog->table_info),
198 dialog->throbber,
199 2, 3, 0, 1,
200 0, 0, 0, 0);
202 /* Account chooser for custom */
203 dialog->account_chooser = empathy_account_chooser_new ();
204 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
205 empathy_account_chooser_filter_is_connected,
206 NULL);
207 gtk_table_attach_defaults (GTK_TABLE (dialog->table_info),
208 dialog->account_chooser,
209 1, 2, 0, 1);
210 gtk_widget_show (dialog->account_chooser);
212 g_signal_connect (GTK_COMBO_BOX (dialog->account_chooser), "changed",
213 G_CALLBACK (new_chatroom_dialog_account_changed_cb),
214 dialog);
215 new_chatroom_dialog_account_changed_cb (GTK_COMBO_BOX (dialog->account_chooser),
216 dialog);
218 if (parent) {
219 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
220 GTK_WINDOW (parent));
223 gtk_widget_show (dialog->window);
226 static void
227 new_chatroom_dialog_response_cb (GtkWidget *widget,
228 gint response,
229 EmpathyNewChatroomDialog *dialog)
231 if (response == GTK_RESPONSE_OK) {
232 new_chatroom_dialog_join (dialog);
235 gtk_widget_destroy (widget);
238 static void
239 new_chatroom_dialog_destroy_cb (GtkWidget *widget,
240 EmpathyNewChatroomDialog *dialog)
242 if (dialog->room_list) {
243 g_object_unref (dialog->room_list);
245 g_object_unref (dialog->model);
247 if (dialog->account != NULL) {
248 g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
249 g_object_unref (dialog->account);
252 g_free (dialog);
255 static void
256 new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog *dialog)
258 GtkTreeView *view;
259 GtkListStore *store;
260 GtkTreeSelection *selection;
262 /* View */
263 view = GTK_TREE_VIEW (dialog->treeview);
265 g_signal_connect (view, "row-activated",
266 G_CALLBACK (new_chatroom_dialog_model_row_activated_cb),
267 dialog);
269 /* Store/Model */
270 store = gtk_list_store_new (COL_COUNT,
271 G_TYPE_STRING, /* Invite */
272 G_TYPE_STRING, /* Password */
273 G_TYPE_STRING, /* Name */
274 G_TYPE_STRING, /* Room */
275 G_TYPE_STRING, /* Member count */
276 G_TYPE_INT, /* Member count int */
277 G_TYPE_STRING); /* Tool tip */
279 dialog->model = GTK_TREE_MODEL (store);
280 gtk_tree_view_set_model (view, dialog->model);
281 gtk_tree_view_set_tooltip_column (view, COL_TOOLTIP);
282 gtk_tree_view_set_search_column (view, COL_NAME);
284 /* Selection */
285 selection = gtk_tree_view_get_selection (view);
286 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
287 COL_NAME, GTK_SORT_ASCENDING);
289 g_signal_connect (selection, "changed",
290 G_CALLBACK (new_chatroom_dialog_model_selection_changed),
291 dialog);
293 /* Columns */
294 new_chatroom_dialog_model_add_columns (dialog);
297 static void
298 new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *dialog)
300 GtkTreeView *view;
301 GtkTreeViewColumn *column;
302 GtkCellRenderer *cell;
303 gint width, height;
305 gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
307 view = GTK_TREE_VIEW (dialog->treeview);
309 cell = gtk_cell_renderer_pixbuf_new ();
310 g_object_set (cell,
311 "width", width,
312 "height", height,
313 "stock-size", GTK_ICON_SIZE_MENU,
314 NULL);
315 column = gtk_tree_view_column_new_with_attributes (NULL,
316 cell,
317 "stock-id", COL_INVITE_ONLY,
318 NULL);
320 gtk_tree_view_column_set_sort_column_id (column, COL_INVITE_ONLY);
321 gtk_tree_view_append_column (view, column);
323 column = gtk_tree_view_column_new_with_attributes (NULL,
324 cell,
325 "stock-id", COL_NEED_PASSWORD,
326 NULL);
328 gtk_tree_view_column_set_sort_column_id (column, COL_NEED_PASSWORD);
329 gtk_tree_view_append_column (view, column);
331 cell = gtk_cell_renderer_text_new ();
332 g_object_set (cell,
333 "xpad", (guint) 4,
334 "ypad", (guint) 2,
335 "ellipsize", PANGO_ELLIPSIZE_END,
336 NULL);
338 column = gtk_tree_view_column_new_with_attributes (_("Chat Room"),
339 cell,
340 "text", COL_NAME,
341 NULL);
343 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
344 gtk_tree_view_column_set_expand (column, TRUE);
345 gtk_tree_view_append_column (view, column);
347 cell = gtk_cell_renderer_text_new ();
348 g_object_set (cell,
349 "xpad", (guint) 4,
350 "ypad", (guint) 2,
351 "ellipsize", PANGO_ELLIPSIZE_END,
352 "alignment", PANGO_ALIGN_RIGHT,
353 NULL);
354 column = gtk_tree_view_column_new_with_attributes (_("Members"),
355 cell,
356 "text", COL_MEMBERS,
357 NULL);
359 gtk_tree_view_column_set_sort_column_id (column, COL_MEMBERS_INT);
360 gtk_tree_view_append_column (view, column);
363 static void
364 update_join_button_sensitivity (EmpathyNewChatroomDialog *dialog)
366 const gchar *room;
367 gboolean sensitive = FALSE;
370 room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
371 if (EMP_STR_EMPTY (room))
372 goto out;
374 if (dialog->account == NULL)
375 goto out;
377 if (tp_account_get_connection_status (dialog->account, NULL) !=
378 TP_CONNECTION_STATUS_CONNECTED)
379 goto out;
381 sensitive = TRUE;
383 out:
384 gtk_widget_set_sensitive (dialog->button_join, sensitive);
387 static void
388 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
390 EmpathyAccountChooser *account_chooser;
391 const gchar *protocol;
393 account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
395 if (dialog->account == NULL)
396 return;
398 protocol = tp_account_get_protocol (dialog->account);
400 gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
402 /* hardcode here known protocols */
403 if (strcmp (protocol, "jabber") == 0) {
404 gtk_widget_set_sensitive (dialog->entry_server, TRUE);
406 else if (strcmp (protocol, "local-xmpp") == 0) {
407 gtk_widget_set_sensitive (dialog->entry_server, FALSE);
409 else if (strcmp (protocol, "irc") == 0) {
410 gtk_widget_set_sensitive (dialog->entry_server, FALSE);
412 else {
413 gtk_widget_set_sensitive (dialog->entry_server, TRUE);
416 update_join_button_sensitivity (dialog);
418 /* Final set up of the dialog */
419 gtk_widget_grab_focus (dialog->entry_room);
422 static void
423 account_status_changed_cb (TpAccount *account,
424 guint old_status,
425 guint new_status,
426 guint reason,
427 gchar *dbus_error_name,
428 GHashTable *details,
429 EmpathyNewChatroomDialog *self)
431 update_join_button_sensitivity (self);
434 static void
435 new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox,
436 EmpathyNewChatroomDialog *dialog)
438 EmpathyAccountChooser *account_chooser;
439 gboolean listing = FALSE;
440 gboolean expanded = FALSE;
442 if (dialog->room_list) {
443 g_object_unref (dialog->room_list);
444 dialog->room_list = NULL;
447 ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
448 new_chatroom_dialog_model_clear (dialog);
450 if (dialog->account != NULL) {
451 g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
452 g_object_unref (dialog->account);
455 account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
456 dialog->account = empathy_account_chooser_dup_account (account_chooser);
457 if (dialog->account == NULL)
458 goto out;
460 dialog->status_changed_id = g_signal_connect (dialog->account,
461 "status-changed", G_CALLBACK (account_status_changed_cb), dialog);
463 dialog->room_list = empathy_tp_roomlist_new (dialog->account);
465 if (dialog->room_list) {
466 g_signal_connect (dialog->room_list, "destroy",
467 G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb),
468 dialog);
469 g_signal_connect (dialog->room_list, "new-room",
470 G_CALLBACK (new_chatroom_dialog_new_room_cb),
471 dialog);
472 g_signal_connect (dialog->room_list, "notify::is-listing",
473 G_CALLBACK (new_chatroom_dialog_listing_cb),
474 dialog);
475 g_signal_connect (dialog->room_list, "error::start",
476 G_CALLBACK (start_listing_error_cb),
477 dialog);
478 g_signal_connect (dialog->room_list, "error::stop",
479 G_CALLBACK (stop_listing_error_cb),
480 dialog);
482 expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
483 if (expanded) {
484 gtk_widget_hide (dialog->viewport_error);
485 gtk_widget_set_sensitive (dialog->treeview, TRUE);
486 new_chatroom_dialog_browse_start (dialog);
489 listing = empathy_tp_roomlist_is_listing (dialog->room_list);
490 if (listing) {
491 ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
495 out:
496 new_chatroom_dialog_update_widgets (dialog);
499 static void
500 new_chatroom_dialog_button_close_error_clicked_cb (GtkButton *button,
501 EmpathyNewChatroomDialog *dialog)
503 gtk_widget_hide (dialog->viewport_error);
506 static void
507 new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist *room_list,
508 EmpathyNewChatroomDialog *dialog)
510 g_object_unref (dialog->room_list);
511 dialog->room_list = NULL;
514 static void
515 new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist *room_list,
516 EmpathyChatroom *chatroom,
517 EmpathyNewChatroomDialog *dialog)
519 GtkTreeView *view;
520 GtkTreeSelection *selection;
521 GtkListStore *store;
522 GtkTreeIter iter;
523 gchar *members;
524 gchar *tooltip;
525 const gchar *need_password;
526 const gchar *invite_only;
528 DEBUG ("New chatroom listed: %s (%s)",
529 empathy_chatroom_get_name (chatroom),
530 empathy_chatroom_get_room (chatroom));
532 /* Add to model */
533 view = GTK_TREE_VIEW (dialog->treeview);
534 selection = gtk_tree_view_get_selection (view);
535 store = GTK_LIST_STORE (dialog->model);
536 members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
537 tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
538 "are a channel name, yes/no, yes/no and a number.",
539 "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
540 empathy_chatroom_get_name (chatroom),
541 empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
542 empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
543 members);
544 invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
545 GTK_STOCK_INDEX : NULL);
546 need_password = (empathy_chatroom_get_need_password (chatroom) ?
547 GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
549 gtk_list_store_append (store, &iter);
550 gtk_list_store_set (store, &iter,
551 COL_NEED_PASSWORD, need_password,
552 COL_INVITE_ONLY, invite_only,
553 COL_NAME, empathy_chatroom_get_name (chatroom),
554 COL_ROOM, empathy_chatroom_get_room (chatroom),
555 COL_MEMBERS, members,
556 COL_MEMBERS_INT, empathy_chatroom_get_members_count (chatroom),
557 COL_TOOLTIP, tooltip,
558 -1);
560 g_free (members);
561 g_free (tooltip);
564 static void
565 start_listing_error_cb (EmpathyTpRoomlist *room_list,
566 GError *error,
567 EmpathyNewChatroomDialog *dialog)
569 gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not start room listing"));
570 gtk_widget_show_all (dialog->viewport_error);
571 gtk_widget_set_sensitive (dialog->treeview, FALSE);
574 static void
575 stop_listing_error_cb (EmpathyTpRoomlist *room_list,
576 GError *error,
577 EmpathyNewChatroomDialog *dialog)
579 gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not stop room listing"));
580 gtk_widget_show_all (dialog->viewport_error);
581 gtk_widget_set_sensitive (dialog->treeview, FALSE);
584 static void
585 new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
586 gpointer unused,
587 EmpathyNewChatroomDialog *dialog)
589 gboolean listing;
591 listing = empathy_tp_roomlist_is_listing (room_list);
593 /* Update the throbber */
594 if (listing) {
595 ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
596 } else {
597 ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
601 static void
602 new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *dialog)
604 GtkListStore *store;
606 store = GTK_LIST_STORE (dialog->model);
607 gtk_list_store_clear (store);
610 static void
611 new_chatroom_dialog_model_row_activated_cb (GtkTreeView *tree_view,
612 GtkTreePath *path,
613 GtkTreeViewColumn *column,
614 EmpathyNewChatroomDialog *dialog)
616 gtk_widget_activate (dialog->button_join);
619 static void
620 new_chatroom_dialog_model_selection_changed (GtkTreeSelection *selection,
621 EmpathyNewChatroomDialog *dialog)
623 GtkTreeModel *model;
624 GtkTreeIter iter;
625 gchar *room = NULL;
626 gchar *server = NULL;
628 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
629 return;
632 gtk_tree_model_get (model, &iter, COL_ROOM, &room, -1);
633 server = strstr (room, "@");
634 if (server) {
635 *server = '\0';
636 server++;
639 gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), server ? server : "");
640 gtk_entry_set_text (GTK_ENTRY (dialog->entry_room), room ? room : "");
642 g_free (room);
645 static void
646 new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
648 EmpathyAccountChooser *account_chooser;
649 TpConnection *connection;
650 const gchar *room;
651 const gchar *server = NULL;
652 gchar *room_name = NULL;
654 room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
655 server = gtk_entry_get_text (GTK_ENTRY (dialog->entry_server));
657 account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
658 connection = empathy_account_chooser_get_connection (account_chooser);
660 if (!EMP_STR_EMPTY (server)) {
661 room_name = g_strconcat (room, "@", server, NULL);
662 } else {
663 room_name = g_strdup (room);
666 DEBUG ("Requesting channel for '%s'", room_name);
667 empathy_dispatcher_join_muc (connection, room_name, NULL, NULL);
669 g_free (room_name);
672 static void
673 new_chatroom_dialog_entry_changed_cb (GtkWidget *entry,
674 EmpathyNewChatroomDialog *dialog)
676 if (entry == dialog->entry_room) {
677 update_join_button_sensitivity (dialog);
679 /* FIXME: Select the room in the list */
683 static void
684 new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *dialog)
686 new_chatroom_dialog_model_clear (dialog);
687 if (dialog->room_list) {
688 empathy_tp_roomlist_start (dialog->room_list);
692 static void
693 new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog *dialog)
695 if (dialog->room_list) {
696 empathy_tp_roomlist_stop (dialog->room_list);
700 static void
701 new_chatroom_dialog_entry_server_activate_cb (GtkWidget *widget,
702 EmpathyNewChatroomDialog *dialog)
704 new_chatroom_dialog_browse_start (dialog);
707 static void
708 new_chatroom_dialog_expander_browse_activate_cb (GtkWidget *widget,
709 EmpathyNewChatroomDialog *dialog)
711 gboolean expanded;
713 expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
714 if (expanded) {
715 new_chatroom_dialog_browse_stop (dialog);
716 gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
717 } else {
718 gtk_widget_hide (dialog->viewport_error);
719 gtk_widget_set_sensitive (dialog->treeview, TRUE);
720 new_chatroom_dialog_browse_start (dialog);
721 gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
725 static gboolean
726 new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget *widget,
727 GdkEventFocus *event,
728 EmpathyNewChatroomDialog *dialog)
730 gboolean expanded;
732 expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
733 if (expanded) {
734 new_chatroom_dialog_browse_start (dialog);
736 return FALSE;