[ekiga/ds-gsettings3: 21/33] GSettings: Ported the sound events part of the engine.



commit edecb965a89c0f4d35853900375eaa4e13c829b5
Author: Damien Sandras <dsandras beip be>
Date:   Sat Apr 20 17:51:36 2013 +0200

    GSettings: Ported the sound events part of the engine.

 lib/engine/audiooutput/audiooutput-core.cpp        |   58 ++++++++++++
 lib/engine/audiooutput/audiooutput-core.h          |    8 ++
 .../audiooutput/audiooutput-gmconf-bridge.cpp      |   96 --------------------
 3 files changed, 66 insertions(+), 96 deletions(-)
---
diff --git a/lib/engine/audiooutput/audiooutput-core.cpp b/lib/engine/audiooutput/audiooutput-core.cpp
index a6ba0f9..0ac44b7 100644
--- a/lib/engine/audiooutput/audiooutput-core.cpp
+++ b/lib/engine/audiooutput/audiooutput-core.cpp
@@ -38,12 +38,26 @@
 #include <math.h>
 
 #include <glib/gi18n.h>
+#include <boost/algorithm/string.hpp>
 
 #include "audiooutput-core.h"
 #include "audiooutput-manager.h"
 
+#include "ekiga-settings.h"
+
 using namespace Ekiga;
 
+static void sound_event_changed (G_GNUC_UNUSED GSettings *settings,
+                                 const gchar *key,
+                                 gpointer data)
+{
+  g_return_if_fail (data != NULL);
+  AudioOutputCore *core = (AudioOutputCore*) (data);
+
+  core->setup_sound_events (key);
+}
+
+
 AudioOutputCore::AudioOutputCore (Ekiga::ServiceCore& core)
 {
   PWaitAndSignal m_pri(core_mutex[primary]);
@@ -70,6 +84,9 @@ AudioOutputCore::AudioOutputCore (Ekiga::ServiceCore& core)
   yield = false;
 
   notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
+  sound_events_settings = g_settings_new (SOUND_EVENTS_SCHEMA);
+
+  setup_sound_events ();
 }
 
 AudioOutputCore::~AudioOutputCore ()
@@ -98,6 +115,47 @@ void AudioOutputCore::setup_conf_bridge ()
    audiooutput_core_conf_bridge = new AudioOutputCoreConfBridge (*this);
 }
 
