diff options
Diffstat (limited to 'src/empathy-chat-window.c')
-rw-r--r-- | src/empathy-chat-window.c | 95 |
1 files changed, 92 insertions, 3 deletions
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index fb04e7c3e..ea63f29aa 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -369,16 +369,97 @@ chat_window_contact_menu_update (EmpathyChatWindowPriv *priv, } } +static guint +get_all_unread_messages (EmpathyChatWindowPriv *priv) +{ + GList *l; + guint nb = 0; + + for (l = priv->chats_new_msg; l != NULL; l = g_list_next (l)) { + EmpathyChat *chat = l->data; + + nb += empathy_chat_get_nb_unread_messages (chat); + } + + return nb; +} + +static gchar * +get_window_title_name (EmpathyChatWindowPriv *priv) +{ + const gchar *active_name; + guint nb_chats; + guint current_unread_msgs; + + nb_chats = g_list_length (priv->chats); + g_assert (nb_chats > 0); + + active_name = empathy_chat_get_name (priv->current_chat); + + current_unread_msgs = empathy_chat_get_nb_unread_messages ( + priv->current_chat); + + if (nb_chats == 1) { + /* only one tab */ + if (current_unread_msgs == 0) + return g_strdup (active_name); + else + return g_strdup_printf (ngettext ( + "%s (%d unread)", + "%s (%d unread)", current_unread_msgs), + active_name, current_unread_msgs); + } else { + guint nb_others = nb_chats - 1; + guint all_unread_msgs; + + all_unread_msgs = get_all_unread_messages (priv); + + if (all_unread_msgs == 0) { + /* no unread message */ + return g_strdup_printf (ngettext ( + "%s (and %u other)", + "%s (and %u others)", nb_others), + active_name, nb_others); + } + + else if (all_unread_msgs == current_unread_msgs) { + /* unread messages are in the current tab */ + return g_strdup_printf (ngettext ( + "%s (%d unread)", + "%s (%d unread)", current_unread_msgs), + active_name, current_unread_msgs); + } + + else if (current_unread_msgs == 0) { + /* unread messages are in other tabs */ + return g_strdup_printf (ngettext ( + "%s (%d unread from others)", + "%s (%d unread from others)", + all_unread_msgs), + active_name, all_unread_msgs); + } + + else { + /* unread messages are in all the tabs */ + return g_strdup_printf (ngettext ( + "%s (%d unread from all)", + "%s (%d unread from all)", + all_unread_msgs), + active_name, all_unread_msgs); + } + } +} + static void chat_window_title_update (EmpathyChatWindowPriv *priv) { - const gchar *name; - - name = empathy_chat_get_name (priv->current_chat); + gchar *name; DEBUG ("Update window : Title"); + name = get_window_title_name (priv); gtk_window_set_title (GTK_WINDOW (priv->dialog), name); + g_free (name); } static void @@ -1127,6 +1208,8 @@ chat_window_new_message_cb (EmpathyChat *chat, } if (has_focus && priv->current_chat == chat) { + /* window and tab are focused so consider the message to be read */ + empathy_chat_messages_read (chat); return; } @@ -1157,6 +1240,9 @@ chat_window_new_message_cb (EmpathyChat *chat, EMPATHY_SOUND_MESSAGE_INCOMING); chat_window_show_or_update_notification (window, message, chat); } + + /* update the number of unread messages */ + chat_window_title_update (priv); } static GtkNotebook * @@ -1213,6 +1299,7 @@ chat_window_page_switched_cb (GtkNotebook *notebook, priv->current_chat = chat; priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat); + empathy_chat_messages_read (chat); chat_window_update_chat_tab (chat); } @@ -1304,6 +1391,7 @@ chat_window_page_removed_cb (GtkNotebook *notebook, /* Keep list of chats up to date */ priv->chats = g_list_remove (priv->chats, chat); priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat); + empathy_chat_messages_read (chat); priv->chats_composing = g_list_remove (priv->chats_composing, chat); if (priv->chats == NULL) { @@ -1325,6 +1413,7 @@ chat_window_focus_in_event_cb (GtkWidget *widget, priv = GET_PRIV (window); priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat); + empathy_chat_messages_read (priv->current_chat); chat_window_set_urgency_hint (window, FALSE); |