]> git.0d.be Git - empathy.git/commitdiff
move empathy-sound to empathy-sound-manager
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 30 Nov 2010 09:14:33 +0000 (10:14 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 30 Nov 2010 09:16:21 +0000 (10:16 +0100)
libempathy-gtk/Makefile.am
libempathy-gtk/empathy-sound-manager.c [new file with mode: 0644]
libempathy-gtk/empathy-sound-manager.h [new file with mode: 0644]
libempathy-gtk/empathy-sound.c [deleted file]
libempathy-gtk/empathy-sound.h [deleted file]
po/POTFILES.in
src/empathy-call-window.c
src/empathy-chat-window.c
src/empathy-event-manager.c
src/empathy-main-window.c

index a28ac9a003f51979b18c8dbd5b88141dafad9834..7e35929b1a715e72a36318f2826cd2d2302e552e 100644 (file)
@@ -75,7 +75,7 @@ libempathy_gtk_handwritten_source =                   \
        empathy-search-bar.c                    \
        empathy-share-my-desktop.c              \
        empathy-smiley-manager.c                \
-       empathy-sound.c                         \
+       empathy-sound-manager.c                 \
        empathy-spell.c                         \
        empathy-status-preset-dialog.c          \
        empathy-string-parser.c                 \
@@ -137,7 +137,7 @@ libempathy_gtk_headers =                    \
        empathy-search-bar.h                    \
        empathy-share-my-desktop.h              \
        empathy-smiley-manager.h                \
-       empathy-sound.h                         \
+       empathy-sound-manager.h                 \
        empathy-spell.h                         \
        empathy-status-preset-dialog.h          \
        empathy-string-parser.h                 \
diff --git a/libempathy-gtk/empathy-sound-manager.c b/libempathy-gtk/empathy-sound-manager.c
new file mode 100644 (file)
index 0000000..459016d
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * empathy-sound-manager.c - Various sound related utility functions.
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <config.h>
+
+#include "empathy-sound-manager.h"
+
+#include <canberra-gtk.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-gsettings.h>
+#include <libempathy/empathy-utils.h>
+
+typedef struct {
+  EmpathySound sound_id;
+  const char * event_ca_id;
+  const char * event_ca_description;
+  const char * key;
+} EmpathySoundEntry;
+
+typedef struct {
+  GtkWidget *widget;
+  gint sound_id;
+  guint play_interval;
+  guint replay_timeout_id;
+} EmpathyRepeatableSound;
+
+/* NOTE: these entries MUST be in the same order than EmpathySound enum */
+static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = {
+  { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant",
+    N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } ,
+  { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant",
+    N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } ,
+  { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant",
+    N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
+  { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login",
+    N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
+  { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout",
+    N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
+  { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login",
+    N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
+  { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout",
+    N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT },
+  { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call",
+    N_("Incoming voice call"), NULL },
+  { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling",
+    N_("Outgoing voice call"), NULL },
+  { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup",
+    N_("Voice call ended"), NULL },
+};
+
+/* An hash table containing currently repeating sounds. The format is the
+ * following:
+ * Key: An EmpathySound
+ * Value : The EmpathyRepeatableSound associated with that EmpathySound. */
+static GHashTable *repeating_sounds;
+
+static gboolean
+empathy_sound_pref_is_enabled (EmpathySound sound_id)
+{
+  EmpathySoundEntry *entry;
+  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
+  gboolean res;
+
+  entry = &(sound_entries[sound_id]);
+  g_return_val_if_fail (entry->sound_id == sound_id, FALSE);
+
+  if (entry->key == NULL)
+    {
+      res = TRUE;
+      goto finally;
+    }
+
+  res = g_settings_get_boolean (gsettings, EMPATHY_PREFS_SOUNDS_ENABLED);
+
+  if (!res)
+    goto finally;
+
+  if (!empathy_check_available_state ())
+    {
+      if (g_settings_get_boolean (gsettings,
+            EMPATHY_PREFS_SOUNDS_DISABLED_AWAY))
+        {
+          res = FALSE;
+          goto finally;
+        }
+    }
+
+  res = g_settings_get_boolean (gsettings, entry->key);
+
+finally:
+  g_object_unref (gsettings);
+
+  return res;
+}
+
+/**
+ * empathy_sound_stop:
+ * @sound_id: The #EmpathySound to stop playing.
+ *
+ * Stop playing a sound. If it has been stated in loop with
+ * empathy_sound_start_playing(), it will also stop replaying.
+ */
+void
+empathy_sound_stop (EmpathySound sound_id)
+{
+  EmpathySoundEntry *entry;
+
+  g_return_if_fail (sound_id < LAST_EMPATHY_SOUND);
+
+  entry = &(sound_entries[sound_id]);
+  g_return_if_fail (entry->sound_id == sound_id);
+
+  if (repeating_sounds != NULL)
+    {
+      EmpathyRepeatableSound *repeatable_sound;
+
+      repeatable_sound = g_hash_table_lookup (repeating_sounds,
+          GINT_TO_POINTER (sound_id));
+      if (repeatable_sound != NULL)
+        {
+          /* The sound must be stopped... If it is waiting for replay, remove
+           * it from hash table to cancel. Otherwise we'll cancel the sound
+           * being played. */
+          if (repeatable_sound->replay_timeout_id != 0)
+            {
+              g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id));
+              return;
+            }
+        }
+    }
+
+  ca_context_cancel (ca_gtk_context_get (), entry->sound_id);
+}
+
+static gboolean
+empathy_sound_play_internal (GtkWidget *widget, EmpathySound sound_id,
+  ca_finish_callback_t callback, gpointer user_data)
+{
+  EmpathySoundEntry *entry;
+  ca_context *c;
+  ca_proplist *p = NULL;
+
+  entry = &(sound_entries[sound_id]);
+  g_return_val_if_fail (entry->sound_id == sound_id, FALSE);
+
+  c = ca_gtk_context_get ();
+  ca_context_cancel (c, entry->sound_id);
+
+  DEBUG ("Play sound \"%s\" (%s)",
+         entry->event_ca_id,
+         entry->event_ca_description);
+
+  if (ca_proplist_create (&p) < 0)
+    goto failed;
+
+  if (ca_proplist_sets (p, CA_PROP_EVENT_ID, entry->event_ca_id) < 0)
+    goto failed;
+
+  if (ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION,
+          gettext (entry->event_ca_description)) < 0)
+    goto failed;
+
+  if (ca_gtk_proplist_set_for_widget (p, widget) < 0)
+    goto failed;
+
+  ca_context_play_full (ca_gtk_context_get (), entry->sound_id, p, callback,
+      user_data);
+
+  ca_proplist_destroy (p);
+
+  return TRUE;
+
+failed:
+  if (p != NULL)
+    ca_proplist_destroy (p);
+
+  return FALSE;
+}
+
+/**
+ * empathy_sound_play_full:
+ * @widget: The #GtkWidget from which the sound is originating.
+ * @sound_id: The #EmpathySound to play.
+ * @callback: The #ca_finish_callback_t function that will be called when the
+ *            sound  has stopped playing.
+ * @user_data: user data to pass to the function.
+ *
+ * Plays a sound.
+ *
+ * Returns %TRUE if the sound has successfully started playing, otherwise
+ * returning %FALSE and @callback won't be called.
+ *
+ * This function returns %FALSE if the sound is already playing in loop using
+ * %empathy_sound_start_playing.
+ *
+ * This function returns %FALSE if the sound is disabled in empathy preferences.
+ *
+ * Return value: %TRUE if the sound has successfully started playing, %FALSE
+ *               otherwise.
+ */
+gboolean
+empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id,
+  ca_finish_callback_t callback, gpointer user_data)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
+
+  if (!empathy_sound_pref_is_enabled (sound_id))
+    return FALSE;
+
+  /* The sound might already be playing repeatedly. If it's the case, we
+   * immediadely return since there's no need to make it play again */
+  if (repeating_sounds != NULL &&
+      g_hash_table_lookup (repeating_sounds, GINT_TO_POINTER (sound_id)) != NULL)
+    return FALSE;
+
+  return empathy_sound_play_internal (widget, sound_id, callback, user_data);
+}
+
+/**
+ * empathy_sound_play:
+ * @widget: The #GtkWidget from which the sound is originating.
+ * @sound_id: The #EmpathySound to play.
+ *
+ * Plays a sound. See %empathy_sound_play_full for details.'
+ *
+ * Return value: %TRUE if the sound has successfully started playing, %FALSE
+ *               otherwise.
+ */
+gboolean
+empathy_sound_play (GtkWidget *widget, EmpathySound sound_id)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
+
+  return empathy_sound_play_full (widget, sound_id, NULL, NULL);
+}
+
+static void playing_finished_cb (ca_context *c, guint id, int error_code,
+  gpointer user_data);
+
+static gboolean
+playing_timeout_cb (gpointer data)
+{
+  EmpathyRepeatableSound *repeatable_sound = data;
+  gboolean playing;
+
+  repeatable_sound->replay_timeout_id = 0;
+
+  playing = empathy_sound_play_internal (repeatable_sound->widget,
+      repeatable_sound->sound_id, playing_finished_cb, data);
+
+  if (!playing)
+    {
+      DEBUG ("Failed to replay sound, stop repeating");
+      g_hash_table_remove (repeating_sounds,
+          GINT_TO_POINTER (repeatable_sound->sound_id));
+    }
+
+  return FALSE;
+}
+
+static void
+playing_finished_cb (ca_context *c, guint id, int error_code,
+  gpointer user_data)
+{
+  EmpathyRepeatableSound *repeatable_sound = user_data;
+
+  if (error_code != CA_SUCCESS)
+    {
+      DEBUG ("Error: %s", ca_strerror (error_code));
+      g_hash_table_remove (repeating_sounds,
+          GINT_TO_POINTER (repeatable_sound->sound_id));
+      return;
+    }
+
+  repeatable_sound->replay_timeout_id = g_timeout_add (
+      repeatable_sound->play_interval, playing_timeout_cb, user_data);
+}
+
+static void
+empathy_sound_widget_destroyed_cb (GtkWidget *widget, gpointer user_data)
+{
+  EmpathyRepeatableSound *repeatable_sound = user_data;
+
+  /* The sound must be stopped... If it is waiting for replay, remove
+   * it from hash table to cancel. Otherwise playing_finished_cb will be
+   * called with an error. */
+  if (repeatable_sound->replay_timeout_id != 0)
+    {
+      g_hash_table_remove (repeating_sounds,
+          GINT_TO_POINTER (repeatable_sound->sound_id));
+    }
+}
+
+static void
+repeating_sounds_item_delete (gpointer data)
+{
+  EmpathyRepeatableSound *repeatable_sound = data;
+
+  if (repeatable_sound->replay_timeout_id != 0)
+    g_source_remove (repeatable_sound->replay_timeout_id);
+
+  g_signal_handlers_disconnect_by_func (repeatable_sound->widget,
+      empathy_sound_widget_destroyed_cb, repeatable_sound);
+
+  g_slice_free (EmpathyRepeatableSound, repeatable_sound);
+}
+
+/**
+ * empathy_sound_start_playing:
+ * @widget: The #GtkWidget from which the sound is originating.
+ * @sound_id: The #EmpathySound to play.
+ * @timeout_before_replay: The amount of time, in milliseconds, between two
+ *                         consecutive play.
+ *
+ * Start playing a sound in loop. To stop the sound, call empathy_call_stop ()
+ * by passing it the same @sound_id. Note that if you start playing a sound
+ * multiple times, you'll have to call %empathy_sound_stop the same number of
+ * times.
+ *
+ * Return value: %TRUE if the sound has successfully started playing.
+ */
+gboolean
+empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id,
+    guint timeout_before_replay)
+{
+  EmpathyRepeatableSound *repeatable_sound;
+  gboolean playing = FALSE;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
+
+  if (!empathy_sound_pref_is_enabled (sound_id))
+    return FALSE;
+
+  if (repeating_sounds == NULL)
+    {
+      repeating_sounds = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+          NULL, repeating_sounds_item_delete);
+    }
+  else if (g_hash_table_lookup (repeating_sounds,
+               GINT_TO_POINTER (sound_id)) != NULL)
+    {
+      /* The sound is already playing in loop. No need to continue. */
+      return FALSE;
+    }
+
+  repeatable_sound = g_slice_new0 (EmpathyRepeatableSound);
+  repeatable_sound->widget = widget;
+  repeatable_sound->sound_id = sound_id;
+  repeatable_sound->play_interval = timeout_before_replay;
+  repeatable_sound->replay_timeout_id = 0;
+
+  g_hash_table_insert (repeating_sounds, GINT_TO_POINTER (sound_id),
+      repeatable_sound);
+
+  g_signal_connect (G_OBJECT (widget), "destroy",
+      G_CALLBACK (empathy_sound_widget_destroyed_cb),
+      repeatable_sound);
+
+  playing = empathy_sound_play_internal (widget, sound_id, playing_finished_cb,
+        repeatable_sound);
+
+  if (!playing)
+      g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id));
+
+  return playing;
+}
diff --git a/libempathy-gtk/empathy-sound-manager.h b/libempathy-gtk/empathy-sound-manager.h
new file mode 100644 (file)
index 0000000..95160b3
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * empathy-sound-manager.h - Various sound related utility functions.
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#ifndef __EMPATHY_SOUND_MANAGER_H__
+#define __EMPATHY_SOUND_MANAGER_H__
+
+#include <gtk/gtk.h>
+
+#include <canberra-gtk.h>
+
+G_BEGIN_DECLS
+
+/* NOTE: Keep this sync with sound_entries in empathy-sound-manager.c */
+typedef enum {
+  EMPATHY_SOUND_MESSAGE_INCOMING = 0,
+  EMPATHY_SOUND_MESSAGE_OUTGOING,
+  EMPATHY_SOUND_CONVERSATION_NEW,
+  EMPATHY_SOUND_CONTACT_CONNECTED,
+  EMPATHY_SOUND_CONTACT_DISCONNECTED,
+  EMPATHY_SOUND_ACCOUNT_CONNECTED,
+  EMPATHY_SOUND_ACCOUNT_DISCONNECTED,
+  EMPATHY_SOUND_PHONE_INCOMING,
+  EMPATHY_SOUND_PHONE_OUTGOING,
+  EMPATHY_SOUND_PHONE_HANGUP,
+  LAST_EMPATHY_SOUND,
+} EmpathySound;
+
+gboolean empathy_sound_play (GtkWidget *widget, EmpathySound sound_id);
+void empathy_sound_stop (EmpathySound sound_id);
+
+gboolean empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id,
+    guint timeout_before_replay);
+
+gboolean empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id,
+    ca_finish_callback_t callback, gpointer user_data);
+
+G_END_DECLS
+
+#endif /* #ifndef __EMPATHY_SOUND_MANAGER_H__ */
diff --git a/libempathy-gtk/empathy-sound.c b/libempathy-gtk/empathy-sound.c
deleted file mode 100644 (file)
index 03f0419..0000000
+++ /dev/null
@@ -1,389 +0,0 @@
-/*
- * empathy-sound.c - Various sound related utility functions.
- * Copyright (C) 2009 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include <config.h>
-
-#include "empathy-sound.h"
-
-#include <canberra-gtk.h>
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-
-#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-utils.h>
-
-typedef struct {
-  EmpathySound sound_id;
-  const char * event_ca_id;
-  const char * event_ca_description;
-  const char * key;
-} EmpathySoundEntry;
-
-typedef struct {
-  GtkWidget *widget;
-  gint sound_id;
-  guint play_interval;
-  guint replay_timeout_id;
-} EmpathyRepeatableSound;
-
-/* NOTE: these entries MUST be in the same order than EmpathySound enum */
-static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = {
-  { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant",
-    N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } ,
-  { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant",
-    N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } ,
-  { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant",
-    N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
-  { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login",
-    N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
-  { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout",
-    N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
-  { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login",
-    N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
-  { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout",
-    N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT },
-  { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call",
-    N_("Incoming voice call"), NULL },
-  { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling",
-    N_("Outgoing voice call"), NULL },
-  { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup",
-    N_("Voice call ended"), NULL },
-};
-
-/* An hash table containing currently repeating sounds. The format is the
- * following:
- * Key: An EmpathySound
- * Value : The EmpathyRepeatableSound associated with that EmpathySound. */
-static GHashTable *repeating_sounds;
-
-static gboolean
-empathy_sound_pref_is_enabled (EmpathySound sound_id)
-{
-  EmpathySoundEntry *entry;
-  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
-  gboolean res;
-
-  entry = &(sound_entries[sound_id]);
-  g_return_val_if_fail (entry->sound_id == sound_id, FALSE);
-
-  if (entry->key == NULL)
-    {
-      res = TRUE;
-      goto finally;
-    }
-
-  res = g_settings_get_boolean (gsettings, EMPATHY_PREFS_SOUNDS_ENABLED);
-
-  if (!res)
-    goto finally;
-
-  if (!empathy_check_available_state ())
-    {
-      if (g_settings_get_boolean (gsettings,
-            EMPATHY_PREFS_SOUNDS_DISABLED_AWAY))
-        {
-          res = FALSE;
-          goto finally;
-        }
-    }
-
-  res = g_settings_get_boolean (gsettings, entry->key);
-
-finally:
-  g_object_unref (gsettings);
-
-  return res;
-}
-
-/**
- * empathy_sound_stop:
- * @sound_id: The #EmpathySound to stop playing.
- *
- * Stop playing a sound. If it has been stated in loop with
- * empathy_sound_start_playing(), it will also stop replaying.
- */
-void
-empathy_sound_stop (EmpathySound sound_id)
-{
-  EmpathySoundEntry *entry;
-
-  g_return_if_fail (sound_id < LAST_EMPATHY_SOUND);
-
-  entry = &(sound_entries[sound_id]);
-  g_return_if_fail (entry->sound_id == sound_id);
-
-  if (repeating_sounds != NULL)
-    {
-      EmpathyRepeatableSound *repeatable_sound;
-
-      repeatable_sound = g_hash_table_lookup (repeating_sounds,
-          GINT_TO_POINTER (sound_id));
-      if (repeatable_sound != NULL)
-        {
-          /* The sound must be stopped... If it is waiting for replay, remove
-           * it from hash table to cancel. Otherwise we'll cancel the sound
-           * being played. */
-          if (repeatable_sound->replay_timeout_id != 0)
-            {
-              g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id));
-              return;
-            }
-        }
-    }
-
-  ca_context_cancel (ca_gtk_context_get (), entry->sound_id);
-}
-
-static gboolean
-empathy_sound_play_internal (GtkWidget *widget, EmpathySound sound_id,
-  ca_finish_callback_t callback, gpointer user_data)
-{
-  EmpathySoundEntry *entry;
-  ca_context *c;
-  ca_proplist *p = NULL;
-
-  entry = &(sound_entries[sound_id]);
-  g_return_val_if_fail (entry->sound_id == sound_id, FALSE);
-
-  c = ca_gtk_context_get ();
-  ca_context_cancel (c, entry->sound_id);
-
-  DEBUG ("Play sound \"%s\" (%s)",
-         entry->event_ca_id,
-         entry->event_ca_description);
-
-  if (ca_proplist_create (&p) < 0)
-    goto failed;
-
-  if (ca_proplist_sets (p, CA_PROP_EVENT_ID, entry->event_ca_id) < 0)
-    goto failed;
-
-  if (ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION,
-          gettext (entry->event_ca_description)) < 0)
-    goto failed;
-
-  if (ca_gtk_proplist_set_for_widget (p, widget) < 0)
-    goto failed;
-
-  ca_context_play_full (ca_gtk_context_get (), entry->sound_id, p, callback,
-      user_data);
-
-  ca_proplist_destroy (p);
-
-  return TRUE;
-
-failed:
-  if (p != NULL)
-    ca_proplist_destroy (p);
-
-  return FALSE;
-}
-
-/**
- * empathy_sound_play_full:
- * @widget: The #GtkWidget from which the sound is originating.
- * @sound_id: The #EmpathySound to play.
- * @callback: The #ca_finish_callback_t function that will be called when the
- *            sound  has stopped playing.
- * @user_data: user data to pass to the function.
- *
- * Plays a sound.
- *
- * Returns %TRUE if the sound has successfully started playing, otherwise
- * returning %FALSE and @callback won't be called.
- *
- * This function returns %FALSE if the sound is already playing in loop using
- * %empathy_sound_start_playing.
- *
- * This function returns %FALSE if the sound is disabled in empathy preferences.
- *
- * Return value: %TRUE if the sound has successfully started playing, %FALSE
- *               otherwise.
- */
-gboolean
-empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id,
-  ca_finish_callback_t callback, gpointer user_data)
-{
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
-
-  if (!empathy_sound_pref_is_enabled (sound_id))
-    return FALSE;
-
-  /* The sound might already be playing repeatedly. If it's the case, we
-   * immediadely return since there's no need to make it play again */
-  if (repeating_sounds != NULL &&
-      g_hash_table_lookup (repeating_sounds, GINT_TO_POINTER (sound_id)) != NULL)
-    return FALSE;
-
-  return empathy_sound_play_internal (widget, sound_id, callback, user_data);
-}
-
-/**
- * empathy_sound_play:
- * @widget: The #GtkWidget from which the sound is originating.
- * @sound_id: The #EmpathySound to play.
- *
- * Plays a sound. See %empathy_sound_play_full for details.'
- *
- * Return value: %TRUE if the sound has successfully started playing, %FALSE
- *               otherwise.
- */
-gboolean
-empathy_sound_play (GtkWidget *widget, EmpathySound sound_id)
-{
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
-
-  return empathy_sound_play_full (widget, sound_id, NULL, NULL);
-}
-
-static void playing_finished_cb (ca_context *c, guint id, int error_code,
-  gpointer user_data);
-
-static gboolean
-playing_timeout_cb (gpointer data)
-{
-  EmpathyRepeatableSound *repeatable_sound = data;
-  gboolean playing;
-
-  repeatable_sound->replay_timeout_id = 0;
-
-  playing = empathy_sound_play_internal (repeatable_sound->widget,
-      repeatable_sound->sound_id, playing_finished_cb, data);
-
-  if (!playing)
-    {
-      DEBUG ("Failed to replay sound, stop repeating");
-      g_hash_table_remove (repeating_sounds,
-          GINT_TO_POINTER (repeatable_sound->sound_id));
-    }
-
-  return FALSE;
-}
-
-static void
-playing_finished_cb (ca_context *c, guint id, int error_code,
-  gpointer user_data)
-{
-  EmpathyRepeatableSound *repeatable_sound = user_data;
-
-  if (error_code != CA_SUCCESS)
-    {
-      DEBUG ("Error: %s", ca_strerror (error_code));
-      g_hash_table_remove (repeating_sounds,
-          GINT_TO_POINTER (repeatable_sound->sound_id));
-      return;
-    }
-
-  repeatable_sound->replay_timeout_id = g_timeout_add (
-      repeatable_sound->play_interval, playing_timeout_cb, user_data);
-}
-
-static void
-empathy_sound_widget_destroyed_cb (GtkWidget *widget, gpointer user_data)
-{
-  EmpathyRepeatableSound *repeatable_sound = user_data;
-
-  /* The sound must be stopped... If it is waiting for replay, remove
-   * it from hash table to cancel. Otherwise playing_finished_cb will be
-   * called with an error. */
-  if (repeatable_sound->replay_timeout_id != 0)
-    {
-      g_hash_table_remove (repeating_sounds,
-          GINT_TO_POINTER (repeatable_sound->sound_id));
-    }
-}
-
-static void
-repeating_sounds_item_delete (gpointer data)
-{
-  EmpathyRepeatableSound *repeatable_sound = data;
-
-  if (repeatable_sound->replay_timeout_id != 0)
-    g_source_remove (repeatable_sound->replay_timeout_id);
-
-  g_signal_handlers_disconnect_by_func (repeatable_sound->widget,
-      empathy_sound_widget_destroyed_cb, repeatable_sound);
-
-  g_slice_free (EmpathyRepeatableSound, repeatable_sound);
-}
-
-/**
- * empathy_sound_start_playing:
- * @widget: The #GtkWidget from which the sound is originating.
- * @sound_id: The #EmpathySound to play.
- * @timeout_before_replay: The amount of time, in milliseconds, between two
- *                         consecutive play.
- *
- * Start playing a sound in loop. To stop the sound, call empathy_call_stop ()
- * by passing it the same @sound_id. Note that if you start playing a sound
- * multiple times, you'll have to call %empathy_sound_stop the same number of
- * times.
- *
- * Return value: %TRUE if the sound has successfully started playing.
- */
-gboolean
-empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id,
-    guint timeout_before_replay)
-{
-  EmpathyRepeatableSound *repeatable_sound;
-  gboolean playing = FALSE;
-
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-  g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
-
-  if (!empathy_sound_pref_is_enabled (sound_id))
-    return FALSE;
-
-  if (repeating_sounds == NULL)
-    {
-      repeating_sounds = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-          NULL, repeating_sounds_item_delete);
-    }
-  else if (g_hash_table_lookup (repeating_sounds,
-               GINT_TO_POINTER (sound_id)) != NULL)
-    {
-      /* The sound is already playing in loop. No need to continue. */
-      return FALSE;
-    }
-
-  repeatable_sound = g_slice_new0 (EmpathyRepeatableSound);
-  repeatable_sound->widget = widget;
-  repeatable_sound->sound_id = sound_id;
-  repeatable_sound->play_interval = timeout_before_replay;
-  repeatable_sound->replay_timeout_id = 0;
-
-  g_hash_table_insert (repeating_sounds, GINT_TO_POINTER (sound_id),
-      repeatable_sound);
-
-  g_signal_connect (G_OBJECT (widget), "destroy",
-      G_CALLBACK (empathy_sound_widget_destroyed_cb),
-      repeatable_sound);
-
-  playing = empathy_sound_play_internal (widget, sound_id, playing_finished_cb,
-        repeatable_sound);
-
-  if (!playing)
-      g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id));
-
-  return playing;
-}
diff --git a/libempathy-gtk/empathy-sound.h b/libempathy-gtk/empathy-sound.h
deleted file mode 100644 (file)
index f65f626..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * empathy-sound.h - Various sound related utility functions.
- * Copyright (C) 2009 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-
-#ifndef __EMPATHY_SOUND_H__
-#define __EMPATHY_SOUND_H__
-
-#include <gtk/gtk.h>
-
-#include <canberra-gtk.h>
-
-G_BEGIN_DECLS
-
-/* NOTE: Keep this sync with sound_entries in empathy-sound.c */
-typedef enum {
-       EMPATHY_SOUND_MESSAGE_INCOMING = 0,
-       EMPATHY_SOUND_MESSAGE_OUTGOING,
-       EMPATHY_SOUND_CONVERSATION_NEW,
-       EMPATHY_SOUND_CONTACT_CONNECTED,
-       EMPATHY_SOUND_CONTACT_DISCONNECTED,
-       EMPATHY_SOUND_ACCOUNT_CONNECTED,
-       EMPATHY_SOUND_ACCOUNT_DISCONNECTED,
-       EMPATHY_SOUND_PHONE_INCOMING,
-       EMPATHY_SOUND_PHONE_OUTGOING,
-       EMPATHY_SOUND_PHONE_HANGUP,
-       LAST_EMPATHY_SOUND,
-} EmpathySound;
-
-gboolean empathy_sound_play (GtkWidget *widget, EmpathySound sound_id);
-void empathy_sound_stop (EmpathySound sound_id);
-
-gboolean empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id,
-    guint timeout_before_replay);
-
-gboolean empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id,
-    ca_finish_callback_t callback, gpointer user_data);
-
-G_END_DECLS
-
-#endif /* #ifndef __EMPATHY_SOUND_H__*/
index 6345358d3ef2f0876d71cc5401a9c54c17fb0d36..7add53452e7368a79befba4d93daaf60fbaffa8d 100644 (file)
@@ -58,7 +58,7 @@ libempathy-gtk/empathy-new-call-dialog.c
 libempathy-gtk/empathy-presence-chooser.c
 libempathy-gtk/empathy-protocol-chooser.c
 [type: gettext/glade]libempathy-gtk/empathy-search-bar.ui
