fix N_SE-47241
authorGwangbok Kim <gwangbok.kim@samsung.com>
Mon, 5 Aug 2013 13:43:33 +0000 (22:43 +0900)
committerGwangbok Kim <gwangbok.kim@samsung.com>
Mon, 5 Aug 2013 13:43:33 +0000 (22:43 +0900)
Change-Id: I65677cf854411e06c82f6764bf912c4b4e39a98b
Signed-off-by: Gwangbok Kim <gwangbok.kim@samsung.com>
src/FScl_AddressbookImpl.cpp
src/FScl_AddressbookManagerImpl.cpp

index c747495..8bb083a 100644 (file)
  */
 #include <contacts.h>
 #include <unique_ptr.h>
+#include <FApp.h>
 #include <FBaseColIListT.h>
 #include <FBaseColArrayListT.h>
 #include <FBaseResult.h>
 #include <FBaseLongLong.h>
 #include <FBaseInteger.h>
+#include <FIoFile.h>
 #include <FSclContact.h>
 #include <FSclCategory.h>
 #include <FSclUserProfile.h>
@@ -54,6 +56,7 @@ using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Graphics;
+using namespace Tizen::Io;
 
 namespace Tizen { namespace Social
 {
@@ -481,7 +484,7 @@ _AddressbookImpl::UpdateContact(const Contact& contact)
                int imageId = -1;
                int imageId2 = -1;
 
-               for (int i = count2 - 1; i >= 0; i--)
+               for (unsigned int i = count2 - 1; i >= 0; i--)
                {
                        contacts_record_get_child_record_at_p(recordHandle, _contacts_contact.image, i, &imageHandle);
                        contacts_record_get_int(imageHandle, _contacts_image.id, &imageId);
@@ -514,8 +517,46 @@ _AddressbookImpl::UpdateContact(const Contact& contact)
                contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
                SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
+               contacts_record_h tempHandle = null;
+               contacts_record_get_child_record_count(copyRecordHandle, _contacts_contact.image, &count);
+
+               char* pCharValue = null;
+               String tempPath;
+
+               for (unsigned int i = 0; i < count; i++)
+               {
+                       contacts_record_get_child_record_at_p(copyRecordHandle, _contacts_contact.image, i, &tempHandle);
+                       contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
+
+                       tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
+                       tempPath.Append((int)i);
+                       tempPath.Append(L".jpg");
+                       String servicePath(pCharValue);
+
+                       File::Copy(servicePath, tempPath, true);
+
+                       std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(tempPath));
+                       SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       contacts_record_set_str(tempHandle, _contacts_image.path, pCharArray.get());
+                       contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
+
+                       tempPath.Clear();
+               }
+
                ret = contacts_db_replace_record(copyRecordHandle, contactId);
                contacts_record_destroy(copyRecordHandle, true);
+
+               for (unsigned int i = 0; i < count; i++)
+               {
+                       tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
+                       tempPath.Append((int)i);
+                       tempPath.Append(L".jpg");
+
+                       File::Remove(tempPath);
+
+                       tempPath.Clear();
+               }
        }
 
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
index cd96957..1bb2e1b 100644 (file)
@@ -21,6 +21,7 @@
  */
 #include <contacts.h>
 #include <unique_ptr.h>
+#include <FApp.h>
 #include <FBaseColIListT.h>
 #include <FBaseColArrayListT.h>
 #include <FBaseColHashMapT.h>
@@ -540,8 +541,46 @@ _AddressbookManagerImpl::UpdateContact(const Contact& contact)
                contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
                SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
+               contacts_record_h tempHandle = null;
+               contacts_record_get_child_record_count(copyRecordHandle, _contacts_contact.image, &count);
+
+               char* pCharValue = null;
+               String tempPath;
+
+               for (int i = 0; i < count; i++)
+               {
+                       contacts_record_get_child_record_at_p(copyRecordHandle, _contacts_contact.image, i, &tempHandle);
+                       contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
+
+                       tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
+                       tempPath.Append(i);
+                       tempPath.Append(L".jpg");
+                       String servicePath(pCharValue);
+
+                       File::Copy(servicePath, tempPath, true);
+
+                       std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(tempPath));
+                       SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       contacts_record_set_str(tempHandle, _contacts_image.path, pCharArray.get());
+                       contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
+
+                       tempPath.Clear();
+               }
+
                ret = contacts_db_replace_record(copyRecordHandle, contactId);
                contacts_record_destroy(copyRecordHandle, true);
+
+               for (int i = 0; i < count; i++)
+               {
+                       tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
+                       tempPath.Append(i);
+                       tempPath.Append(L".jpg");
+
+                       File::Remove(tempPath);
+
+                       tempPath.Clear();
+               }
        }
 
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));