Change default sound, vibration name
[platform/core/api/notification.git] / notification-ex / stub.cc
index 70c91e0..3a9b575 100644 (file)
@@ -42,6 +42,7 @@
 #include "notification-ex/dbus_event_listener.h"
 #include "notification-ex/exception.h"
 #include "notification-ex/iitem_info_internal.h"
+#include "notification-ex/icon_item.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -431,6 +432,47 @@ extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
   return NOTI_EX_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int noti_ex_item_button_set_image(
+    noti_ex_item_h handle, char *path) {
+  if (handle == nullptr || path == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  Handle* h = static_cast<Handle*>(handle);
+  if (!h->IsValidType(AbstractItem::Button)) {
+    LOGE("Invalid handle type");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  ButtonItem* p = static_cast<ButtonItem*>(h->Get());
+  p->SetImgPath(path);
+
+  return NOTI_EX_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int noti_ex_item_button_get_image(
+    noti_ex_item_h handle, char **path) {
+  if (handle == nullptr || path == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  Handle* h = static_cast<Handle*>(handle);
+  if (!h->IsValidType(AbstractItem::Button)) {
+    LOGE("Invalid handle type");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  ButtonItem* p = static_cast<ButtonItem*>(h->Get());
+  if (!p->GetImgPath().empty())
+    *path = strdup(p->GetImgPath().c_str());
+  else
+    *path = nullptr;
+
+  return NOTI_EX_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
     noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
     noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
@@ -1971,36 +2013,6 @@ extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
   return NOTI_EX_ERROR_NONE;
 }
 
-extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
-    char ***path, int *count) {
-  if (handle == nullptr || path == nullptr || count == nullptr) {
-    LOGE("Invalid parameter");
-    return NOTI_EX_ERROR_INVALID_PARAMETER;
-  }
-  Handle* p = static_cast<Handle*>(handle);
-  list<string> shared_path = p->Get()->GetSharedPath();
-  char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
-  if (tmp_path == nullptr) {
-    LOGE("Fail to create items");
-    return NOTI_EX_ERROR_OUT_OF_MEMORY;
-  }
-
-  int idx = 0;
-  for (auto& i : shared_path) {
-    tmp_path[idx] = strdup(i.c_str());
-    if (tmp_path[idx] == nullptr) {
-      __noti_ex_free_str_array(tmp_path, idx);
-      LOGE("Out of memory");
-      return NOTI_EX_ERROR_OUT_OF_MEMORY;
-    }
-    idx++;
-  }
-
-  *path = tmp_path;
-  *count = shared_path.size();
-  return NOTI_EX_ERROR_NONE;
-}
-
 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
     char **id) {
   if (handle == nullptr || id == nullptr) {
@@ -2711,6 +2723,24 @@ extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
   return NOTI_EX_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
+    noti_ex_manager_h handle, char* channel, int* request_id) {
+  if (handle == nullptr || channel == nullptr || request_id == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  try {
+    ManagerStub* stub = static_cast<ManagerStub*>(handle);
+    *request_id = stub->DeleteByChannel(channel);
+  } catch (Exception &ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return NOTI_EX_ERROR_IO_ERROR;
+  }
+
+  return NOTI_EX_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
     noti_ex_item_h noti, int *request_id) {
   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
@@ -3076,6 +3106,24 @@ extern "C" EXPORT_API int noti_ex_reporter_delete_all(
   return NOTI_EX_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
+    noti_ex_reporter_h handle, char* channel, int* request_id) {
+  if (handle == nullptr || channel == nullptr || request_id == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  try {
+    ReporterStub* stub = static_cast<ReporterStub*>(handle);
+    *request_id = stub->DeleteByChannel(channel);
+  } catch (Exception &ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return NOTI_EX_ERROR_IO_ERROR;
+  }
+
+  return NOTI_EX_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
   if (handle == nullptr || root_id == nullptr || item == nullptr) {
@@ -3443,3 +3491,52 @@ extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h hand
 
   return NOTI_EX_ERROR_NONE;
 }
+
+extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
+    const char *id, const char *icon_path) {
+  if (handle == nullptr || icon_path == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  IconItem* p;
+  if (id)
+    p = new (std::nothrow) IconItem(id, icon_path);
+  else
+    p = new (std::nothrow) IconItem(icon_path);
+
+  if (p == nullptr) {
+    LOGE("Out-of-memory");
+    return NOTI_EX_ERROR_OUT_OF_MEMORY;
+  }
+
+  *handle = new Handle(shared_ptr<AbstractItem>(p));
+
+  return NOTI_EX_ERROR_NONE;
+}
+
+int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
+  if (handle == nullptr || icon_path == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  Handle* h = static_cast<Handle*>(handle);
+  if (!h->IsValidType(AbstractItem::Icon)) {
+    LOGE("Invalid handle type");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  IconItem* p = static_cast<IconItem*>(h->Get());
+  if (!p->GetImagePath().empty()) {
+    *icon_path = strdup(p->GetImagePath().c_str());
+    if (*icon_path == nullptr) {
+      LOGE("Out-of-memory");
+      return NOTI_EX_ERROR_OUT_OF_MEMORY;
+    }
+  } else {
+    *icon_path = nullptr;
+  }
+
+  return NOTI_EX_ERROR_NONE;
+}