diff options
author | Jaeyun Jeong <jyjeong@samsung.com> | 2012-08-21 18:40:43 +0900 |
---|---|---|
committer | Jaeyun Jeong <jyjeong@samsung.com> | 2012-08-21 18:40:43 +0900 |
commit | 92abf425ce0d141f966ddaecf1c4bc325fc9e189 (patch) | |
tree | 411d692f37dbfbd292f19c41f9cd717523c18295 /class0/msg-ui-class0-main.c | |
parent | 5f6271abd18e2d811315f56c48ecd927c9e9436c (diff) | |
download | message-app-92abf425ce0d141f966ddaecf1c4bc325fc9e189.tar.gz message-app-92abf425ce0d141f966ddaecf1c4bc325fc9e189.tar.bz2 message-app-92abf425ce0d141f966ddaecf1c4bc325fc9e189.zip |
Implement tizen 2.0 beta.
Change-Id: Ifea6bc144e2628ddfaa3cafa8f4f250d78005356
Diffstat (limited to 'class0/msg-ui-class0-main.c')
-rwxr-xr-x | class0/msg-ui-class0-main.c | 488 |
1 files changed, 488 insertions, 0 deletions
diff --git a/class0/msg-ui-class0-main.c b/class0/msg-ui-class0-main.c new file mode 100755 index 0000000..9d3794f --- /dev/null +++ b/class0/msg-ui-class0-main.c @@ -0,0 +1,488 @@ +/* + * 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 "msg-ui-class0-main.h" + +static Eina_Bool __msg_ui_class0_keydown_cb(void *data, int type, void *event); +static int __msg_ui_class0_load_msg_data(void *data); +static char *__msg_ui_str_append(char *str, const char *txt, int *len, int *alloc); +static char *__msg_ui_text_to_markup(const char *text); +static void __msg_ui_class0_btn_clicked_event(void *data, Evas_Object *obj, void *event_info); +static Evas_Object *__msg_ui_class0_create_contents(void *data); +static int __msg_ui_class0_create_view(void *data); + +static void __msg_ui_class0_win_del(void *data, Evas_Object *obj, void *event); +static Evas_Object *__msg_ui_class0_create_win(const char *name); + + +void msg_ui_class0_exit(void *data) +{ + struct appdata *ad = data; + + int ret = 0; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + if (ad->msgInfo != NULL) { + msg_release_struct(&ad->msgInfo); + ad->msgInfo = NULL; + } + + if (ad->msgHandle != NULL) { + ret = msg_close_msg_handle(&ad->msgHandle); + if (ret != MSG_SUCCESS) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_close_msg_handle() is failed !! : ret value is %d", ret); + } + } + + elm_exit(); +} + +static Eina_Bool __msg_ui_class0_keydown_cb(void *data, int type, void *event) +{ + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + if (data == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "data is null, calling elm_exit...\n"); + elm_exit(); + } + + Ecore_Event_Key *ev = event; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "KEY = %s\n", ev->keyname); + + if (!strcmp(ev->keyname, KEY_END)) { + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "keyname = %s ...calling elm_exit...\n", ev->keyname); + elm_exit(); + } + + return EINA_FALSE; +} + +static int __msg_ui_class0_load_msg_data(void *data) +{ + struct appdata *ad = data; + + msg_error_t err = MSG_SUCCESS; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + if (ad->msgHandle == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msgHandle is NULL !!"); + return MSG_UI_RET_ERR; + } + + ad->msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + if (ad->msgInfo == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_new_message() is failed!"); + return MSG_UI_RET_ERR; + } + + msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + + err = msg_get_message(ad->msgHandle, ad->msg_id, ad->msgInfo, sendOpt); + if (err != MSG_SUCCESS) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_get_message is failed! : %d", err); + if (ad->msgInfo != NULL) { + msg_release_struct(&ad->msgInfo); + ad->msgInfo = NULL; + } + + return MSG_UI_RET_ERR; + } else + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_get_message is success"); + + return MSG_UI_RET_SUCCESS; +} + +static char * +__msg_ui_str_append(char *str, const char *txt, int *len, int *alloc) +{ + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + int txt_len = strlen(txt); + + if (txt_len <= 0) + return str; + + if ((*len + txt_len) >= *alloc) { + char *str2; + int alloc2; + + alloc2 = *alloc + txt_len + 128; + str2 = realloc(str, alloc2); + if (!str2) + return str; + + *alloc = alloc2; + str = str2; + } + + strcpy(str + *len, txt); + *len += txt_len; + return str; +} + +static char * +__msg_ui_text_to_markup(const char *text) +{ + char *str = NULL; + int str_len = 0, str_alloc = 0; + int ch, pos = 0, pos2 = 0; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + if (!text) + return NULL; + + for (;;) { + pos = pos2; + pos2 = evas_string_char_next_get(text, pos2, &ch); + if ((ch <= 0) || (pos2 <= 0)) + break; + + if (ch == '\n') + str = __msg_ui_str_append(str, "<br>", &str_len, &str_alloc); + else if (ch == '\t') + str = __msg_ui_str_append(str, "<\t>", &str_len, &str_alloc); + else if (ch == '<') + str = __msg_ui_str_append(str, "<", &str_len, &str_alloc); + else if (ch == '>') + str = __msg_ui_str_append(str, ">", &str_len, &str_alloc); + else if (ch == '&') + str = __msg_ui_str_append(str, "&", &str_len, &str_alloc); + else { + char tstr[16]; + + strncpy(tstr, text + pos, pos2 - pos); + tstr[pos2 - pos] = 0; + str = __msg_ui_str_append(str, tstr, &str_len, &str_alloc); + } + } + + return str; +} + +static void __msg_ui_class0_btn_clicked_event(void *data, Evas_Object *obj, void *event_info) +{ + struct appdata *ad = data; + + int err = MSG_SUCCESS; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "obj = 0x%x", obj); + + if (obj == ad->right_btn) { + /* Save it to Inbox. */ + err = msg_move_msg_to_folder(ad->msgHandle, ad->msg_id, MSG_INBOX_ID); + if (err != MSG_SUCCESS) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_move_msg_to_folder() is failed : err = %d", err); + } + + msg_ui_class0_exit(ad); + } else if (obj == ad->left_btn) { + /* Discard this message */ + err = msg_delete_message(ad->msgHandle, ad->msg_id); + if (err != MSG_SUCCESS) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_delete_message() is failed : err = %d", err); + } + + msg_ui_class0_exit(ad); + } else { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid obj = 0x%x", obj); + return; + } +} + +static Evas_Object* +__msg_ui_class0_create_contents(void *data) +{ + struct appdata *ad = data; + + Evas_Object *scroller = NULL; + + char buf[2048] = { 0, }; + char *str = NULL; + + int msgSize = 0; + char pMsgBody[2048] = {0,}; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + /* Create scroller. */ + scroller = elm_scroller_add(ad->navi_frame); + evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_scroller_page_relative_set(scroller, 0.0, 0.0); + elm_scroller_bounce_set(scroller, FALSE, TRUE); + evas_object_show(scroller); + + /* Create label. */ + ad->label = elm_label_add(scroller); + elm_object_style_set(ad->label, "detail_view/description"); + evas_object_size_hint_align_set(ad->label, EVAS_HINT_FILL, 0.0); + evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, 0.0); + + msg_get_int_value(ad->msgInfo, MSG_MESSAGE_DATA_SIZE_INT, &msgSize); + if (msgSize > 0) { + msg_get_str_value(ad->msgInfo, MSG_MESSAGE_SMS_DATA_STR, pMsgBody, sizeof(pMsgBody)); + if (pMsgBody[0] != '\0') { + snprintf(buf, sizeof(buf), "%s", pMsgBody); + } else { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_sms_get_message_body() is failed !!"); + snprintf(buf, sizeof(buf), "Message is empty !!"); + } + } else { + snprintf(buf, sizeof(buf), "Message is empty !!"); + } + + buf[2047] = '\n'; + + str = __msg_ui_text_to_markup(buf); + elm_object_text_set(ad->label, str); + elm_label_line_wrap_set(ad->label, TRUE); + elm_object_content_set(scroller, ad->label); + evas_object_show(ad->label); + + if (str) + free(str); + + return scroller; +} + +static int __msg_ui_class0_create_view(void *data) +{ + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); + + struct appdata *ad = data; + + Evas_Object *content = NULL; + + Evas_Object *ctrl_bar; + Evas_Object *ctrl_btn_left; + Evas_Object *ctrl_btn_right; + Elm_Object_Item *ctrl_left_item; + Elm_Object_Item *ctrl_right_item; + Evas_Object *icon_left; + Evas_Object *icon_right; + + char buf[DEF_BUF_LEN_S]; + + /* Create layout */ + ad->layout_main = elm_layout_add(ad->win_main); + elm_layout_theme_set(ad->layout_main, "layout", "application", "default"); + evas_object_size_hint_weight_set(ad->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(ad->win_main, ad->layout_main); + evas_object_show(ad->layout_main); + + /* Create navi_frame */ + ad->navi_frame = elm_naviframe_add(ad->layout_main); + elm_object_part_content_set(ad->layout_main, "elm.swallow.content", ad->navi_frame); + evas_object_show(ad->navi_frame); + + content = __msg_ui_class0_create_contents(ad); + if (content == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "__msg_ui_class0_create_contents() is failed !!"); + return MSG_UI_RET_ERR; + } + + ctrl_bar = elm_toolbar_add(ad->navi_frame); + elm_toolbar_shrink_mode_set(ctrl_bar, ELM_TOOLBAR_SHRINK_EXPAND); + MSG_UI_RETVM_IF(MSG_UI_LEVEL_DEBUG, ctrl_bar == NULL, MSG_UI_RET_ERR, "ctrl_bar is NULL !!"); + + elm_object_style_set(ctrl_bar, "naviframe"); + + ctrl_btn_left = elm_button_add(ctrl_bar); + elm_object_style_set(ctrl_btn_left, "naviframe_control/left"); + evas_object_size_hint_align_set(ctrl_btn_left, EVAS_HINT_FILL, 0.5); + icon_left = elm_icon_add(ctrl_btn_left); + memset(buf, 0x0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s", MSG_HEADER_ICON_CANCEL); + elm_icon_file_set(icon_left, buf, NULL); + elm_object_part_content_set(ctrl_btn_left, "elm.swallow.content", icon_left); + elm_object_text_set(ctrl_btn_left, dgettext(MESSAGE_PKGNAME, "IDS_MSGF_OPT_DISCARD")); + evas_object_show(ctrl_btn_left); + evas_object_smart_callback_add(ctrl_btn_left, "clicked", __msg_ui_class0_btn_clicked_event, ad); + ad->left_btn = ctrl_btn_left; + + ctrl_btn_right = elm_button_add(ctrl_bar); + elm_object_style_set(ctrl_btn_right, "naviframe_control/right"); + evas_object_size_hint_align_set(ctrl_btn_right, EVAS_HINT_FILL, 0.5); + icon_right = elm_icon_add(ctrl_btn_right); + memset(buf, 0x0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s", MSG_HEADER_ICON_DONE); + elm_icon_file_set(icon_right, buf, NULL); + elm_object_part_content_set(ctrl_btn_right, "elm.swallow.content", icon_right); + elm_object_text_set(ctrl_btn_right, dgettext("sys_string", "IDS_COM_SK_SAVE")); + evas_object_show(ctrl_btn_right); + evas_object_smart_callback_add(ctrl_btn_right, "clicked", __msg_ui_class0_btn_clicked_event, ad); + ad->right_btn = ctrl_btn_right; + + ctrl_left_item = elm_toolbar_item_append(ctrl_bar, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(ctrl_left_item, "object", ctrl_btn_left); + elm_toolbar_item_append(ctrl_bar, NULL, NULL, NULL, NULL); + ctrl_right_item = elm_toolbar_item_append(ctrl_bar, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(ctrl_right_item, "object", ctrl_btn_right); + + Elm_Object_Item *nf_it = elm_naviframe_item_push(ad->navi_frame, dgettext(MESSAGE_PKGNAME, "Class 0 message"), NULL, NULL, content, NULL); + elm_object_item_part_content_set(nf_it, "optionheader", ctrl_bar); + + return MSG_UI_RET_SUCCESS; +} + +static void __msg_ui_class0_win_del(void *data, Evas_Object *obj, void *event) +{ + elm_exit(); +} + +static Evas_Object *__msg_ui_class0_create_win(const char *name) +{ + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); + Evas_Object *eo; + int w, h; + + eo = elm_win_add(NULL, name, ELM_WIN_BASIC); + if (eo) { + elm_win_title_set(eo, name); + evas_object_smart_callback_add(eo, "delete,request", __msg_ui_class0_win_del, NULL); + ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); + evas_object_resize(eo, w, h); + } + + return eo; +} + +static bool app_create(void *data) +{ + struct appdata *ad = data; + + int ret = 0; + + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "msg ID = %d", ad->msg_id); + + ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __msg_ui_class0_keydown_cb, ad); + + ret = msg_open_msg_handle(&ad->msgHandle); + if (ret != MSG_SUCCESS) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "msg_open_msg_handle() is failed : ret = %d", ret); + msg_ui_class0_exit(ad); + return FALSE; + } + + /* init internationalization */ + if (bindtextdomain(MESSAGE_PKGNAME, LOCALEDIR) == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "bindtextdomain() is failed : ret = %d", ret); + return FALSE; + } + + if (textdomain(MESSAGE_PKGNAME) == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "textdomain() is failed : ret = %d", ret); + return FALSE; + } + + ad->win_main = __msg_ui_class0_create_win(PACKAGE); + if (ad->win_main == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "Main window is NULL"); + return FALSE; + } else { + evas_object_show(ad->win_main); + } + + /* Indicator */ + elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_HIDE); + + evas_object_geometry_get(ad->win_main, NULL, NULL, &ad->root_w, &ad->root_h); + MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "main window width[%d], height[%d]", ad->root_w, ad->root_h); + + /* draw background image */ + ad->bg = elm_bg_add(ad->win_main); + evas_object_size_hint_weight_set(ad->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(ad->win_main, ad->bg); + evas_object_show(ad->bg); + + return TRUE; +} + +static void app_terminate(void *data) +{ + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); + + msg_ui_class0_exit(data); +} + +static void app_pause(void *data) +{ + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); +} + +static void app_resume(void *data) +{ + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); +} + +static void app_service(service_h service, void *data) +{ + struct appdata *ad = data; + + char *strMsgId = NULL; + int ret = 0; + + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); + + service_get_extra_data(service, MSG_BUNDLE_KEY_MSG_ID, &strMsgId); + + if (strMsgId == NULL) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_get_extra_data() is failed !!"); + return; + } else { + ad->msg_id = atoi(strMsgId); + + /* Load message data by using message ID. */ + ret = __msg_ui_class0_load_msg_data(ad); + if (ret < 0) { + MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "__msg_ui_class0_load_msg_data() is failed : ret = %d", ret); + msg_ui_class0_exit(ad); + return; + } + + /* Create main view */ + __msg_ui_class0_create_view(ad); + + evas_object_show(ad->win_main); + } +} + +int main(int argc, char *argv[]) +{ + MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); + + struct appdata ad; + memset(&ad, 0x0, sizeof(struct appdata)); + + app_event_callback_s event_callback; + + event_callback.create = app_create; + event_callback.terminate = app_terminate; + event_callback.pause = app_pause; + event_callback.resume = app_resume; + event_callback.service = app_service; + event_callback.low_memory = NULL; + event_callback.low_battery = NULL; + event_callback.device_orientation = NULL; + event_callback.language_changed = NULL; + event_callback.region_format_changed = NULL; + + return app_efl_main(&argc, &argv, &event_callback, &ad); +} |