-libempathy-gtk/empathy-sound.c
+libempathy-gtk/empathy-sound-manager.c
 libempathy-gtk/empathy-status-preset-dialog.c
 [type: gettext/glade]libempathy-gtk/empathy-status-preset-dialog.ui
 libempathy-gtk/empathy-theme-adium.c
index 00ea56728a009f76240d80bd3b765412c15c6c05..4d2d99c2711640de16717673cf592b0d7d02c305 100644 (file)
@@ -44,7 +44,7 @@
 #include <libempathy-gtk/empathy-audio-sink.h>
 #include <libempathy-gtk/empathy-video-src.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-sound.h>
+#include <libempathy-gtk/empathy-sound-manager.h>
 #include <libempathy-gtk/empathy-geometry.h>
 #include <libempathy-gtk/empathy-images.h>
 
index 6616a18d7d024e439e5c8420c8e422d956bf5ecf..97514e63dc2efe8c23ad08d68432bbc391e81e59 100644 (file)
@@ -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>
 
index e40d1c25f8c6b81875cc25bb58909e10909fd3ba..0877c2699a5a8625fe46b102dd3fe508335dedba 100644 (file)
@@ -43,7 +43,7 @@
 
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-contact-dialogs.h>
-#include <libempathy-gtk/empathy-sound.h>
+#include <libempathy-gtk/empathy-sound-manager.h>
 
 #include "empathy-event-manager.h"
 #include "empathy-main-window.h"
index cdf0deddb38bfdfdd6c49ca6943268e5c25d0585..8b96618382b6cf656cfb44e0dd4ecd9dfdfaaf49 100644 (file)
@@ -60,7 +60,7 @@
 #include <libempathy-gtk/empathy-new-call-dialog.h>
 #include <libempathy-gtk/empathy-log-window.h>
 #include <libempathy-gtk/empathy-presence-chooser.h>
-#include <libempathy-gtk/empathy-sound.h>
+#include <libempathy-gtk/empathy-sound-manager.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 
 #include "empathy-accounts-dialog.h"