merge wrt-plugins-tizen_0.2.0-12
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Contact / AddressBook.cpp
index ab00a29..ab66928 100755 (executable)
@@ -73,7 +73,15 @@ void AddressBook::add(const ContactPtr &contact)
                ThrowMsg(InvalidArgumentException, "Contact argument is wrong");
 
        internalAddContact(contact);
-       m_latestVersion = get_contact_version();
+
+       string id = contact->getId();
+       if(id != "")
+       {
+               ContactPtr insertedContact = internalGetById(id);
+               contact->copy(insertedContact);
+       }
+
+       //m_latestVersion = get_contact_version();
 }
 
 void AddressBook::update(const ContactPtr &contact)
@@ -83,7 +91,7 @@ void AddressBook::update(const ContactPtr &contact)
                ThrowMsg(InvalidArgumentException, "Contact argument is wrong");
 
        internalAddContact(contact);
-       m_latestVersion = get_contact_version();
+       //m_latestVersion = get_contact_version();
 }
 
 void AddressBook::remove(const string &id)
@@ -107,7 +115,7 @@ void AddressBook::remove(const string &id)
                LogError("Error during deleting contact. " << _rethrown_exception.GetMessage());
                ThrowMsg(PlatformException, "Error during deleting contact.");
        }
-       m_latestVersion = get_contact_version();
+       //m_latestVersion = get_contact_version();
 }
 
 long AddressBook::addChangeListener(const EventAddressBookChangeListenerEmitterPtr &emitter)
@@ -182,6 +190,18 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
                        LogError("error code " << ret);
                        ThrowMsg(PlatformException, "Error during executing contacts_svc_end_trans()");
                }
+
+               for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
+               {
+                       ContactPtr contact = *i;
+
+                       string id = contact->getId();
+                       if(id != "")
+                       {
+                               ContactPtr insertedContact = internalGetById(id);
+                               contact->copy(insertedContact);
+                       }
+               }
        }
        Catch (NotFoundException)
        {
@@ -198,7 +218,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
                event->setExceptionCode(ExceptionCodes::PlatformException);
                return;
        }
-       m_latestVersion = get_contact_version();
+       //m_latestVersion = get_contact_version();
 
        event->setResult(true);
        event->setExceptionCode(ExceptionCodes::None);
@@ -259,7 +279,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookUpdateBatchPtr &event)
                event->setExceptionCode(ExceptionCodes::PlatformException);
                return;
        }
-       m_latestVersion = get_contact_version();
+       //m_latestVersion = get_contact_version();
 
        event->setResult(true);
        event->setExceptionCode(ExceptionCodes::None);
@@ -337,7 +357,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookRemoveBatchPtr &event)
                event->setExceptionCode(ExceptionCodes::PlatformException);
                return;
        }
-       m_latestVersion = get_contact_version();
+       //m_latestVersion = get_contact_version();
 
        event->setResult(true);
        event->setExceptionCode(ExceptionCodes::None);
@@ -454,13 +474,7 @@ void AddressBook::internalAddContact(const ContactPtr &newContact)
                        LogError("error code " << id);
                        ThrowMsg(PlatformException, "Error during executing contacts_svc_insert_contact()");
                }
-
-               std::stringstream oss;
-               oss << id;
-               std::string idStr = oss.str();
-               ContactPtr insertedContact = internalGetById(idStr);
-
-               newContact->copy(insertedContact);
+               newContact->setId(id);
        }
 }