]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Always set urgency hint on p2p chat windows when receiving a message.
[empathy.git] / src / empathy-chat-window.c
index 6dd55cbae8b39ab2fe0554f5323fa340deff0ba4..b841506ba639bac213b9ee664921e29c6d4a4a22 100644 (file)
@@ -262,47 +262,15 @@ chat_window_create_label (EmpathyChatWindow *window,
        return hbox;
 }
 
-static void
-chat_window_update_menu (EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv;
-       gboolean              first_page;
-       gboolean              last_page;
-       gboolean              is_connected;
-       gint                  num_pages;
-       gint                  page_num;
-
-       priv = GET_PRIV (window);
-
-       /* Notebook pages */
-       page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
-       num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
-       first_page = (page_num == 0);
-       last_page = (page_num == (num_pages - 1));
-
-       gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
-       gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
-
-       is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
-       gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
-}
-
 static const gchar *
 chat_window_get_chat_name (EmpathyChat *chat)
 {
-       EmpathyTpChat  *tp_chat;
        EmpathyContact *remote_contact = NULL;
        const gchar    *name = NULL;
 
        name = empathy_chat_get_name (chat);
        if (!name) {
-               tp_chat = empathy_chat_get_tp_chat (chat);
-               if (tp_chat) {
-                       remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
-               }
+               remote_contact = empathy_chat_get_remote_contact (chat);
                if (remote_contact) {
                        name = empathy_contact_get_name (remote_contact);
                } else {
@@ -314,14 +282,37 @@ chat_window_get_chat_name (EmpathyChat *chat)
 }
 
 static void
-chat_window_update_title (EmpathyChatWindow *window)
+chat_window_update (EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               first_page;
+       gboolean               last_page;
+       gboolean               is_connected;
+       gint                   num_pages;
+       gint                   page_num;
        const gchar           *name;
        guint                  n_chats;
 
+       /* Get information */
+       page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
+       num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+       first_page = (page_num == 0);
+       last_page = (page_num == (num_pages - 1));
+       is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
        name = chat_window_get_chat_name (priv->current_chat);
        n_chats = g_list_length (priv->chats);
+
+       empathy_debug (DEBUG_DOMAIN, "Update window");
+
+       /* Update menu */
+       gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
+       gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
+       gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
+       gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
+       gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
+       gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
+
+       /* Update window title */
        if (n_chats == 1) {
                gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
        } else {
@@ -331,6 +322,8 @@ chat_window_update_title (EmpathyChatWindow *window)
                gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
                g_free (title);
        }
+
+       /* Update window icon */
        if (priv->chats_new_msg) {
                gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
                                          EMPATHY_IMAGE_MESSAGE);
@@ -340,12 +333,11 @@ chat_window_update_title (EmpathyChatWindow *window)
 }
 
 static void
-chat_window_update_chat (EmpathyChat *chat)
+chat_window_update_chat_tab (EmpathyChat *chat)
 {
        EmpathyChatWindow     *window;
        EmpathyChatWindowPriv *priv;
-       EmpathyTpChat         *tp_chat;
-       EmpathyContact        *remote_contact = NULL;
+       EmpathyContact        *remote_contact;
        const gchar           *name;
        const gchar           *subject;
        GtkWidget             *widget;
@@ -354,15 +346,18 @@ chat_window_update_chat (EmpathyChat *chat)
        const gchar           *icon_name;
 
        window = chat_window_find_chat (chat);
+       if (!window) {
+               return;
+       }
        priv = GET_PRIV (window);
 
        /* Get information */
        name = chat_window_get_chat_name (chat);
        subject = empathy_chat_get_subject (chat);
-       tp_chat = empathy_chat_get_tp_chat (chat);
-       if (tp_chat) {
-               remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
-       }
+       remote_contact = empathy_chat_get_remote_contact (chat);
+
+       empathy_debug (DEBUG_DOMAIN, "Updating chat tab, name=%s, subject=%s, "
+                      "remote_contact=%p", name, subject, remote_contact);
 
        /* Update tab image */
        if (g_list_find (priv->chats_new_msg, chat)) {
@@ -404,24 +399,20 @@ chat_window_update_chat (EmpathyChat *chat)
        widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
        gtk_label_set_text (GTK_LABEL (widget), name);
 
-       /* Update window title? */
+       /* Update the window if it's the current chat */
        if (priv->current_chat == chat) {
-               chat_window_update_title (window);
+               chat_window_update (window);
        }
 }
 
 static void
-chat_window_remote_contact_notify_cb (EmpathyChat *chat)
+chat_window_chat_notify_cb (EmpathyChat *chat)
 {
-       EmpathyTpChat  *tp_chat;
        EmpathyContact *old_remote_contact;
        EmpathyContact *remote_contact = NULL;
 
        old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
-       tp_chat = empathy_chat_get_tp_chat (chat);
-       if (tp_chat) {
-               remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
-       }
+       remote_contact = empathy_chat_get_remote_contact (chat);
 
        if (old_remote_contact != remote_contact) {
                /* The remote-contact associated with the chat changed, we need
@@ -429,79 +420,20 @@ chat_window_remote_contact_notify_cb (EmpathyChat *chat)
                 * window each time. */
                if (remote_contact) {
                        g_signal_connect_swapped (remote_contact, "notify",
-                                                 G_CALLBACK (chat_window_update_chat),
+                                                 G_CALLBACK (chat_window_update_chat_tab),
                                                  chat);
                }
                if (old_remote_contact) {
                        g_signal_handlers_disconnect_by_func (old_remote_contact,
-                                                             chat_window_update_chat,
+                                                             chat_window_update_chat_tab,
                                                              chat);
                }
 
                g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
                                   remote_contact);
-
-               chat_window_update_chat (chat);
-       }
-}
-
-static void
-chat_window_weak_ref_cb (gpointer  data,
-                        GObject  *chat)
-{
-       EmpathyTpChat  *tp_chat;
-       EmpathyContact *remote_contact;
-
-       tp_chat = g_object_get_data (chat, "chat-window-tp-chat");
-       if (tp_chat) {
-               g_signal_handlers_disconnect_by_func (tp_chat,
-                                                     chat_window_remote_contact_notify_cb,
-                                                     chat);
-       }
-
-       remote_contact = g_object_get_data (chat, "chat-window-remote-contact");
-       if (remote_contact) {
-               g_signal_handlers_disconnect_by_func (remote_contact,
-                                                     chat_window_update_chat,
-                                                     chat);
-       }
-}
-
-static void
-chat_window_chat_notify_cb (EmpathyChat *chat)
-{
-       EmpathyTpChat *tp_chat;
-       EmpathyTpChat *old_tp_chat;
-
-       old_tp_chat = g_object_get_data (G_OBJECT (chat), "chat-window-tp-chat");
-       tp_chat = empathy_chat_get_tp_chat (chat);
-
-       if (old_tp_chat != tp_chat) {
-               /* The TpChat associated with the chat has changed, we need to
-                * keep track of it's remote-contact if there is one. */
-               if (tp_chat) {
-                       g_signal_connect_swapped (tp_chat, "notify::remote-contact",
-                                                 G_CALLBACK (chat_window_remote_contact_notify_cb),
-                                                 chat);
-                       g_object_weak_ref (G_OBJECT (chat),
-                                          chat_window_weak_ref_cb,
-                                          NULL);
-               }
-               if (old_tp_chat) {
-                       g_signal_handlers_disconnect_by_func (old_tp_chat,
-                                                             chat_window_remote_contact_notify_cb,
-                                                             chat);
-               }
-               g_object_set_data (G_OBJECT (chat), "chat-window-tp-chat", tp_chat);
-
-               /* This will call chat_window_update_chat() if the remote-contact
-                * changed, so we don't have to call it again. That's why we
-                * return here. */
-               chat_window_remote_contact_notify_cb (chat);
-               return;
        }
 
-       chat_window_update_chat (chat);
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -797,7 +729,7 @@ chat_window_composing_cb (EmpathyChat       *chat,
                priv->chats_composing = g_list_remove (priv->chats_composing, chat);
        }
 
-       chat_window_update_chat (chat);
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -825,12 +757,16 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        priv = GET_PRIV (window);
 
        has_focus = empathy_chat_window_has_focus (window);
-       
+
        if (has_focus && priv->current_chat == chat) {
                return;
        }
        
-       needs_urgency = empathy_message_should_highlight (message);
+       if (empathy_chat_get_members_count (chat) > 2) {
+               needs_urgency = empathy_message_should_highlight (message);
+       } else {
+               needs_urgency = TRUE;
+       }
 
        if (needs_urgency && !has_focus) {
                chat_window_set_urgency_hint (window, TRUE);
@@ -838,7 +774,7 @@ chat_window_new_message_cb (EmpathyChat       *chat,
 
        if (!g_list_find (priv->chats_new_msg, chat)) {
                priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
-               chat_window_update_chat (chat);
+               chat_window_update_chat_tab (chat);
        }
 }
 
@@ -897,20 +833,7 @@ chat_window_page_switched_cb (GtkNotebook      *notebook,
        priv->current_chat = chat;
        priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
 
-       chat_window_update_menu (window);
-       chat_window_update_title (window);
-}
-
-static void
-chat_window_page_reordered_cb (GtkNotebook      *notebook,
-                              GtkWidget        *widget,
-                              guint             page_num,
-                              EmpathyChatWindow *window)
-{
-       empathy_debug (DEBUG_DOMAIN, "Page reordered");
-       
-       chat_window_update_menu (window);
-       chat_window_update_title (window);
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -954,6 +877,8 @@ chat_window_page_added_cb (GtkNotebook      *notebook,
 
        /* Get list of chats up to date */
        priv->chats = g_list_append (priv->chats, chat);
+
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -997,7 +922,7 @@ chat_window_page_removed_cb (GtkNotebook      *notebook,
        if (priv->chats == NULL) {
                g_object_unref (window);
        } else {
-               chat_window_update_chat (chat);
+               chat_window_update (window);
        }
 }
 
@@ -1017,7 +942,7 @@ chat_window_focus_in_event_cb (GtkWidget        *widget,
        chat_window_set_urgency_hint (window, FALSE);
        
        /* Update the title, since we now mark all unread messages as read. */
-       chat_window_update_chat (priv->current_chat);
+       chat_window_update_chat_tab (priv->current_chat);
 
        return FALSE;
 }
@@ -1036,12 +961,10 @@ chat_window_drag_data_received (GtkWidget        *widget,
                EmpathyChat           *chat;
                EmpathyChatWindow     *old_window;
                McAccount             *account;
-               const gchar           *id = NULL;
+               const gchar           *id;
                gchar                **strv;
 
-               if (selection) {
-                       id = (const gchar*) selection->data;
-               }
+               id = (const gchar*) selection->data;
 
                empathy_debug (DEBUG_DOMAIN, "DND contact from roster with id:'%s'", id);
                
@@ -1081,21 +1004,14 @@ chat_window_drag_data_received (GtkWidget        *widget,
                gtk_drag_finish (context, TRUE, FALSE, time);
        }
        else if (info == DND_DRAG_TYPE_TAB) {
-               EmpathyChat        *chat = NULL;
-               EmpathyChatWindow  *old_window;
-               GtkWidget        **child = NULL;
+               EmpathyChat        **chat;
+               EmpathyChatWindow   *old_window = NULL;
 
                empathy_debug (DEBUG_DOMAIN, "DND tab");
 
-               if (selection) {
-                       child = (void*) selection->data;
-               }
-
-               if (child) {
-                       chat = EMPATHY_CHAT (child);
-               }
+               chat = (void*) selection->data;
+               old_window = chat_window_find_chat (*chat);
 
-               old_window = chat_window_find_chat (chat);
                if (old_window) {
                        EmpathyChatWindowPriv *priv;
 
@@ -1277,10 +1193,6 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                "switch_page",
                                G_CALLBACK (chat_window_page_switched_cb),
                                window);
-       g_signal_connect (priv->notebook,
-                         "page_reordered",
-                         G_CALLBACK (chat_window_page_reordered_cb),
-                         window);
        g_signal_connect (priv->notebook,
                          "page_added",
                          G_CALLBACK (chat_window_page_added_cb),
@@ -1399,6 +1311,7 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
 
        child = GTK_WIDGET (chat);
        label = chat_window_create_label (window, chat); 
+       gtk_widget_show (child);
 
        g_signal_connect (chat, "notify::name",
                          G_CALLBACK (chat_window_chat_notify_cb),
@@ -1406,7 +1319,7 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        g_signal_connect (chat, "notify::subject",
                          G_CALLBACK (chat_window_chat_notify_cb),
                          NULL);
-       g_signal_connect (chat, "notify::tp-chat",
+       g_signal_connect (chat, "notify::remote-contact",
                          G_CALLBACK (chat_window_chat_notify_cb),
                          NULL);
        chat_window_chat_notify_cb (chat);
@@ -1416,7 +1329,6 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
        gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
                                            TRUE, TRUE, GTK_PACK_START); 
-       gtk_widget_show (child);
 
        empathy_debug (DEBUG_DOMAIN, 
                      "Chat added (%d references)",
@@ -1428,7 +1340,8 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
                                 EmpathyChat       *chat)
 {
        EmpathyChatWindowPriv *priv;
-       gint                  position;
+       gint                   position;
+       EmpathyContact        *remote_contact;
 
        g_return_if_fail (window != NULL);
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
@@ -1438,6 +1351,13 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
        g_signal_handlers_disconnect_by_func (chat,
                                              chat_window_chat_notify_cb,
                                              NULL);
+       remote_contact = g_object_get_data (G_OBJECT (chat),
+                                           "chat-window-remote-contact");
+       if (remote_contact) {
+               g_signal_handlers_disconnect_by_func (remote_contact,
+                                                     chat_window_update_chat_tab,
+                                                     chat);
+       }
 
        position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
                                          GTK_WIDGET (chat));