Support to create thumbnail of the sticker 46/229146/4
authorInHong Han <inhong1.han@samsung.com>
Fri, 27 Mar 2020 07:44:07 +0000 (16:44 +0900)
committerInHong Han <inhong1.han@samsung.com>
Mon, 30 Mar 2020 08:41:34 +0000 (17:41 +0900)
Change-Id: I78df10b6422fe225910870640381ecd2cdead1fa

packaging/capi-ui-sticker.spec
receiver/CMakeLists.txt
receiver/inc/config.h
receiver/inc/sticker_data.h
receiver/inc/sticker_info.h
receiver/src/ft.cpp
receiver/src/sticker_data.cpp
receiver/src/sticker_info.cpp
receiver/tizen-manifest.xml

index ee59659..4d158b4 100644 (file)
@@ -32,6 +32,7 @@ BuildRequires:  pkgconfig(capi-appfw-alarm)
 BuildRequires:  pkgconfig(capi-system-device)
 BuildRequires:  pkgconfig(sap-client-stub-api)
 BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(capi-media-thumbnail-util)
 BuildRequires:  hash-signer
 
 Requires(post): signing-client
index 4a875d9..49b6d42 100644 (file)
@@ -22,6 +22,7 @@ pkg_check_modules(pkgs_test REQUIRED
     sap-client-stub-api
     json-glib-1.0
     vconf
+    capi-media-thumbnail-util
 )
 
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc)
index 88eee4d..454bd5d 100644 (file)
@@ -28,4 +28,7 @@
 
 #define MINIMUM_BATTERY 15
 
+#define THUMBNAIL_WIDTH 96
+#define THUMBNAIL_HEIGHT 96
+
 #endif /* __CONFIG_H__ */
index 97f82cc..2989c2b 100644 (file)
@@ -32,6 +32,7 @@ struct sticker_info {
     string keyword;
     string disp_type;
     string description;
+    string thumbnail_path;
 };
 
 #endif /* __STICKER_DATA_H__ */
index 2e20ad8..3a70556 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __STICKER_INFO_H__
 #define __STICKER_INFO_H__
 
-void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc);
+void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail);
 int create_sticker_provider_handle(void);
 void destroy_sticker_provider_handle(void);
 void delete_sticker_data(const char *fileName);
index 8f81c0a..8aa293f 100644 (file)
@@ -32,6 +32,7 @@
 #include <json-glib/json-glib.h>
 #include <vconf.h>
 #include <queue>
+#include <thumbnail_util.h>
 
 #include "ft.h"
 #include "log.h"
@@ -157,11 +158,31 @@ static void _on_send_completed(sap_file_transaction_h file_transaction,
         else {
             LOGI("Succeed to change permission : %s", sticker_data.file_path.c_str());
             if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                insert_sticker_data(sticker_data.file_path.c_str(), sticker_data.keyword.c_str(), sticker_data.group.c_str(), sticker_data.description.c_str());
-                destroy_sticker_provider_handle();
+                char thumb_path[PATH_MAX];
+                char *data_path = NULL;
+                data_path = app_get_shared_data_path();
+                sprintf(thumb_path, "%s/thumbnail/%s", data_path, incoming_file_name.c_str());
+                sticker_data.thumbnail_path = string(thumb_path);
+
+                if (data_path)
+                    free(data_path);
+
+                int ret = thumbnail_util_extract_to_file(sticker_data.file_path.c_str(), THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, sticker_data.thumbnail_path.c_str());
+                if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
+                    LOGE("Failed to create thumbnail. msg : %s", get_error_message(ret));
+                    sticker_data.thumbnail_path.clear();
+                } else {
+                    insert_sticker_data(sticker_data.file_path.c_str(), sticker_data.keyword.c_str(), sticker_data.group.c_str(), sticker_data.description.c_str(), sticker_data.thumbnail_path.c_str());
+                    destroy_sticker_provider_handle();
+                }
 
                 if (unlink(sticker_data.file_path.c_str()) == -1)
                     LOGE("Failed to remove sticker file");
+
+                if (!sticker_data.thumbnail_path.empty()) {
+                    if (unlink(sticker_data.thumbnail_path.c_str()) == -1)
+                        LOGE("Failed to remove sticker thumbnail");
+                }
             }
         }
 
@@ -244,7 +265,9 @@ void accept_file()
     sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str());
     LOGI("Receive filepath : %s", file_path);
     sticker_data.file_path = string(file_path);
-    free(data_path);
+
+    if (data_path)
+        free(data_path);
 
     ret = sap_file_transfer_receive(priv_data.file_socket, file_path);
     switch(ret) {
@@ -309,6 +332,19 @@ bool request_sticker_data(const char *mode, const char *category, const char *ty
     return result;
 }
 
+static int _create_directory(const char *path)
+{
+    if (access(path, F_OK) == 0)
+        return 0;
+
+    if (mkdir(path, 0755) == -1) {
+        LOGE("directory create error");
+        return -1;
+    }
+
+    return 0;
+}
+
 void request_sticker_feature()
 {
     JsonObject *j_object = NULL;
@@ -335,6 +371,14 @@ void request_sticker_feature()
     }
 
     json_object_unref(j_object);
+
+    char thumb_path[PATH_MAX];
+    char *data_path = NULL;
+    data_path = app_get_shared_data_path();
+    sprintf(thumb_path, "%s/thumbnail", data_path);
+
+    if (_create_directory(thumb_path) != 0)
+        LOGE("Failed to create thumbnail directory");
 }
 
 void reject_file()
index bd94ee5..df0792b 100644 (file)
@@ -33,4 +33,5 @@ void sticker_info::reset()
     keyword.clear();
     disp_type.clear();
     description.clear();
+    thumbnail_path.clear();
 }
\ No newline at end of file
index 16ca72e..38c9709 100644 (file)
@@ -82,12 +82,12 @@ int len, const char* group, const char* thumbnail, const char* description)
 }
 
 void
-insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc)
+insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail)
 {
     sticker_data_h data_handle;
     int ret;
 
-    data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, NULL, desc);
+    data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc);
 
     ret = sticker_provider_insert_data(sticker_provider, data_handle);
     if (ret != STICKER_ERROR_NONE) {
index 1d23be5..27a1454 100644 (file)
@@ -13,6 +13,7 @@
             <privilege>http://developer.samsung.com/tizen/privilege/accessoryprotocol</privilege>
             <privilege>http://tizen.org/privilege/content.write</privilege>
             <privilege>http://tizen.org/privilege/mediastorage</privilege>
+            <privilege>http://tizen.org/privilege/externalstorage</privilege>
             <privilege>http://tizen.org/privilege/appdir.shareddata</privilege>
             <privilege>http://tizen.org/privilege/alarm.set</privilege>
             <privilege>http://tizen.org/privilege/alarm.get</privilege>