Add gettext support for internationalization
[profile/ivi/lemolo.git] / dialer / history.c
index f987f95..0224265 100644 (file)
@@ -12,6 +12,8 @@
 #include "log.h"
 #include "util.h"
 #include "gui.h"
+#include "simple-popup.h"
+#include "i18n.h"
 
 #ifndef EET_COMPRESSION_DEFAULT
 #define EET_COMPRESSION_DEFAULT 1
@@ -49,6 +51,10 @@ typedef struct _Call_Info {
        History *history;
        Elm_Object_Item *it_all; /*not in edd */
        Elm_Object_Item *it_missed; /*not in edd */
+       const Contact_Info *contact; /* not in edd */
+       const char *contact_type; /* not in edd */
+       double contact_last; /* not in edd, last time it was searched */
+#define CONTACT_LAST_THRESHOLD 1.0
 } Call_Info;
 
 static OFono_Callback_List_Call_Node *callback_node_call_removed = NULL;
@@ -228,18 +234,6 @@ static Eina_Bool _history_call_info_update(Call_Info *call_info)
        return EINA_FALSE;
 }
 
-static void _dial_reply(void *data, OFono_Error err,
-                       OFono_Call *call __UNUSED__)
-{
-       const char *number = data;
-
-       if (err != OFONO_ERROR_NONE) {
-               char buf[1024];
-               snprintf(buf, sizeof(buf), "Could not call: %s", number);
-               gui_simple_popup("Error", buf);
-       }
-}
-
 static void _on_item_clicked(void *data, Evas_Object *obj __UNUSED__,
                                void *event_info)
 {
@@ -247,7 +241,7 @@ static void _on_item_clicked(void *data, Evas_Object *obj __UNUSED__,
        const char *number = data;
 
        INF("call %s", number);
-       ofono_dial(number, NULL, _dial_reply, number);
+       gui_dial(number);
        elm_genlist_item_selected_set(it, EINA_FALSE);
 }
 
@@ -375,8 +369,47 @@ static void _history_call_removed(void *data, OFono_Call *call)
        }
 }
 
