]> git.0d.be Git - empathy.git/blobdiff - src/empathy-new-chatroom-dialog.c
Merge branch 'people-nearby-fake-group-613558'
[empathy.git] / src / empathy-new-chatroom-dialog.c
index e16da91a7b2076d2fc7f9aeca5a7a5ac6520f989..c814e4433427b7ed163832eccebc2bca07c52e82 100644 (file)
@@ -32,8 +32,7 @@
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 
-#include <libmissioncontrol/mission-control.h>
-#include <libmissioncontrol/mc-profile.h>
+#include <telepathy-glib/interfaces.h>
 
 #include <libempathy/empathy-tp-roomlist.h>
 #include <libempathy/empathy-chatroom.h>
 
 typedef struct {
        EmpathyTpRoomlist *room_list;
+       /* Currently selected account */
+       TpAccount         *account;
+       /* Signal id of the "status-changed" signal connected on the currently
+        * selected account */
+       gulong             status_changed_id;
 
        GtkWidget         *window;
        GtkWidget         *vbox_widgets;
@@ -129,6 +133,48 @@ static void        new_chatroom_dialog_button_close_error_clicked_cb   (GtkButton
 
 static EmpathyNewChatroomDialog *dialog_p = NULL;
 
+/**
+ * empathy_account_chooser_filter_supports_multichat:
+ * @account: a #TpAccount
+ * @user_data: user data or %NULL
+ *
+ * An #EmpathyAccountChooserFilterFunc that returns accounts that both
+ * support multiuser text chat and are connected.
+ *
+ * Return value: TRUE if @account both supports muc and is connected
+ */
+static gboolean
+empathy_account_chooser_filter_supports_multichat (TpAccount *account,
+                                                  gpointer   user_data)
+{
+       TpConnection *connection;
+       EmpathyDispatcher *dispatcher;
+       GList *classes;
+
+       if (tp_account_get_connection_status (account, NULL) !=
+           TP_CONNECTION_STATUS_CONNECTED)
+       return FALSE;
+
+       /* check if CM supports multiuser text chat */
+       connection = tp_account_get_connection (account);
+       if (connection == NULL)
+               return FALSE;
+
+       dispatcher = empathy_dispatcher_dup_singleton ();
+
+       classes = empathy_dispatcher_find_requestable_channel_classes
+               (dispatcher, connection, TP_IFACE_CHANNEL_TYPE_TEXT,
+               TP_HANDLE_TYPE_ROOM, NULL);
+
+       g_object_unref (dispatcher);
+
+       if (classes == NULL)
+               return FALSE;
+
+       g_list_free (classes);
+       return TRUE;
+}
+
 void
 empathy_new_chatroom_dialog_show (GtkWindow *parent)
 {
@@ -200,7 +246,7 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
        /* Account chooser for custom */
        dialog->account_chooser = empathy_account_chooser_new ();
        empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
-                                           empathy_account_chooser_filter_is_connected,
+                                           empathy_account_chooser_filter_supports_multichat,
                                            NULL);
        gtk_table_attach_defaults (GTK_TABLE (dialog->table_info),
                                   dialog->account_chooser,
@@ -242,6 +288,11 @@ new_chatroom_dialog_destroy_cb (GtkWidget               *widget,
        }
        g_object_unref (dialog->model);
 
+       if (dialog->account != NULL) {
+               g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
+               g_object_unref (dialog->account);
+       }
+
        g_free (dialog);
 }
 
@@ -353,19 +404,42 @@ new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *dialog)
        gtk_tree_view_append_column (view, column);
 }
 
+static void
+update_join_button_sensitivity (EmpathyNewChatroomDialog *dialog)
+{
+       const gchar           *room;
+       gboolean               sensitive = FALSE;
+
+
+       room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
+       if (EMP_STR_EMPTY (room))
+               goto out;
+
+       if (dialog->account == NULL)
+               goto out;
+
+       if (tp_account_get_connection_status (dialog->account, NULL) !=
+                     TP_CONNECTION_STATUS_CONNECTED)
+               goto out;
+
+       sensitive = TRUE;
+
+out:
+       gtk_widget_set_sensitive (dialog->button_join, sensitive);
+}
+
 static void
 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       EmpathyAccount        *account;
