Add default viewer launch feature for ex-noti 31/215731/2
authorJusung Son <jusung07.son@samsung.com>
Tue, 15 Oct 2019 04:17:51 +0000 (13:17 +0900)
committerJusung Son <jusung07.son@samsung.com>
Mon, 21 Oct 2019 02:19:27 +0000 (11:19 +0900)
Related change
[notification] https://review.tizen.org/gerrit/#/c/platform/core/api/notification/+/215730/

Change-Id: I7136c3c59d7db5c1ccb4bccf4178355a3a87b273
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/notification_ex_service.cc [changed mode: 0755->0644]
src/notification_service.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index b9f44f4..1d36b95
@@ -17,6 +17,8 @@
 #include <dlog.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <notification_type.h>
+#include <notification_viewer.h>
 
 #include <iostream>
 #include <sstream>
@@ -66,6 +68,38 @@ class DPMFacade {
     manager_->SendEvent(info, noti);
   }
 
+  void LaunchDefaultViewer(list<shared_ptr<item::AbstractItem>> item,
+                                   notification_op_type_e status) {
+    int64_t priv_id;
+    if (item.size() == 0)
+      return;
+
+    if (item.size() > 1)
+      priv_id = NOTIFICATION_PRIV_ID_NONE;
+    else
+      priv_id = static_pointer_cast<IItemInfoInternal>(
+                    item.front()->GetInfo())->GetPrivateId();
+
+    LaunchDefaultViewer(priv_id, status,
+                        static_pointer_cast<IItemInfoInternal>(
+                            item.front()->GetInfo())->GetUid());
+  }
+  void LaunchDefaultViewer(shared_ptr<item::AbstractItem> item,
+              notification_op_type_e status) {
+    LaunchDefaultViewer(
+        static_pointer_cast<IItemInfoInternal>(item->GetInfo())->GetPrivateId(),
+        status,
+        static_pointer_cast<IItemInfoInternal>(item->GetInfo())->GetUid());
+  }
+
+  void LaunchDefaultViewer(int64_t privId, notification_op_type_e status,
+                                   uid_t uid) {
+    int ret = notification_launch_default_viewer(
+                   static_cast<int>(privId), status, uid);
+    if (ret != ERROR_NONE)
+      ERR("Failed to launch default viewer [%d]", ret);
+  }
+
   unique_ptr<Reporter> reporter_;
   unique_ptr<Manager> manager_;
   map<string, string> hide_map_;
@@ -253,6 +287,7 @@ class DPMManager : public Manager {
     ret = DBManager::InsertNotification(addedItem);
     if (ret == ERROR_NONE) {
       facade_->DelegateReporterEvent(info, addedItem);
+      facade_->LaunchDefaultViewer(addedItem, NOTIFICATION_OP_INSERT);
     } else {
         DBG("SendError !!!");
         SendError(info, static_cast<NotificationError>(ret));
@@ -269,12 +304,13 @@ class DPMManager : public Manager {
     ret = DBManager::UpdateNotification(updatedItem);
     if (ret == ERROR_NONE) {
       facade_->DelegateReporterEvent(info, updatedItem);
+      facade_->LaunchDefaultViewer(updatedItem, NOTIFICATION_OP_UPDATE);
     } else {
       SendError(info, static_cast<NotificationError>(ret));
     }
   }
 
-  void DoDelete(const IEventInfo& info,
+  int DoDelete(const IEventInfo& info,
       shared_ptr<item::AbstractItem> deletedItem) {
     int ret = DBManager::DeleteNotification(deletedItem);
     if (ret == ERROR_NONE) {
@@ -282,6 +318,7 @@ class DPMManager : public Manager {
     } else {
       SendError(info, static_cast<NotificationError>(ret));
     }
+    return ret;
   }
 
   void OnDelete(const IEventInfo& info,
@@ -294,8 +331,11 @@ class DPMManager : public Manager {
       for (auto& i : noti_list) {
         DoDelete(info, i);
       }
+      facade_->LaunchDefaultViewer(noti_list, NOTIFICATION_OP_DELETE_ALL);
     } else {
-      DoDelete(info, deletedItem);
+      int ret = DoDelete(info, deletedItem);
+      if (ret == ERROR_NONE)
+        facade_->LaunchDefaultViewer(deletedItem, NOTIFICATION_OP_DELETE);
     }
   }
 
@@ -330,6 +370,8 @@ HAPI int notification_ex_service_init() {
         unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
         unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())))));
 
+  notification_init_default_viewer();
+
   return ERROR_NONE;
 }
 
old mode 100755 (executable)
new mode 100644 (file)
index aeebd8a..73cbc87
@@ -51,8 +51,6 @@ static GHashTable *_monitoring_hash;
 
 static GList *_dnd_alarm_id_list;
 
