Fixes to add to contacts button and contact naming.
authoreshe <jessehakanen@gmail.com>
Wed, 11 Aug 2010 10:13:29 +0000 (11:13 +0100)
committereshe <jessehakanen@gmail.com>
Wed, 11 Aug 2010 10:13:29 +0000 (11:13 +0100)
src/common/contactmanager.cpp
src/common/contactmanager.h
src/gui/detailwindow.cpp

index cf459b4..bb8c675 100644 (file)
@@ -75,11 +75,10 @@ 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())
     {
@@ -118,6 +117,31 @@ 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)
+    {
+        name.firstname = QString(ename->given);
+        name.surname = QString(ename->family);
+
+        QString additional = QString(ename->additional);
+
+        if(!additional.isEmpty())
+        {
+            name.firstname += " " + additional;
+        }
+
+        e_contact_name_free(ename);
+    }
+    else
+    {
+        name.surname = strname;
+    }
+}
+
+
 bool ContactManager::load()
 {
     if(book_)
index 9a27b88..291a52c 100644 (file)
 class ContactManager
 {
 public:
+    struct Name
+    {
+        QString firstname;
+        QString surname;
+    };
+
     struct Contact
     {
-        QString name;
+        Name name;
         QString number;
         QString street;
         QString zipCode;
@@ -42,6 +48,7 @@ public:
     ~ContactManager();
     bool addContact(Contact const& contact);
     bool numberExists(QString const& number);
+    static void stringToName(QString const& strname, Name& name);
 
 private:
     bool load();
index 39cc7bf..4d6107d 100644 (file)
@@ -158,7 +158,7 @@ void DetailWindow::addToContacts()
     QString street;
     getDetails(street, number,
                contact.zipCode, contact.city, contact.street);
-    contact.name = addContactInput_->text();
+    ContactManager::stringToName(addContactInput_->text(), contact.name);
     contact.number = numberButton_->valueText();
     contact.country = country_;