Fixed some issues with special characters and adding contact to address book.
[jenirok] / src / common / contactmanager.cpp
index 67cd7ca..f9047b5 100644 (file)
@@ -75,17 +75,16 @@ bool ContactManager::addContact(Contact const& contact)
     GError* error = NULL;
     EContactAddress* addr = NULL;
 
-    if(!contact.name.isEmpty())
-    {
-        char* name = contact.name.toUtf8().data();
-        e_contact_set(newContact, E_CONTACT_FULL_NAME, (gpointer)name);
-    }
+    char* firstname = contact.name.firstname.toUtf8().data();
+    char* surname = contact.name.surname.toUtf8().data();
+    e_contact_set(newContact, E_CONTACT_GIVEN_NAME, (gpointer)firstname);
+    e_contact_set(newContact, E_CONTACT_FAMILY_NAME, (gpointer)surname);
 
     if(!contact.city.isEmpty() || !contact.street.isEmpty())
     {
         addr = g_new0 (EContactAddress, 1);
         addr->address_format = g_strdup("");
-        addr->po = g_strdup(contact.streetNumber.toUtf8().data());
+        addr->po = g_strdup("");
         addr->ext = g_strdup("");
         addr->region = g_strdup("");
         addr->code = g_strdup(contact.zipCode.toUtf8().data());
@@ -118,6 +117,33 @@ bool ContactManager::addContact(Contact const& contact)
     return ret;
 }
 
+void ContactManager::stringToName(QString const& strname, ContactManager::Name& name)
+{
+    EContactName* ename = e_contact_name_from_string(strname.toUtf8().data());
+
+    if(ename)
+    {
+        QString additional = QString::fromUtf8(ename->additional);
+
+        if(additional.isEmpty())
+        {
+            name.firstname = QString::fromUtf8(ename->given);
+            name.surname = QString::fromUtf8(ename->family);
+        }
+        else
+        {
+            name.surname = strname;
+        }
+
+        e_contact_name_free(ename);
+    }
+    else
+    {
+        name.surname = strname;
+    }
+}
+
+
 bool ContactManager::load()
 {
     if(book_)