Implement last user mode 46/12346/1 accepted/tizen/ivi accepted/tizen/20131115.212927 submit/tizen/20131113.194509
authorJimmy Huang <jimmy.huang@intel.com>
Wed, 13 Nov 2013 18:51:00 +0000 (10:51 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Wed, 13 Nov 2013 18:53:40 +0000 (10:53 -0800)
- Loads and store last user mode settings that keeps track of last GUI view

Change-Id: Ib49b5bfe412c26a87069d0b0ee6d6e0ddd9f98a2
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
dialer/gui.c
dialer/history.c
dialer/keypad.c
packaging/lemolo.changes
utils/util.c
utils/util.h

index 4b03cd9..c23b369 100644 (file)
@@ -68,6 +68,9 @@ OFono_Pending *gui_dial(const char *number)
 
 static void _gui_show(Evas_Object *o)
 {
+       Last_User_Mode *last;
+
+       last = util_get_last_user_mode();
        if (o == keypad)
                elm_object_signal_emit(main_layout, "show,keypad", "gui");
        else if (o == contacts)
@@ -76,6 +79,17 @@ static void _gui_show(Evas_Object *o)
                elm_object_signal_emit(main_layout, "show,history", "gui");
        elm_object_focus_set(o, EINA_TRUE);
        current_view = o;
+
+       if (last) {
+               if (current_view == keypad)
+                       last->last_view = DIALER_LAST_VIEW_KEYPAD;
+               else if (current_view == contacts)
+                       last->last_view = DIALER_LAST_VIEW_CONTACTS;
+               else if (current_view == history)
+                       last->last_view = DIALER_LAST_VIEW_HISTORY;
+
+               util_set_last_user_mode(last);
+       }
 }
 
 Evas_Object *gui_simple_popup(const char *title, const char *message)
@@ -267,6 +281,36 @@ static void _on_contacts_selected(void *data __UNUSED__,
        gui_dial(number);
 }
 
+static void _load_last_user_view() {
+       Last_User_Mode *last;
+
+       last = util_get_last_user_mode();
+       if (!last) {
+               DBG("Last user config file not found - create default view");
+               last = calloc(1, sizeof(Last_User_Mode));
+               last->last_view = DIALER_LAST_VIEW_KEYPAD;
+               last->last_history_view = DIALER_LAST_HISTORY_VIEW_ALL;
+               last->last_number = eina_stringshare_add("");
+               util_set_last_user_mode(last);
+       }
+
+       if(last->last_number) {
+               keypad_number_set(keypad, last->last_number, EINA_FALSE);
+       }
+       if (last->last_view == DIALER_LAST_VIEW_KEYPAD) {
+               _gui_show(keypad);
+       } else if (last->last_view == DIALER_LAST_VIEW_CONTACTS) {
+               _gui_show(contacts);
+       } else if (last->last_view == DIALER_LAST_VIEW_HISTORY) {
+               _gui_show(history);
+               if (last->last_history_view != DIALER_LAST_HISTORY_VIEW_ALL) {
+                       elm_object_signal_emit(history, "show,missed", "gui");
+               }
+       }
+       eina_stringshare_del(last->last_number);
+       free(last);
+}
+
 Eina_Bool gui_init(void)
 {
        Evas_Object *lay, *obj;
@@ -320,8 +364,6 @@ Eina_Bool gui_init(void)
        EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
        elm_object_part_content_set(lay, "elm.swallow.history", obj);
 
-       _gui_show(keypad);
-
        cs = obj = callscreen_add(win);
        EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
        evas_object_size_hint_weight_set(obj,
@@ -330,6 +372,8 @@ Eina_Bool gui_init(void)
        elm_object_part_content_set(flip, "back", obj);
        evas_object_show(obj);
 
+       _load_last_user_view();
+
        callback_node_modem_changed =
                ofono_modem_changed_cb_add(_ofono_changed, NULL);
        callback_node_ussd_notify =
index 472064e..2bfef25 100644 (file)
@@ -720,16 +720,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")) {
index c3ac333..d5b54cd 100644 (file)
@@ -43,6 +43,14 @@ static void _number_display(Keypad *ctx)
        const char *number = eina_strbuf_string_get(ctx->number);
        char *s = phone_format(number);
        const char *type;
+       Last_User_Mode *last;
+
+       last = util_get_last_user_mode();
+       if (last) {
+               eina_stringshare_replace(&(last->last_number), number);
+               util_set_last_user_mode(last);
+       }
+
        if (!s) {
                elm_object_part_text_set(ctx->self, "elm.text.display", "");
                elm_object_part_text_set(ctx->self, "elm.text.contact-and-type",
index 9baa544..81c7acf 100644 (file)
@@ -1,3 +1,6 @@
+* Wed Nov 13 2013 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/20130920.213555@96e7dfe
+- Implement last user mode
+
 * Thu Sep 19 2013 Jimmy Huang <jimmy.huang@intel.com>
 - Implement system notification for incoming call
 - Fixed compilation warnings
index 81bb9b2..98fb83e 100644 (file)
@@ -11,6 +11,8 @@
 #include "log.h"
 
 static char def_theme[PATH_MAX] = "";
+static char *_last_user_mode_config_path;
+static Eet_Data_Descriptor *_last_user_mode_descriptor;
 
 /* TODO: find a configurable way to format the number.
  * Right now it's: 1-234-567-8901 as per
@@ -182,8 +184,76 @@ Eina_Bool util_set_night_mode(Eina_Bool night_mode)
        return EINA_TRUE;
 }
 
+Eina_Bool util_set_last_user_mode(Last_User_Mode *mode) {
+       Eina_Bool ret;
+       Eet_File *efile;
+
+       EINA_SAFETY_ON_NULL_RETURN_VAL(_last_user_mode_config_path, EINA_FALSE);
+       EINA_SAFETY_ON_NULL_RETURN_VAL(_last_user_mode_descriptor, EINA_FALSE);
+
+       efile = eet_open(_last_user_mode_config_path, EET_FILE_MODE_WRITE);
+       if (!efile) {
+               ERR("Cannot open %s for write", _last_user_mode_config_path);
+               return EINA_FALSE;
+       }
+
+       ret = eet_data_write(efile, _last_user_mode_descriptor, LAST_USER_MODE_ENTRY, mode, EINA_TRUE);
+       if (!ret) {
+               ERR("Cannot write to %s", _last_user_mode_config_path);
+       }
+       eet_close(efile);
+       return ret;
+}
+
+Last_User_Mode *util_get_last_user_mode() {
+       Eet_File *efile;
+       Last_User_Mode *mode;
+
+       EINA_SAFETY_ON_NULL_RETURN_VAL(_last_user_mode_config_path, NULL);
+
+       efile = eet_open(_last_user_mode_config_path, EET_FILE_MODE_READ);
+       if (!efile) {
+               ERR("Cannot open %s for read", _last_user_mode_config_path);
+               return NULL;
+       }
+
+       mode = eet_data_read(efile, _last_user_mode_descriptor, LAST_USER_MODE_ENTRY);
+       eet_close(efile);
+
+       return mode;
+}
+
+static void _last_user_mode_descriptor_init(void) {
+       Eet_Data_Descriptor_Class eddc;
+
+       EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Last_User_Mode);
+       _last_user_mode_descriptor = eet_data_descriptor_stream_new(&eddc);
+
+       EET_DATA_DESCRIPTOR_ADD_BASIC(_last_user_mode_descriptor, Last_User_Mode,
+                                       "last_view", last_view, EET_T_UINT);
+       EET_DATA_DESCRIPTOR_ADD_BASIC(_last_user_mode_descriptor, Last_User_Mode,
+                                       "last_history_view", last_history_view, EET_T_UINT);
+       EET_DATA_DESCRIPTOR_ADD_BASIC(_last_user_mode_descriptor, Last_User_Mode,
+                                       "last_number", last_number, EET_T_STRING);
+}
+
+
 Eina_Bool util_init(const char *theme)
 {
+       int ret;
+       const char *config_path;
+       char base_dir[PATH_MAX];
+       Eet_File *efile;
+
+       eet_init();
+       config_path = efreet_config_home_get();
+       snprintf(base_dir, sizeof(base_dir), "%s/%s", config_path, PACKAGE_NAME);
+       ecore_file_mkpath(base_dir);
+       ret = asprintf(&_last_user_mode_config_path,  "%s/%s/last_user_mode.eet", config_path, PACKAGE_NAME);
+       if (ret < 0)
+               return EINA_FALSE;
+
+       _last_user_mode_descriptor_init();
        elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
        elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
        elm_app_info_set(util_init, "ofono-efl", "themes/default.edj");
@@ -214,4 +284,9 @@ Eina_Bool util_init(const char *theme)
 
 void util_shutdown(void)
 {
+       if (_last_user_mode_config_path)
+               free(_last_user_mode_config_path);
+       if (_last_user_mode_descriptor)
+               eet_data_descriptor_free(_last_user_mode_descriptor);
+       eet_shutdown();
 }
index cb0a279..1a837ba 100644 (file)
@@ -8,6 +8,26 @@
 #define MONTH ((DAY) * 30)
 #define YEAR ((MONTH) *12)
 
+enum {
+       DIALER_LAST_VIEW_KEYPAD = 0,
+       DIALER_LAST_VIEW_CONTACTS,
+       DIALER_LAST_VIEW_HISTORY
+};
+
+enum {
+       DIALER_LAST_HISTORY_VIEW_ALL = 0,
+       DIALER_LAST_HISTORY_VIEW_MISSED
+};
+
+#define LAST_USER_MODE_ENTRY "last_user_mode"
+
+typedef struct
+{
+       int last_view;
+       int last_history_view;
+       const char *last_number;
+} Last_User_Mode;
+
 char *phone_format(const char *number);
 
 char *date_format(time_t date);
@@ -19,6 +39,10 @@ Evas_Object *layout_add(Evas_Object *parent, const char *style);
 
 Eina_Bool util_set_night_mode(Eina_Bool night_mode);
 
+Eina_Bool util_set_last_user_mode(Last_User_Mode *mode);
+
+Last_User_Mode *util_get_last_user_mode();
+
 Eina_Bool util_init(const char *theme);
 void util_shutdown(void);