]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Merge branch 'sasl'
[empathy.git] / src / empathy-chat-window.c
index fe2783667550c610680990b4877232ebdca63d17..16329ee7be4ebde149b65519b669b92f88e85dd3 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2003-2007 Imendio AB
- * Copyright (C) 2007-2008 Collabora Ltd.
+ * Copyright (C) 2007-2010 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -51,7 +51,7 @@
 #include <libempathy-gtk/empathy-log-window.h>
 #include <libempathy-gtk/empathy-geometry.h>
 #include <libempathy-gtk/empathy-smiley-manager.h>
-#include <libempathy-gtk/empathy-sound.h>
+#include <libempathy-gtk/empathy-sound-manager.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 #include <libempathy-gtk/empathy-notify-manager.h>
 
@@ -111,6 +111,12 @@ typedef struct {
 
        /* Last user action time we acted upon to show a tab */
        guint32    x_user_action_time;
+
+       GSettings *gsettings_chat;
+       GSettings *gsettings_notif;
+       GSettings *gsettings_ui;
+
+       EmpathySoundManager *sound_mgr;
 } EmpathyChatWindowPriv;
 
 static GList *chat_windows = NULL;
@@ -533,9 +539,7 @@ chat_window_icon_update (EmpathyChatWindowPriv *priv)
                gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
                                          EMPATHY_IMAGE_MESSAGE);
        } else {
-               GSettings *gsettings = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
-
-               avatar_in_icon = g_settings_get_boolean (gsettings,
+               avatar_in_icon = g_settings_get_boolean (priv->gsettings_chat,
                                EMPATHY_PREFS_CHAT_AVATAR_IN_ICON);
 
                if (n_chats == 1 && avatar_in_icon) {
@@ -549,8 +553,6 @@ chat_window_icon_update (EmpathyChatWindowPriv *priv)
                } else {
                        gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
                }
-
-               g_object_unref (gsettings);
        }
 }
 
