]> git.0d.be Git - empathy.git/blobdiff - src/empathy-new-chatroom-dialog.c
Update Simplified Chinese help translation.
[empathy.git] / src / empathy-new-chatroom-dialog.c
index 50b5f5d82b7ec13c315c32c1c02e2297f046f370..a09a5f7106d4939e1fb6ab7f5f45d10f076ad841 100644 (file)
@@ -25,7 +25,6 @@
 #include <config.h>
 
 #include <string.h>
-#include <stdio.h>
 
 #include <gtk/gtk.h>
 #include <glib.h>
@@ -37,7 +36,7 @@
 #include <libempathy/empathy-tp-roomlist.h>
 #include <libempathy/empathy-chatroom.h>
 #include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-dispatcher.h>
+#include <libempathy/empathy-request-util.h>
 
 #include <libempathy-gtk/empathy-account-chooser.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
@@ -133,47 +132,6 @@ 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)
@@ -243,7 +201,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_supports_multichat,
+                                           empathy_account_chooser_filter_supports_chatrooms,
                                            NULL);
        gtk_table_attach_defaults (GTK_TABLE (dialog->table_info),
                                   dialog->account_chooser,
@@ -428,11 +386,8 @@ out:
 static void
 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
 {
-       EmpathyAccountChooser *account_chooser;
        const gchar           *protocol;
 
-       account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
-
        if (dialog->account == NULL)
                return;
 
@@ -480,8 +435,7 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
        gboolean               listing = FALSE;
        gboolean               expanded = FALSE;
        TpConnection          *connection;
-       EmpathyDispatcher     *dispatcher;
-       GList                 *classes = NULL;
+       TpCapabilities *caps;
 
        if (dialog->room_list) {
                g_object_unref (dialog->room_list);
@@ -506,25 +460,21 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
        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);
-       }
+       /* empathy_account_chooser_filter_supports_chatrooms ensures that the
+       * account has a connection and CAPABILITIES has been prepared. */
+       g_assert (connection != NULL);
+       g_assert (tp_proxy_is_prepared (connection,
+               TP_CONNECTION_FEATURE_CAPABILITIES));
+       caps = tp_connection_get_capabilities (connection);
 
-       if (classes != NULL) {
+       if (tp_capabilities_supports_room_list (caps, 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",
                                  G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb),
@@ -582,31 +532,30 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
                                 EmpathyChatroom          *chatroom,
                                 EmpathyNewChatroomDialog *dialog)
 {
-       GtkTreeView      *view;
-       GtkTreeSelection *selection;
        GtkListStore     *store;
        GtkTreeIter       iter;
        gchar            *members;
        gchar            *tooltip;
        const gchar      *need_password;
        const gchar      *invite_only;
+       gchar            *tmp;
 
        DEBUG ("New chatroom listed: %s (%s)",
                empathy_chatroom_get_name (chatroom),
                empathy_chatroom_get_room (chatroom));
 
        /* Add to model */
-       view = GTK_TREE_VIEW (dialog->treeview);
-       selection = gtk_tree_view_get_selection (view);
        store = GTK_LIST_STORE (dialog->model);
        members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
+       tmp = g_strdup_printf ("<b>%s</b>", empathy_chatroom_get_name (chatroom));
        /* 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),
+       tooltip = g_strdup_printf (_("%s\nInvite required: %s\nPassword required: %s\nMembers: %s"),
+               tmp,
                empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
                empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
                members);
+       g_free (tmp);
        invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
                GTK_STOCK_INDEX : NULL);
        need_password = (empathy_chatroom_get_need_password (chatroom) ?
@@ -714,7 +663,7 @@ static void
 new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       TpConnection          *connection;
+       TpAccount *account;
        const gchar           *room;
        const gchar           *server = NULL;
        gchar                 *room_name = NULL;
@@ -723,7 +672,7 @@ new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
        server = gtk_entry_get_text (GTK_ENTRY (dialog->entry_server));
 
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
-       connection = empathy_account_chooser_get_connection (account_chooser);
+       account = empathy_account_chooser_get_account (account_chooser);
 
        if (!EMP_STR_EMPTY (server)) {
                room_name = g_strconcat (room, "@", server, NULL);
@@ -731,9 +680,11 @@ new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
                room_name = g_strdup (room);
        }
 
+       g_strstrip (room_name);
+
        DEBUG ("Requesting channel for '%s'", room_name);
-       empathy_dispatcher_join_muc (connection, room_name,
-               gtk_get_current_event_time (), NULL, NULL);
+
+       empathy_join_muc (account, room_name, empathy_get_current_action_time ());
 
        g_free (room_name);
 }