fix thumbnail is not set properly 48/49948/1
authorGukhwan Cho <gh78.cho@samsung.com>
Thu, 1 Oct 2015 03:15:49 +0000 (12:15 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Thu, 22 Oct 2015 02:45:12 +0000 (11:45 +0900)
Change-Id: I6d44becf2d1e7bd40de4b9dcd6a6d41d660a2a76
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
server/db/ctsvc_db_plugin_contact.c
server/db/ctsvc_db_plugin_my_profile.c

index f3abf09..3454be9 100644 (file)
@@ -1221,30 +1221,30 @@ static int __ctsvc_db_contact_update_record(contacts_record_h record)
                }
        }
 
-       /******************************/
-       /* this code will be removed. */
+       /* thumbnail */
        if (contact->images) {
                int ret = CONTACTS_ERROR_NONE;
-               contacts_record_h record_image = NULL;
                int count = 0;
                ctsvc_image_s *image;
 
                contacts_list_get_count((contacts_list_h)contact->images, &count);
                if (count) {
                        contacts_list_first((contacts_list_h)contact->images);
-                       ret = contacts_list_get_current_record_p((contacts_list_h)contact->images, &record_image);
-
-                       if (CONTACTS_ERROR_NONE != ret) {
-                               CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
-                               ctsvc_end_trans(false);
-                               return CONTACTS_ERROR_DB;
-                       }
+                       do {
+                               ret = contacts_list_get_current_record_p((contacts_list_h)contact->images, (contacts_record_h*)&image);
+                               if (CONTACTS_ERROR_NONE != ret) {
+                                       CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
+                                       ctsvc_end_trans(false);
+                                       return CONTACTS_ERROR_DB;
+                               }
 
-                       image = (ctsvc_image_s*)record_image;
+                               if (image->is_default)
+                                       break;
+                       } while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
 
                        if ((NULL == contact->image_thumbnail_path && image->path) ||
                                        (contact->image_thumbnail_path && NULL == image->path) ||
-                                       (contact->image_thumbnail_path && image->path && STRING_EQUAL != strcmp(contact->image_thumbnail_path, image->path))) {
+                                       (contact->image_thumbnail_path && image->path && (STRING_EQUAL != strcmp(contact->image_thumbnail_path, image->path)))) {
                                ctsvc_record_set_property_flag((ctsvc_record_s *)contact, _contacts_contact.image_thumbnail_path, CTSVC_PROPERTY_FLAG_DIRTY);
 
                                if (ctsvc_contact_check_image_location(image->path))
@@ -1268,8 +1268,6 @@ static int __ctsvc_db_contact_update_record(contacts_record_h record)
                        }
                }
        }
-       /* this code will be removed. */
-       /******************************/
 
        if (is_invalid) {
                ctsvc_contact_s* temp_contact;
@@ -2050,19 +2048,14 @@ static int __ctsvc_db_contact_insert_record(contacts_record_h record, int *id)
                return ret;
        }
 
-       /******************************/
-       /* this code will be removed. */
+       /* thumbnail */
        free(contact->image_thumbnail_path);
        contact->image_thumbnail_path = NULL;
-
        if (contact->images) {
                ctsvc_image_s *image;
-               int count = 0;
 
-               contacts_list_get_count((contacts_list_h)contact->images, &count);
-
-               while (count) {
-                       contacts_list_first((contacts_list_h)contact->images);
+               contacts_list_first((contacts_list_h)contact->images);
+               do {
                        ret = contacts_list_get_current_record_p((contacts_list_h)contact->images, (contacts_record_h*)&image);
                        if (CONTACTS_ERROR_NONE != ret) {
                                CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
@@ -2074,11 +2067,8 @@ static int __ctsvc_db_contact_insert_record(contacts_record_h record, int *id)
                                contact->image_thumbnail_path = strdup(image->path);
                                break;
                        }
-                       count--;
-               }
+               } while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
        }
-       /* this code will be removed. */
-       /******************************/
 
        version = ctsvc_get_next_ver();
 
@@ -2311,26 +2301,27 @@ static int __ctsvc_db_contact_replace_record(contacts_record_h record, int conta
                }
        }
 
