contacts: rename "name" to "first_name", and add explit getters.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 10 Aug 2012 23:30:46 +0000 (20:30 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 10 Aug 2012 23:30:46 +0000 (20:30 -0300)
we've created it with just "name", then we split in a very hackish
way. Make it more sane now:
 - first name: comes from DB
 - last name: comes from DB
 - full name: created on the fly, when needed. cached.

all the getters return references to internal stringshares.

data/scripts/ofono-efl-contacts-db-create.py
dialer/callscreen.c
dialer/contacts.c
dialer/contacts.h
dialer/history.c
dialer/keypad.c

index 22dc610..3280a76 100755 (executable)
@@ -43,7 +43,7 @@ for row in reader:
             value "work" string: "%(work)s";
             value "home" string: "%(home)s";
             value "mobile" string: "%(mobile)s";
-            value "name" string: "%(first)s";
+            value "first_name" string: "%(first)s";
             value "last_name" string: "%(last)s";
         }
 """ % {"first": first, "last": last,
index 5c3eef7..75d892b 100644 (file)
@@ -643,9 +643,8 @@ static char *_call_name_or_id(const OFono_Call *call)
        const char *s = ofono_call_line_id_get(call);
        Contact_Info *info = gui_contact_search(s, NULL);
 
-       if (info) {
-               return strdup(contact_info_name_get(info));
-       }
+       if (info)
+               return strdup(contact_info_full_name_get(info));
 
        return phone_format(ofono_call_line_id_get(call));
 }
index 3dbf7f0..2ab8b95 100644 (file)
@@ -34,12 +34,13 @@ typedef struct _Contacts {
 } Contacts;
 
 struct _Contact_Info {
-       const char *name;
+       const char *first_name;
+       const char *last_name;
+       const char *full_name; /* not in edd */
        const char *mobile;
        const char *home;
        const char *work;
        const char *picture;
-       const char *last_name;
 
        Contacts *contacts; /* not in edd */
        Elm_Object_Item *it; /* not in edd */
@@ -95,12 +96,31 @@ Contact_Info *contact_search(Evas_Object *obj, const char *number, const char **
        return NULL;
 }
 
-const char *contact_info_name_get(const Contact_Info *c)
+const char *contact_info_full_name_get(const Contact_Info *c)
 {
+       Contact_Info *c2;
+
        EINA_SAFETY_ON_NULL_RETURN_VAL(c, NULL);
-       char buf[PATH_MAX];
-       snprintf(buf, sizeof(buf), "%s %s", c->name, c->last_name);
-       return strdup(buf);
+
+       if (c->full_name)
+               return c->full_name;
+
+       c2 = (Contact_Info *)c;
+       c2->full_name = eina_stringshare_printf("%s %s",
+                                               c->first_name, c->last_name);
+       return c->full_name;
+}
+
+const char *contact_info_first_name_get(const Contact_Info *c)
+{
+       EINA_SAFETY_ON_NULL_RETURN_VAL(c, NULL);
+       return c->first_name;
+}
+
+const char *contact_info_last_name_get(const Contact_Info *c)
+{
+       EINA_SAFETY_ON_NULL_RETURN_VAL(c, NULL);
+       return c->last_name;
 }
 
 const char *contact_info_picture_get(const Contact_Info *c)
@@ -227,10 +247,12 @@ Eina_Bool contact_info_first_name_set(Contact_Info *c, const char *name)
        EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE);
        EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
 
-       DBG("c=%p, was=%s, new=%s", c, c->name, name);
+       DBG("c=%p, was=%s, new=%s", c, c->first_name, name);
 
-       if (eina_stringshare_replace(&(c->name), name))
+       if (eina_stringshare_replace(&(c->first_name), name)) {
+               eina_stringshare_replace(&(c->full_name), NULL);
                _contact_info_changed(c);
+       }
 
        return EINA_TRUE;
 }
@@ -242,8 +264,10 @@ Eina_Bool contact_info_last_name_set(Contact_Info *c, const char *name)
 
        DBG("c=%p, was=%s, new=%s", c, c->last_name, name);
 
-       if (eina_stringshare_replace(&(c->last_name), name))
+       if (eina_stringshare_replace(&(c->last_name), name)) {
+               eina_stringshare_replace(&(c->full_name), NULL);
                _contact_info_changed(c);
+       }
 
        return EINA_TRUE;
 }
@@ -422,7 +446,7 @@ static void _contacts_info_descriptor_init(Eet_Data_Descriptor **edd,
        EET_DATA_DESCRIPTOR_ADD_BASIC(*edd, Contact_Info,
                                        "mobile", mobile, EET_T_STRING);
        EET_DATA_DESCRIPTOR_ADD_BASIC(*edd, Contact_Info,
-                                       "name", name, EET_T_STRING);
+                                       "first_name", first_name, EET_T_STRING);
        EET_DATA_DESCRIPTOR_ADD_BASIC(*edd, Contact_Info,
                                        "last_name", last_name, EET_T_STRING);
 
@@ -436,7 +460,7 @@ static void _contact_info_free(Contact_Info *c_info)
 
        if (c_info->on_changed_cbs.deleted) {
                ERR("contact still have changed deleted listeners: %p %s %s",
-                       c_info, c_info->name, c_info->last_name);
+                       c_info, c_info->first_name, c_info->last_name);
                eina_list_free(c_info->on_changed_cbs.deleted);
        }
 
@@ -457,12 +481,13 @@ static void _contact_info_free(Contact_Info *c_info)
        if (c_info->changed_idler)
                ecore_idler_del(c_info->changed_idler);
 
-       eina_stringshare_del(c_info->name);
+       eina_stringshare_del(c_info->first_name);
+       eina_stringshare_del(c_info->last_name);
+       eina_stringshare_del(c_info->full_name);
        eina_stringshare_del(c_info->mobile);
        eina_stringshare_del(c_info->home);
        eina_stringshare_del(c_info->work);
        eina_stringshare_del(c_info->picture);
-       eina_stringshare_del(c_info->last_name);
        free(c_info);
 }
 
@@ -513,7 +538,7 @@ static void _on_item_click(void *data, Evas_Object *obj __UNUSED__,
        elm_genlist_item_selected_set(item, EINA_FALSE);
        elm_layout_box_remove_all(details, "box.phones", EINA_TRUE);
 
-       elm_object_part_text_set(details, "text.name", c_info->name);
+       elm_object_part_text_set(details, "text.name", c_info->first_name);
        elm_object_part_text_set(details, "text.last.name", c_info->last_name);
 
        photo = picture_icon_get(details, c_info->picture);
@@ -569,13 +594,19 @@ static void _on_item_click(void *data, Evas_Object *obj __UNUSED__,
 static int _sort_by_name_cb(const void *v1, const void *v2)
 {
        const Contact_Info *c1, *c2;
+       int r;
+
        c1 = v1;
        c2 = v2;
 
        if (!c1) return 1;
        if (!c2) return -1;
 
-       return strcmp(c1->name, c2->name);
+       r = strcmp(c1->first_name, c2->first_name);
+       if (r == 0)
+               return strcmp(c1->last_name, c2->last_name);
+
+       return r;
 }
 
 static void _contacts_read(Contacts *contacts)
@@ -612,8 +643,8 @@ static void _contacts_read(Contacts *contacts)
        EINA_LIST_FOREACH(contacts->c_list->list, l, c_info) {
                if (!c_info)
                        continue;
-               if (group != c_info->name[0]) {
-                       group = c_info->name[0];
+               if (group != c_info->first_name[0]) {
+                       group = c_info->first_name[0];
                        it = elm_genlist_item_append(contacts->genlist,
                                                        contacts->group,
                                                        c_info, NULL,
@@ -642,7 +673,7 @@ static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__,
        part += strlen("text.contacts.");
 
        if (strcmp(part, "name") == 0)
-               return strdup(c_info->name);
+               return strdup(c_info->first_name);
        else if (strcmp(part, "last") == 0)
                return strdup(c_info->last_name);
 
@@ -655,7 +686,7 @@ static char *_group_label_get(void *data, Evas_Object *obj __UNUSED__,
 {
        Contact_Info *c_info = data;
        char buf[2];
-       snprintf(buf, sizeof(buf), "%c", c_info->name[0]);
+       snprintf(buf, sizeof(buf), "%c", c_info->first_name[0]);
        return strdup(buf);
 }
 
index af2ada6..53fdf24 100644 (file)
@@ -9,7 +9,9 @@ Contact_Info *contact_search(Evas_Object *obj, const char *number, const char **
 
 const char *contact_info_picture_get(const Contact_Info *c);
 
-const char *contact_info_name_get(const Contact_Info *c);
+const char *contact_info_full_name_get(const Contact_Info *c);
+const char *contact_info_first_name_get(const Contact_Info *c);
+const char *contact_info_last_name_get(const Contact_Info *c);
 
 const char *contact_info_detail_get(const Contact_Info *c, const char *type);
 
index a1039d9..43bf5ac 100644 (file)
@@ -695,7 +695,7 @@ static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__,
        if (!strcmp(part, "name")) {
                if (!call_info->contact)
                        return strdup(call_info->line_id);
-               return contact_info_name_get(call_info->contact);
+               return strdup(contact_info_full_name_get(call_info->contact));
        }
 
        if (!strcmp(part, "time")) {
index 986e449..ba94706 100644 (file)
@@ -40,7 +40,7 @@ static void _number_display(Keypad *ctx)
 
        Contact_Info *info = gui_contact_search(number, &type);
        if (info) {
-               elm_object_part_text_set(ctx->self, "elm.text.contact", contact_info_name_get(info));
+               elm_object_part_text_set(ctx->self, "elm.text.contact", contact_info_full_name_get(info));
                elm_object_part_text_set(ctx->self, "elm.text.phone.type", type);
                elm_object_signal_emit(ctx->self, "show,contact", "keypad");
        } else