2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
26 #include "email-debug.h"
27 #include "email-setting.h"
28 #include "email-setting-utils.h"
29 #include "email-view-setting.h"
30 #include "email-view-sp-select.h"
31 #include "email-view-account-edit.h"
32 #include "email-view-account-setup.h"
33 #include "email-view-manual-setup.h"
34 #include "email-view-mailbox-mapping.h"
35 #include "email-view-account-options.h"
36 #include "email-view-initial.h"
37 #include "email-view-sync-schedule.h"
38 #include "email-view-sync-setup.h"
40 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv);
41 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv);
42 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv);
43 static void on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv);
44 static void on_destroy(ui_gadget_h ug, service_h service, void *priv);
45 static void on_resume(ui_gadget_h ug, service_h service, void *priv);
46 static void on_pause(ui_gadget_h ug, service_h service, void *priv);
47 static void on_start(ui_gadget_h ug, service_h service, void *priv);
49 static void _init_data(struct ug_data *ugd);
50 static void _couple_data(struct ug_data *ugd, Viewtype t, struct viewdata *vd);
51 static void _dbus_receiver_setup(struct ug_data *ugd);
52 static void _remove_dbus_receiver(struct ug_data *ugd);
53 static int _account_init(struct ug_data *ugd);
54 static int _account_finalize(EmailSettingUGD *ugd);
55 static int _parse_option(service_h service, struct ug_data *ugd);
56 static void _dispatch_view(struct ug_data *ugd);
57 static void _create_navigationbar(struct ug_data *ugd);
58 static Evas_Object *_create_layout(Evas_Object *parent, struct ug_data *ugd);
59 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event);
61 static void _layout_block_cb(ui_gadget_h ug, enum ug_mode mode, void *priv);
62 static void _result_block_cb(ui_gadget_h ug, service_h service, void *priv);
63 static void _destroy_block_cb(ui_gadget_h ug, void *priv);
65 static void _popup_ok_cb(void *data, Evas_Object *obj, void *event_info);
67 static void _create_max_account_popup_create(EmailSettingUGD *ugd);
68 static void _max_account_popup_ok_cb(void *data, Evas_Object *obj, void *event_info);
69 static void _language_changed_cb(EmailSettingUGD *ugd);
72 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
79 ugd = calloc(1, sizeof(struct ug_data));
83 ops->create = on_create;
84 ops->start = on_start;
85 ops->pause = on_pause;
86 ops->resume = on_resume;
87 ops->destroy = on_destroy;
88 ops->message = on_message;
89 ops->event = on_event;
90 ops->key_event = on_key_event;
92 ops->opt = UG_OPT_INDICATOR_ENABLE;
97 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
110 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
115 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
127 parent = ug_get_window();
132 ugd->evas = evas_object_evas_get(ugd->win);
134 bindtextdomain(PACKAGE, LOCALEDIR);
136 ugd->block_cbs.layout_cb = _layout_block_cb;
137 ugd->block_cbs.result_cb = _result_block_cb;
138 ugd->block_cbs.destroy_cb = _destroy_block_cb;
139 ugd->block_cbs.priv = (void *)ugd;
141 /* Init Setting View Data */
144 /* theme extension */
145 ugd->theme = elm_theme_new();
146 elm_theme_ref_set(ugd->theme, NULL);
148 ugd->layout_main = _create_layout(parent, ugd);
149 evas_object_smart_callback_add(ugd->win, "profile,changed", _win_profile_changed_cb, ugd);
150 _create_navigationbar(ugd);
151 ugd->base = ugd->layout_main;
152 elm_win_indicator_mode_set(ugd->win, ELM_WIN_INDICATOR_SHOW);
154 return ugd->layout_main;
157 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
164 EmailSettingUGD *ugd;
168 case UG_EVENT_LOW_MEMORY:
170 case UG_EVENT_LOW_BATTERY:
172 case UG_EVENT_LANG_CHANGE:
173 _language_changed_cb(ugd);
175 case UG_EVENT_ROTATE_PORTRAIT:
176 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
177 case UG_EVENT_ROTATE_LANDSCAPE:
178 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
179 if (ugd->custom_rotate_cb && ugd->custom_rotate_cb_data)
180 ugd->custom_rotate_cb(ugd->custom_rotate_cb_data);
182 case UG_EVENT_REGION_CHANGE:
190 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
197 EmailSettingUGD *ugd;
201 case UG_KEY_EVENT_END:
202 ugd->end_key_event = 1;
204 if (elm_naviframe_top_item_get(ugd->navi_bar) == elm_naviframe_bottom_item_get(ugd->navi_bar)) {
205 if (ugd->popup_one != NULL || ugd->popup_validate != NULL) {
206 if (ugd->popup_one) {
207 evas_object_del(ugd->popup_one);
208 ugd->popup_one = NULL;
211 if (ugd->popup_validate) {
212 evas_object_del(ugd->popup_validate);
213 ugd->popup_validate = NULL;
215 ugd->cancel_event = 1;
216 email_engine_stop_working(ugd->account_id, ugd->handle);
222 if (ugd->popup_one != NULL || ugd->popup_validate != NULL) {
223 if (ugd->popup_one) {
224 evas_object_del(ugd->popup_one);
225 ugd->popup_one = NULL;
228 if (ugd->popup_validate) {
229 evas_object_del(ugd->popup_validate);
230 ugd->popup_validate = NULL;
232 ugd->cancel_event = 1;
233 email_engine_stop_working(ugd->account_id, ugd->handle);
236 if (ugd->change_view_ing == 0)
237 setting_change_view(VIEW_BACK, ugd);
247 static void on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
250 EmailSettingUGD *ugd = NULL;
251 char *rotation_str = NULL;
252 int rotation_mode = UG_EVENT_ROTATE_PORTRAIT;
254 ugd = (EmailSettingUGD *)priv;
258 service_get_extra_data(msg, EMAIL_BUNDLE_KEY_ROTATE, &rotation_str);
260 debug_log("rotation mode: %s", rotation_str);
262 rotation_mode = atoi(rotation_str);
263 switch (rotation_mode) {
264 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
267 case UG_EVENT_ROTATE_LANDSCAPE:
270 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
273 case UG_EVENT_ROTATE_PORTRAIT:
279 elm_win_rotation_with_resize_set(ugd->win, angle);
284 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
287 EmailSettingUGD *ugd;
288 struct viewdata *vd = NULL;
295 evas_object_del(ugd->base);
298 if (ugd->popup_one) {
299 evas_object_del(ugd->popup_one);
300 ugd->popup_one = NULL;
303 if (ugd->popup_validate) {
304 evas_object_del(ugd->popup_validate);
305 ugd->popup_validate = NULL;
308 if (ugd->focus_timer) {
309 ecore_timer_del(ugd->focus_timer);
310 ugd->focus_timer = NULL;
313 if (ugd->preset_vc_timer) {
314 ecore_timer_del(ugd->preset_vc_timer);
315 ugd->preset_vc_timer = NULL;
318 if (ugd->other_vc_timer) {
319 ecore_timer_del(ugd->other_vc_timer);
320 ugd->other_vc_timer = NULL;
323 if (ugd->edit_vc_timer) {
324 ecore_timer_del(ugd->edit_vc_timer);
325 ugd->edit_vc_timer = NULL;
328 if (ugd->del_timer) {
329 ecore_timer_del(ugd->del_timer);
330 ugd->del_timer = NULL;
333 setting_free_sp_desc(ugd);
335 /* theme extension */
336 elm_theme_free(ugd->theme);
338 /* destroying view */
341 if (ugd->view_top >= 0) {
342 for (count = ugd->view_top; count >= 0; count--) {
343 cur_view = ugd->view_st[count];
344 vd = ugd->vd[cur_view];
345 debug_log("destorying view: %s", vd->grp_nm);
351 /* Free Viewdata's memory */
352 for (i = VIEW_SETTING; i < VIEW_END; i++) {
355 debug_log("Memory Free");
360 email_engine_finalize();
361 r = _account_finalize(ugd);
362 _remove_dbus_receiver(ugd);
365 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
381 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
397 static void on_start(ui_gadget_h ug, service_h service, void *priv)
407 ugd->conformant = (Evas_Object *)ug_get_conformant();
409 /* Init Email Service */
410 if (!email_engine_initialize()) {
411 Evas_Object *popup = elm_popup_add(ugd->layout_main);
412 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
413 elm_object_part_text_set(popup, "title,text", EMAIL_SETTING_STRING_WARNING);
414 elm_object_text_set(popup, EMAIL_SETTING_STRING_FAILED_TO_START_EMAIL_APPLICATION);
416 Evas_Object *btn1 = elm_button_add(popup);
417 elm_object_style_set(btn1, "popup_button/default");
418 elm_object_text_set(btn1, EMAIL_SETTING_STRING_OK);
419 elm_object_part_content_set(popup, "button1", btn1);
420 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
421 evas_object_show(popup);
425 /* Init Emf Account */
426 if (!_account_init(ugd)) {
427 debug_log("Failed to get account list");
430 /* create xml tree */
431 setting_free_sp_desc(ugd);
433 xmlDocPtr xml_source = setting_create_xml_tree(SP_XML_PATH);
435 Evas_Object *popup = elm_popup_add(ugd->layout_main);
436 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
437 elm_object_part_text_set(popup, "title,text", EMAIL_SETTING_STRING_WARNING);
438 elm_object_text_set(popup, EMAIL_SETTING_STRING_FAIL_PARSE_XML);
440 Evas_Object *btn1 = elm_button_add(popup);
441 elm_object_style_set(btn1, "popup_button/default");
442 elm_object_text_set(btn1, EMAIL_SETTING_STRING_OK);
443 elm_object_part_content_set(popup, "button1", btn1);
444 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
445 evas_object_show(popup);
448 ugd->xml_source = xml_source;
450 /* traverse xml tree */
452 root= xmlDocGetRootElement(xml_source);
453 int sp_count = xmlChildElementCount(root);
454 ugd->sp_list_len = sp_count;
455 debug_log("Count of SP list:%d", sp_count);
457 ugd->sp_list = (EmailSpDesc *)calloc(sp_count, sizeof(EmailSpDesc));
458 setting_traverse_xml_node(root, 0, (void *)ugd, 1);
459 setting_dump_sp_desc(ugd);
461 setting_cleanup_xml_parser(xml_source);
463 if (!_parse_option(service, ugd)) {
470 _dbus_receiver_setup(ugd);
475 static void _init_data(struct ug_data *ugd)
478 struct viewdata *view_setting = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
479 struct viewdata *view_sp_select = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
480 struct viewdata *view_account_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
481 struct viewdata *view_manual_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
482 struct viewdata *view_account_edit = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
483 struct viewdata *view_mailbox_mapping = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
484 struct viewdata *view_account_options = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
485 struct viewdata *view_initial_access = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
486 struct viewdata *view_sync_schedule = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
487 struct viewdata *view_sync_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
489 setting_init_setting_view(view_setting);
490 setting_init_sp_select_view(view_sp_select);
491 setting_init_account_setup_view(view_account_setup);
492 setting_init_manual_setup_view(view_manual_setup);
493 setting_init_account_edit_view(view_account_edit);
494 setting_init_mailbox_mapping_view(view_mailbox_mapping);
495 setting_init_account_options_view(view_account_options);
496 setting_init_initial_access_view(view_initial_access);
497 setting_init_sync_schedule_view(view_sync_schedule);
498 setting_init_sync_setup_view(view_sync_setup);
502 _couple_data(ugd, VIEW_SETTING, view_setting);
503 _couple_data(ugd, VIEW_SP_SELECT, view_sp_select);
504 _couple_data(ugd, VIEW_ACCOUNT_SETUP, view_account_setup);
505 _couple_data(ugd, VIEW_MANUAL_SETUP, view_manual_setup);
506 _couple_data(ugd, VIEW_ACCOUNT_EDIT, view_account_edit);
507 _couple_data(ugd, VIEW_MAILBOX_MAPPING, view_mailbox_mapping);
508 _couple_data(ugd, VIEW_ACCOUNT_OPTIONS, view_account_options);
509 _couple_data(ugd, VIEW_INITIAL_ACCESS, view_initial_access);
510 _couple_data(ugd, VIEW_SYNC_SCHEDULE, view_sync_schedule);
511 _couple_data(ugd, VIEW_SYNC_SETUP, view_sync_setup);
513 /* add more views... */
516 static void _couple_data(struct ug_data *ugd, Viewtype t, struct viewdata *vd)
519 debug_log("View type number%d", t);
524 static void _dbus_receiver_setup(struct ug_data *ugd)
529 debug_log("ugd == NULL");
533 int ret = e_dbus_init();
534 debug_log("ret: %d", ret);
538 if (ugd->dbus_conn == NULL) {
540 dbus_error_init(&derror);
541 ugd->dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
543 if (ugd->dbus_conn == NULL) {
544 debug_log("e_dbus_bus_get return NULL");
548 if (e_dbus_request_name(ugd->dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
549 debug_critical("Failed to e_dbus_request_name()");
553 if (ugd->signal_handler_storage != NULL) {
554 debug_log("_g_setting_signal_handler_storage != NULL");
557 ugd->signal_handler_storage = e_dbus_signal_handler_add(ugd->dbus_conn, NULL,
558 "/User/Email/StorageChange",
559 "User.Email.StorageChange", "email",
560 setting_edbus_event_receive,
561 (struct ug_data *)ugd);
563 if (ugd->signal_handler_storage == NULL) {
564 debug_log("Failed to e_dbus_signal_handler_add()");
569 if (e_dbus_request_name(ugd->dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
570 debug_critical("Failed to e_dbus_request_name()");
573 if (ugd->signal_handler_network != NULL) {
574 debug_log("_g_setting_signal_handler_network != NULL");
576 ugd->signal_handler_network = e_dbus_signal_handler_add(ugd->dbus_conn, NULL,
577 "/User/Email/NetworkStatus",
578 "User.Email.NetworkStatus", "email",
579 setting_edbus_event_receive,
580 (struct ug_data *)ugd);
582 if (ugd->signal_handler_network == NULL) {
583 debug_critical("Failed to e_dbus_signal_handler_add()");
589 static void _remove_dbus_receiver(struct ug_data *ugd)
594 debug_log("ugd == NULL");
598 if (ugd->signal_handler_storage != NULL) {
599 e_dbus_signal_handler_del(ugd->dbus_conn, ugd->signal_handler_storage);
600 ugd->signal_handler_storage = NULL;
603 if (ugd->signal_handler_network != NULL) {
604 e_dbus_signal_handler_del(ugd->dbus_conn, ugd->signal_handler_network);
605 ugd->signal_handler_network = NULL;
608 if (e_dbus_release_name(ugd->dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
609 debug_critical("e_dbus_release_name to failed");
612 if (e_dbus_release_name(ugd->dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
613 debug_critical("e_dbus_release_name to failed");
616 if (ugd->dbus_conn != NULL) {
617 /*e_dbus_connection_close(ugd->dbus_conn);*/
618 ugd->dbus_conn = NULL;
622 static int _account_init(struct ug_data *ugd)
627 /* Get Email Account List Info */
628 ugd->account_list = NULL;
629 if (!email_engine_get_account_list(&ugd->account_count, &ugd->account_list)) {
633 for (i = 0; i < ugd->account_count; i++) {
634 debug_log("*************Sending Option Details*************");
635 debug_log("Acct Id : %d", ugd->account_list[i].account_id);
636 debug_log("Email Addr : %s", ugd->account_list[i].user_email_address);
637 debug_log("1.Priority : %d", ugd->account_list[i].options.priority);
638 debug_log("2.Keep a copy : %d", ugd->account_list[i].options.keep_local_copy);
639 debug_log("3.Reply with body : %d", ugd->account_list[i].options.reply_with_body);
640 debug_log("4.Forward with files : %d", ugd->account_list[i].options.forward_with_files);
641 debug_log("5.Get read report : %d", ugd->account_list[i].options.req_read_receipt);
642 debug_log("6.Get delivery report: %d", ugd->account_list[i].options.req_delivery_receipt);
643 debug_log("7.Add my namecard : %d", ugd->account_list[i].options.add_myname_card);
644 debug_log("8.Add signature : %d", ugd->account_list[i].options.add_signature);
650 static int _account_finalize(EmailSettingUGD *ugd)
655 /* Free Account List Info */
656 if (ugd->account_list != NULL) {
657 r = email_engine_free_account_list(&(ugd->account_list), ugd->account_count);
658 retv_if(r == FALSE, -1);
660 ugd->account_list = NULL;
665 static int _parse_option(service_h service, struct ug_data *ugd)
670 debug_log("service is NULL");
675 char *operation = NULL;
676 ret = service_get_operation(service, &operation);
677 debug_log("service_get_operation: %d", ret);
678 debug_log("operation = %s", operation);
682 if (g_strcmp0(operation, ACCOUNT_OPERATION_SIGNIN) == 0) {
683 char *email_sp = NULL;
684 debug_log("Operation ACCOUNT_OPERATION_SIGNIN");
685 service_get_extra_data(service, /*ACCOUNT_DATA_SERVICE_PROVIDER*/ "http://tizen.org/account/data/service_provider", &email_sp);
690 debug_log("SP:%s", email_sp);
692 if (ugd->start_view_type)
693 g_free(ugd->start_view_type);
695 ugd->start_view_type = g_strdup(EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD);
697 EmailSpDesc *desc = NULL;
698 if (g_strcmp0(email_sp, "gmail") == 0)
699 desc = setting_find_sp_desc("Gmail", ugd);
700 else if (g_strcmp0(email_sp, "msn") == 0)
701 desc = setting_find_sp_desc("Hotmail", ugd);
706 ugd->account_info = desc;
708 ugd->account_info = NULL;
713 } else if (g_strcmp0(operation, ACCOUNT_OPERATION_VIEW) == 0) {
714 char *account_id = NULL;
715 char *username = NULL;
716 debug_log("Operation ACCOUNT_OPERATION_VIEW");
718 service_get_extra_data(service, ACCOUNT_DATA_ID, &account_id);
719 service_get_extra_data(service, ACCOUNT_DATA_USERNAME, &username);
725 int my_account_id = 0;
726 my_account_id = atoi(account_id);
728 debug_log("MY_ACCOUNT_ID:%d", my_account_id);
730 if (ugd->start_view_type)
731 g_free(ugd->start_view_type);
733 ugd->start_view_type = g_strdup(EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT);
737 if (ugd->account_list == NULL || ugd->account_count == 0) {
738 debug_critical("account info is @niL");
739 Evas_Object *popup = elm_popup_add(ugd->layout_main);
740 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
741 elm_object_part_text_set(popup, "title,text", EMAIL_SETTING_STRING_WARNING);
742 elm_object_text_set(popup, EMAIL_SETTING_STRING_ACCOUNT_LIST_NOT_FOUND);
744 Evas_Object *btn1 = elm_button_add(popup);
745 elm_object_style_set(btn1, "popup_button/default");
746 elm_object_text_set(btn1, EMAIL_SETTING_STRING_OK);
747 elm_object_part_content_set(popup, "button1", btn1);
748 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
749 evas_object_show(popup);
753 for (i = 0; i < ugd->account_count; i++) {
754 if (ugd->account_list[i].account_svc_id == my_account_id) {
755 ugd->account_id = ugd->account_list[i].account_id;
756 debug_log("ACCOUNT_ID:%d", ugd->account_id);
765 service_get_extra_data(service, EMAIL_BUNDLE_KEY_VIEW_TYPE, &(ugd->start_view_type));
766 debug_log("VIEW TYPE:%s", ugd->start_view_type);
768 if (strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT) == 0) {
769 /* account edit view */
771 int my_account_id = 0;
772 service_get_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, &str);
773 my_account_id = atoi(str);
775 debug_log("MY_ACCOUNT_ID:%d", my_account_id);
779 if (ugd->account_list == NULL || ugd->account_count == 0) {
780 debug_critical("account info is @niL");
781 Evas_Object *popup = elm_popup_add(ugd->layout_main);
782 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
783 elm_object_part_text_set(popup, "title,text", EMAIL_SETTING_STRING_WARNING);
784 elm_object_text_set(popup, EMAIL_SETTING_STRING_ACCOUNT_LIST_NOT_FOUND);
786 Evas_Object *btn1 = elm_button_add(popup);
787 elm_object_style_set(btn1, "popup_button/default");
788 elm_object_text_set(btn1, EMAIL_SETTING_STRING_OK);
789 elm_object_part_content_set(popup, "button1", btn1);
790 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
791 evas_object_show(popup);
795 for (i = 0; i < ugd->account_count; i++) {
796 if (ugd->account_list[i].account_svc_id == my_account_id) {
797 ugd->account_id = ugd->account_list[i].account_id;
798 debug_log("ACCOUNT_ID:%d", ugd->account_id);
801 } else if (strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD) == 0) {
802 /* account add view */
803 char *account_name = NULL;
804 service_get_extra_data(service, EMAIL_BUNDLE_KEY_ESP_NAME, &account_name);
805 debug_log("Account name:%s", account_name);
807 EmailSpDesc *desc = NULL;
808 if (g_strcmp0(account_name, "gmail") == 0)
809 desc = setting_find_sp_desc("Gmail", ugd);
810 else if (g_strcmp0(account_name, "msn") == 0)
811 desc = setting_find_sp_desc("Hotmail", ugd);
816 ugd->account_info = desc;
818 ugd->account_info = NULL;
820 g_free(account_name);
827 static void _dispatch_view(struct ug_data *ugd)
831 if (ugd->start_view_type) {
832 if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_SETTING_MAIN)) {
833 debug_log("Setting mail is up");
834 setting_change_view(VIEW_SETTING, ugd);
835 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_FIRST_SETUP)) {
836 debug_log("Setup wizard is up");
837 ugd->account_info = NULL;
838 setting_change_view(VIEW_ACCOUNT_SETUP, ugd);
839 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT)) {
840 debug_log("Edit view is up");
841 setting_change_view(VIEW_SYNC_SCHEDULE, ugd);
842 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD)) {
843 if(ugd->account_count >= MAX_ACCOUNT_COUNT) {
844 _create_max_account_popup_create(ugd);
846 debug_log("Add view is up");
847 setting_change_view(VIEW_ACCOUNT_SETUP, ugd);
849 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_SELECT_ACCOUNT)) {
850 debug_log("select account view is up");
851 ugd->account_info = NULL;
852 setting_change_view(VIEW_ACCOUNT_SETUP, ugd);
854 setting_change_view(VIEW_SETTING, ugd);
857 debug_log("No service value!");
858 setting_change_view(VIEW_SETTING, ugd);
863 static void _create_navigationbar(struct ug_data *ugd)
866 ugd->navi_bar = elm_naviframe_add(ugd->layout_main);
868 elm_object_part_content_set(ugd->layout_main, "elm.swallow.content", ugd->navi_bar);
869 evas_object_show(ugd->navi_bar);
872 static Evas_Object *_create_layout(Evas_Object *parent, struct ug_data *ugd)
877 ugd->bg = elm_bg_add(ugd->win);
878 evas_object_size_hint_weight_set(ugd->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
879 elm_win_resize_object_add(ugd->win, ugd->bg);
880 /*elm_object_theme_set(ugd->bg, ugd->theme);*/
881 evas_object_show(ugd->bg);
883 base = elm_layout_add(parent);
885 debug_log("base == NULL");
889 elm_layout_theme_set(base, "layout", "application", "default");
890 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
891 evas_object_show(base);
893 elm_object_style_set(ugd->bg, "group_list");
894 elm_object_part_content_set(base, "elm.swallow.bg", ugd->bg);
899 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event)
903 debug_log("data is NULL");
907 EmailSettingUGD *ugd = (EmailSettingUGD *)data;
909 const char *profile = elm_config_profile_get();
910 if (!g_strcmp0(profile, "desktop"))
911 elm_layout_theme_set(ugd->layout_main, "layout", "application", "noindicator");
913 elm_layout_theme_set(ugd->layout_main, "layout", "application", "default");
915 evas_object_size_hint_weight_set(ugd->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
916 evas_object_show(ugd->layout_main);
919 static void _layout_block_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
922 EmailSettingUGD *ugd;
928 ugd = (EmailSettingUGD *)priv;
930 base = ug_get_layout(ug);
935 case UG_MODE_FULLVIEW:
936 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
937 evas_object_show(base);
944 static void _result_block_cb(ui_gadget_h ug, service_h service, void *priv)
947 EmailSettingUGD *ugd;
952 ugd = (EmailSettingUGD *)priv;
957 static void _destroy_block_cb(ui_gadget_h ug, void *priv)
960 EmailSettingUGD *ugd;
965 ugd = (EmailSettingUGD *)priv;
967 if (ug == ugd->ug_block) {
968 ug_destroy(ugd->ug_block);
969 ugd->ug_block = NULL;
975 static void _popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
980 debug_log("data is NULL");
985 evas_object_del(obj);
987 EmailSettingUGD *ugd = (EmailSettingUGD *)data;
988 ug_destroy_me(ugd->ug);
991 static void _create_max_account_popup_create(EmailSettingUGD *ugd)
994 Evas_Object *popup = elm_popup_add(ugd->win);
995 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
996 elm_object_text_set(popup, EMAIL_SETTING_STRING_ACCOUNT_NUM_MAX);
997 ugd->popup_one = popup; //Use ugd->popup_one member
999 Evas_Object *btn1 = elm_button_add(popup);
1000 elm_object_text_set(btn1, EMAIL_SETTING_STRING_OK);
1001 elm_object_part_content_set(popup, "button1", btn1);
1002 evas_object_smart_callback_add(btn1, "clicked", _max_account_popup_ok_cb, ugd);
1003 evas_object_show(popup);
1007 static void _max_account_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
1012 debug_log("data is NULL");
1015 EmailSettingUGD *ugd = (EmailSettingUGD *)data;
1017 if (ugd->popup_one) {
1018 evas_object_del(ugd->popup_one);
1019 ugd->popup_one = NULL;
1022 ug_destroy_me(ugd->ug);
1026 static void _language_changed_cb(EmailSettingUGD *ugd)
1029 struct viewdata *vd = NULL;
1033 if (ugd->view_top < 0) {
1034 debug_log("View stack is empty..");
1038 for (count = ugd->view_top; count >= 0; count--) {
1039 cur_view = ugd->view_st[count];
1040 vd = ugd->vd[cur_view];
1041 debug_log("language change: %s", vd->grp_nm);
1042 if (vd->lang_change)
1043 vd->lang_change(vd);