N#19140 System alerts still audible despite being turned off
authorLuc Pionchon <luc.pionchon@nokia.com>
Thu, 13 Oct 2005 12:24:18 +0000 (12:24 +0000)
committerLuc Pionchon <luc.pionchon@nokia.com>
Thu, 13 Oct 2005 12:24:18 +0000 (12:24 +0000)
* hildon-widgets/hildon-note.c (sound_handling):

        * hildon-system-sound.[ch]: New files, implements hildon_play_system_sound.

        * hildon-note.c (sound_handling): Changed to use new
        hildon_play_system_sound.
        (hildon_note_init): Signal handler id is changed to be in private
        structure, not in global variable.

        * hildon-note.c: Removed unused defines etc.

        * Makefile.am: Appended new files to build rules.

ChangeLog
hildon-widgets/Makefile.am
hildon-widgets/hildon-note.c
hildon-widgets/hildon-system-sound.c [new file with mode: 0644]
hildon-widgets/hildon-system-sound.h [new file with mode: 0644]

index a247891..4426f50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2005-10-12  Luc Pionchon  <luc.pionchon@nokia.com>
+
+        N#19140 System alerts still audible despite being turned off
+       
+       * hildon-widgets/hildon-note.c (sound_handling): 
+
+       * hildon-system-sound.[ch]: New files, implements hildon_play_system_sound.
+
+       * hildon-note.c (sound_handling): Changed to use new
+       hildon_play_system_sound.
+       (hildon_note_init): Signal handler id is changed to be in private
+       structure, not in global variable.
+       
+       * hildon-note.c: Removed unused defines etc.
+
+        * Makefile.am: Appended new files to build rules.
+
 2005-10-05  Luc Pionchon  <luc.pionchon@nokia.com>
 
        * configure.ac: 0.9.51
index 61a5afc..38489a2 100644 (file)
@@ -80,7 +80,9 @@ libhildonwidgets_la_SOURCES = \
        hildon-color-popup.c \
        hildon-color-popup.h \
        hildon-color-button.c \
-       hildon-color-button.h
+       hildon-color-button.h \
+       hildon-system-sound.c \
+       hildon-system-sound.h
 
 hildon-marshalers.h: hildon-marshalers.list
        glib-genmarshal --prefix _hildon_marshal --header \
@@ -123,4 +125,5 @@ hildonwidgetsincludeinst_DATA = \
        hildon-scroll-area.h \
        hildon-wizard-dialog.h \
        hildon-color-popup.h \
-       hildon-color-button.h
+       hildon-color-button.h \
+       hildon-system-sound.h
index e9fd2c3..ed42385 100644 (file)
 #include <gtk/gtkbutton.h>
 #include <libintl.h>
 #include <hildon-widgets/hildon-defines.h>
+#include <hildon-widgets/hildon-system-sound.h>
 
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <signal.h>
 
-#include <esd.h>
-
 /* Can these be included from somewhere? */
 
-#define OSSO_MEDIA_SERVICE "com.nokia.osso_media_server"
-#define OSSO_MEDIA_PATH "/com/nokia/osso_media_server"
-#define OSSO_MEDIA_INTERFACE "com.nokia.osso_media_server.sound"
-#define OSSO_MEDIA_PLAY_METHOD "play_sound"
-
-#define CONFIRMATION_SOUND_URI "file:///usr/share/sounds/"\
-                                "ui-confirmation_note.wav"
 #define CONFIRMATION_SOUND_PATH "/usr/share/sounds/ui-confirmation_note.wav"
-
-#define INFORMATION_SOUND_URI "file:///usr/share/sounds/"\
-                               "ui-information_note.wav"
 #define INFORMATION_SOUND_PATH "/usr/share/sounds/ui-information_note.wav"
 
 #define HILDON_NOTE_CONFIRMATION_ICON        "qgn_note_confirm"
 #define ELLIPSATION_STRING "\342\200\246"
 #define BOX_SPACING 10
 
-/* Not exactly sure what this actually _should_ be, because there is
-   practically no documentation for the ESD... */
-
-#define ESD_NAME "hildon-note-instance"
-
 #define _(String) dgettext(PACKAGE, String)
 
 static GtkDialogClass *parent_class;
@@ -110,7 +94,7 @@ static void hildon_note_get_property(GObject * object,
                                      GValue * value, GParamSpec * pspec);
 
 static gboolean
-sound_handling(GtkWidget * widget, gpointer data);
+sound_handling(GtkWidget * widget, GdkEventExpose *event, gpointer data);
 
 /* common measurement */
 const int _HILDON_NOTE_CONFIRMATION_TEXT_MAX_WIDTH = 319; 
@@ -123,6 +107,7 @@ struct _HildonNotePrivate {
 
     HildonNoteType note_n;
     GtkWidget *progressbar;
+    gulong sound_signal_handler;
     gchar *icon;
 
     gchar *original_description;
@@ -138,8 +123,6 @@ enum {
     PROP_HILDON_NOTE_PROGRESSBAR
 };
 
-gulong sound_signal_handler = 0;
-
 /* This function is just a modified version of two_lines_truncate
  * in gtk-infoprint.c */
 static void
@@ -557,7 +540,7 @@ static void hildon_note_init(HildonNote * dialog)
 
     /* Because ESD is synchronous, we wish to play sound after the
        note is already on screen to avoid blocking its appearance */
-    sound_signal_handler = 
+    priv->sound_signal_handler = 
       g_signal_connect_after(G_OBJECT(dialog), "expose-event",
                             G_CALLBACK(sound_handling), dialog);
 }