@@ -1287,14 +1289,9 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        if (!empathy_notify_manager_notification_is_enabled (priv->notify_mgr)) {
                return;
        } else {
-               GSettings *gsettings = g_settings_new (
-                               EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
-
-               res = g_settings_get_boolean (gsettings,
+               res = g_settings_get_boolean (priv->gsettings_notif,
                                EMPATHY_PREFS_NOTIFICATIONS_FOCUS);
 
-               g_object_unref (gsettings);
-
                if (!res) {
                        return;
                }
@@ -1320,7 +1317,7 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
                   to an existing notification with the same title.
                   In this way the previous message will not be lost: the new
                   message will appear below it, in the same notification */
-               notification = notify_notification_new (header, escaped, NULL, NULL);
+               notification = notify_notification_new (header, escaped, NULL);
 
                if (priv->notification == NULL) {
                        priv->notification = notification;
@@ -1386,6 +1383,7 @@ empathy_chat_window_has_focus (EmpathyChatWindow *window)
 static void
 chat_window_new_message_cb (EmpathyChat       *chat,
                            EmpathyMessage    *message,
+                           gboolean pending,
                            EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -1407,7 +1405,7 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        sender = empathy_message_get_sender (message);
 
        if (empathy_contact_is_user (sender)) {
-               empathy_sound_play (GTK_WIDGET (priv->dialog),
+               empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (priv->dialog),
                                    EMPATHY_SOUND_MESSAGE_OUTGOING);
        }
 
@@ -1458,9 +1456,13 @@ chat_window_new_message_cb (EmpathyChat       *chat,
                        chat_window_set_highlight_room_tab_label (chat);
                }
 
-               empathy_sound_play (GTK_WIDGET (priv->dialog),
+               empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (priv->dialog),
                    EMPATHY_SOUND_MESSAGE_INCOMING);
-               chat_window_show_or_update_notification (window, message, chat);
+
+               /* Pending messages have already been displayed in the approver, so we don't
+               * display a notification for those. */
+               if (!pending)
+                       chat_window_show_or_update_notification (window, message, chat);
        }
 
        /* update the number of unread messages and the window icon */
@@ -1875,6 +1877,10 @@ chat_window_finalize (GObject *object)
        g_object_unref (priv->ui_manager);
        g_object_unref (priv->chatroom_manager);
        g_object_unref (priv->notify_mgr);
+       g_object_unref (priv->gsettings_chat);
+       g_object_unref (priv->gsettings_notif);
+       g_object_unref (priv->gsettings_ui);
+       g_object_unref (priv->sound_mgr);
 
        if (priv->notification != NULL) {
                notify_notification_close (priv->notification, NULL);
@@ -1985,8 +1991,13 @@ empathy_chat_window_init (EmpathyChatWindow *window)
        g_object_ref (priv->ui_manager);
        g_object_unref (gui);
 
+       priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
+       priv->gsettings_notif = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
+       priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
        priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
 
+       priv->sound_mgr = empathy_sound_manager_dup_singleton ();
+
        priv->notebook = gtk_notebook_new ();
 
        g_signal_connect (priv->notebook, "create-window",
@@ -2091,12 +2102,12 @@ empathy_chat_window_init (EmpathyChatWindow *window)
 
        priv->chat_manager = empathy_chat_manager_dup_singleton ();
        priv->chat_manager_chats_changed_id =
-               g_signal_connect (priv->chat_manager, "chats-changed",
+               g_signal_connect (priv->chat_manager, "closed-chats-changed",
                                  G_CALLBACK (chat_window_chat_manager_chats_changed_cb),
                                  window);
 
        chat_window_chat_manager_chats_changed_cb (priv->chat_manager,
-                                                  empathy_chat_manager_get_num_chats (priv->chat_manager),
+                                                  empathy_chat_manager_get_num_closed_chats (priv->chat_manager),
                                                   window);
 }
 
@@ -2112,9 +2123,8 @@ empathy_chat_window_get_dialog (EmpathyChatWindow *window)
        return priv->dialog;
 }
 
-/* Returns the window to open a new tab in if there is only one window
- * visble, otherwise, returns NULL indicating that a new window should
- * be added.
+/* 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.
  */
 static EmpathyChatWindow *
 empathy_chat_window_get_default (gboolean room)
@@ -2137,26 +2147,27 @@ empathy_chat_window_get_default (gboolean room)
                EmpathyChatWindowPriv *priv;
                EmpathyChatWindow *chat_window;
                GtkWidget         *dialog;
+               guint nb_rooms, nb_private;
 
                chat_window = l->data;
                priv = GET_PRIV (chat_window);
 
                dialog = empathy_chat_window_get_dialog (chat_window);
-               if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
-                       guint nb_rooms, nb_private;
-                       empathy_chat_window_get_nb_chats (chat_window, &nb_rooms, &nb_private);
 
-                       /* Skip the window if there aren't any rooms in it */
-                       if (room && nb_rooms == 0)
-                               continue;
+               empathy_chat_window_get_nb_chats (chat_window, &nb_rooms, &nb_private);
 
-                       /* Skip the window if there aren't any 1-1 chats in it */
-                       if (!room && nb_private == 0)
-                               continue;
+               /* Skip the window if there aren't any rooms in it */
+               if (room && nb_rooms == 0)
+                       continue;
 
-                       /* Found a visible window on this desktop */
-                       return chat_window;
-               }
+               /* Skip the window if there aren't any 1-1 chats in it */
+               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;
        }
 
        return NULL;
@@ -2182,15 +2193,12 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
 
        /* If this window has just been created, position it */
        if (priv->chats == NULL) {
-               GSettings *gsettings = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
                const gchar *name = "chat-window";
                gboolean     separate_windows;
 
-               separate_windows = g_settings_get_boolean (gsettings,
+               separate_windows = g_settings_get_boolean (priv->gsettings_ui,
                                EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS);
 
-               g_object_unref (gsettings);
-
                if (empathy_chat_is_room (chat))
                        name = "room-window";