-       /******************************/
-       /* this code will be removed. */
+       /* thumbnail */
        if (contact->images) {
                int ret = CONTACTS_ERROR_NONE;
-               contacts_record_h record_image = NULL;
                int count = 0;
                ctsvc_image_s *image;
 
                contacts_list_get_count((contacts_list_h)contact->images, &count);
                if (count) {
                        contacts_list_first((contacts_list_h)contact->images);
-                       ret = contacts_list_get_current_record_p((contacts_list_h)contact->images, &record_image);
+                       do {
+                               ret = contacts_list_get_current_record_p((contacts_list_h)contact->images, (contacts_record_h*)&image);
+                               if (CONTACTS_ERROR_NONE != ret) {
+                                       CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
+                                       ctsvc_end_trans(false);
+                                       return CONTACTS_ERROR_DB;
+                               }
 
-                       if (CONTACTS_ERROR_NONE != ret) {
-                               CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
-                               ctsvc_end_trans(false);
-                               return CONTACTS_ERROR_DB;
-                       }
+                               if (image->is_default)
+                                       break;
+                       } while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
 
-                       image = (ctsvc_image_s*)record_image;
                        if ((NULL == contact->image_thumbnail_path && image->path) ||
                                        (contact->image_thumbnail_path && NULL == image->path) ||
                                        (contact->image_thumbnail_path && image->path && STRING_EQUAL != strcmp(contact->image_thumbnail_path, image->path))) {
@@ -2356,8 +2347,6 @@ static int __ctsvc_db_contact_replace_record(contacts_record_h record, int conta
                        }
                }
        }
-       /* this code will be removed. */
-       /******************************/
        version = ctsvc_get_next_ver();
 
        len = snprintf(query, sizeof(query),
index 59888cf..cc7b60b 100644 (file)
@@ -726,26 +726,27 @@ static int __ctsvc_db_my_profile_update_record(contacts_record_h record)
                return ret;
        }
 
-       /******************************/
-       /* this code will be removed. */
+       /* thumbnail */
        if (my_profile->images) {
                int ret = CONTACTS_ERROR_NONE;
-               contacts_record_h record_image = NULL;
                int count = 0;
                ctsvc_image_s *image;
 
                contacts_list_get_count((contacts_list_h)my_profile->images, &count);
                if (count) {
                        contacts_list_first((contacts_list_h)my_profile->images);
-                       ret = contacts_list_get_current_record_p((contacts_list_h)my_profile->images, &record_image);
+                       do {
+                               ret = contacts_list_get_current_record_p((contacts_list_h)my_profile->images, (contacts_record_h*)&image);
+                               if (CONTACTS_ERROR_NONE != ret) {
+                                       CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
+                                       ctsvc_end_trans(false);
+                                       return CONTACTS_ERROR_DB;
+                               }
 
-                       if (CONTACTS_ERROR_NONE != ret) {
-                               CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
-                               ctsvc_end_trans(false);
-                               return CONTACTS_ERROR_DB;
-                       }
+                               if (image->is_default)
+                                       break;
+                       } while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)my_profile->images));
 
-                       image = (ctsvc_image_s*)record_image;
                        if ((NULL == my_profile->image_thumbnail_path && image->path) ||
                                        (my_profile->image_thumbnail_path && NULL == image->path) ||
                                        (my_profile->image_thumbnail_path && image->path && STRING_EQUAL != strcmp(my_profile->image_thumbnail_path, image->path))) {
@@ -763,8 +764,6 @@ static int __ctsvc_db_my_profile_update_record(contacts_record_h record)
                        ctsvc_record_set_property_flag((ctsvc_record_s *)my_profile, _contacts_my_profile.image_thumbnail_path, CTSVC_PROPERTY_FLAG_DIRTY);
                }
        }
-       /* this code will be removed. */
-       /******************************/
 
        do {
                int len = 0;
@@ -1189,19 +1188,14 @@ static int __ctsvc_db_my_profile_insert_record(contacts_record_h record, int *id
                return ret;
        }
 
-       /******************************/
-       /* this code will be removed. */
+       /* thumbnail */
        free(my_profile->image_thumbnail_path);
        my_profile->image_thumbnail_path = NULL;
-
        if (my_profile->images) {
                ctsvc_image_s *image;
-               int count = 0;
-
-               contacts_list_get_count((contacts_list_h)my_profile->images, &count);
 
-               while (count) {
-                       contacts_list_first((contacts_list_h)my_profile->images);
+               contacts_list_first((contacts_list_h)my_profile->images);
+               do {
                        ret = contacts_list_get_current_record_p((contacts_list_h)my_profile->images, (contacts_record_h*)&image);
                        if (CONTACTS_ERROR_NONE != ret) {
                                CTS_ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
@@ -1213,11 +1207,8 @@ static int __ctsvc_db_my_profile_insert_record(contacts_record_h record, int *id
                                my_profile->image_thumbnail_path = strdup(image->path);
                                break;
                        }
-                       count--;
-               }
+               } while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)my_profile->images));
        }
-       /* this code will be removed. */
-       /******************************/
 
        version = ctsvc_get_next_ver();