Some fixes to connection manager.
[jenirok] / src / common / contactmanager.cpp
index cf459b4..fc0c62d 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <QtCore/QDebug>
+#include <QtCore/QRegExp>
 #include "contactmanager.h"
 
 
@@ -75,11 +76,11 @@ 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 +119,36 @@ 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)
+    {
+        static QRegExp check("([A-Z]+)");
+        QString additional = QString::fromUtf8(ename->additional);
+        QString firstname = QString::fromUtf8(ename->given);
+        QString surname = QString::fromUtf8(ename->family);
+
+        if(additional.isEmpty() && check.indexIn(firstname, 1) == -1 && check.indexIn(surname, 1) == -1)
+        {
+            name.firstname = firstname;
+            name.surname = surname;
+        }
+        else
+        {
+            name.surname = strname;
+        }
+
+        e_contact_name_free(ename);
+    }
+    else
+    {
+        name.surname = strname;
+    }
+}
+
+
 bool ContactManager::load()
 {
     if(book_)