[Notification] Add support for sound
authorRicardo de Almeida Gonzaga <ricardo.gonzaga@intel.com>
Mon, 11 Nov 2013 18:03:04 +0000 (16:03 -0200)
committerRicardo de Almeida Gonzaga <ricardo.gonzaga@intel.com>
Thu, 14 Nov 2013 15:57:27 +0000 (13:57 -0200)
notification/notification_api.js
notification/notification_instance_mobile.cc
notification/notification_parameters.cc
notification/notification_parameters.h

index 87a6989..c99ec46 100644 (file)
@@ -17,6 +17,7 @@ var NOTIFICATION_PROPERTIES = [
   'title',
   'content',
   'iconPath',
+  'soundPath',
   'progressType',
   'progressValue',
   'subIconPath',
index 98d5f22..ee2cc06 100644 (file)
@@ -48,6 +48,37 @@ bool SetImage(notification_h n, notification_image_type_e type,
   return true;
 }
 
+bool SetSound(notification_h n, const std::string& notificationType,
+              const std::string& soundPath) {
+  if (soundPath.empty() || soundPath == "null") {
+    notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_DEFAULT;
+    if (notificationType == "ONGOING" || notificationType == "PROGRESS")
+      type = NOTIFICATION_SOUND_TYPE_NONE;
+
+    if (notification_set_sound(n, type, NULL) != NOTIFICATION_ERROR_NONE)
+      return false;
+    return true;
+  }
+
+  const char* oldSoundPath = NULL;
+  notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
+
+  if (notification_get_sound(n, &type, &oldSoundPath)
+      != NOTIFICATION_ERROR_NONE)
+    return false;
+
+  if (oldSoundPath && type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
+    if (soundPath == oldSoundPath)
+      return true;
+  }
+
+  if (notification_set_sound(n, NOTIFICATION_SOUND_TYPE_USER_DATA,
+                             soundPath.c_str())
+      != NOTIFICATION_ERROR_NONE)
+    return false;
+  return true;
+}
+
 bool SetLedColor(notification_h n, const std::string& ledColor) {
   std::string color = ledColor;
   notification_led_op_e type = NOTIFICATION_LED_OP_OFF;
@@ -118,6 +149,9 @@ bool FillNotificationHandle(notification_h n, const NotificationParameters& p) {
       return false;
   }
 
+  if (!SetSound(n, p.status_type, p.sound_path))
+    return false;
+
   if (!p.led_color.empty()) {
     if (!SetLedColor(n, p.led_color))
       return false;
index c9cfd2c..e0ac34f 100644 (file)
@@ -15,6 +15,8 @@ NotificationParameters ReadNotificationParameters(const picojson::value& v) {
 
   GetStringFromJSONValue(v.get("iconPath"), &params.icon_path);
 
+  GetStringFromJSONValue(v.get("soundPath"), &params.sound_path);
+
   if (params.status_type == "PROGRESS") {
     GetStringFromJSONValue(v.get("progressType"), &params.progress_type);
     GetULongFromJSONValue(v.get("progressValue"), &params.progress_value);
index 610890a..7319030 100644 (file)
@@ -20,6 +20,8 @@ struct NotificationParameters {
 
   std::string icon_path;
 
+  std::string sound_path;
+
   std::string progress_type;
   uint64_t progress_value;