From 5b03daed5d035b510b97a440959bffc8d7445967 Mon Sep 17 00:00:00 2001 From: eshe Date: Wed, 11 Aug 2010 11:13:29 +0100 Subject: [PATCH] Fixes to add to contacts button and contact naming. --- src/common/contactmanager.cpp | 34 +++++++++++++++++++++++++++++----- src/common/contactmanager.h | 9 ++++++++- src/gui/detailwindow.cpp | 2 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/common/contactmanager.cpp b/src/common/contactmanager.cpp index cf459b4..bb8c675 100644 --- a/src/common/contactmanager.cpp +++ b/src/common/contactmanager.cpp @@ -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_) diff --git a/src/common/contactmanager.h b/src/common/contactmanager.h index 9a27b88..291a52c 100644 --- a/src/common/contactmanager.h +++ b/src/common/contactmanager.h @@ -28,9 +28,15 @@ 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(); diff --git a/src/gui/detailwindow.cpp b/src/gui/detailwindow.cpp index 39cc7bf..4d6107d 100644 --- a/src/gui/detailwindow.cpp +++ b/src/gui/detailwindow.cpp @@ -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_; -- 1.7.9.5