Support to copy thumbnail to RW directory
[platform/core/uifw/capi-ui-sticker.git] / server / stickerd_data_manager.c
index 4f0b5b2..fc5492b 100644 (file)
@@ -214,6 +214,7 @@ int stickerd_register_dbus_interface(void)
 
             "        <method name='update_sticker_thumbnail'>"
             "          <arg type='i' name='record_id' direction='in'/>"
+            "          <arg type='s' name='app_id' direction='in'/>"
             "          <arg type='s' name='thumbnail' direction='in'/>"
             "        </method>"
 
@@ -595,6 +596,21 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
         }
     }
 
+    if (sticker_info->thumbnail) {
+        if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) {
+            sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id);
+            if (!sticker_info->thumbnail) {
+                LOGE("failed to copy sticker thumbnail");
+                ret = STICKERD_SERVER_ERROR_FILE_EXISTS;
+                goto cleanup;
+            }
+        } else {
+            LOGE("sticker thumbnail does not exist");
+            ret = STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+            goto cleanup;
+        }
+    }
+
     ret = stickerd_db_insert_sticker_info(&record_id, sticker_info);
     if (ret != STICKERD_SERVER_ERROR_NONE) {
         LOGE("Failed to insert sticker info");
@@ -738,8 +754,15 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_
                 goto free_memory;
 
             sticker_info->thumbnail = _get_string_from_object(info_object, "thumbnail");
-            if (!sticker_info->thumbnail)
-                goto free_memory;
+            if (sticker_info->thumbnail) {
+                if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) {
+                    sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id);
+                    if (!sticker_info->thumbnail)
+                        goto free_memory;
+                } else {
+                    goto free_memory;
+                }
+            }
 
             sticker_info->description = _get_string_from_object(info_object, "description");
 
@@ -892,6 +915,7 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod
 {
     int ret;
     int record_id;
+    char *app_id;
     char *thumbnail;
 
     *reply_body = g_variant_new("()");
@@ -900,7 +924,17 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod
         return STICKERD_SERVER_ERROR_OPERATION_FAILED;
     }
 
-    g_variant_get(parameters, "(i&s)", &record_id, &thumbnail);
+    g_variant_get(parameters, "(i&s&s)", &record_id, &app_id, &thumbnail);
+
+    if (_check_file_exist(app_id, thumbnail) == 0) {
+        thumbnail = _convert_sticker_uri(thumbnail, app_id);
+        if (!thumbnail) {
+            LOGE("failed to copy sticker thumbnail");
+            return STICKERD_SERVER_ERROR_FILE_EXISTS;
+        }
+    } else {
+        return STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+    }
 
     ret = stickerd_db_update_sticker_info(record_id, STICKER_DB_STICKER_THUMBNAIL, (void *)thumbnail);
     if (ret != STICKERD_SERVER_ERROR_NONE) {