Fixed issues with special characters and adding contact to address book. Small fix...
[jenirok] / src / common / contactmanager.cpp
index 974c7a5..67cd7ca 100644 (file)
@@ -73,36 +73,49 @@ bool ContactManager::addContact(Contact const& contact)
 
     EContact* newContact = e_contact_new();
     GError* error = NULL;
-    //EContactAddress* addr = new EContactAddress;
+    EContactAddress* addr = NULL;
 
     if(!contact.name.isEmpty())
     {
-        char* name = contact.name.toLatin1().data();
+        char* name = contact.name.toUtf8().data();
         e_contact_set(newContact, E_CONTACT_FULL_NAME, (gpointer)name);
     }
 
-    // Doesn't work for some reason
-    /*if(!contact.city.isEmpty() || !contact.street.isEmpty())
-       {
-               addr->street = contact.street.toLatin1().data();
-               addr->locality = contact.city.toLatin1().data();
-               e_contact_set(newContact, E_CONTACT_ADDRESS_HOME, (gpointer)addr);
-       }*/
+    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->ext = g_strdup("");
+        addr->region = g_strdup("");
+        addr->code = g_strdup(contact.zipCode.toUtf8().data());
+        addr->country = g_strdup(contact.country.toUtf8().data());
+        addr->street = g_strdup(contact.street.toUtf8().data());
+        addr->locality = g_strdup(contact.city.toUtf8().data());
+        e_contact_set(newContact, E_CONTACT_ADDRESS_OTHER, (gpointer)addr);
+    }
 
     if(!contact.number.isEmpty())
     {
-        char* number = contact.number.toLatin1().data();
-        e_contact_set(newContact, E_CONTACT_PHONE_HOME, (gpointer)number);
+        char* number = contact.number.toUtf8().data();
+        e_contact_set(newContact, E_CONTACT_PHONE_OTHER, (gpointer)number);
     }
 
+    bool ret = true;
+
     if(!e_book_add_contact(book_, newContact, &error))
     {
-        qDebug() << "Couldn't add contact: %s" <<  error->message;
+        qDebug() << "Couldn't add contact: " <<  error->message;
         g_error_free(error);
-        return false;
+        ret = false;
     }
 
-    return true;
+    if(addr)
+    {
+        e_contact_address_free(addr);
+    }
+
+    return ret;
 }
 
 bool ContactManager::load()