]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Merge remote-tracking branch 'pochu/error-dialog'
[empathy.git] / src / empathy-chat-window.c
index af94ddc77bad060c9000c431faaeaaeb40d494f2..46f76466b2d838b9ea945a7e9b98a72572453138 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <telepathy-glib/telepathy-glib.h>
 
+#include <libempathy/empathy-client-factory.h>
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-message.h>
 #include <libempathy/empathy-chatroom-manager.h>
@@ -403,7 +404,7 @@ chat_window_conversation_menu_update (EmpathyChatWindowPriv *priv,
        tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
 
        if (tp_chat != NULL) {
-               connection = empathy_tp_chat_get_connection (tp_chat);
+               connection = tp_channel_borrow_connection (TP_CHANNEL (tp_chat));
 
                sensitive = empathy_tp_chat_can_add_contact (tp_chat) &&
                        (tp_connection_get_status (connection, NULL) ==
@@ -975,24 +976,6 @@ chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
        empathy_chat_set_show_contacts (priv->current_chat, active);
 }
 
-static void
-got_contact_cb (TpConnection            *connection,
-                EmpathyContact          *contact,
-                const GError            *error,
-                gpointer                 user_data,
-                GObject                 *object)
-{
-       EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (user_data);
-
-       if (error != NULL) {
-               DEBUG ("Failed: %s", error->message);
-               return;
-       } else {
-               empathy_contact_list_add (EMPATHY_CONTACT_LIST (tp_chat),
-                               contact, _("Inviting you to this room"));
-       }
-}
-
 static void
 chat_window_invite_participant_activate_cb (GtkAction         *action,
                                            EmpathyChatWindow *window)
@@ -1000,35 +983,34 @@ chat_window_invite_participant_activate_cb (GtkAction         *action,
        EmpathyChatWindowPriv *priv;
        GtkWidget             *dialog;
        EmpathyTpChat         *tp_chat;
-       TpChannel             *channel;
        int                    response;
-       TpAccount             *account;
 
        priv = GET_PRIV (window);
 
        g_return_if_fail (priv->current_chat != NULL);
 
        tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
-       channel = empathy_tp_chat_get_channel (tp_chat);
-       account = empathy_chat_get_account (priv->current_chat);
 
        dialog = empathy_invite_participant_dialog_new (
-                       GTK_WINDOW (priv->dialog), account);
+                       GTK_WINDOW (priv->dialog), tp_chat);
        gtk_widget_show (dialog);
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
 
        if (response == GTK_RESPONSE_ACCEPT) {
-               TpConnection *connection;
-               const char *id;
+               TpContact *tp_contact;
+               EmpathyContact *contact;
+
+               tp_contact = empathy_invite_participant_dialog_get_selected (
+                       EMPATHY_INVITE_PARTICIPANT_DIALOG (dialog));
+               if (tp_contact == NULL) goto out;
 
-               id = empathy_contact_selector_dialog_get_selected (
-                               EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, NULL);
-               if (EMP_STR_EMPTY (id)) goto out;
+               contact = empathy_contact_dup_from_tp_contact (tp_contact);
+
+               empathy_contact_list_add (EMPATHY_CONTACT_LIST (tp_chat),
+                               contact, _("Inviting you to this room"));
 
-               connection = tp_channel_borrow_connection (channel);
-               empathy_tp_contact_factory_get_from_id (connection, id,
-                       got_contact_cb, tp_chat,  NULL, NULL);
+               g_object_unref (contact);
        }
 
 out:
@@ -1191,7 +1173,8 @@ chat_window_tabs_undo_close_tab_activate_cb (GtkAction         *action,
                                             EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
-       empathy_chat_manager_undo_closed_chat (priv->chat_manager);
+       empathy_chat_manager_undo_closed_chat (priv->chat_manager,
+                                              empathy_get_current_action_time ());
 }
 
 static void
@@ -1392,6 +1375,10 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
                        notify_notification_set_hint_string (notification,
                                EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "1");
                }
+
+               notify_notification_set_hint (notification,
+                       EMPATHY_NOTIFY_MANAGER_CAP_CATEGORY,
+                       g_variant_new_string ("im.received"));
        }
 
        pixbuf = empathy_notify_manager_get_pixbuf_for_notification (priv->notify_mgr,
@@ -1495,8 +1482,7 @@ chat_window_new_message_cb (EmpathyChat       *chat,
         *   a) the chatroom's always_urgent property is TRUE
         *   b) the message contains our alias
         */
