1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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>
31 #include <glib/gi18n.h>
32 #include <glib/gprintf.h>
34 #include <telepathy-glib/interfaces.h>
36 #include <libempathy/empathy-tp-roomlist.h>
37 #include <libempathy/empathy-chatroom.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-request-util.h>
40 #include <libempathy/empathy-gsettings.h>
42 #include <libempathy-gtk/empathy-account-chooser.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include "empathy-new-chatroom-dialog.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
48 #include <libempathy/empathy-debug.h>
51 EmpathyTpRoomlist
*room_list
;
52 /* Currently selected account */
54 /* Signal id of the "status-changed" signal connected on the currently
56 gulong status_changed_id
;
59 GtkWidget
*vbox_widgets
;
60 GtkWidget
*table_grid
;
61 GtkWidget
*label_account
;
62 GtkWidget
*account_chooser
;
63 GtkWidget
*label_server
;
64 GtkWidget
*entry_server
;
65 GtkWidget
*label_room
;
66 GtkWidget
*entry_room
;
67 GtkWidget
*expander_browse
;
68 GtkWidget
*hbox_expander
;
72 GtkWidget
*button_join
;
73 GtkWidget
*label_error_message
;
74 GtkWidget
*viewport_error
;
77 } EmpathyNewChatroomDialog
;
90 static void new_chatroom_dialog_response_cb (GtkWidget
*widget
,
92 EmpathyNewChatroomDialog
*dialog
);
93 static void new_chatroom_dialog_destroy_cb (GtkWidget
*widget
,
94 EmpathyNewChatroomDialog
*dialog
);
95 static void new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog
*dialog
);
96 static void new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog
*dialog
);
97 static void new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog
*dialog
);
98 static void new_chatroom_dialog_account_changed_cb (GtkComboBox
*combobox
,
99 EmpathyNewChatroomDialog
*dialog
);
100 static void new_chatroom_dialog_account_ready_cb (EmpathyAccountChooser
*combobox
,
101 EmpathyNewChatroomDialog
*dialog
);
102 static void new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist
*room_list
,
103 EmpathyNewChatroomDialog
*dialog
);
104 static void new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist
*room_list
,
105 EmpathyChatroom
*chatroom
,
106 EmpathyNewChatroomDialog
*dialog
);
107 static void new_chatroom_dialog_listing_cb (EmpathyTpRoomlist
*room_list
,
109 EmpathyNewChatroomDialog
*dialog
);
110 static void start_listing_error_cb (EmpathyTpRoomlist
*room_list
,
112 EmpathyNewChatroomDialog
*dialog
);
113 static void stop_listing_error_cb (EmpathyTpRoomlist
*room_list
,
115 EmpathyNewChatroomDialog
*dialog
);
116 static void new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog
*dialog
);
117 static void new_chatroom_dialog_model_row_activated_cb (GtkTreeView
*tree_view
,
119 GtkTreeViewColumn
*column
,
120 EmpathyNewChatroomDialog
*dialog
);
121 static void new_chatroom_dialog_model_selection_changed (GtkTreeSelection
*selection
,
122 EmpathyNewChatroomDialog
*dialog
);
123 static void new_chatroom_dialog_join (EmpathyNewChatroomDialog
*dialog
);
124 static void new_chatroom_dialog_entry_changed_cb (GtkWidget
*entry
,
125 EmpathyNewChatroomDialog
*dialog
);
126 static void new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog
*dialog
);
127 static void new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog
*dialog
);
128 static void new_chatroom_dialog_entry_server_activate_cb (GtkWidget
*widget
,
129 EmpathyNewChatroomDialog
*dialog
);
130 static void new_chatroom_dialog_expander_browse_activate_cb (GtkWidget
*widget
,
131 EmpathyNewChatroomDialog
*dialog
);
132 static gboolean
new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget
*widget
,
133 GdkEventFocus
*event
,
134 EmpathyNewChatroomDialog
*dialog
);
135 static void new_chatroom_dialog_button_close_error_clicked_cb (GtkButton
*button
,
136 EmpathyNewChatroomDialog
*dialog
);
138 static EmpathyNewChatroomDialog
*dialog_p
= NULL
;
142 empathy_new_chatroom_dialog_show (GtkWindow
*parent
)
144 EmpathyNewChatroomDialog
*dialog
;
146 GtkSizeGroup
*size_group
;
150 gtk_window_present (GTK_WINDOW (dialog_p
->window
));
154 dialog_p
= dialog
= g_new0 (EmpathyNewChatroomDialog
, 1);
156 filename
= empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src");
157 gui
= empathy_builder_get_file (filename
,
158 "new_chatroom_dialog", &dialog
->window
,
159 "table_grid", &dialog
->table_grid
,
160 "label_account", &dialog
->label_account
,
161 "label_server", &dialog
->label_server
,
162 "label_room", &dialog
->label_room
,
163 "entry_server", &dialog
->entry_server
,
164 "entry_room", &dialog
->entry_room
,
165 "treeview", &dialog
->treeview
,
166 "button_join", &dialog
->button_join
,
167 "expander_browse", &dialog
->expander_browse
,
168 "hbox_expander", &dialog
->hbox_expander
,
169 "label_error_message", &dialog
->label_error_message
,
170 "viewport_error", &dialog
->viewport_error
,
174 empathy_builder_connect (gui
, dialog
,
175 "new_chatroom_dialog", "response", new_chatroom_dialog_response_cb
,
176 "new_chatroom_dialog", "destroy", new_chatroom_dialog_destroy_cb
,
177 "entry_server", "changed", new_chatroom_dialog_entry_changed_cb
,
178 "entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb
,
179 "entry_server", "focus-out-event", new_chatroom_dialog_entry_server_focus_out_cb
,
180 "entry_room", "changed", new_chatroom_dialog_entry_changed_cb
,
181 "expander_browse", "activate", new_chatroom_dialog_expander_browse_activate_cb
,
182 "button_close_error", "clicked", new_chatroom_dialog_button_close_error_clicked_cb
,
185 g_object_unref (gui
);
187 g_object_add_weak_pointer (G_OBJECT (dialog
->window
), (gpointer
) &dialog_p
);
189 /* Label alignment */
190 size_group
= gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL
);
192 gtk_size_group_add_widget (size_group
, dialog
->label_account
);
193 gtk_size_group_add_widget (size_group
, dialog
->label_server
);
194 gtk_size_group_add_widget (size_group
, dialog
->label_room
);
196 g_object_unref (size_group
);
198 /* Set up chatrooms treeview */
199 new_chatroom_dialog_model_setup (dialog
);
202 dialog
->throbber
= gtk_spinner_new ();
203 gtk_box_pack_start (GTK_BOX (dialog
->hbox_expander
), dialog
->throbber
,
206 dialog
->gsettings
= g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA
);
208 /* Account chooser for custom */
209 dialog
->account_chooser
= empathy_account_chooser_new ();
210 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog
->account_chooser
),
211 empathy_account_chooser_filter_supports_chatrooms
,
213 gtk_grid_attach (GTK_GRID (dialog
->table_grid
),
214 dialog
->account_chooser
,
216 gtk_widget_show (dialog
->account_chooser
);
218 g_signal_connect (EMPATHY_ACCOUNT_CHOOSER (dialog
->account_chooser
), "ready",
219 G_CALLBACK (new_chatroom_dialog_account_ready_cb
),
221 g_signal_connect (GTK_COMBO_BOX (dialog
->account_chooser
), "changed",
222 G_CALLBACK (new_chatroom_dialog_account_changed_cb
),
224 new_chatroom_dialog_account_changed_cb (GTK_COMBO_BOX (dialog
->account_chooser
),
228 gtk_window_set_transient_for (GTK_WINDOW (dialog
->window
),
229 GTK_WINDOW (parent
));
232 gtk_widget_show (dialog
->window
);
236 new_chatroom_dialog_store_last_account (GSettings
*gsettings
,
237 EmpathyAccountChooser
*account_chooser
)
240 const char *account_path
;
242 account
= empathy_account_chooser_get_account (account_chooser
);
246 account_path
= tp_proxy_get_object_path (account
);
247 DEBUG ("Storing account path '%s'", account_path
);
249 g_settings_set (gsettings
, EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT
,
254 new_chatroom_dialog_response_cb (GtkWidget
*widget
,
256 EmpathyNewChatroomDialog
*dialog
)
258 if (response
== GTK_RESPONSE_OK
) {
259 new_chatroom_dialog_join (dialog
);
260 new_chatroom_dialog_store_last_account (dialog
->gsettings
,
261 EMPATHY_ACCOUNT_CHOOSER (dialog
->account_chooser
));
264 gtk_widget_destroy (widget
);
268 new_chatroom_dialog_destroy_cb (GtkWidget
*widget
,
269 EmpathyNewChatroomDialog
*dialog
)
271 if (dialog
->room_list
) {
272 g_object_unref (dialog
->room_list
);
274 g_object_unref (dialog
->model
);
276 if (dialog
->account
!= NULL
) {
277 g_signal_handler_disconnect (dialog
->account
, dialog
->status_changed_id
);
278 g_object_unref (dialog
->account
);
281 g_clear_object (&dialog
->gsettings
);
287 new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog
*dialog
)
291 GtkTreeSelection
*selection
;
294 view
= GTK_TREE_VIEW (dialog
->treeview
);
296 g_signal_connect (view
, "row-activated",
297 G_CALLBACK (new_chatroom_dialog_model_row_activated_cb
),
301 store
= gtk_list_store_new (COL_COUNT
,
302 G_TYPE_STRING
, /* Invite */
303 G_TYPE_STRING
, /* Password */
304 G_TYPE_STRING
, /* Name */
305 G_TYPE_STRING
, /* Room */
306 G_TYPE_STRING
, /* Member count */
307 G_TYPE_INT
, /* Member count int */
308 G_TYPE_STRING
); /* Tool tip */
310 dialog
->model
= GTK_TREE_MODEL (store
);
311 gtk_tree_view_set_model (view
, dialog
->model
);
312 gtk_tree_view_set_tooltip_column (view
, COL_TOOLTIP
);
313 gtk_tree_view_set_search_column (view
, COL_NAME
);
316 selection
= gtk_tree_view_get_selection (view
);
317 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
318 COL_NAME
, GTK_SORT_ASCENDING
);
320 g_signal_connect (selection
, "changed",
321 G_CALLBACK (new_chatroom_dialog_model_selection_changed
),
325 new_chatroom_dialog_model_add_columns (dialog
);
329 new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog
*dialog
)
332 GtkTreeViewColumn
*column
;
333 GtkCellRenderer
*cell
;
336 gtk_icon_size_lookup (GTK_ICON_SIZE_MENU
, &width
, &height
);
338 view
= GTK_TREE_VIEW (dialog
->treeview
);
340 cell
= gtk_cell_renderer_pixbuf_new ();
344 "stock-size", GTK_ICON_SIZE_MENU
,
346 column
= gtk_tree_view_column_new_with_attributes (NULL
,
348 "stock-id", COL_INVITE_ONLY
,
351 gtk_tree_view_column_set_sort_column_id (column
, COL_INVITE_ONLY
);
352 gtk_tree_view_append_column (view
, column
);
354 column
= gtk_tree_view_column_new_with_attributes (NULL
,
356 "stock-id", COL_NEED_PASSWORD
,
359 gtk_tree_view_column_set_sort_column_id (column
, COL_NEED_PASSWORD
);
360 gtk_tree_view_append_column (view
, column
);
362 cell
= gtk_cell_renderer_text_new ();
366 "ellipsize", PANGO_ELLIPSIZE_END
,
369 column
= gtk_tree_view_column_new_with_attributes (_("Chat Room"),
374 gtk_tree_view_column_set_sort_column_id (column
, COL_NAME
);
375 gtk_tree_view_column_set_expand (column
, TRUE
);
376 gtk_tree_view_append_column (view
, column
);
378 cell
= gtk_cell_renderer_text_new ();
382 "ellipsize", PANGO_ELLIPSIZE_END
,
383 "alignment", PANGO_ALIGN_RIGHT
,
385 column
= gtk_tree_view_column_new_with_attributes (_("Members"),
390 gtk_tree_view_column_set_sort_column_id (column
, COL_MEMBERS_INT
);
391 gtk_tree_view_append_column (view
, column
);
395 update_join_button_sensitivity (EmpathyNewChatroomDialog
*dialog
)
398 const gchar
*protocol
;
399 gboolean sensitive
= FALSE
;
402 room
= gtk_entry_get_text (GTK_ENTRY (dialog
->entry_room
));
403 protocol
= tp_account_get_protocol (dialog
->account
);
404 if (EMP_STR_EMPTY (room
))
407 if (!tp_strdiff (protocol
, "irc") && (!tp_strdiff (room
, "#") ||
408 !tp_strdiff (room
, "&")))
413 if (dialog
->account
== NULL
)
416 if (tp_account_get_connection_status (dialog
->account
, NULL
) !=
417 TP_CONNECTION_STATUS_CONNECTED
)
423 gtk_widget_set_sensitive (dialog
->button_join
, sensitive
);
427 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog
*dialog
)
429 const gchar
*protocol
;
431 if (dialog
->account
== NULL
)
434 protocol
= tp_account_get_protocol (dialog
->account
);
436 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_server
), "");
438 /* hardcode here known protocols */
439 if (strcmp (protocol
, "jabber") == 0) {
440 gtk_widget_set_sensitive (dialog
->entry_server
, TRUE
);
442 else if (strcmp (protocol
, "local-xmpp") == 0) {
443 gtk_widget_set_sensitive (dialog
->entry_server
, FALSE
);
445 else if (strcmp (protocol
, "irc") == 0) {
446 gtk_widget_set_sensitive (dialog
->entry_server
, FALSE
);
449 gtk_widget_set_sensitive (dialog
->entry_server
, TRUE
);
452 if (!tp_strdiff (protocol
, "irc"))
453 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_room
), "#");
455 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_room
), "");
457 update_join_button_sensitivity (dialog
);
459 /* Final set up of the dialog */
460 gtk_widget_grab_focus (dialog
->entry_room
);
461 gtk_editable_set_position (GTK_EDITABLE (dialog
->entry_room
), -1);
465 account_status_changed_cb (TpAccount
*account
,
469 gchar
*dbus_error_name
,
471 EmpathyNewChatroomDialog
*self
)
473 update_join_button_sensitivity (self
);
477 new_chatroom_dialog_select_last_account (GSettings
*gsettings
,
478 EmpathyAccountChooser
*account_chooser
)
480 const gchar
*account_path
;
481 TpAccountManager
*manager
;
482 TpSimpleClientFactory
*factory
;
484 TpConnectionStatus status
;
486 account_path
= g_settings_get_string (gsettings
, EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT
);
487 DEBUG ("Selecting account path '%s'", account_path
);
489 manager
= tp_account_manager_dup ();
490 factory
= tp_proxy_get_factory (manager
);
491 account
= tp_simple_client_factory_ensure_account (factory
,
496 if (account
!= NULL
) {
497 status
= tp_account_get_connection_status (account
, NULL
);
498 if (status
== TP_CONNECTION_STATUS_CONNECTED
) {
499 empathy_account_chooser_set_account (account_chooser
,
502 g_object_unref (account
);
504 g_object_unref (manager
);
508 new_chatroom_dialog_account_ready_cb (EmpathyAccountChooser
*combobox
,
509 EmpathyNewChatroomDialog
*dialog
)
511 new_chatroom_dialog_select_last_account (dialog
->gsettings
, combobox
);
515 new_chatroom_dialog_account_changed_cb (GtkComboBox
*combobox
,
516 EmpathyNewChatroomDialog
*dialog
)
518 EmpathyAccountChooser
*account_chooser
;
519 gboolean listing
= FALSE
;
520 gboolean expanded
= FALSE
;
521 TpConnection
*connection
;
522 TpCapabilities
*caps
;
524 if (dialog
->room_list
) {
525 g_object_unref (dialog
->room_list
);
526 dialog
->room_list
= NULL
;
529 gtk_spinner_stop (GTK_SPINNER (dialog
->throbber
));
530 gtk_widget_hide (dialog
->throbber
);
531 new_chatroom_dialog_model_clear (dialog
);
533 if (dialog
->account
!= NULL
) {
534 g_signal_handler_disconnect (dialog
->account
, dialog
->status_changed_id
);
535 g_object_unref (dialog
->account
);
538 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (dialog
->account_chooser
);
539 dialog
->account
= empathy_account_chooser_dup_account (account_chooser
);
540 connection
= empathy_account_chooser_get_connection (account_chooser
);
541 if (dialog
->account
== NULL
)
544 dialog
->status_changed_id
= g_signal_connect (dialog
->account
,
545 "status-changed", G_CALLBACK (account_status_changed_cb
), dialog
);
547 /* empathy_account_chooser_filter_supports_chatrooms ensures that the
548 * account has a connection and CAPABILITIES has been prepared. */
549 g_assert (connection
!= NULL
);
550 g_assert (tp_proxy_is_prepared (connection
,
551 TP_CONNECTION_FEATURE_CAPABILITIES
));
552 caps
= tp_connection_get_capabilities (connection
);
554 if (tp_capabilities_supports_room_list (caps
, NULL
)) {
555 /* Roomlist channels are supported */
556 dialog
->room_list
= empathy_tp_roomlist_new (dialog
->account
);
559 dialog
->room_list
= NULL
;
562 if (dialog
->room_list
) {
563 g_signal_connect (dialog
->room_list
, "destroy",
564 G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb
),
566 g_signal_connect (dialog
->room_list
, "new-room",
567 G_CALLBACK (new_chatroom_dialog_new_room_cb
),
569 g_signal_connect (dialog
->room_list
, "notify::is-listing",
570 G_CALLBACK (new_chatroom_dialog_listing_cb
),
572 g_signal_connect (dialog
->room_list
, "error::start",
573 G_CALLBACK (start_listing_error_cb
),
575 g_signal_connect (dialog
->room_list
, "error::stop",
576 G_CALLBACK (stop_listing_error_cb
),
579 expanded
= gtk_expander_get_expanded (GTK_EXPANDER (dialog
->expander_browse
));
581 gtk_widget_hide (dialog
->viewport_error
);
582 gtk_widget_set_sensitive (dialog
->treeview
, TRUE
);
583 new_chatroom_dialog_browse_start (dialog
);
586 listing
= empathy_tp_roomlist_is_listing (dialog
->room_list
);
588 gtk_spinner_start (GTK_SPINNER (dialog
->throbber
));
589 gtk_widget_show (dialog
->throbber
);
593 gtk_widget_set_sensitive (dialog
->expander_browse
, dialog
->room_list
!= NULL
);
596 new_chatroom_dialog_update_widgets (dialog
);
600 new_chatroom_dialog_button_close_error_clicked_cb (GtkButton
*button
,
601 EmpathyNewChatroomDialog
*dialog
)
603 gtk_widget_hide (dialog
->viewport_error
);
607 new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist
*room_list
,
608 EmpathyNewChatroomDialog
*dialog
)
610 g_object_unref (dialog
->room_list
);
611 dialog
->room_list
= NULL
;
615 new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist
*room_list
,
616 EmpathyChatroom
*chatroom
,
617 EmpathyNewChatroomDialog
*dialog
)
623 const gchar
*need_password
;
624 const gchar
*invite_only
;
627 DEBUG ("New chatroom listed: %s (%s)",
628 empathy_chatroom_get_name (chatroom
),
629 empathy_chatroom_get_room (chatroom
));
632 store
= GTK_LIST_STORE (dialog
->model
);
633 members
= g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom
));
634 tmp
= g_strdup_printf ("<b>%s</b>", empathy_chatroom_get_name (chatroom
));
635 /* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
636 yes/no, yes/no and a number. */
637 tooltip
= g_strdup_printf (_("%s\nInvite required: %s\nPassword required: %s\nMembers: %s"),
639 empathy_chatroom_get_invite_only (chatroom
) ? _("Yes") : _("No"),
640 empathy_chatroom_get_need_password (chatroom
) ? _("Yes") : _("No"),
643 invite_only
= (empathy_chatroom_get_invite_only (chatroom
) ?
644 GTK_STOCK_INDEX
: NULL
);
645 need_password
= (empathy_chatroom_get_need_password (chatroom
) ?
646 GTK_STOCK_DIALOG_AUTHENTICATION
: NULL
);
648 gtk_list_store_append (store
, &iter
);
649 gtk_list_store_set (store
, &iter
,
650 COL_NEED_PASSWORD
, need_password
,
651 COL_INVITE_ONLY
, invite_only
,
652 COL_NAME
, empathy_chatroom_get_name (chatroom
),
653 COL_ROOM
, empathy_chatroom_get_room (chatroom
),
654 COL_MEMBERS
, members
,
655 COL_MEMBERS_INT
, empathy_chatroom_get_members_count (chatroom
),
656 COL_TOOLTIP
, tooltip
,
664 start_listing_error_cb (EmpathyTpRoomlist
*room_list
,
666 EmpathyNewChatroomDialog
*dialog
)
668 gtk_label_set_text (GTK_LABEL (dialog
->label_error_message
), _("Could not start room listing"));
669 gtk_widget_show_all (dialog
->viewport_error
);
670 gtk_widget_set_sensitive (dialog
->treeview
, FALSE
);
674 stop_listing_error_cb (EmpathyTpRoomlist
*room_list
,
676 EmpathyNewChatroomDialog
*dialog
)
678 gtk_label_set_text (GTK_LABEL (dialog
->label_error_message
), _("Could not stop room listing"));
679 gtk_widget_show_all (dialog
->viewport_error
);
680 gtk_widget_set_sensitive (dialog
->treeview
, FALSE
);
684 new_chatroom_dialog_listing_cb (EmpathyTpRoomlist
*room_list
,
686 EmpathyNewChatroomDialog
*dialog
)
690 listing
= empathy_tp_roomlist_is_listing (room_list
);
692 /* Update the throbber */
694 gtk_spinner_start (GTK_SPINNER (dialog
->throbber
));
695 gtk_widget_show (dialog
->throbber
);
697 gtk_spinner_stop (GTK_SPINNER (dialog
->throbber
));
698 gtk_widget_hide (dialog
->throbber
);
703 new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog
*dialog
)
707 store
= GTK_LIST_STORE (dialog
->model
);
708 gtk_list_store_clear (store
);
712 new_chatroom_dialog_model_row_activated_cb (GtkTreeView
*tree_view
,
714 GtkTreeViewColumn
*column
,
715 EmpathyNewChatroomDialog
*dialog
)
717 gtk_widget_activate (dialog
->button_join
);
721 new_chatroom_dialog_model_selection_changed (GtkTreeSelection
*selection
,
722 EmpathyNewChatroomDialog
*dialog
)
727 gchar
*server
= NULL
;
729 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
)) {
733 gtk_tree_model_get (model
, &iter
, COL_ROOM
, &room
, -1);
734 server
= strstr (room
, "@");
740 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_server
), server
? server
: "");
741 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_room
), room
? room
: "");
747 new_chatroom_dialog_join (EmpathyNewChatroomDialog
*dialog
)
749 EmpathyAccountChooser
*account_chooser
;
752 const gchar
*server
= NULL
;
753 gchar
*room_name
= NULL
;
755 room
= gtk_entry_get_text (GTK_ENTRY (dialog
->entry_room
));
756 server
= gtk_entry_get_text (GTK_ENTRY (dialog
->entry_server
));
758 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (dialog
->account_chooser
);
759 account
= empathy_account_chooser_get_account (account_chooser
);
761 if (!EMP_STR_EMPTY (server
)) {
762 room_name
= g_strconcat (room
, "@", server
, NULL
);
764 room_name
= g_strdup (room
);
767 g_strstrip (room_name
);
769 DEBUG ("Requesting channel for '%s'", room_name
);
771 empathy_join_muc (account
, room_name
, empathy_get_current_action_time ());
777 new_chatroom_dialog_entry_changed_cb (GtkWidget
*entry
,
778 EmpathyNewChatroomDialog
*dialog
)
780 if (entry
== dialog
->entry_room
) {
781 update_join_button_sensitivity (dialog
);
783 /* FIXME: Select the room in the list */
788 new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog
*dialog
)
790 new_chatroom_dialog_model_clear (dialog
);
791 if (dialog
->room_list
) {
792 empathy_tp_roomlist_start (dialog
->room_list
);
797 new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog
*dialog
)
799 if (dialog
->room_list
) {
800 empathy_tp_roomlist_stop (dialog
->room_list
);
805 new_chatroom_dialog_entry_server_activate_cb (GtkWidget
*widget
,
806 EmpathyNewChatroomDialog
*dialog
)
808 new_chatroom_dialog_browse_start (dialog
);
812 new_chatroom_dialog_expander_browse_activate_cb (GtkWidget
*widget
,
813 EmpathyNewChatroomDialog
*dialog
)
817 expanded
= gtk_expander_get_expanded (GTK_EXPANDER (widget
));
819 new_chatroom_dialog_browse_stop (dialog
);
820 gtk_window_set_resizable (GTK_WINDOW (dialog
->window
), FALSE
);
822 gtk_widget_hide (dialog
->viewport_error
);
823 gtk_widget_set_sensitive (dialog
->treeview
, TRUE
);
824 new_chatroom_dialog_browse_start (dialog
);
825 gtk_window_set_resizable (GTK_WINDOW (dialog
->window
), TRUE
);
830 new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget
*widget
,
831 GdkEventFocus
*event
,
832 EmpathyNewChatroomDialog
*dialog
)
836 expanded
= gtk_expander_get_expanded (GTK_EXPANDER (dialog
->expander_browse
));
838 new_chatroom_dialog_browse_start (dialog
);