empathy r2393 - trunk/src



Author: xclaesse
Date: Tue Feb  3 09:03:26 2009
New Revision: 2393
URL: http://svn.gnome.org/viewvc/empathy?rev=2393&view=rev

Log:
Let the event-manager manage the sounds

Let the event-manager handle sounds instead of the main window. Also make the
incoming phone sound be played in a loop.

Signed-off-by: Sjoerd Simons <sjoerd simons collabora co uk>

Modified:
   trunk/src/empathy-event-manager.c
   trunk/src/empathy-main-window.c

Modified: trunk/src/empathy-event-manager.c
==============================================================================
--- trunk/src/empathy-event-manager.c	(original)
+++ trunk/src/empathy-event-manager.c	Tue Feb  3 09:03:26 2009
@@ -37,8 +37,10 @@
 
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-contact-dialogs.h>
+#include <libempathy-gtk/empathy-ui-utils.h>
 
 #include "empathy-event-manager.h"
+#include "empathy-main-window.h"
 #include "empathy-tube-dispatch.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
@@ -66,6 +68,10 @@
   GSList *events;
   /* Ongoing approvals */
   GSList *approvals;
+
+  /* voip ringing sound */
+  guint voip_timeout;
+  gint ringing;
 } EmpathyEventManagerPriv;
 
 typedef struct _EventPriv EventPriv;
@@ -141,6 +147,81 @@
   g_slice_free (EventPriv, event);
 }
 
+static void event_manager_ringing_finished_cb (ca_context *c, guint id,
+  int error_code, gpointer user_data);
+
+static gboolean
+event_manager_ringing_timeout_cb (gpointer data)
+{
+  EmpathyEventManager *manager = EMPATHY_EVENT_MANAGER (data);
+  EmpathyEventManagerPriv *priv = GET_PRIV (manager);
+
+  priv->voip_timeout = 0;
+
+  empathy_sound_play_full (empathy_main_window_get (),
+      EMPATHY_SOUND_PHONE_INCOMING, event_manager_ringing_finished_cb,
+      manager);
+
+  return FALSE;
+}
+
+static gboolean
+event_manager_ringing_idle_cb (gpointer data)
+{
+  EmpathyEventManager *manager = EMPATHY_EVENT_MANAGER (data);
+  EmpathyEventManagerPriv *priv = GET_PRIV (manager);
+
+  if (priv->ringing > 0)
+    priv->voip_timeout = g_timeout_add (500, event_manager_ringing_timeout_cb,
+      data);
+
+  return FALSE;
+}
+
+static void
+event_manager_ringing_finished_cb (ca_context *c, guint id, int error_code,
+  gpointer user_data)
+{
+  if (error_code == CA_ERROR_CANCELED)
+    return;
+
+  g_idle_add (event_manager_ringing_idle_cb, user_data);
+}
+
+static void
+event_manager_start_ringing (EmpathyEventManager *manager)
+{
+  EmpathyEventManagerPriv *priv = GET_PRIV (manager);
+
+  priv->ringing++;
+
+  if (priv->ringing == 1)
+    {
+      empathy_sound_play_full (empathy_main_window_get (),
+        EMPATHY_SOUND_PHONE_INCOMING, event_manager_ringing_finished_cb,
+        manager);
+    }
+}
+
+static void
+event_manager_stop_ringing (EmpathyEventManager *manager)
+{
+  EmpathyEventManagerPriv *priv = GET_PRIV (manager);
+
+  priv->ringing--;
+
+  if (priv->ringing > 0)
+    return;
+
+  empathy_sound_stop (EMPATHY_SOUND_PHONE_INCOMING);
+
+  if (priv->voip_timeout != 0)
+    {
+      g_source_remove (priv->voip_timeout);
+      priv->voip_timeout = 0;
+    }
+}
+
 static void
 event_remove (EventPriv *event)
 {
@@ -271,6 +352,10 @@
       msg, approval, event_text_channel_process_func, NULL);
 
   g_free (header);
+  empathy_sound_play (empathy_main_window_get (),
+    EMPATHY_SOUND_CONVERSATION_NEW);
+
+  g_free (msg);
 }
 
 static void
@@ -279,6 +364,18 @@
   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
   GSList                  *l;
 
+  if (approval->operation != NULL)
+    {
+      GQuark channel_type;
+
+      channel_type = empathy_dispatch_operation_get_channel_type_id (
+          approval->operation);
+      if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
+        {
+          event_manager_stop_ringing (approval->manager);
+        }
+    }
+
   priv->approvals = g_slist_remove (priv->approvals, approval);
 
   for (l = priv->events; l; l = l->next)
@@ -339,6 +436,9 @@
     approval, event_channel_process_func, NULL);
 
   g_free (header);
+  event_manager_start_ringing (approval->manager);
+
+  g_free (msg);
 }
 
 static void
@@ -397,6 +497,11 @@
     msg, approval, event_manager_tube_approved_cb, approval);
 
   g_free (header);
+  /* FIXME better sound for incoming tubes ? */
+  empathy_sound_play (empathy_main_window_get (),
+    EMPATHY_SOUND_CONVERSATION_NEW);
+
+  g_free (msg);
 }
 
 static void
@@ -528,6 +633,10 @@
       event_manager_add (manager, contact, EMPATHY_IMAGE_DOCUMENT_SEND,
         header, NULL, approval, event_channel_process_func, NULL);
 
+      /* FIXME better sound for incoming file transfers ?*/
+      empathy_sound_play (empathy_main_window_get (),
+        EMPATHY_SOUND_CONVERSATION_NEW);
+
       g_object_unref (factory);
       g_object_unref (account);
       g_free (header);

Modified: trunk/src/empathy-main-window.c
==============================================================================
--- trunk/src/empathy-main-window.c	(original)
+++ trunk/src/empathy-main-window.c	Tue Feb  3 09:03:26 2009
@@ -292,9 +292,6 @@
 static void
 main_window_flash_start (EmpathyMainWindow *window)
 {
-	empathy_sound_play (GTK_WIDGET (window->window),
-			    EMPATHY_SOUND_CONVERSATION_NEW);
-
 	if (window->flash_timeout_id != 0) {
 		return;
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]