From: Jongkyu Koo Date: Tue, 13 Dec 2016 01:01:47 +0000 (+0900) Subject: The original image is used as a thumbnail when the thumbnail is not made X-Git-Tag: accepted/tizen/3.0/common/20161216.122626~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68901b4337ffd49c03474cc73f449862c0482c38;p=platform%2Fcore%2Fpim%2Fcontacts-service.git The original image is used as a thumbnail when the thumbnail is not made Change-Id: Idca5ba79eb279931a303505b2ef1a162eff797df Signed-off-by: Jongkyu Koo --- diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index 23785af..e10a2f6 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,6 +1,6 @@ Name: contacts-service Summary: Contacts Service -Version: 0.13.62 +Version: 0.13.63 Release: 0 Group: Social & Content/Service License: Apache-2.0 diff --git a/server/ctsvc_server_person.c b/server/ctsvc_server_person.c index 5773c79..1bf883d 100644 --- a/server/ctsvc_server_person.c +++ b/server/ctsvc_server_person.c @@ -367,7 +367,7 @@ static inline int __ctsvc_put_person_default_image(int person_id, int id) thumbnail_path = ctsvc_utils_make_thumbnail(image_path); } else { - thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path); + thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path, TRUE); } free(image_path); diff --git a/server/db/ctsvc_db_plugin_contact_helper.c b/server/db/ctsvc_db_plugin_contact_helper.c index 21fcaf1..96d1f4c 100644 --- a/server/db/ctsvc_db_plugin_contact_helper.c +++ b/server/db/ctsvc_db_plugin_contact_helper.c @@ -186,7 +186,7 @@ int ctsvc_contact_update_image_file(int parent_id, int img_id, WARN("unlink() Fail(%d)", errno); /* remove thumbnail */ - thumbnail_path = ctsvc_utils_get_thumbnail_path(dest); + thumbnail_path = ctsvc_utils_get_thumbnail_path(dest, FALSE); if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) { ret = unlink(thumbnail_path); if (ret < 0) @@ -233,7 +233,7 @@ int ctsvc_contact_delete_image_file_with_path(const unsigned char *image_path) WARN("unlink() Fail(%d)", errno); /* remove thumbnail */ - thumbnail_path = ctsvc_utils_get_thumbnail_path(full_path); + thumbnail_path = ctsvc_utils_get_thumbnail_path(full_path, FALSE); if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) { ret = unlink(thumbnail_path); if (ret < 0) diff --git a/server/db/ctsvc_db_plugin_image.c b/server/db/ctsvc_db_plugin_image.c index 7247d57..5ae1579 100644 --- a/server/db/ctsvc_db_plugin_image.c +++ b/server/db/ctsvc_db_plugin_image.c @@ -599,7 +599,7 @@ static int __ctsvc_db_image_delete_record(int id) ret = __ctsvc_db_image_get_primary_default_image_id(person_id, &image_id, &image_path); if (CONTACTS_ERROR_NONE == ret && 0 != image_id && NULL != image_path) { __ctsvc_db_image_set_primary_default(image_id, true); - thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path); + thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path, TRUE); __ctsvc_db_image_update_person_image(person_id, thumbnail_path); } else { __ctsvc_db_image_update_person_image(person_id, NULL); diff --git a/server/db/ctsvc_db_plugin_person_helper.c b/server/db/ctsvc_db_plugin_person_helper.c index 71bd658..17b5b29 100644 --- a/server/db/ctsvc_db_plugin_person_helper.c +++ b/server/db/ctsvc_db_plugin_person_helper.c @@ -454,7 +454,7 @@ static inline int __ctsvc_db_update_person_default(int person_id, int datatype) "UPDATE "CTS_TABLE_PERSONS" SET image_thumbnail_path=? WHERE person_id=%d", person_id); ret = ctsvc_query_prepare(query, &stmt); RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret); - thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path); + thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path, TRUE); ctsvc_stmt_bind_text(stmt, 1, thumbnail_path); ret = ctsvc_stmt_step(stmt); ctsvc_stmt_finalize(stmt); diff --git a/server/db/ctsvc_db_utils.c b/server/db/ctsvc_db_utils.c index 3e48723..3f749f7 100644 --- a/server/db/ctsvc_db_utils.c +++ b/server/db/ctsvc_db_utils.c @@ -550,7 +550,7 @@ int ctsvc_utils_copy_image(const char *dir, const char *src, const char *file) return CONTACTS_ERROR_NONE; } -char* ctsvc_utils_get_thumbnail_path(const char *image_path) +char* ctsvc_utils_get_thumbnail_path(const char *image_path, bool check_file) { int name_len = 0; int full_len = 0; @@ -578,6 +578,20 @@ char* ctsvc_utils_get_thumbnail_path(const char *image_path) snprintf(thumbnail_path, full_len, "%s%s", image_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX); } + if (check_file) { + char full_path[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0}; + if (NULL != strstr(thumbnail_path, CTSVC_CONTACT_IMG_FULL_LOCATION)) + snprintf(full_path, sizeof(full_path), "%s", thumbnail_path); + else + snprintf(full_path, sizeof(full_path), "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, thumbnail_path); + + if (0 != access(full_path, F_OK)) { + free(thumbnail_path); + /* The original image is used as a thumbnail when the thumbnail is not made */ + return strdup(image_path); + } + } + return thumbnail_path; } @@ -589,7 +603,12 @@ char* ctsvc_utils_get_image_path(const char *thumbnail_path) char *ext = NULL; RETV_IF(NULL == thumbnail_path, NULL); - RETV_IF(NULL == strstr(thumbnail_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX), NULL); + + if (NULL == strstr(thumbnail_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX)) { + /* The original image is used as a thumbnail when the thumbnail is not made */ + return strdup(thumbnail_path); + + } full_len = strlen(thumbnail_path) - strlen(CTSVC_IMAGE_THUMBNAIL_SUFFIX) + 1; image_path = calloc(1, full_len); @@ -630,7 +649,7 @@ char* ctsvc_utils_make_thumbnail(const char *image_path) /* LCOV_EXCL_STOP */ } - thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path); + thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path, FALSE); if (NULL == thumbnail_path) { /* LCOV_EXCL_START */ ERR("ctsvc_image_util_get_thumbnail_path() Fail"); @@ -651,11 +670,12 @@ char* ctsvc_utils_make_thumbnail(const char *image_path) /* LCOV_EXCL_START */ ERR("_ctsvc_image_encode() Fail(%d)", ret); free(thumbnail_path); - return NULL; + /* The original image is used as a thumbnail when the thumbnail is not made */ + return strdup(image_path); /* LCOV_EXCL_STOP */ } - return strdup(thumbnail_path); + return thumbnail_path; } int ctsvc_get_next_ver(void) diff --git a/server/db/ctsvc_db_utils.h b/server/db/ctsvc_db_utils.h index 19ce400..f432b64 100644 --- a/server/db/ctsvc_db_utils.h +++ b/server/db/ctsvc_db_utils.h @@ -32,7 +32,7 @@ int ctsvc_get_transaction_ver(void); int ctsvc_utils_copy_image(const char *dir, const char *src, const char *file); void ctsvc_utils_make_image_file_name(int parent_id, int id, char *src_img, char *dest, int dest_size); -char* ctsvc_utils_get_thumbnail_path(const char *image_path); +char* ctsvc_utils_get_thumbnail_path(const char *image_path, bool check_file); char* ctsvc_utils_get_image_path(const char *thumbnail_path); char* ctsvc_utils_make_thumbnail(const char *image_path);