+void AudioOutputCore::setup_sound_events (std::string e)
+{
+  static const char *events[] =
+    {
+      "busy-tone-sound",
+      "incoming-call-sound",
+      "new-message-sound",
+      "new-voicemail-sound",
+      "ring-tone-sound"
+    };
+
+  boost::replace_all (e, "enable-", "");
+  for (int i = 0 ; i < 5 ; i++) {
+    std::string event = events[i];
+
+    if (e.empty () || e == event) {
+      gchar *file_name = NULL;
+      bool enabled;
+
+      file_name = g_settings_get_string (sound_events_settings, event.c_str ());
+      enabled = g_settings_get_boolean (sound_events_settings, ("enable-" + event).c_str ());
+      if (file_name == NULL) {
+        PTRACE(1, "AudioOutputCoreConfBridge\t" << event << " is NULL");
+        return;
+      }
+      else
+        PTRACE(1, "AudioOutputCoreConfBridge\t" << event << " set to " << file_name);
+
+      map_event (event, file_name, primary, enabled);
+      g_free (file_name);
+    }
+
+    if (e.empty ()) {
+      g_signal_connect (sound_events_settings, ("changed::" + event).c_str (),
+                        G_CALLBACK (sound_event_changed), this);
+      g_signal_connect (sound_events_settings, ("changed::enable-" + event).c_str (),
+                        G_CALLBACK (sound_event_changed), this);
+    }
+  }
+}
+
 void AudioOutputCore::add_manager (AudioOutputManager &manager)
 {
   managers.insert (&manager);
diff --git a/lib/engine/audiooutput/audiooutput-core.h b/lib/engine/audiooutput/audiooutput-core.h
index 5b6a74e..003eed1 100644
--- a/lib/engine/audiooutput/audiooutput-core.h
+++ b/lib/engine/audiooutput/audiooutput-core.h
@@ -47,6 +47,8 @@
 
 #include <ptlib.h>
 
+#include <gio/gio.h>
+
 #define AUDIO_OUTPUT_FALLBACK_DEVICE_TYPE "Ekiga"
 #define AUDIO_OUTPUT_FALLBACK_DEVICE_SOURCE "Ekiga"
 #define AUDIO_OUTPUT_FALLBACK_DEVICE_NAME   "SILENT"
@@ -99,6 +101,10 @@ namespace Ekiga
        */
       void setup_conf_bridge();
 
+      /** Set up sound events
+       * @param The sound event to setup. Leave empty for all.
+       */
+      void setup_sound_events (std::string event = "");
 
       /*** Service Implementation ***/
 
@@ -366,6 +372,8 @@ namespace Ekiga
       bool yield;
 
       boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+
+      GSettings *sound_events_settings;
     };
 /**
  * @}
diff --git a/lib/engine/audiooutput/audiooutput-gmconf-bridge.cpp 
b/lib/engine/audiooutput/audiooutput-gmconf-bridge.cpp
index bf8dc6c..a0e121c 100644
--- a/lib/engine/audiooutput/audiooutput-gmconf-bridge.cpp
+++ b/lib/engine/audiooutput/audiooutput-gmconf-bridge.cpp
@@ -46,16 +46,6 @@ AudioOutputCoreConfBridge::AudioOutputCoreConfBridge (Ekiga::AudioOutputCore& _c
 
   keys.push_back (AUDIO_DEVICES_KEY "output_device");
   keys.push_back (SOUND_EVENTS_KEY "output_device");
-  keys.push_back (SOUND_EVENTS_KEY "busy_tone_sound");
-  keys.push_back (SOUND_EVENTS_KEY "incoming_call_sound");
-  keys.push_back (SOUND_EVENTS_KEY "new_message_sound");
-  keys.push_back (SOUND_EVENTS_KEY "new_voicemail_sound");
-  keys.push_back (SOUND_EVENTS_KEY "ring_tone_sound");
-  keys.push_back (SOUND_EVENTS_KEY "enable_busy_tone_sound");
-  keys.push_back (SOUND_EVENTS_KEY "enable_incoming_call_sound");
-  keys.push_back (SOUND_EVENTS_KEY "enable_new_message_sound");
-  keys.push_back (SOUND_EVENTS_KEY "enable_new_voicemail_sound");
-  keys.push_back (SOUND_EVENTS_KEY "enable_ring_tone_sound");
 
   load (keys);
 }
@@ -133,91 +123,5 @@ AudioOutputCoreConfBridge::on_property_changed (std::string key,
     }
     audiooutput_core.set_device (secondary, device);
   }
-
-  if ( (key == SOUND_EVENTS_KEY "busy_tone_sound") ||
-       (key == SOUND_EVENTS_KEY "enable_busy_tone_sound") ) {
-
-    gchar *c_file_name = NULL;
-    c_file_name = gm_conf_get_string (SOUND_EVENTS_KEY "busy_tone_sound");
-    if (c_file_name == NULL) {
-      PTRACE(1, "AudioOutputCoreConfBridge\t" << SOUND_EVENTS_KEY "busy_tone_sound" << " is NULL");
-      return;
-    }
-
-    name = "busy_tone_sound";
-    file_name = c_file_name;
-    g_free (c_file_name);
-    enabled = gm_conf_get_bool (SOUND_EVENTS_KEY "enable_busy_tone_sound");
-    audiooutput_core.map_event (name, file_name, primary, enabled);
-  }
-
-  if ( (key == SOUND_EVENTS_KEY "incoming_call_sound") ||
-       (key == SOUND_EVENTS_KEY "enable_incoming_call_sound") ) {
-
-    gchar *c_file_name = NULL;
-    c_file_name = gm_conf_get_string (SOUND_EVENTS_KEY "incoming_call_sound");
-    if (c_file_name == NULL) {
-      PTRACE(1, "AudioOutputCoreConfBridge\t" <<  SOUND_EVENTS_KEY "incoming_call_sound" << " is NULL");
-      return;
-    }
-
-    name = "incoming_call_sound";
-    file_name = c_file_name;
-    g_free (c_file_name);
-    enabled = gm_conf_get_bool (SOUND_EVENTS_KEY "enable_incoming_call_sound");
-    audiooutput_core.map_event (name, file_name, secondary, enabled);
-  }
-
-  if ( (key == SOUND_EVENTS_KEY "new_message_sound") ||
-       (key == SOUND_EVENTS_KEY "enable_new_message_sound") ) {
-
-    gchar *c_file_name = NULL;
-    c_file_name = gm_conf_get_string (SOUND_EVENTS_KEY "new_message_sound");
-    if (c_file_name == NULL) {
-      PTRACE(1, "AudioOutputCoreConfBridge\t" <<  SOUND_EVENTS_KEY "new_message_sound" << " is NULL");
-      return;
-    }
-
-    name = "new_message_sound";
-    file_name = c_file_name;
-    g_free (c_file_name);
-    enabled = gm_conf_get_bool (SOUND_EVENTS_KEY "enable_new_message_sound");
-    audiooutput_core.map_event (name, file_name, secondary, enabled);
-
-  }
-
-  if ( (key == SOUND_EVENTS_KEY "new_voicemail_sound") ||
-       (key == SOUND_EVENTS_KEY "enable_new_voicemail_sound") ) {
-
-    gchar *c_file_name = NULL;
-    c_file_name = gm_conf_get_string (SOUND_EVENTS_KEY "new_voicemail_sound");
-    if (c_file_name == NULL) {
-      PTRACE(1, "AudioOutputCoreConfBridge\t" <<  SOUND_EVENTS_KEY "new_voicemail_sound" << " is NULL");
-      return;
-    }
-
-    name = "new_voicemail_sound";
-    file_name = c_file_name;
-    g_free (c_file_name);
-    enabled = gm_conf_get_bool (SOUND_EVENTS_KEY "enable_new_voicemail_sound");
-    audiooutput_core.map_event (name, file_name, secondary, enabled);
-  }
-
-  if ( (key == SOUND_EVENTS_KEY "ring_tone_sound") ||
-       (key == SOUND_EVENTS_KEY "enable_ring_tone_sound") ) {
-
-    gchar *c_file_name = NULL;
-    c_file_name = gm_conf_get_string (SOUND_EVENTS_KEY "ring_tone_sound");
-    if (c_file_name == NULL) {
-      PTRACE(1, "AudioOutputCoreConfBridge\t" <<  SOUND_EVENTS_KEY "ring_tone_sound" << " is NULL");
-      return;
-    }
-
-    name = "ring_tone_sound";
-    file_name = c_file_name;
-    g_free (c_file_name);
-    enabled = gm_conf_get_bool (SOUND_EVENTS_KEY "enable_ring_tone_sound");
-    audiooutput_core.map_event (name, file_name, primary, enabled);
-  }
 }
 


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