summaryrefslogtreecommitdiff
path: root/lib/ct-front/ct-front-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ct-front/ct-front-view.c')
-rwxr-xr-xlib/ct-front/ct-front-view.c434
1 files changed, 434 insertions, 0 deletions
diff --git a/lib/ct-front/ct-front-view.c b/lib/ct-front/ct-front-view.c
new file mode 100755
index 0000000..85b559d
--- /dev/null
+++ b/lib/ct-front/ct-front-view.c
@@ -0,0 +1,434 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <bundle.h>
+#include <app.h>
+#include "phone.h"
+#include "ct-front.h"
+#include "phone-log.h"
+#include "ct-front-view.h"
+#include "ct-list.h"
+#include "ct-favor.h"
+
+static void cfront_view_reset_current_sub_view(ct_front_data *cfront_d)
+{
+ PH_FN_CALL;
+ p_ret_if(cfront_d->select_tab <= CT_VIEW_NONE || CT_VIEW_MAX <= cfront_d->select_tab);
+ if (cfront_d->sub_view[cfront_d->select_tab]) {
+ switch (cfront_d->select_tab) {
+ case CT_VIEW_CONTACT :
+ ctui_list_view_reset(evas_object_data_get(cfront_d->navi, "clist_d"));
+ break;
+ case CT_VIEW_LOG :
+ phone_log_view_reset(cfront_d->navi);
+ phone_log_set_background(cfront_d->navi, true);
+ break;
+ case CT_VIEW_FAVORITE :
+ phone_favor_view_reset(cfront_d->sub_view[CT_VIEW_FAVORITE]);
+ phone_favor_set_background(cfront_d->sub_view[CT_VIEW_FAVORITE], true);
+ break;
+ }
+ }
+}
+
+static void cfront_view_load_sub_view(ct_front_data *cfront_d, int tab_index)
+{
+ PH_FN_CALL;
+ ph_view_info *view_info;
+ view_info = calloc(1, sizeof(ph_view_info));
+ phone_set_view_info(view_info, cfront_d->win, cfront_d->navi, cfront_d->ug, cfront_d->ug_request,
+ cfront_d->cnt_max, cfront_d->ug_data);
+ switch (tab_index) {
+ case CT_VIEW_CONTACT:
+ cfront_d->sub_view[tab_index] = ctui_create_phone_list_view(view_info);
+ return;
+ case CT_VIEW_LOG:
+ cfront_d->sub_view[tab_index] = phone_create_log_view(view_info);
+ break;
+ case CT_VIEW_FAVORITE:
+ cfront_d->sub_view[tab_index] = phone_favor_create_view(view_info);
+ break;
+ default:
+ return;
+ };
+ free(view_info);
+}
+
+static void cfront_view_show_sub_view(ct_front_data *cfront_d, int tab_index)
+{
+ PH_FN_CALL;
+ Evas_Object *view;
+ ph_view_info *view_info;
+ p_retm_if(tab_index <= CT_VIEW_NONE || CT_VIEW_MAX <= tab_index, "tab index is invalid");
+ p_retm_if(cfront_d->select_tab == tab_index, "The tab is already shown");
+
+ cfront_view_reset_current_sub_view(cfront_d);
+ phone_hide_notify(cfront_d->navi);
+
+ view_info = calloc(1, sizeof(ph_view_info));
+ phone_set_view_info(view_info, cfront_d->win, cfront_d->navi, cfront_d->ug, cfront_d->ug_request,
+ cfront_d->cnt_max, cfront_d->ug_data);
+
+ switch (tab_index) {
+ case CT_VIEW_CONTACT:
+ if (NULL == cfront_d->sub_view[tab_index])
+ cfront_d->sub_view[tab_index] = ctui_create_phone_list_view(view_info);
+
+ if (PH_UG_REQUEST_CHECK == cfront_d->ug_request ||
+ PH_UG_REQUEST_CHECK_FOR_NUMBER == cfront_d->ug_request ||
+ PH_UG_REQUEST_CHECK_FOR_EMAIL == cfront_d->ug_request) {
+ ctui_list_edit_mode_start(evas_object_data_get(cfront_d->navi, "clist_d"));
+ }
+ else
+ ctui_list_navi_set(CT_LIST_MODE_DEFAULT, evas_object_data_get(cfront_d->navi, "clist_d"));
+ break;
+ case CT_VIEW_LOG:
+ if (NULL == cfront_d->sub_view[tab_index])
+ cfront_d->sub_view[tab_index] = phone_create_log_view(view_info);
+ phone_log_set_background(cfront_d->navi, false);
+ if (PH_UG_REQUEST_CHECK == cfront_d->ug_request ||
+ PH_UG_REQUEST_CHECK_FOR_NUMBER == cfront_d->ug_request)
+ phone_log_check_mode_start(evas_object_data_get(cfront_d->navi, "log_data"));
+ else
+ phone_log_set_navi(cfront_d->navi);
+ break;
+ case CT_VIEW_FAVORITE:
+ if (NULL == cfront_d->sub_view[tab_index])
+ cfront_d->sub_view[tab_index] = phone_favor_create_view(view_info);
+ phone_favor_set_background(cfront_d->sub_view[CT_VIEW_FAVORITE], false);
+ if (cfront_d->ug &&
+ (PH_UG_REQUEST_CHECK == cfront_d->ug_request ||
+ PH_UG_REQUEST_CHECK_FOR_NUMBER == cfront_d->ug_request ||
+ PH_UG_REQUEST_CHECK_FOR_EMAIL == cfront_d->ug_request)) {
+ phone_favor_edit_mode_start(evas_object_data_get(cfront_d->sub_view[tab_index], "favor_d"));
+ }
+ else
+ phone_favor_set_navi(cfront_d->sub_view[tab_index], PH_FAVOR_MODE_DEFAULT);
+ break;
+ default:
+ free(view_info);
+ return;
+ }
+ cfront_d->select_tab = tab_index;
+
+ view = elm_object_part_content_get(cfront_d->layout, "elm.swallow.content");
+ if (view) {
+ elm_object_part_content_unset(cfront_d->layout, "elm.swallow.content");
+ evas_object_hide(view);
+ }
+ elm_object_part_content_set(cfront_d->layout, "elm.swallow.content", cfront_d->sub_view[tab_index]);
+ evas_object_show(cfront_d->sub_view[tab_index]);
+
+ free(view_info);
+}
+
+static Eina_Bool cfront_view_load_all_sub_view(void *data)
+{
+ PH_FN_CALL;
+ ct_front_data *cfront_d = data;
+ int i;
+
+ for (i=CT_VIEW_CONTACT;i<CT_VIEW_MAX;i++) {
+ if (cfront_d->view_visible[i] && NULL == cfront_d->sub_view[i]) {
+ cfront_view_load_sub_view(cfront_d, i);
+ return ECORE_CALLBACK_RENEW;
+ }
+ }
+ cfront_d->idler = NULL;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+API Eina_Bool ctui_front_view_load_timer(void *data)
+{
+ ct_front_data *cfront_d = data;
+ cfront_d->idler = ecore_idler_add(cfront_view_load_all_sub_view, cfront_d);
+ cfront_d->timer = NULL;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static void cfront_view_change_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ PH_FN_CALL;
+ int i;
+ Elm_Object_Item *selected_it;
+ ct_front_data *cfront_d = data;
+
+ selected_it = elm_toolbar_selected_item_get(obj);
+
+ for (i=CT_VIEW_CONTACT;i<CT_VIEW_MAX;i++) {
+ if (cfront_d->item[i])
+ if (selected_it == cfront_d->item[i]) break;
+ }
+ PH_DBG("cur sel : %d, sel index : %d", cfront_d->select_tab, i);
+ cfront_view_show_sub_view(cfront_d, i);
+}
+
+static void cfront_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ PH_FN_CALL;
+ ct_front_data *cfront_d = data;
+ int i;
+
+ p_retm_if(NULL == cfront_d, "cfront_d is null");
+
+ for (i=0;i<CT_VIEW_MAX;i++) {
+ if (cfront_d->sub_view[i])
+ evas_object_del(cfront_d->sub_view[i]);
+ }
+
+ if (cfront_d->idler)
+ ecore_idler_del(cfront_d->idler);
+
+ if (cfront_d->timer)
+ ecore_timer_del(cfront_d->timer);
+
+ free(cfront_d);
+ PH_FN_END;
+}
+
+Evas_Object* ct_front_view_create_toolbar(ct_front_data *cfront_d)
+{
+ Evas_Object *base;
+ Evas_Object *layout;
+ Evas_Object *naviframe;
+ Evas_Object *toolbar;
+ Elm_Object_Item *navi_it;
+
+ base = elm_layout_add(cfront_d->win);
+ p_retvm_if(NULL == base, NULL, "elm_layout_add() Failed");
+ evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_layout_theme_set(base, "layout", "application", "default");
+ elm_win_resize_object_add(cfront_d->win, base);
+ evas_object_show(base);
+
+ naviframe = elm_naviframe_add(base);
+ elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
+ elm_object_part_content_set(base, "elm.swallow.content", naviframe);
+ cfront_d->navi = naviframe;
+
+ layout = elm_layout_add(naviframe);
+ p_retvm_if(NULL == layout, NULL, "elm_layout_add() Failed");
+ elm_layout_theme_set(layout, "layout", "tabbar", "default");
+ cfront_d->layout = layout;
+
+ toolbar = elm_toolbar_add(naviframe);
+ p_retvm_if(NULL == toolbar, NULL, "elm_toolbar_add() Failed");
+ elm_object_style_set(toolbar, "tabbar");
+ elm_object_part_content_set(layout, "elm.swallow.tabbar", toolbar);
+ cfront_d->tabbar = toolbar;
+
+ elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
+
+ if (cfront_d->view_visible[CT_VIEW_CONTACT])
+ cfront_d->item[CT_VIEW_CONTACT] = elm_toolbar_item_append(toolbar,
+ PH_IMG_ICON_CONTACTS, S_(PH_SYS_BODY_CONTACTS), cfront_view_change_cb, cfront_d);
+ if (cfront_d->view_visible[CT_VIEW_FAVORITE])
+ cfront_d->item[CT_VIEW_FAVORITE] = elm_toolbar_item_append(toolbar,
+ PH_IMG_ICON_FAVORITE, T_(PH_GET_TEXT_BASIC, PHTEXT_FAVORITES), cfront_view_change_cb, cfront_d);
+ if (cfront_d->view_visible[CT_VIEW_LOG])
+ cfront_d->item[CT_VIEW_LOG] = elm_toolbar_item_append(toolbar,
+ PH_IMG_ICON_LOGS, T_(PH_GET_TEXT_BASIC, PHTEXT_LOGS), cfront_view_change_cb, cfront_d);
+
+ navi_it = elm_naviframe_item_push(naviframe, NULL, NULL, NULL, layout, NULL);
+ elm_naviframe_item_title_visible_set(navi_it, EINA_FALSE);
+ evas_object_event_callback_add(base, EVAS_CALLBACK_DEL, cfront_view_delete_cb, cfront_d);
+
+ return base;
+}
+
+API ct_front_data* ctui_front_view_create(Evas_Object *win)
+{
+ PH_FN_CALL;
+ Evas_Object *bg;
+ Evas_Object *layout;
+ ct_front_data *cfront_d = calloc(1, sizeof(ct_front_data));
+ cfront_d->win = win;
+ cfront_d->select_tab = CT_VIEW_NONE;
+
+ cfront_d->view_visible[CT_VIEW_CONTACT] = true;
+ cfront_d->view_visible[CT_VIEW_FAVORITE] = true;
+
+ layout = ct_front_view_create_toolbar(cfront_d);
+ if (NULL == layout) {
+ PH_DBG("layout_main is null");
+ free(cfront_d);
+ return NULL;
+ }
+
+ bg = phone_create_bg(layout);
+ if (NULL == bg) {
+ PH_DBG("phone_create_bg() return NULL");
+ free(cfront_d);
+ return NULL;
+ }
+
+ return cfront_d;
+}
+
+API void ctui_front_view_region_changed(ct_front_data *cfront_d)
+{
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_LOG])
+ phone_log_views_update(cfront_d->navi);
+ // TODO: update contact detail history view
+}
+
+API void ctui_front_view_pause(ct_front_data *cfront_d)
+{
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_LOG])
+ phone_log_set_background(cfront_d->navi, true);
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_CONTACT])
+ ctui_list_view_pause(cfront_d->navi);
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_FAVORITE])
+ phone_favor_set_background(cfront_d->sub_view[CT_VIEW_FAVORITE], true);
+}
+
+API void ctui_front_view_resume(ct_front_data *cfront_d)
+{
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_LOG]) {
+ if (CT_VIEW_LOG == cfront_d->select_tab) {
+ phone_log_set_background(cfront_d->navi, false);
+ phone_log_view_resume(cfront_d->navi);
+ }
+ }
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_CONTACT])
+ ctui_list_view_resume(cfront_d->navi);
+
+ if (cfront_d && cfront_d->sub_view[CT_VIEW_FAVORITE] && CT_VIEW_FAVORITE == cfront_d->select_tab)
+ phone_favor_set_background(cfront_d->sub_view[CT_VIEW_FAVORITE], false);
+}
+
+static void cfront_view_win_activate(void *data, Evas *e, void *even_info)
+{
+ elm_win_activate(data);
+ evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, cfront_view_win_activate);
+}
+
+API int ctui_front_view_rotate(ct_front_data *cfront_d, app_device_orientation_e orientation)
+{
+ int rotate;
+ int ret = 0;
+
+ switch (orientation) {
+ case APP_DEVICE_ORIENTATION_0:
+ rotate = 0;
+ ret = ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
+ phone_resize_notify(cfront_d->navi, rotate);
+ break;
+ case APP_DEVICE_ORIENTATION_180:
+ rotate = 180;
+ ret = ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
+ phone_resize_notify(cfront_d->navi, rotate);
+ break;
+ case APP_DEVICE_ORIENTATION_270:
+ rotate = 270;
+ ret = ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
+ phone_resize_notify(cfront_d->navi, rotate);
+ break;
+ case APP_DEVICE_ORIENTATION_90:
+ rotate = 90;
+ ret = ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
+ phone_resize_notify(cfront_d->navi, rotate);
+ break;
+ default:
+ rotate = -1;
+ break;
+ }
+ evas_object_data_set(cfront_d->navi, "phone_rotate", (void *)rotate);
+ if (0 <= rotate)
+ elm_win_rotation_with_resize_set(cfront_d->win, rotate);
+ return ret;
+}
+
+API void ctui_front_view_reset(ct_front_data *cfront_d, int select_index, int op, service_h service)
+{
+ PH_FN_CALL;
+ int call_launched = FALSE;
+ ph_view_info *view_info;
+ Evas_Object *view;
+ char *buf = NULL;
+ int ret;
+
+ elm_toolbar_select_mode_set(cfront_d->tabbar, ELM_OBJECT_SELECT_MODE_NONE);
+
+ cfront_view_reset_current_sub_view(cfront_d);
+ if (cfront_d->sub_view[CT_VIEW_CONTACT])
+ ctui_list_view_resume(cfront_d->navi);
+
+ view = elm_object_part_content_get(cfront_d->layout, "elm.swallow.content");
+ if (view) {
+ elm_object_part_content_unset(cfront_d->layout, "elm.swallow.content");
+ evas_object_hide(view);
+ }
+
+ elm_toolbar_select_mode_set(cfront_d->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
+
+ view_info = calloc(1, sizeof(ph_view_info));
+ phone_set_view_info(view_info, cfront_d->win, cfront_d->navi, cfront_d->ug, cfront_d->ug_request,
+ cfront_d->cnt_max, cfront_d->ug_data);
+
+ switch (select_index) {
+ case CT_VIEW_CONTACT:
+ if (NULL == cfront_d->sub_view[select_index]) {
+ cfront_d->sub_view[CT_VIEW_CONTACT] = ctui_create_phone_list_view(view_info);
+ }
+ ctui_list_navi_set(CT_LIST_MODE_DEFAULT, evas_object_data_get(cfront_d->navi, "clist_d"));
+ if (CT_FRONT_CONTACT_NEW == op)
+ ctui_list_new_btn_clicked_cb(evas_object_data_get(cfront_d->navi, "clist_d"), NULL, NULL);
+ else if (CT_FRONT_CONTACT_SEARCH == op) {
+ ret = service_get_extra_data(service, "search_name", &buf);
+ p_warn_if(SERVICE_ERROR_NONE != ret, "service_get_extra_data is failed(%d)", ret);
+ ctui_list_set_search_text(evas_object_data_get(cfront_d->navi, "clist_d"), buf);
+ free(buf);
+ }
+ break;
+ case CT_VIEW_LOG:
+ if (NULL == cfront_d->sub_view[select_index])
+ cfront_d->sub_view[select_index] = phone_create_log_view(view_info);
+ if (!cfront_d->ug)
+ phone_log_missed_info_update(cfront_d->navi);
+ phone_log_set_navi(cfront_d->navi);
+ break;
+ case CT_VIEW_FAVORITE:
+ if (NULL == cfront_d->sub_view[select_index])
+ cfront_d->sub_view[select_index] = phone_favor_create_view(view_info);
+ phone_favor_set_navi(cfront_d->sub_view[select_index], PH_FAVOR_MODE_DEFAULT);
+ break;
+ default:
+ break;
+ }
+
+ cfront_d->select_tab = select_index;
+
+ if (CT_VIEW_NONE < select_index && select_index < CT_VIEW_MAX) {
+ elm_object_part_content_set(cfront_d->layout, "elm.swallow.content", cfront_d->sub_view[select_index]);
+ evas_object_show(cfront_d->sub_view[select_index]);
+ elm_toolbar_item_selected_set(cfront_d->item[select_index], EINA_TRUE);
+ }
+
+ if (cfront_d->win && FALSE == call_launched && CT_VIEW_NONE != select_index){
+ if (EINA_FALSE == evas_object_visible_get(cfront_d->win))
+ evas_object_show(cfront_d->win);
+ evas_event_callback_add(evas_object_evas_get(cfront_d->navi),
+ EVAS_CALLBACK_RENDER_FLUSH_POST, cfront_view_win_activate, cfront_d->win);
+ }
+ else
+ elm_win_lower(cfront_d->win);
+ cfront_d->timer = ecore_timer_add(3.0, ctui_front_view_load_timer, cfront_d);
+
+ free(view_info);
+ PH_FN_END;
+}
+