Now we use libcanberra and libprofile for sounds
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 4 Dec 2008 21:24:20 +0000 (21:24 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 4 Dec 2008 21:24:20 +0000 (21:24 +0000)
pmo-drop-split-view-r6666

configure.ac
src/hildon2/modest-platform.c

index 7c86bbc..933fdf6 100644 (file)
@@ -162,6 +162,8 @@ if test "$have_hildon1" = "true"; then
    if test "$have_hildon2" = "true"; then
       echo "DETECTED HILDON 2 $have_hildon2."
       detected_toolkit=hildon2
+      hildonpkgs="$hildonpkgs libcanberra profile"
+      echo "HILDON 2 PACKAGES $hildonpkgs"
    fi
 else
    hildonpkgs="hildon-libs hildon-fm"
index 1b422ec..c3347d0 100644 (file)
@@ -58,6 +58,9 @@
 #include <osso-mem.h>
 #include "hildon2/modest-hildon2-details-dialog.h"
 #include "hildon2/modest-hildon2-window-mgr.h"
+#include <keys_nokia.h>
+#include <libprofile.h>
+#include <canberra.h>
 
 #ifdef MODEST_HAVE_MCE
 #include <mce/dbus-names.h>
 
 #define HILDON_OSSO_URI_ACTION "uri-action"
 #define URI_ACTION_COPY "copy:"
-#define MODEST_NEW_MAIL_SOUND_FILE "/usr/share/sounds/ui-new_email.wav"
 #define MODEST_NEW_MAIL_LIGHTING_PATTERN "PatternCommunicationEmail"
+#define PROFILE_MAIL_TONE PROFILEKEY_EMAIL_ALERT_TONE
+#define PROFILE_MAIL_VOLUME PROFILEKEY_EMAIL_ALERT_VOLUME
+
+static void _modest_platform_play_email_tone (void);
+
 
 static void    
 on_modest_conf_update_interval_changed (ModestConf* self, 
@@ -1145,26 +1152,16 @@ modest_platform_set_update_interval (guint minutes)
 void
 modest_platform_push_email_notification(void)
 {
-       gboolean play_sound;
        gboolean screen_on = TRUE, app_in_foreground;
 
-       /* Check whether or not we should play a sound */
-       play_sound = modest_conf_get_bool (modest_runtime_get_conf (),
-                                          MODEST_CONF_PLAY_SOUND_MSG_ARRIVE,
-                                          NULL);
-
-       /* Get the screen status */
-       /* TODO :obtain properly the screen_is_on status */
-
        /* Get the window status */
        app_in_foreground = hildon_program_get_is_topmost (hildon_program_get_instance ());
 
        /* If the screen is on and the app is in the
           foreground we don't show anything */
        if (!(screen_on && app_in_foreground)) {
-               /* Play a sound */
-               if (play_sound)
-                       hildon_play_system_sound (MODEST_NEW_MAIL_SOUND_FILE);
+
+               _modest_platform_play_email_tone ();
 
                /* Activate LED. This must be deactivated by
                   modest_platform_remove_new_mail_notifications */
@@ -1199,13 +1196,6 @@ modest_platform_on_new_headers_received (TnyList *header_list,
        }
 
 #ifdef MODEST_HAVE_HILDON_NOTIFY
-       gboolean play_sound;
-
-       /* Check whether or not we should play a sound */
-       play_sound = modest_conf_get_bool (modest_runtime_get_conf (),
-                                          MODEST_CONF_PLAY_SOUND_MSG_ARRIVE,
-                                          NULL);
-
        HildonNotification *notification;
        TnyIterator *iter;
        GSList *notifications_list = NULL;
@@ -1257,11 +1247,25 @@ modest_platform_on_new_headers_received (TnyList *header_list,
                /* Play sound if the user wants. Show the LED
                   pattern. Show and play just one */
                if (G_UNLIKELY (first_notification)) {
+                       gchar *active_profile;
+                       gchar *mail_tone;
+                       gchar *mail_volume;
+                       gint mail_volume_int;
+
                        first_notification = FALSE;
-                       if (play_sound)  {
+
+                       active_profile = profile_get_profile ();
+                       mail_tone = profile_get_value (active_profile, PROFILE_MAIL_TONE);
+                       mail_volume = profile_get_value (active_profile, PROFILE_MAIL_VOLUME);
+                       mail_volume_int = profile_parse_int (mail_volume);
+
+                       if (mail_volume_int > 0)
                                notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification),
-                                                                   "sound-file", MODEST_NEW_MAIL_SOUND_FILE);
-                       }
+                                                                   "sound-file", mail_tone);
+
+                       g_free (mail_volume);
+                       g_free (mail_tone);
+                       g_free (active_profile);
 
                        /* Set the led pattern */
                        notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION (notification),
@@ -2106,3 +2110,48 @@ modest_platform_get_osso_context (void)
 {
        return modest_maemo_utils_get_osso_context ();
 }
+
+static void
+_modest_platform_play_email_tone (void)
+{
+       gchar *active_profile;
+       gchar *mail_tone;
+       gchar *mail_volume;
+       gint mail_volume_int;
+       int ret;
+       ca_context *ca_con = NULL;
+       ca_proplist *pl = NULL;
+
+       active_profile = profile_get_profile ();
+       mail_tone = profile_get_value (active_profile, PROFILE_MAIL_TONE);
+       mail_volume = profile_get_value (active_profile, PROFILE_MAIL_VOLUME);
+       mail_volume_int = profile_parse_int (mail_volume);
+
+       if (mail_volume_int > 0) {
+
+               if ((ret = ca_context_create(&ca_con)) != CA_SUCCESS) {
+                       g_warning("ca_context_create: %s\n", ca_strerror(ret));
+                       return;
+               }
+
+               if ((ret = ca_context_open(ca_con)) != CA_SUCCESS) {
+                       g_warning("ca_context_open: %s\n", ca_strerror(ret));
+                       ca_context_destroy(ca_con);
+                       return;
+               }
+
+               ca_proplist_create(&pl);
+               ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, mail_tone);
+               ca_proplist_setf(pl, CA_PROP_CANBERRA_VOLUME, "%f", (gfloat) mail_volume_int);
+
+               ret = ca_context_play_full(ca_con, 0, pl, NULL, NULL);
+               g_debug("ca_context_play_full (vol %f): %s\n", (gfloat) mail_volume_int, ca_strerror(ret));
+
+               ca_proplist_destroy(pl);
+               ca_context_destroy(ca_con);
+       }
+
+       g_free (mail_volume);
+       g_free (mail_tone);
+       g_free (active_profile);
+}