-       if (empathy_chat_is_room (chat) ||
-           empathy_chat_get_remote_contact (chat) == NULL) {
+       if (empathy_chat_is_room (chat)) {
                TpAccount             *account;
                const gchar           *room;
                EmpathyChatroom       *chatroom;
@@ -1538,6 +1524,48 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        chat_window_icon_update (priv, TRUE);
 }
 
+static void
+chat_window_command_part (EmpathyChat *chat,
+                          GStrv        strv)
+{
+       EmpathyChat *chat_to_be_parted;
+       EmpathyTpChat *tp_chat = NULL;
+
+       if (strv[1] == NULL) {
+               /* No chatroom ID specified  */
+               tp_chat = empathy_chat_get_tp_chat (chat);
+               if (tp_chat)
+                       empathy_tp_chat_leave (tp_chat, "");
+               return;
+       }
+       chat_to_be_parted = empathy_chat_window_find_chat (
+               empathy_chat_get_account (chat), strv[1], FALSE);
+
+       if (chat_to_be_parted != NULL) {
+               /* Found a chatroom matching the specified ID */
+               tp_chat = empathy_chat_get_tp_chat (chat_to_be_parted);
+               if (tp_chat)
+                       empathy_tp_chat_leave (tp_chat, strv[2]);
+       } else {
+               gchar *message;
+
+               /* Going by the syntax of PART command:
+                *
+                * /PART [<chatroom-ID>] [<reason>]
+                *
+                * Chatroom-ID is not a must to specify a reason.
+                * If strv[1] (chatroom-ID) is not a valid identifier for a connected
+                * MUC then the current chatroom should be parted and srtv[1] should
+                * be treated as part of the optional part-message. */
+               message = g_strconcat (strv[1], " ", strv[2], NULL);
+               tp_chat = empathy_chat_get_tp_chat (chat);
+               if (tp_chat)
+                       empathy_tp_chat_leave (tp_chat, message);
+
+               g_free (message);
+       }
+}
+
 static GtkNotebook *
 notebook_create_window_cb (GtkNotebook *source,
                         GtkWidget   *page,
@@ -1623,6 +1651,9 @@ chat_window_page_added_cb (GtkNotebook      *notebook,
        g_signal_connect (chat, "new-message",
                          G_CALLBACK (chat_window_new_message_cb),
                          window);
+       g_signal_connect (chat, "part-command-entered",
+                         G_CALLBACK (chat_window_command_part),
+                         NULL);
        g_signal_connect (chat, "notify::tp-chat",
                          G_CALLBACK (chat_window_update_chat_tab),
                          window);
@@ -1800,7 +1831,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
                EmpathyChat           *chat = NULL;
                EmpathyChatWindow     *old_window;
                TpAccount             *account = NULL;
-               TpAccountManager      *account_manager;
+               EmpathyClientFactory  *factory;
                const gchar           *id;
                gchar                **strv;
                const gchar           *account_id;
@@ -1808,9 +1839,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                id = (const gchar*) gtk_selection_data_get_data (selection);
 
-               /* FIXME: Perhaps should be sure that the account manager is
-                * prepared before calling _ensure_account on it. */
-               account_manager = tp_account_manager_dup ();
+               factory = empathy_client_factory_dup ();
 
                DEBUG ("DND contact from roster with id:'%s'", id);
 
@@ -1819,7 +1848,11 @@ chat_window_drag_data_received (GtkWidget        *widget,
                        account_id = strv[0];
                        contact_id = strv[1];
                        account =
-                               tp_account_manager_ensure_account (account_manager, account_id);
+                               tp_simple_client_factory_ensure_account (
+                               TP_SIMPLE_CLIENT_FACTORY (factory), account_id,
+                                NULL, NULL);
+
+                       g_object_unref (factory);
                        if (account != NULL)
                                chat = empathy_chat_window_find_chat (account, contact_id, FALSE);
                }
@@ -1832,12 +1865,13 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                if (!chat) {
                        empathy_chat_with_contact_id (
-                               account, contact_id, gtk_get_current_event_time ());
+                               account, contact_id,
+                               empathy_get_current_action_time (),
+                               NULL, NULL);
 
                        g_strfreev (strv);
                        return;
                }
-               g_object_unref (account_manager);
                g_strfreev (strv);
 
                old_window = chat_window_find_chat (chat);
@@ -2154,18 +2188,6 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                                   window);
 }
 
-static GtkWidget *
-empathy_chat_window_get_dialog (EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv;
-
-       g_return_val_if_fail (window != NULL, NULL);
-
-       priv = GET_PRIV (window);
-
-       return priv->dialog;
-}
-
 /* Returns the window to open a new tab in if there is a suitable window,
  * otherwise, returns NULL indicating that a new window should be added.
  */
@@ -2188,13 +2210,10 @@ empathy_chat_window_get_default (gboolean room)
 
        for (l = chat_windows; l; l = l->next) {
                EmpathyChatWindow *chat_window;
-               GtkWidget         *dialog;
                guint nb_rooms, nb_private;
 
                chat_window = l->data;
 
-               dialog = empathy_chat_window_get_dialog (chat_window);
-
                empathy_chat_window_get_nb_chats (chat_window, &nb_rooms, &nb_private);
 
                /* Skip the window if there aren't any rooms in it */
@@ -2205,9 +2224,6 @@ empathy_chat_window_get_default (gboolean room)
                if (!room && nb_private == 0)
                        continue;
 
-               /* Found a window on this desktop, make it visible if necessary */
-               if (!empathy_window_get_is_visible (GTK_WINDOW (dialog)))
-                       empathy_window_present (GTK_WINDOW (dialog));
                return chat_window;
        }
 
@@ -2441,6 +2457,11 @@ empathy_chat_window_present_chat (EmpathyChat *chat,
                window = empathy_chat_window_get_default (empathy_chat_is_room (chat));
                if (!window) {
                        window = empathy_chat_window_new ();
+
+                       /* we want to display the newly created window even if we don't present
+                       * it */
+                       priv = GET_PRIV (window);
+                       gtk_widget_show (priv->dialog);
                }
 
                empathy_chat_window_add_chat (window, chat);