email_0.0.13 package upload
[apps/core/preloaded/email.git] / setting / src / email-setting.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *    http://www.tizenopensource.org/license
9  *
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.
15  */
16
17 #ifndef UG_MODULE_API
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
19 #endif
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <getopt.h>
24 #include <utilX.h>
25
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"
39
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);
48
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
60 static void _layout_block_cb(ui_gadget_h ug, enum ug_mode mode, void *priv);
61 static void _result_block_cb(ui_gadget_h ug, service_h service, void *priv);
62 static void _destroy_block_cb(ui_gadget_h ug, void *priv);
63
64 static void _popup_ok_cb(void *data, Evas_Object *obj, void *event_info);
65
66
67 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
68 {
69         debug_log("");
70         struct ug_data *ugd;
71         if (!ops)
72                 return -1;
73
74         ugd = calloc(1, sizeof(struct ug_data));
75         if (!ugd)
76                 return -1;
77
78         ops->create = on_create;
79         ops->start = on_start;
80         ops->pause = on_pause;
81         ops->resume = on_resume;
82         ops->destroy = on_destroy;
83         ops->message = on_message;
84         ops->event = on_event;
85         ops->key_event = on_key_event;
86         ops->priv = ugd;
87         ops->opt = UG_OPT_INDICATOR_ENABLE;
88
89         return 0;
90 }
91
92 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
93 {
94         debug_log("");
95         struct ug_data *ugd;
96
97         if (!ops)
98                 return;
99
100         ugd = ops->priv;
101         if (ugd)
102                 free(ugd);
103 }
104
105 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
106 {
107         return 0;
108 }
109
110 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
111 {
112         debug_log("");
113         Evas_Object *parent;
114         struct ug_data *ugd;
115
116         if (!ug || !priv)
117                 return NULL;
118
119         ugd = priv;
120         ugd->ug = ug;
121
122         parent = ug_get_window();
123         if (!parent)
124                 return NULL;
125
126         ugd->win = parent;
127         ugd->evas = evas_object_evas_get(ugd->win);
128
129         bindtextdomain(PACKAGE, LOCALEDIR);
130
131         ugd->block_cbs.layout_cb = _layout_block_cb;
132         ugd->block_cbs.result_cb = _result_block_cb;
133         ugd->block_cbs.destroy_cb = _destroy_block_cb;
134         ugd->block_cbs.priv = (void *)ugd;
135
136         /* Init Setting View Data */
137         _init_data(ugd);
138
139         /* DBUS */
140         _dbus_receiver_setup(ugd);
141
142         /* theme extension */
143         ugd->theme = elm_theme_new();
144         elm_theme_ref_set(ugd->theme, NULL);
145         /*elm_theme_extension_add(ugd->theme, EV_BLOCK_THEME_PATH); //Use block theme*/
146
147         ugd->layout_main = _create_layout(parent, ugd);
148         _create_navigationbar(ugd);
149         ugd->base = ugd->layout_main;
150         elm_win_indicator_mode_set(ugd->win, ELM_WIN_INDICATOR_SHOW);
151
152         return ugd->layout_main;
153 }
154
155 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
156 {
157         debug_log("");
158         switch (event) {
159         case UG_EVENT_LOW_MEMORY:
160                 break;
161         case UG_EVENT_LOW_BATTERY:
162                 break;
163         case UG_EVENT_LANG_CHANGE:
164                 break;
165         case UG_EVENT_ROTATE_PORTRAIT:
166                 break;
167         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
168                 break;
169         case UG_EVENT_ROTATE_LANDSCAPE:
170                 break;
171         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
172                 break;
173         case UG_EVENT_REGION_CHANGE:
174                 break;
175         default:
176                 break;
177         }
178         return;
179 }
180
181 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
182 {
183         debug_log("");
184
185         if (!ug || !priv)
186                 return;
187
188         EmailSettingUGD *ugd;
189         ugd = priv;
190
191         switch (event) {
192         case UG_KEY_EVENT_END:
193                 ugd->end_key_event = 1;
194
195                 if (elm_naviframe_top_item_get(ugd->navi_bar) == elm_naviframe_bottom_item_get(ugd->navi_bar)) {
196                         if (ugd->popup_one != NULL || ugd->popup_validate != NULL) {
197                                 if (ugd->popup_one) {
198                                         evas_object_del(ugd->popup_one);
199                                         ugd->popup_one = NULL;
200                                 }
201
202                                 if (ugd->popup_validate) {
203                                         evas_object_del(ugd->popup_validate);
204                                         ugd->popup_validate = NULL;
205
206                                         ugd->cancel_event = 1;
207                                         email_engine_stop_working(ugd->account_id, ugd->handle);
208                                 }
209                         } else {
210                                 ug_destroy_me(ug);
211                         }
212                 } else {
213                         if (ugd->popup_one != NULL || ugd->popup_validate != NULL) {
214                                 if (ugd->popup_one) {
215                                         evas_object_del(ugd->popup_one);
216                                         ugd->popup_one = NULL;
217                                 }
218
219                                 if (ugd->popup_validate) {
220                                         evas_object_del(ugd->popup_validate);
221                                         ugd->popup_validate = NULL;
222
223                                         ugd->cancel_event = 1;
224                                         email_engine_stop_working(ugd->account_id, ugd->handle);
225                                 }
226                         } else {
227                                 if (ugd->change_view_ing == 0)
228                                         setting_change_view(VIEW_BACK, ugd);
229                         }
230                 }
231                 break;
232
233         default:
234                 break;
235         }
236 }
237
238 static void on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
239 {
240         debug_log("");
241         return;
242 }
243
244 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
245 {
246         debug_log("");
247         EmailSettingUGD *ugd;
248         struct viewdata *vd = NULL;
249         int i, r = 0;
250
251         if (!ug || !priv)
252                 return;
253
254         ugd = priv;
255         evas_object_del(ugd->base);
256         ugd->base = NULL;
257
258         if (ugd->popup_one) {
259                 evas_object_del(ugd->popup_one);
260                 ugd->popup_one = NULL;
261         }
262
263         if (ugd->popup_validate) {
264                 evas_object_del(ugd->popup_validate);
265                 ugd->popup_validate = NULL;
266         }
267
268         if (ugd->password_timer) {
269                 ecore_timer_del(ugd->password_timer);
270                 ugd->password_timer = NULL;
271         }
272
273         if (ugd->focus_timer) {
274                 ecore_timer_del(ugd->focus_timer);
275                 ugd->focus_timer = NULL;
276         }
277
278         if (ugd->preset_vc_timer) {
279                 ecore_timer_del(ugd->preset_vc_timer);
280                 ugd->preset_vc_timer = NULL;
281         }
282
283         if (ugd->other_vc_timer) {
284                 ecore_timer_del(ugd->other_vc_timer);
285                 ugd->other_vc_timer = NULL;
286         }
287
288         if (ugd->edit_vc_timer) {
289                 ecore_timer_del(ugd->edit_vc_timer);
290                 ugd->edit_vc_timer = NULL;
291         }
292
293         if (ugd->del_timer) {
294                 ecore_timer_del(ugd->del_timer);
295                 ugd->del_timer = NULL;
296         }
297
298         setting_free_sp_desc(ugd);
299
300         /* theme extension */
301         /*elm_theme_extension_del(ugd->theme, EV_BLOCK_THEME_PATH);*/
302         elm_theme_free(ugd->theme);
303
304         /* Free Viewdata's memory */
305         for (i = VIEW_SETTING; i < VIEW_END; i++) {
306                 vd = ugd->vd[i];
307                 if (vd != NULL) {
308                         debug_log("Memory Free");
309                         free(vd);
310                 }
311         }
312
313         email_engine_finalize();
314         r = _account_finalize(ugd);
315         _remove_dbus_receiver(ugd);
316 }
317
318 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
319 {
320         debug_log("");
321
322         struct ug_data *ugd;
323
324         if (!ug || !priv)
325                 return;
326
327         ugd = priv;
328
329         ugd->b_on_pause = 0;
330
331         return;
332 }
333
334 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
335 {
336         debug_log("");
337
338         struct ug_data *ugd;
339
340         if (!ug || !priv)
341                 return;
342
343         ugd = priv;
344
345         ugd->b_on_pause = 1;
346
347         return;
348 }
349
350 static void on_start(ui_gadget_h ug, service_h service, void *priv)
351 {
352         debug_log("");
353         struct ug_data *ugd;
354
355         if (!ug || !priv)
356                 return;
357
358         ugd = priv;
359
360         /* Init Email Service */
361         if (!email_engine_initialize()) {
362                 Evas_Object *popup = elm_popup_add(ugd->layout_main);
363                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
364                 elm_object_part_text_set(popup, "title,text", dgettext("sys_string", "IDS_COM_POP_WARNING"));
365                 elm_object_text_set(popup, _("IDS_EMAIL_POP_FAILED_TO_START_EMAIL_APPLICATION"));
366
367                 Evas_Object *btn1 = elm_button_add(popup);
368                 elm_object_style_set(btn1, "popup_button/default");
369                 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_OK"));
370                 elm_object_part_content_set(popup, "button1", btn1);
371                 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
372                 evas_object_show(popup);
373                 return;
374         }
375
376         /* Init Emf Account */
377         if (!_account_init(ugd)) {
378                 debug_log("Failed to get account list");
379         }
380
381         /* create xml tree */
382         setting_free_sp_desc(ugd);
383
384         xmlDocPtr xml_source = setting_create_xml_tree(SP_XML_PATH);
385         if(!xml_source) {
386                 Evas_Object *popup = elm_popup_add(ugd->layout_main);
387                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
388                 elm_object_part_text_set(popup, "title,text", dgettext("sys_string", "IDS_COM_POP_WARNING"));
389                 elm_object_text_set(popup, N_("Failed to parse resource XML"));
390
391                 Evas_Object *btn1 = elm_button_add(popup);
392                 elm_object_style_set(btn1, "popup_button/default");
393                 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_OK"));
394                 elm_object_part_content_set(popup, "button1", btn1);
395                 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
396                 evas_object_show(popup);
397                 return;
398         }
399         ugd->xml_source = xml_source;
400
401         /* traverse xml tree */
402         xmlNode *root;
403         root= xmlDocGetRootElement(xml_source);
404         int sp_count = xmlChildElementCount(root);
405         ugd->sp_list_len = sp_count;
406         debug_log("Count of SP list:%d", sp_count);
407         if (sp_count > 0) {
408                 ugd->sp_list = (EmailSpDesc *)calloc(sp_count, sizeof(EmailSpDesc));
409                 setting_traverse_xml_node(root, 0, (void *)ugd, 1);
410                 setting_dump_sp_desc(ugd);
411         }
412         setting_cleanup_xml_parser(xml_source);
413
414         if (!_parse_option(service, ugd)) {
415                 return;
416         }
417
418         _dispatch_view(ugd);
419
420         return;
421 }
422
423 static void _init_data(struct ug_data *ugd)
424 {
425         debug_log("");
426         struct viewdata *view_setting = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
427         struct viewdata *view_sp_select = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
428         struct viewdata *view_account_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
429         struct viewdata *view_manual_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
430         struct viewdata *view_account_edit = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
431         struct viewdata *view_mailbox_mapping = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
432         struct viewdata *view_account_options = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
433         struct viewdata *view_initial_access = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
434         struct viewdata *view_sync_schedule = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
435         struct viewdata *view_sync_setup = (struct viewdata *)calloc(sizeof(struct viewdata), 1);
436
437         setting_init_setting_view(view_setting);
438         setting_init_sp_select_view(view_sp_select);
439         setting_init_account_setup_view(view_account_setup);
440         setting_init_manual_setup_view(view_manual_setup);
441         setting_init_account_edit_view(view_account_edit);
442         setting_init_mailbox_mapping_view(view_mailbox_mapping);
443         setting_init_account_options_view(view_account_options);
444         setting_init_initial_access_view(view_initial_access);
445         setting_init_sync_schedule_view(view_sync_schedule);
446         setting_init_sync_setup_view(view_sync_setup);
447
448         ugd->view_top = -1;
449
450         _couple_data(ugd, VIEW_SETTING, view_setting);
451         _couple_data(ugd, VIEW_SP_SELECT, view_sp_select);
452         _couple_data(ugd, VIEW_ACCOUNT_SETUP, view_account_setup);
453         _couple_data(ugd, VIEW_MANUAL_SETUP, view_manual_setup);
454         _couple_data(ugd, VIEW_ACCOUNT_EDIT, view_account_edit);
455         _couple_data(ugd, VIEW_MAILBOX_MAPPING, view_mailbox_mapping);
456         _couple_data(ugd, VIEW_ACCOUNT_OPTIONS, view_account_options);
457         _couple_data(ugd, VIEW_INITIAL_ACCESS, view_initial_access);
458         _couple_data(ugd, VIEW_SYNC_SCHEDULE, view_sync_schedule);
459         _couple_data(ugd, VIEW_SYNC_SETUP, view_sync_setup);
460
461         /* add more views... */
462 }
463
464 static void _couple_data(struct ug_data *ugd, Viewtype t, struct viewdata *vd)
465 {
466         debug_log("");
467         debug_log("View type number%d", t);
468         ugd->vd[t] = vd;
469         vd->ugd = ugd;
470 }
471
472 static void _dbus_receiver_setup(struct ug_data *ugd)
473 {
474         debug_log("");
475
476         if (!ugd) {
477                 debug_log("ugd == NULL");
478                 return;
479         }
480
481         int ret = e_dbus_init();
482         debug_log("ret: %d", ret);
483
484         DBusError derror;
485
486         if (ugd->dbus_conn == NULL) {
487                 debug_log("");
488                 dbus_error_init(&derror);
489                 ugd->dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
490
491                 if (ugd->dbus_conn == NULL) {
492                         debug_log("e_dbus_bus_get return NULL");
493                 }
494
495                 /* storage */
496                 if (e_dbus_request_name(ugd->dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
497                         debug_critical("Failed to e_dbus_request_name()");
498                         return;
499                 }
500
501                 if (ugd->signal_handler_storage != NULL) {
502                         debug_log("_g_setting_signal_handler_storage != NULL");
503                 }
504
505                 ugd->signal_handler_storage = e_dbus_signal_handler_add(ugd->dbus_conn, NULL,
506                                                                         "/User/Email/StorageChange",
507                                                                         "User.Email.StorageChange", "email",
508                                                                         setting_edbus_event_receive,
509                                                                         (struct ug_data *)ugd);
510
511                 if (ugd->signal_handler_storage == NULL) {
512                         debug_log("Failed to e_dbus_signal_handler_add()");
513                         return;
514                 }
515
516                 /* network */
517                 if (e_dbus_request_name(ugd->dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
518                         debug_critical("Failed to e_dbus_request_name()");
519                         return;
520                 }
521                 if (ugd->signal_handler_network != NULL) {
522                         debug_log("_g_setting_signal_handler_network != NULL");
523                 }
524                 ugd->signal_handler_network = e_dbus_signal_handler_add(ugd->dbus_conn, NULL,
525                                                                         "/User/Email/NetworkStatus",
526                                                                         "User.Email.NetworkStatus", "email",
527                                                                         setting_edbus_event_receive,
528                                                                         (struct ug_data *)ugd);
529
530                 if (ugd->signal_handler_network == NULL) {
531                         debug_critical("Failed to e_dbus_signal_handler_add()");
532                         return;
533                 }
534         }
535 }
536
537 static void _remove_dbus_receiver(struct ug_data *ugd)
538 {
539         debug_log("");
540
541         if (!ugd) {
542                 debug_log("ugd == NULL");
543                 return;
544         }
545
546         if (ugd->signal_handler_storage != NULL) {
547                 e_dbus_signal_handler_del(ugd->dbus_conn, ugd->signal_handler_storage);
548                 ugd->signal_handler_storage = NULL;
549         }
550
551         if (ugd->signal_handler_network != NULL) {
552                 e_dbus_signal_handler_del(ugd->dbus_conn, ugd->signal_handler_network);
553                 ugd->signal_handler_network = NULL;
554         }
555
556         if (e_dbus_release_name(ugd->dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
557                 debug_critical("e_dbus_release_name to failed");
558         }
559
560         if (e_dbus_release_name(ugd->dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
561                 debug_critical("e_dbus_release_name to failed");
562         }
563
564         if (ugd->dbus_conn != NULL) {
565                 /*e_dbus_connection_close(ugd->dbus_conn);*/
566                 ugd->dbus_conn = NULL;
567         }
568 }
569
570 static int _account_init(struct ug_data *ugd)
571 {
572         debug_log("");
573         int i = 0;
574
575         /* Get Email Account List Info */
576         ugd->account_list = NULL;
577         if (!email_engine_get_account_list(&ugd->account_count, &ugd->account_list)) {
578                 return FALSE;
579         }
580
581         for (i = 0; i < ugd->account_count; i++) {
582                 debug_log("*************Sending Option Details*************");
583                 debug_log("Acct Id                              : %d", ugd->account_list[i].account_id);
584                 debug_log("Email Addr                   : %s", ugd->account_list[i].user_email_address);
585                 debug_log("1.Priority                   : %d", ugd->account_list[i].options.priority);
586                 debug_log("2.Keep a copy                : %d", ugd->account_list[i].options.keep_local_copy);
587                 debug_log("3.Reply with body    : %d", ugd->account_list[i].options.reply_with_body);
588                 debug_log("4.Forward with files : %d", ugd->account_list[i].options.forward_with_files);
589                 debug_log("5.Get read report    : %d", ugd->account_list[i].options.req_read_receipt);
590                 debug_log("6.Get delivery report: %d", ugd->account_list[i].options.req_delivery_receipt);
591                 debug_log("7.Add my namecard    : %d", ugd->account_list[i].options.add_myname_card);
592                 debug_log("8.Add signature              : %d", ugd->account_list[i].options.add_signature);
593         }
594
595         return TRUE;
596 }
597
598 static int _account_finalize(EmailSettingUGD *ugd)
599 {
600         debug_log("");
601         int r;
602
603         /* Free Account List Info */
604         if (ugd->account_list != NULL) {
605                 r = email_engine_free_account_list(&(ugd->account_list), ugd->account_count);
606                 retv_if(r == FALSE, -1);
607         }
608         ugd->account_list = NULL;
609
610         return TRUE;
611 }
612
613 static int _parse_option(service_h service, struct ug_data *ugd)
614 {
615         debug_log("");
616
617         if (!service) {
618                 debug_log("service is NULL");
619                 return FALSE;
620         }
621
622         int ret;
623         char *operation = NULL;
624         ret = service_get_operation(service, &operation);
625         debug_log("service_get_operation: %d", ret);
626         debug_log("operation = %s", operation);
627
628         if (operation) {
629 #if 0
630                 if (g_strcmp0(operation, ACCOUNT_OPERATION_SIGNIN) == 0) {
631                         char *email_sp = NULL;
632                         debug_log("Operation ACCOUNT_OPERATION_SIGNIN");
633                         service_get_extra_data(service, /*ACCOUNT_DATA_SERVICE_PROVIDER*/ "http://tizen.org/account/data/service_provider", &email_sp);
634
635                         if (!email_sp) {
636                                 return FALSE;
637                         }
638                         debug_log("SP:%s", email_sp);
639
640                         if (ugd->start_view_type)
641                                 g_free(ugd->start_view_type);
642
643                         ugd->start_view_type = g_strdup(EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD);
644
645                         EmailSpDesc *desc = NULL;
646                         if (g_strcmp0(email_sp, "gmail") == 0)
647                                 desc = setting_find_sp_desc("Gmail", ugd);
648                         else if (g_strcmp0(email_sp, "msn") == 0)
649                                 desc = setting_find_sp_desc("Hotmail", ugd);
650                         else
651                                 desc = NULL;
652
653                         if (desc)
654                                 ugd->account_info = desc;
655                         else
656                                 ugd->account_info = NULL;
657
658                         g_free(email_sp);
659                         return TRUE;
660
661                 } else if (g_strcmp0(operation, ACCOUNT_OPERATION_VIEW) == 0) {
662                         char *account_id = NULL;
663                         char *username = NULL;
664                         debug_log("Operation ACCOUNT_OPERATION_VIEW");
665
666                         service_get_extra_data(service, ACCOUNT_DATA_ID, &account_id);
667                         service_get_extra_data(service, ACCOUNT_DATA_USERNAME, &username);
668
669                         if (!account_id) {
670                                 return FALSE;
671                         }
672
673                         int my_account_id = 0;
674                         my_account_id = atoi(account_id);
675                         g_free(account_id);
676                         debug_log("MY_ACCOUNT_ID:%d", my_account_id);
677
678                         if (ugd->start_view_type)
679                                 g_free(ugd->start_view_type);
680
681                         ugd->start_view_type = g_strdup(EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT);
682
683                         int i = 0;
684
685                         if (ugd->account_list == NULL || ugd->account_count == 0) {
686                                 debug_critical("account info is @niL");
687                                 Evas_Object *popup = elm_popup_add(ugd->layout_main);
688                                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
689                                 elm_object_part_text_set(popup, "title,text", dgettext("sys_string", "IDS_COM_POP_WARNING"));
690                                 elm_object_text_set(popup, _("IDS_EMAIL_POP_ACCOUNT_LIST_NOT_FOUND"));
691
692                                 Evas_Object *btn1 = elm_button_add(popup);
693                                 elm_object_style_set(btn1, "popup_button/default");
694                                 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_OK"));
695                                 elm_object_part_content_set(popup, "button1", btn1);
696                                 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
697                                 evas_object_show(popup);
698                                 return FALSE;
699                         }
700
701                         for (i = 0; i < ugd->account_count; i++) {
702                                 if (ugd->account_list[i].account_svc_id == my_account_id) {
703                                         ugd->account_id = ugd->account_list[i].account_id;
704                                         debug_log("ACCOUNT_ID:%d", ugd->account_id);
705                                 }
706                         }
707
708                         return TRUE;
709
710                 }
711 #endif
712         } else {
713                 service_get_extra_data(service, EMAIL_BUNDLE_KEY_VIEW_TYPE, &(ugd->start_view_type));
714                 debug_log("VIEW TYPE:%s", ugd->start_view_type);
715
716                 if (strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT) == 0) {
717                         /* account edit view */
718                         char *str = NULL;
719                         int my_account_id = 0;
720                         service_get_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, &str);
721                         my_account_id = atoi(str);
722                         g_free(str);
723                         debug_log("MY_ACCOUNT_ID:%d", my_account_id);
724
725                         int i = 0;
726
727                         if (ugd->account_list == NULL || ugd->account_count == 0) {
728                                 debug_critical("account info is @niL");
729                                 Evas_Object *popup = elm_popup_add(ugd->layout_main);
730                                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
731                                 elm_object_part_text_set(popup, "title,text", dgettext("sys_string", "IDS_COM_POP_WARNING"));
732                                 elm_object_text_set(popup, _("IDS_EMAIL_POP_ACCOUNT_LIST_NOT_FOUND"));
733
734                                 Evas_Object *btn1 = elm_button_add(popup);
735                                 elm_object_style_set(btn1, "popup_button/default");
736                                 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_OK"));
737                                 elm_object_part_content_set(popup, "button1", btn1);
738                                 evas_object_smart_callback_add(btn1, "clicked", _popup_ok_cb, ugd);
739                                 evas_object_show(popup);
740                                 return FALSE;
741                         }
742
743                         for (i = 0; i < ugd->account_count; i++) {
744                                 if (ugd->account_list[i].account_svc_id == my_account_id) {
745                                         ugd->account_id = ugd->account_list[i].account_id;
746                                         debug_log("ACCOUNT_ID:%d", ugd->account_id);
747                                 }
748                         }
749                 } else if (strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD) == 0) {
750                         /* account add view */
751                         char *account_name = NULL;
752                         service_get_extra_data(service, EMAIL_BUNDLE_KEY_ESP_NAME, &account_name);
753                         debug_log("Account name:%s", account_name);
754
755                         EmailSpDesc *desc = NULL;
756                         if (g_strcmp0(account_name, "gmail") == 0)
757                                 desc = setting_find_sp_desc("Gmail", ugd);
758                         else if (g_strcmp0(account_name, "msn") == 0)
759                                 desc = setting_find_sp_desc("Hotmail", ugd);
760                         else
761                                 desc = NULL;
762
763                         if (desc)
764                                 ugd->account_info = desc;
765                         else
766                                 ugd->account_info = NULL;
767
768                         g_free(account_name);
769                 }
770         }
771
772         return TRUE;
773 }
774
775 static void _dispatch_view(struct ug_data *ugd)
776 {
777         debug_log("");
778
779         if (ugd->start_view_type) {
780                 if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_SETTING_MAIN)) {
781                         debug_log("Setting mail is up");
782                         setting_change_view(VIEW_SETTING, ugd);
783                 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_FIRST_SETUP)) {
784                         debug_log("Setup wizard is up");
785                         setting_change_view(VIEW_INITIAL_ACCESS, ugd);
786                 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_EDIT)) {
787                         debug_log("Edit view is up");
788                         setting_change_view(VIEW_SYNC_SCHEDULE, ugd);
789                 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_ACCOUNT_ADD)) {
790                         debug_log("Add view is up");
791                         setting_change_view(VIEW_ACCOUNT_SETUP, ugd);
792                 } else if (!strcmp(ugd->start_view_type, EMAIL_BUNDLE_VAL_VIEW_SELECT_ACCOUNT)) {
793                         debug_log("select account view is up");
794                         setting_change_view(VIEW_SP_SELECT, ugd);
795                 } else {
796                         setting_change_view(VIEW_SETTING, ugd);
797                 }
798         } else {
799                 debug_log("No service value!");
800                 setting_change_view(VIEW_SETTING, ugd);
801         }
802         return;
803 }
804
805 static void _create_navigationbar(struct ug_data *ugd)
806 {
807         debug_log("");
808         ugd->navi_bar = elm_naviframe_add(ugd->layout_main);
809
810         elm_object_part_content_set(ugd->layout_main, "elm.swallow.content", ugd->navi_bar);
811         evas_object_show(ugd->navi_bar);
812 }
813
814 static Evas_Object *_create_layout(Evas_Object *parent, struct ug_data *ugd)
815 {
816         debug_log("");
817         Evas_Object *base;
818
819         ugd->bg = elm_bg_add(ugd->win);
820         evas_object_size_hint_weight_set(ugd->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
821         elm_win_resize_object_add(ugd->win, ugd->bg);
822         /*elm_object_theme_set(ugd->bg, ugd->theme);*/
823         evas_object_show(ugd->bg);
824
825         base = elm_layout_add(parent);
826         if (base == NULL) {
827                 debug_log("base == NULL");
828                 return NULL;
829         }
830
831         elm_layout_theme_set(base, "layout", "application", "default");
832         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
833         evas_object_show(base);
834
835         elm_object_style_set(ugd->bg, "group_list");
836         elm_object_part_content_set(base, "elm.swallow.bg", ugd->bg);
837
838         return base;
839 }
840
841 static void _layout_block_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
842 {
843         debug_log("");
844         EmailSettingUGD *ugd;
845         Evas_Object *base;
846
847         if (!ug || !priv)
848                 return;
849
850         ugd = (EmailSettingUGD *)priv;
851
852         base = ug_get_layout(ug);
853         if (!base)
854                 return;
855
856         switch (mode) {
857         case UG_MODE_FULLVIEW:
858                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
859                 evas_object_show(base);
860                 break;
861         default:
862                 break;
863         }
864 }
865
866 static void _result_block_cb(ui_gadget_h ug, service_h service, void *priv)
867 {
868         debug_log("");
869         EmailSettingUGD *ugd;
870
871         if (!ug || !priv)
872                 return;
873
874         ugd = (EmailSettingUGD *)priv;
875
876         return;
877 }
878
879 static void _destroy_block_cb(ui_gadget_h ug, void *priv)
880 {
881         debug_log("");
882         EmailSettingUGD *ugd;
883
884         if (!ug || !priv)
885                 return;
886
887         ugd = (EmailSettingUGD *)priv;
888
889         if (ug == ugd->ug_block) {
890                 ug_destroy(ugd->ug_block);
891                 ugd->ug_block = NULL;
892         }
893
894         return;
895 }
896
897 static void _popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
898 {
899         debug_log("");
900
901         if (!data) {
902                 debug_log("data is NULL");
903                 return;
904         }
905
906         if (obj)
907                 evas_object_del(obj);
908
909         EmailSettingUGD *ugd = (EmailSettingUGD *)data;
910         ug_destroy_me(ugd->ug);
911 }
912
913 /* EOF */