-       McProfile             *profile;
        const gchar           *protocol;
-       const gchar           *room;
 
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
-       account = empathy_account_chooser_dup_account (account_chooser);
-       profile = empathy_account_get_profile (account);
-       protocol = mc_profile_get_protocol_name (profile);
+
+       if (dialog->account == NULL)
+               return;
+
+       protocol = tp_account_get_protocol (dialog->account);
 
        gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
 
@@ -383,14 +457,22 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
                gtk_widget_set_sensitive (dialog->entry_server, TRUE);
        }
 
-       room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
-       gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
+       update_join_button_sensitivity (dialog);
 
        /* Final set up of the dialog */
        gtk_widget_grab_focus (dialog->entry_room);
+}
 
-       g_object_unref (account);
-       g_object_unref (profile);
+static void
+account_status_changed_cb (TpAccount *account,
+                           guint old_status,
+                           guint new_status,
+                           guint reason,
+                           gchar *dbus_error_name,
+                           GHashTable *details,
+                           EmpathyNewChatroomDialog *self)
+{
+       update_join_button_sensitivity (self);
 }
 
 static void
@@ -398,9 +480,11 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                                        EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       EmpathyAccount        *account;
        gboolean               listing = FALSE;
        gboolean               expanded = FALSE;
+       TpConnection          *connection;
+       EmpathyDispatcher     *dispatcher;
+       GList                 *classes = NULL;
 
        if (dialog->room_list) {
                g_object_unref (dialog->room_list);
@@ -410,12 +494,38 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
        ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
        new_chatroom_dialog_model_clear (dialog);
 
+       if (dialog->account != NULL) {
+               g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
+               g_object_unref (dialog->account);
+       }
+
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
-       account = empathy_account_chooser_dup_account (account_chooser);
-       if (account == NULL)
+       dialog->account = empathy_account_chooser_dup_account (account_chooser);
+       connection = empathy_account_chooser_get_connection (account_chooser);
+       if (dialog->account == NULL)
                goto out;
 
-       dialog->room_list = empathy_tp_roomlist_new (account);
+       dialog->status_changed_id = g_signal_connect (dialog->account,
+                     "status-changed", G_CALLBACK (account_status_changed_cb), dialog);
+
+       dispatcher = empathy_dispatcher_dup_singleton ();
+
+       if (connection != NULL) {
+               classes = empathy_dispatcher_find_requestable_channel_classes (dispatcher,
+                       connection, TP_IFACE_CHANNEL_TYPE_ROOM_LIST,
+                       TP_HANDLE_TYPE_NONE, NULL);
+       }
+
+       if (classes != NULL) {
+               /* Roomlist channels are supported */
+               dialog->room_list = empathy_tp_roomlist_new (dialog->account);
+               g_list_free (classes);
+       }
+       else {
+               dialog->room_list = NULL;
+       }
+
+       g_object_unref (dispatcher);
 
        if (dialog->room_list) {
                g_signal_connect (dialog->room_list, "destroy",
@@ -447,7 +557,7 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                }
        }
 
-       g_object_unref (account);
+       gtk_widget_set_sensitive (dialog->expander_browse, dialog->room_list != NULL);
 
 out:
        new_chatroom_dialog_update_widgets (dialog);
@@ -491,9 +601,9 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
        selection = gtk_tree_view_get_selection (view);
        store = GTK_LIST_STORE (dialog->model);
        members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
-       tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
-               "are a channel name, yes/no, yes/no and a number.",
-               "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
+       /* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
+       yes/no, yes/no and a number. */
+       tooltip = g_strdup_printf (_("<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
                empathy_chatroom_get_name (chatroom),
                empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
                empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
@@ -631,10 +741,8 @@ new_chatroom_dialog_entry_changed_cb (GtkWidget                *entry,
                                      EmpathyNewChatroomDialog *dialog)
 {
        if (entry == dialog->entry_room) {
-               const gchar *room;
+               update_join_button_sensitivity (dialog);
 
-               room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
-               gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
                /* FIXME: Select the room in the list */
        }
 }