+static void _on_contact_del(void *data, const Contact_Info *contact __UNUSED__)
+{
+       Call_Info *call_info = data;
+       call_info->contact = NULL;
+       call_info->contact_type = NULL;
+       call_info->contact_last = 0.0;
+}
+
+static void _on_contact_changed(void *data, Contact_Info *contact)
+{
+       Call_Info *call_info = data;
+
+       if (contact_info_number_check(contact, call_info->line_id))
+               goto update;
+
+       contact_info_on_del_callback_del(contact, _on_contact_del, call_info);
+       contact_info_on_changed_callback_del(contact, _on_contact_changed,
+                                               call_info);
+
+       call_info->contact = NULL;
+       call_info->contact_type = NULL;
+       call_info->contact_last = 0.0;
+
+update:
+       if (call_info->it_all)
+               elm_genlist_item_update(call_info->it_all);
+       if (call_info->it_missed)
+               elm_genlist_item_update(call_info->it_missed);
+}
+
 static void _call_info_free(Call_Info *call_info)
 {
+       if (call_info->contact) {
+               Contact_Info *contact = (Contact_Info *)call_info->contact;
+               contact_info_on_del_callback_del(contact, _on_contact_del,
+                                                       call_info);
+               contact_info_on_changed_callback_del(contact,
+                                                       _on_contact_changed,
+                                                       call_info);
+       }
+
        eina_stringshare_del(call_info->line_id);
        eina_stringshare_del(call_info->name);
        free(call_info);
@@ -597,27 +630,21 @@ static void _history_clear_cancel(void *data, Evas_Object *obj __UNUSED__,
 
 static void _history_clear(History *ctx)
 {
-       Evas_Object *p, *bt;
+       Evas_Object *p;
 
        EINA_SAFETY_ON_TRUE_RETURN(ctx->clear_popup != NULL);
 
-       ctx->clear_popup = p = elm_popup_add(ctx->self);
-       evas_object_size_hint_weight_set(p, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       elm_object_part_text_set(p, "title,text", "Clear History");
-       elm_object_text_set(p, "Do you want to clear all history entries?");
-
-       bt = elm_button_add(p);
-       elm_object_text_set(bt, "No");
-       elm_object_part_content_set(p, "button1", bt);
-       evas_object_smart_callback_add(bt, "clicked",
-                                       _history_clear_cancel, ctx);
-
-       bt = elm_button_add(p);
-       elm_object_text_set(bt, "Yes, Clear");
-       elm_object_part_content_set(p, "button2", bt);
-       evas_object_smart_callback_add(bt, "clicked", _history_clear_do, ctx);
-
-       evas_object_show(p);
+       ctx->clear_popup = p = gui_simple_popup(_("Clear History"),
+                               _("Do you want to clear all history entries?"));
+
+       simple_popup_buttons_set(p,
+                                       _("Dismiss"),
+                                       "dialer",
+                                       _history_clear_cancel,
+                                       _("Yes, Clear"),
+                                       "dialer-caution",
+                                       _history_clear_do,
+                                       ctx);
 }
 
 static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__,
@@ -630,11 +657,29 @@ static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__,
 
        part += strlen("text.call.");
 
+       if (!call_info->contact) {
+               double now = ecore_loop_time_get();
+               double diff = now - call_info->contact_last;
+               if (diff > CONTACT_LAST_THRESHOLD) {
+                       Contact_Info *contact = gui_contact_search(
+                               call_info->line_id, &(call_info->contact_type));
+
+                       call_info->contact_last = now;
+                       call_info->contact = contact;
+                       if (contact) {
+                               contact_info_on_del_callback_add(
+                                       contact, _on_contact_del, call_info);
+                               contact_info_on_changed_callback_add(
+                                       contact, _on_contact_changed,
+                                       call_info);
+                       }
+               }
+       }
+
        if (!strcmp(part, "name")) {
-               Contact_Info *info = gui_contact_search(call_info->line_id, NULL);
-               if(!info)
+               if (!call_info->contact)
                        return strdup(call_info->line_id);
-               return strdup(contact_info_name_get(info));
+               return strdup(contact_info_full_name_get(call_info->contact));
        }
 
        if (!strcmp(part, "time")) {
@@ -644,11 +689,9 @@ static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__,
        }
 
        if (!strcmp(part, "type")) {
-               const char *type;
-               Contact_Info *info = gui_contact_search(call_info->line_id, &type);
-               if (!info)
-                       return strdup("Unknown");
-               return strdup(type);
+               if (!call_info->contact_type)
+                       return strdup(_("Unknown"));
+               return strdup(call_info->contact_type);
        }
 
        ERR("Unexpected text part: %s", part);
@@ -678,16 +721,28 @@ static void _on_clicked(void *data, Evas_Object *obj __UNUSED__,
                        const char *emission, const char *source __UNUSED__)
 {
        History *ctx = data;
+       Last_User_Mode *last;
 
        EINA_SAFETY_ON_NULL_RETURN(emission);
        emission += strlen("clicked,");
 
        DBG("ctx=%p, signal: %s", ctx, emission);
+       last = util_get_last_user_mode();
 
-       if (!strcmp(emission, "all"))
+       if (!strcmp(emission, "all")) {
                elm_object_signal_emit(obj, "show,all", "gui");
-       else if (!strcmp(emission, "missed"))
+               if (last) {
+                       last->last_history_view = DIALER_LAST_HISTORY_VIEW_ALL;
+                       util_set_last_user_mode(last);
+               }
+       }
+       else if (!strcmp(emission, "missed")) {
                elm_object_signal_emit(obj, "show,missed", "gui");
+               if (last) {
+                       last->last_history_view = DIALER_LAST_HISTORY_VIEW_MISSED;
+                       util_set_last_user_mode(last);
+               }
+       }
        else if (!strcmp(emission, "clear"))
                _history_clear(ctx);
        else if (!strcmp(emission, "edit")) {
@@ -723,7 +778,7 @@ static Evas_Object *_item_content_get(void *data, Evas_Object *obj,
        Evas_Object *btn = NULL;
 
        if (strcmp(part, "call.swallow.more") == 0) {
-               btn = gui_layout_add(obj, "history/img");
+               btn = layout_add(obj, "history/img");
                EINA_SAFETY_ON_NULL_RETURN_VAL(btn, NULL);
                elm_object_signal_callback_add(btn, "clicked,more", "gui",
                                                _on_more_clicked, NULL);
@@ -782,14 +837,14 @@ Evas_Object *history_add(Evas_Object *parent)
        history = calloc(1, sizeof(History));
        EINA_SAFETY_ON_NULL_RETURN_VAL(history, NULL);
 
-       history->self = obj = gui_layout_add(parent, "history_bg");
+       history->self = obj = layout_add(parent, "history_bg");
        EINA_SAFETY_ON_NULL_GOTO(obj, err_layout);
 
        genlist_all = elm_genlist_add(obj);
        EINA_SAFETY_ON_NULL_GOTO(genlist_all, err_object_new);
        elm_object_style_set(genlist_all, "history");
+       elm_genlist_homogeneous_set(genlist_all, EINA_TRUE);
 
-       /* TODO: */
        evas_object_smart_callback_add(genlist_all, "drag,start,right",
                                        _on_list_slide_enter, history);
        evas_object_smart_callback_add(genlist_all, "drag,start,left",
@@ -802,6 +857,7 @@ Evas_Object *history_add(Evas_Object *parent)
        genlist_missed = elm_genlist_add(obj);
        EINA_SAFETY_ON_NULL_GOTO(genlist_missed, err_object_new);
        elm_object_style_set(genlist_missed, "history");
+       elm_genlist_homogeneous_set(genlist_missed, EINA_TRUE);
 
        evas_object_smart_callback_add(genlist_missed, "drag,start,right",
                                        _on_list_slide_enter, history);