@@ -1059,41 +1042,25 @@ void hildon_note_set_button_texts(HildonNote * note, const gchar * textOk,
     }
 }
 
-
-
 static gboolean
-sound_handling(GtkWidget * widget, gpointer data)
+sound_handling(GtkWidget * widget, GdkEventExpose *event, gpointer data)
 {
-  
-  HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(HILDON_NOTE(widget));
-
-  if (priv->note_n != HILDON_NOTE_INFORMATION_TYPE &&
-      priv->note_n != HILDON_NOTE_INFORMATION_THEME_TYPE &&
-      priv->note_n != HILDON_NOTE_CONFIRMATION_TYPE &&
-      priv->note_n != HILDON_NOTE_CONFIRMATION_BUTTON_TYPE)
-    {
-      g_signal_handler_disconnect(G_OBJECT(widget),
-                                 sound_signal_handler);
-      return FALSE;
-    }
-
-  if (priv->note_n == HILDON_NOTE_INFORMATION_TYPE ||
-      priv->note_n == HILDON_NOTE_INFORMATION_THEME_TYPE)
-    {
-      esd_play_file(ESD_NAME, INFORMATION_SOUND_PATH, 1);
-
-      g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);
-      return FALSE;
-    }
-
-    else if (priv->note_n == HILDON_NOTE_CONFIRMATION_TYPE ||
-          priv->note_n ==  HILDON_NOTE_CONFIRMATION_BUTTON_TYPE)
-    {
-      esd_play_file(ESD_NAME, CONFIRMATION_SOUND_PATH, 1);
+  HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE(widget);
+  g_signal_handler_disconnect(widget, priv->sound_signal_handler);
+
+  switch (priv->note_n)
+  {
+    case HILDON_NOTE_INFORMATION_TYPE:
+    case HILDON_NOTE_INFORMATION_THEME_TYPE:
+      hildon_play_system_sound(INFORMATION_SOUND_PATH);
+      break;
+    case HILDON_NOTE_CONFIRMATION_TYPE:
+    case HILDON_NOTE_CONFIRMATION_BUTTON_TYPE:
+      hildon_play_system_sound(CONFIRMATION_SOUND_PATH);
+      break;
+    default:
+      break;
+  };
 
-      g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);
-      return FALSE;
-    }
-  g_signal_handler_disconnect(G_OBJECT(widget), sound_signal_handler);
   return FALSE;
 }
diff --git a/hildon-widgets/hildon-system-sound.c b/hildon-widgets/hildon-system-sound.c
new file mode 100644 (file)
index 0000000..f3a16eb
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * This file is part of hildon-libs
+ *
+ * Copyright (C) 2005 Nokia Corporation.
+ *
+ * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ *
+ * 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 <gconf/gconf-client.h>
+#include <esd.h>
+#include "hildon-system-sound.h"
+
+#define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
+
+/**
+ * hildon_play_system_sound:
+ * @sample: Sound file to play
+ * 
+ * Plays the given sample using esd sound daemon.
+ * Volume level is received from gconf. 
+ */
+void hildon_play_system_sound(const gchar *sample)
+{
+  GConfClient *client;
+  GConfValue *value;
+  gint volume, scale, sock, sample_id;
+
+  client = gconf_client_get_default();
+  value = gconf_client_get(client, ALARM_GCONF_PATH, NULL);
+
+  /* We want error cases to match full volume, not silence, so
+     we do not want to use gconf_client_get_int */
+  if (!value || value->type != GCONF_VALUE_INT) {
+    g_message("Failed to get volume level. Using default");
+    volume = 2;
+  }
+  else
+    volume = gconf_value_get_int(value);
+
+  if (value)
+    gconf_value_free(value);
+  g_object_unref(client);
+
+  switch (volume)
+  {
+    case 0:
+      g_message("System sounds are off");
+      return;
+    case 1:
+      scale = 0x80;
+      break;
+    case 2:
+    default:
+      scale = 0xff;
+      break;
+  };
+    
+  sock = esd_open_sound(NULL);
+  if (sock <= 0) {
+    g_warning("Failed to setup ESD");
+    return;
+  }
+
+  sample_id = esd_file_cache(sock, g_get_prgname(), sample);
+  if (sample_id < 0) {
+    close(sock);
+    g_warning("error while caching sample.");
+    return;
+  }
+  
+  g_message("Playing sample %s at volume %d", sample, scale);
+  esd_set_default_sample_pan(sock, sample_id, scale, scale);
+  esd_sample_play(sock, sample_id);
+  esd_sample_free(sock, sample_id);
+  close(sock);
+}
diff --git a/hildon-widgets/hildon-system-sound.h b/hildon-widgets/hildon-system-sound.h
new file mode 100644 (file)
index 0000000..646e71f
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * This file is part of hildon-libs
+ *
+ * Copyright (C) 2005 Nokia Corporation.
+ *
+ * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ *
+ * 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 __HILDON_SYSTEM_SOUND_H__
+#define __HILDON_SYSTEM_SOUND_H__
+
+G_BEGIN_DECLS
+
+void hildon_play_system_sound(const gchar *sample);
+
+G_END_DECLS
+#endif /* __HILDON_SYSTEM_SOUND_H__ */