-static char *default_viewer;
-
 typedef struct _dnd_alarm_id {
        uid_t uid;
        alarm_id_t dnd_start_id;
@@ -506,15 +504,14 @@ static int _add_noti(GVariant **reply_body, notification_h noti, uid_t uid)
                return ret;
        }
 
-       if (default_viewer != NULL) {
-               ret = notification_launch_default_viewer(default_viewer,
-                               priv_id, NOTIFICATION_OP_INSERT, uid);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Failed to launch default viewer [%d]", ret);
-                       ret = NOTIFICATION_ERROR_NONE;
-               }
+       ret = notification_launch_default_viewer(priv_id,
+                       NOTIFICATION_OP_INSERT, uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Failed to launch default viewer [%d]", ret);
+               ret = NOTIFICATION_ERROR_NONE;
        }
 
+
        *reply_body = g_variant_new("(i)", priv_id);
        if (*reply_body == NULL) {
                ERR("Failed to make reply");
@@ -786,13 +783,11 @@ static int _update_noti(GVariant **reply_body, notification_h noti, uid_t uid)
                return ret;
        }
 
-       if (default_viewer != NULL) {
-               ret = notification_launch_default_viewer(default_viewer,
-                               priv_id, NOTIFICATION_OP_UPDATE, uid);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Failed to launch default viewer [%d]", ret);
-                       ret = NOTIFICATION_ERROR_NONE;
-               }
+       ret = notification_launch_default_viewer(priv_id,
+                       NOTIFICATION_OP_UPDATE, uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Failed to launch default viewer [%d]", ret);
+               ret = NOTIFICATION_ERROR_NONE;
        }
 
        *reply_body = g_variant_new("(i)", priv_id);
@@ -1430,15 +1425,12 @@ static int _delete_noti(const char *app_id, int priv_id, uid_t uid)
                if (ret != NOTIFICATION_ERROR_NONE)
                        return ret;
 
-               if (default_viewer != NULL) {
-                       ret = notification_launch_default_viewer(default_viewer,
-                                       NOTIFICATION_PRIV_ID_NONE,
-                                       NOTIFICATION_OP_DELETE,
-                                       uid);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Failed to launch default viewer [%d]", ret);
-                               ret = NOTIFICATION_ERROR_NONE;
-                       }
+               ret = notification_launch_default_viewer(NOTIFICATION_PRIV_ID_NONE,
+                               NOTIFICATION_OP_DELETE,
+                               uid);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ERR("Failed to launch default viewer [%d]", ret);
+                       ret = NOTIFICATION_ERROR_NONE;
                }
        }
 
@@ -1526,15 +1518,12 @@ int notification_del_noti_multiple(GVariant *parameters, GVariant **reply_body,
 
                free(list_deleted);
 
-               if (default_viewer != NULL) {
-                       ret = notification_launch_default_viewer(default_viewer,
-                               NOTIFICATION_PRIV_ID_NONE,
-                               NOTIFICATION_OP_DELETE_ALL,
-                               param_uid);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Failed to launch default viewer [%d]", ret);
-                               ret = NOTIFICATION_ERROR_NONE;
-                       }
+               ret = notification_launch_default_viewer(NOTIFICATION_PRIV_ID_NONE,
+                       NOTIFICATION_OP_DELETE_ALL,
+                       param_uid);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ERR("Failed to launch default viewer [%d]", ret);
+                       ret = NOTIFICATION_ERROR_NONE;
                }
        }
 
@@ -1615,15 +1604,12 @@ int notification_del_noti_by_display_applist(GVariant *parameters,
                        return ret;
                }
 
-               if (default_viewer != NULL) {
-                       ret = notification_launch_default_viewer(default_viewer,
-                               NOTIFICATION_PRIV_ID_NONE,
-                               NOTIFICATION_OP_DELETE_ALL,
-                               param_uid);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Failed to launch default viewer [%d]", ret);
-                               ret = NOTIFICATION_ERROR_NONE;
-                       }
+               ret = notification_launch_default_viewer(NOTIFICATION_PRIV_ID_NONE,
+                       NOTIFICATION_OP_DELETE_ALL,
+                       param_uid);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ERR("Failed to launch default viewer [%d]", ret);
+                       ret = NOTIFICATION_ERROR_NONE;
                }
        }
 
@@ -2640,8 +2626,6 @@ static gboolean __refresh_setting_table(gpointer data)
  */
 HAPI int notification_service_init(void)
 {
-#define DEFAULT_VIEWER_CONF_FILE "/usr/share/notification/notification.ini"
-
        int ret, i;
        int count = 0;
        uid_t *uids = NULL;
@@ -2659,7 +2643,7 @@ HAPI int notification_service_init(void)
                return NOTIFICATION_ERROR_IO_ERROR;
        }
 
-       notification_get_default_viewer(DEFAULT_VIEWER_CONF_FILE, &default_viewer);
+       notification_init_default_viewer();
        notification_noti_init_data();
        notification_system_setting_init_system_setting_table(tzplatform_getuid(TZ_SYS_DEFAULT_USER));