4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Tarun Kumar <tarun.kr@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "myaccount_ug.h"
23 #include "myaccount_ug_common.h"
24 #include "myaccount_ug_addaccount.h"
25 #include "myaccount_ug_account_list.h"
26 #include <iniparser.h>
27 #include <app_control_internal.h>
28 #include <account_internal.h>
30 static myaccount_appdata *g_myaccount_appdata = NULL;
32 #define MYACCOUNT_MAX_EMAIL_COUNT 10
33 #define MYACCOUNT_LAUNCH_TIME_OUT 0.7
34 #define MYACCOUNT_RELAUNCH_INTERVAL 0.3
35 #define MYACCOUNT_MAX_TOUCH_BLOCK_INTERVAL 2.5
38 void *myaccount_init_appdata()
40 if (g_myaccount_appdata == NULL) {
41 g_myaccount_appdata = calloc(1, sizeof(myaccount_appdata));
42 g_myaccount_appdata->item_selected_state = false;
44 return g_myaccount_appdata;
47 void myaccount_destroy_appdata()
49 if (g_myaccount_appdata == NULL) {
50 MYACCOUNT_ERROR("myaccount_destroy_appdata: appdata NULL \n");
54 if (g_myaccount_appdata->base) {
55 evas_object_del(g_myaccount_appdata->base);
56 g_myaccount_appdata->base = NULL;
59 MA_MEMFREE(g_myaccount_appdata->capability_filter)
61 /* For accounts list */
62 if (g_myaccount_appdata->ug_called) {
63 ug_destroy(g_myaccount_appdata->ug_called);
64 g_myaccount_appdata->ug_called = NULL;
66 if (g_myaccount_appdata->layout_main) {
67 evas_object_del(g_myaccount_appdata->layout_main);
68 g_myaccount_appdata->layout_main = NULL;
70 if (g_myaccount_appdata->layout_addaccount) {
71 evas_object_del(g_myaccount_appdata->layout_addaccount);
72 g_myaccount_appdata->layout_addaccount = NULL;
74 if (g_myaccount_appdata->navi_bar) {
75 evas_object_del(g_myaccount_appdata->navi_bar);
76 g_myaccount_appdata->navi_bar = NULL;
78 if (g_myaccount_appdata->help_label) {
79 evas_object_del(g_myaccount_appdata->help_label);
80 g_myaccount_appdata->help_label = NULL;
82 if (g_myaccount_appdata->refresh_btn) {
83 evas_object_del(g_myaccount_appdata->refresh_btn);
84 g_myaccount_appdata->refresh_btn = NULL;
86 if (g_myaccount_appdata->refresh_icon) {
87 evas_object_del(g_myaccount_appdata->refresh_icon);
88 g_myaccount_appdata->refresh_icon = NULL;
90 if (g_myaccount_appdata->cancel_sync_icon) {
91 evas_object_del(g_myaccount_appdata->cancel_sync_icon);
92 g_myaccount_appdata->cancel_sync_icon = NULL;
94 if (g_myaccount_appdata->auto_sync_check) {
95 evas_object_del(g_myaccount_appdata->auto_sync_check);
96 g_myaccount_appdata->auto_sync_check = NULL;
98 if (g_myaccount_appdata->bg) {
99 evas_object_del(g_myaccount_appdata->bg);
100 g_myaccount_appdata->bg = NULL;
102 if (g_myaccount_appdata->ly) {
103 elm_object_part_content_unset(g_myaccount_appdata->ly, "elm.swallow.content");
104 evas_object_del(g_myaccount_appdata->ly);
105 g_myaccount_appdata->ly = NULL;
107 if (g_myaccount_appdata->modal_popup) {
108 evas_object_del(g_myaccount_appdata->modal_popup);
109 g_myaccount_appdata->modal_popup = NULL;
111 if (g_myaccount_appdata->r_title_sk) {
112 evas_object_del(g_myaccount_appdata->r_title_sk);
113 g_myaccount_appdata->r_title_sk = NULL;
116 if (g_myaccount_appdata->progress_timer) {
117 ecore_timer_del(g_myaccount_appdata->progress_timer);
118 g_myaccount_appdata->progress_timer = NULL;
120 if (g_myaccount_appdata->relaunch_timer) {
121 ecore_timer_del(g_myaccount_appdata->relaunch_timer);
122 g_myaccount_appdata->relaunch_timer = NULL;
124 if (g_myaccount_appdata->pc) {
125 pkgmgr_client_free(g_myaccount_appdata->pc);
126 g_myaccount_appdata->pc = NULL;
129 if(g_myaccount_appdata->theme) {
130 elm_theme_free(g_myaccount_appdata->theme);
131 g_myaccount_appdata->theme = NULL;
134 if(g_myaccount_appdata->clickblock_timer){
135 ecore_timer_del(g_myaccount_appdata->clickblock_timer);
136 g_myaccount_appdata->clickblock_timer = NULL;
139 g_myaccount_appdata->sorted_sp_list= NULL;
140 g_myaccount_appdata->sorted_account_list= NULL;
142 MA_MEMFREE(g_myaccount_appdata->caller_userdata);
143 MA_MEMFREE(g_myaccount_appdata->called_from);
144 MA_MEMFREE(g_myaccount_appdata);
148 void * myaccount_get_appdata()
150 return g_myaccount_appdata;
153 static Eina_Bool _myaccount_common_click_block_timer_cb(void *data)
155 myaccount_appdata *ad = (myaccount_appdata *)data;
158 return ECORE_CALLBACK_CANCEL;
161 if(ad->clickblock_timer){
162 ecore_timer_del(ad->clickblock_timer);
163 ad->clickblock_timer = NULL;
166 MYACCOUNT_DBUG("_myaccount_common_click_block_timer_cb: ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
167 myaccount_common_set_item_selected_state(FALSE);
169 return ECORE_CALLBACK_CANCEL;
173 void myaccount_common_set_item_selected_state(bool val)
175 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
177 MYACCOUNT_DBUG("myaccount_common_set_item_selected_state[%s]", val ? "true":"false");
179 MYACCOUNT_ERROR("appdata is NULL");
183 appdata->item_selected_state = val;
185 if(appdata->clickblock_timer){
186 ecore_timer_del(appdata->clickblock_timer);
187 appdata->clickblock_timer = NULL;
191 appdata->clickblock_timer = ecore_timer_add(MYACCOUNT_MAX_TOUCH_BLOCK_INTERVAL, _myaccount_common_click_block_timer_cb, appdata);
195 bool myaccount_common_get_item_selected_state()
197 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
199 return (appdata->item_selected_state);
202 void myaccount_common_get_icon_by_name(char *domain_name,
206 MYACCOUNT_ERROR("\n !!! domain_name is NULL \n");
209 char tmp_domain_name[64] = {0,};
210 myaccount_common_lowercase(domain_name, tmp_domain_name);
213 MYACCOUNT_ERROR("\n !!! icon_path is NULL \n");
217 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "A01_2_Icon_default.png");
220 MyAccountProviderType myaccount_common_get_provider_type(
223 MyAccountProviderType sp_type = MYACCOUNT_TYPE_UNKNOWN;
226 MYACCOUNT_ERROR("myaccount_common_get_provider_type : package name is NULL\n");
230 if (!strcmp(package_name, "com.samsung.picasa"))
231 sp_type = MYACCOUNT_TYPE_PICASA;
232 else if (!strcmp(package_name, "com.samsung.youtube"))
233 sp_type = MYACCOUNT_TYPE_YOUTUBE;
234 else if (!strcmp(package_name, "email-setting-efl"))
235 sp_type = MYACCOUNT_TYPE_GOOGLE;
236 else if (!strcmp(package_name, "activesync-ui") || !strcmp(package_name, "activesync-efl"))
237 sp_type = MYACCOUNT_TYPE_EXCHANGE;
238 // else if (!strcmp(package_name, "com.samsung.facebook"))
239 // sp_type = MYACCOUNT_TYPE_FACEBOOK;
240 else if (!strcmp(package_name, SAMSUNG_ACCOUNT_APPID))
241 sp_type = MYACCOUNT_TYPE_SAMSUNG;
243 sp_type = MYACCOUNT_TYPE_UNKNOWN;
248 void myaccount_common_lowercase(char *src, char *dest)
254 MYACCOUNT_ERROR("myaccount_common_lowercase src=%p, dest=%p\n",
258 src_len = strlen(src);
259 for(i=0;i<src_len;i++) {
260 dest[i] = tolower(src[i]);
265 void myaccount_common_handle_notification(const char* event_type)
267 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
270 MYACCOUNT_ERROR("App data NULL!!! \n");
277 myaccount_common_set_item_selected_state(false);
279 MYACCOUNT_DBUG("called_from[%s],eMode(%d),event_type(%s), capability_filter(%s)\n", appdata->called_from, appdata->eMode,event_type, appdata->capability_filter);
280 if(appdata->capability_filter && strlen(appdata->capability_filter)) {
281 if(!strcmp(appdata->capability_filter, "http://tizen.org/account/capability/tizen_email")){
285 error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
286 if (error_code != ACCOUNT_ERROR_NONE) {
287 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID) code(%d)cnt1(%d) \n", error_code, cnt1);
290 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
291 if (error_code != ACCOUNT_ERROR_NONE) {
292 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID) code(%d)cnt2(%d) \n", error_code, cnt2);
295 error_code = myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID, &cnt3);
296 if (error_code != ACCOUNT_ERROR_NONE) {
297 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID) code(%d)cnt3(%d) \n", error_code, cnt3);
299 count = cnt1+cnt2+cnt3;
302 error_code = myaccount_common_get_account_cnt_by_capability(appdata->capability_filter, &count);
303 if (error_code != ACCOUNT_ERROR_NONE) {
304 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_capability code(%d)count(%d) \n", error_code, count);
310 error_code = myaccount_common_get_all_account_cnt(&count, false);
311 if (error_code != ACCOUNT_ERROR_NONE) {
312 MYACCOUNT_ERROR("myaccount_common_handle_notification: myaccount_common_get_all_account_cnt code(%d) \n",
316 MYACCOUNT_DBUG("count[%d],appdata->add_genlist[%p],appdata->account_genlist[%p]", count,appdata->add_genlist,appdata->account_genlist);
318 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
320 if (appdata->add_genlist) {
321 if( strcmp(event_type, ACCOUNT_NOTI_NAME_SYNC_UPDATE)){ // not sync update -> insert, update, delete
322 MYACCOUNT_DBUG("# recved noti-event(%s) -> elm_naviframe_item_pop / quit_cb should be called.", (event_type != NULL) ? event_type : "null");
323 elm_naviframe_item_pop(appdata->navi_bar);
324 appdata->add_genlist = NULL;
325 MYACCOUNT_DBUG("elm_naviframe_item_pop func finished.\n");
327 // if sync update received, do nothing.
328 MYACCOUNT_DBUG("recved noti-event(%s) -> do nothing.", (event_type != NULL) ? event_type : "null");
332 if (appdata->account_genlist) {
333 myaccount_list_refresh_item_list(appdata);
335 myaccount_ug_account_list_create((void*)appdata);
338 if (appdata->add_genlist) {
339 evas_object_show(appdata->add_genlist);
341 MYACCOUNT_DBUG("eMYACCOUNT_ACCOUNT_LIST mode, count=0, add_genlist=NULL, event_type must be delete.");
342 myaccount_addaccount_create_view(appdata); // event_type=delete, fix duplicate elm_naviframe_item_push happening.
345 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
346 MYACCOUNT_SLOGD("myaccount_common_handle_notification: ADD_ACCOUNT, event_type = %s\n", event_type);
348 if (appdata->ug && count > 0) {
349 if (!g_strcmp0(event_type, ACCOUNT_NOTI_NAME_INSERT) || !g_strcmp0(event_type, ACCOUNT_NOTI_NAME_SYNC_UPDATE)) {
350 app_control_h app_control = NULL;
351 app_control_create(&app_control);
352 app_control_add_extra_data(app_control, "account_noti", event_type);
353 error_code = ug_send_result(appdata->ug, app_control);
354 ui_gadget_h ug = appdata->ug;
355 error_code = ug_destroy_me(ug);
356 app_control_destroy(app_control);
363 bool myaccount_samsung_callback(char* result_code, char* user_id, void *user_data)
365 MYACCOUNT_SLOGD("Result Code = %s\n", result_code);
366 MYACCOUNT_SLOGD("User Id = %s\n", user_id);
369 int* test = (int*)user_data;
377 static void _myaccount_common_popup_cb(void *data, Evas_Object *obj, void *event_info)
379 myaccount_appdata *ad = (myaccount_appdata *)data;
382 evas_object_del(ad->modal_popup);
383 ad->modal_popup = NULL;
386 Evas_Object* _myaccount_common_add_popup(Evas_Object* parent, const char* text, const char* title)
388 myaccount_appdata *ad = (myaccount_appdata*)myaccount_get_appdata();
390 MYACCOUNT_DBUG("multi window not enabled.\n");
391 ad->modal_popup = elm_popup_add(parent);
393 evas_object_size_hint_weight_set(ad->modal_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
395 elm_object_text_set(ad->modal_popup, text);
397 elm_object_part_text_set(ad->modal_popup, "title,text", title);
398 evas_object_smart_callback_add(ad->modal_popup, "block,clicked", _myaccount_common_popup_cb, (void*)ad);
399 // elm_popup_timeout_set(ad->modal_popup, 3);
400 // evas_object_smart_callback_add(ad->modal_popup, "timeout", _myaccount_common_popup_cb, NULL);
402 Evas_Object *ok_btn = elm_button_add(ad->modal_popup);
403 elm_object_text_set(ok_btn, dgettext(MA_UG_NAME, "IDS_MA_BUTTON_OK"));
404 elm_object_part_content_set(ad->modal_popup, "button1", ok_btn);
405 evas_object_smart_callback_add(ok_btn, "clicked", _myaccount_common_popup_cb, (void*)ad);
406 elm_object_style_set(ok_btn, "popup_button/default");
408 evas_object_show(ad->modal_popup);
409 return ad->modal_popup;
412 static bool _myaccount_common_synchronise_query_cb(account_h account, void *user_data)
414 int ret = ACCOUNT_ERROR_NONE;
415 char** tmp_count = (char**)user_data;
418 MYACCOUNT_ERROR("account handle is NULL\n");
422 ret = account_get_custom(account, "profile_count", tmp_count);
423 if(ret != ACCOUNT_ERROR_NONE) {
424 MYACCOUNT_ERROR("account_get_custom fail(%x)\n", ret);
431 static Eina_Bool _myaccount_common_relaunch_application_timer_cb(void *data)
433 myaccount_appdata *ad = (myaccount_appdata *)data;
436 return ECORE_CALLBACK_CANCEL;
439 if(ad->relaunch_timer){
440 ecore_timer_del(ad->relaunch_timer);
441 ad->relaunch_timer = NULL;
444 app_control_send_launch_request(ad->appsvc_handle, NULL, NULL);
446 MYACCOUNT_DBUG("ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
447 myaccount_common_set_item_selected_state(FALSE);
449 app_control_destroy(ad->appsvc_handle);
450 ad->appsvc_handle = NULL;
452 return ECORE_CALLBACK_CANCEL;
455 static void _myaccount_common_try_relaunch(myaccount_appdata* ad, app_control_h app_control)
457 if(ad->relaunch_timer){
458 ecore_timer_del(ad->relaunch_timer);
459 ad->relaunch_timer = NULL;
462 ad->appsvc_handle = app_control;
464 ad->relaunch_timer = ecore_timer_add(MYACCOUNT_RELAUNCH_INTERVAL, _myaccount_common_relaunch_application_timer_cb, ad);
468 static int _myaccount_common_launch_samsung_account(myaccount_appdata *ad)
471 app_control_h app_control = NULL;
473 ret = app_control_create(&app_control);
474 if ( ret != APP_CONTROL_ERROR_NONE ) {
475 MYACCOUNT_SLOGE("app_control_cteate() fail, ret = %d\n", ret);
478 ret = app_control_set_app_id(app_control,SAMSUNG_ACCOUNT_APPID);
479 if ( ret != APP_CONTROL_ERROR_NONE ) {
480 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
483 ret = app_control_set_operation(app_control,ACCOUNT_OPERATION_SIGNIN);
484 if ( ret != APP_CONTROL_ERROR_NONE ) {
485 MYACCOUNT_SLOGE("app_control_set_operation() fail, ret = %d\n", ret);
488 Ecore_X_Window win_id = elm_win_xwindow_get(ad->win_main);
489 ret = app_control_set_window(app_control, win_id);
490 if ( ret != APP_CONTROL_ERROR_NONE ) {
491 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
494 ret = app_control_add_extra_data (app_control, "service_category", "from_myaccounts");
495 if ( ret != APP_CONTROL_ERROR_NONE ) {
496 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
499 ret = app_control_add_extra_data (app_control, "client_id", "gr47by21a5");
500 if ( ret != APP_CONTROL_ERROR_NONE ) {
501 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
504 ret = app_control_add_extra_data (app_control, "client_secret", "BD1F21218D46C1C082651EA0B8026721");
505 if ( ret != APP_CONTROL_ERROR_NONE ) {
506 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
509 ret = app_control_send_launch_request(app_control, NULL, NULL);
511 if(ret != APP_CONTROL_ERROR_NONE) {
512 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", SAMSUNG_ACCOUNT_APPID, ret);
513 _myaccount_common_try_relaunch(ad, app_control);
517 ret = app_control_destroy(app_control);
518 if ( ret != APP_CONTROL_ERROR_NONE ) {
519 MYACCOUNT_SLOGE("app_control_destroy() fail, ret = %d\n", ret);
525 static int _myaccount_common_launch_tizen_account(myaccount_appdata *ad)
528 app_control_h app_control = NULL;
530 ret = app_control_create(&app_control);
531 if ( ret != APP_CONTROL_ERROR_NONE ) {
532 MYACCOUNT_SLOGE("app_control_create() fail, ret = %d\n", ret);
535 ret = app_control_set_app_id(app_control,TIZEN_ACCOUNT_APPID);
536 if ( ret != APP_CONTROL_ERROR_NONE ) {
537 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
540 ret = app_control_set_operation(app_control,ACCOUNT_OPERATION_SIGNIN);
541 if ( ret != APP_CONTROL_ERROR_NONE ) {
542 MYACCOUNT_SLOGE("app_control_set_operation() fail, ret = %d\n", ret);
546 Ecore_X_Window win_id = elm_win_xwindow_get(ad->win_main);
547 ret = app_control_set_window(app_control, win_id);
548 if ( ret != APP_CONTROL_ERROR_NONE ) {
549 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
552 ret = app_control_add_extra_data (app_control, "client_id", "j5p7llxxxx");
553 if ( ret != APP_CONTROL_ERROR_NONE ) {
554 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
557 ret = app_control_add_extra_data (app_control, "client_secret", "5113D0052DC14XXXXX751F753384E9XX");
558 if ( ret != APP_CONTROL_ERROR_NONE ) {
559 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
562 ret = app_control_add_extra_data (app_control, "service_category", "from_myaccounts");
563 if ( ret != APP_CONTROL_ERROR_NONE ) {
564 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
567 ret = app_control_send_launch_request(app_control, NULL, NULL);
569 if(ret != APP_CONTROL_ERROR_NONE) {
570 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", TIZEN_ACCOUNT_APPID, ret);
571 _myaccount_common_try_relaunch(ad, app_control);
575 ret = app_control_destroy(app_control);
576 if ( ret != APP_CONTROL_ERROR_NONE ) {
577 MYACCOUNT_SLOGE("app_control_destroy() fail, ret = %d\n", ret);
583 static Eina_Bool _myaccount_common_launch_application_timer_cb(void *data)
585 myaccount_appdata *ad = (myaccount_appdata *)data;
588 return ECORE_CALLBACK_CANCEL;
591 if(ad->progress_timer){
592 ecore_timer_del(ad->progress_timer);
593 ad->progress_timer = NULL;
596 MYACCOUNT_DBUG("ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
598 return ECORE_CALLBACK_CANCEL;
601 static void _myaccount_common_launch_timer_start(myaccount_appdata *ad)
603 if(ad->progress_timer){
604 ecore_timer_del(ad->progress_timer);
605 ad->progress_timer = NULL;
608 ad->progress_timer = ecore_timer_add(MYACCOUNT_LAUNCH_TIME_OUT, _myaccount_common_launch_application_timer_cb, ad);
611 static bool _myaccount_common_is_email_count_max()
613 int cnt1 = 0, cnt2 = 0, cnt3 = 0, count = 0;
615 myaccount_common_get_account_cnt_by_appid("email-setting-efl", &cnt1);
616 myaccount_common_get_account_cnt_by_appid("com.samsung.google-service-account", &cnt2);
617 myaccount_common_get_account_cnt_by_appid("activesync-ui", &cnt3);
618 count = cnt1 + cnt2 + cnt3;
620 MYACCOUNT_DBUG("count(%d)cnt1(%d)cnt2(%d)cnt3(%d)", count, cnt1, cnt2, cnt3);
621 if(count >= MYACCOUNT_MAX_EMAIL_COUNT){
627 int myaccount_common_launch_application(MyAccountRequestViewType
633 MyAccountProviderType sp_type,
636 int ret = APP_CONTROL_ERROR_NONE;
637 app_control_h app_control = NULL;
638 myaccount_appdata *ad = (myaccount_appdata *) data;
639 char win_id_buf[64]={0,};
640 char id_buf[64] = {0,};
642 if (!ad || !package_name) {
643 MYACCOUNT_SLOGE("myaccount_common_launch_application: App data=%p, package_name=%p\n",
648 MYACCOUNT_SLOGD("trying to launch (%s)\n", package_name);
650 ad->win_id = elm_win_xwindow_get(ad->win_main);
651 MA_SNPRINTF(win_id_buf, sizeof(win_id_buf)-1, "%d", ad->win_id);
653 if(!strcmp(package_name,SAMSUNG_ACCOUNT_APPID)){
655 _myaccount_common_launch_samsung_account(ad);
656 _myaccount_common_launch_timer_start(ad);
658 MA_MEMFREE(package_name);
661 ret = app_control_create(&app_control);
662 if ( ret != APP_CONTROL_ERROR_NONE ) {
663 MYACCOUNT_SLOGE("app_control_create() fail, ret = %d\n", ret);
666 ret = app_control_set_window(app_control, ad->win_id);
667 if ( ret != APP_CONTROL_ERROR_NONE ) {
668 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
671 ret = app_control_set_app_id(app_control, package_name);
672 if ( ret != APP_CONTROL_ERROR_NONE ) {
673 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
676 if(ad->caller_userdata) {
677 ret = app_control_add_extra_data(app_control, "myaccount_userdata", ad->caller_userdata);
678 if ( ret != APP_CONTROL_ERROR_NONE ) {
679 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
685 if (ret != APP_CONTROL_ERROR_NONE)
686 MYACCOUNT_ERROR("myaccount_common_launch_application: service_set_package failed\n");
688 switch (request_type) {
689 case MYACCOUNT_REQUEST_SIGNIN :
690 //Check MAX synchronise count
691 if(strcmp(package_name,"setting-synchronise-efl") == 0){
692 int ret = -1, sync_cnt = 0;
693 char* synchronise_count = NULL;
694 ret = account_query_account_by_package_name(_myaccount_common_synchronise_query_cb, "setting-synchronise-efl", (void*)&synchronise_count);
695 if(ret != ACCOUNT_ERROR_NONE) {
696 MYACCOUNT_ERROR("account_query_account_by_package_name fail (%x)\n", ret);
699 if(synchronise_count)
700 sync_cnt = atoi(synchronise_count);
703 // draw popup and return
706 MA_SNPRINTF(buf, sizeof(buf), "Synchronise profile is full");
707 _myaccount_common_add_popup(ad->layout_main, buf, "Error");
708 myaccount_common_set_item_selected_state(FALSE);
709 MA_MEMFREE(synchronise_count);
711 app_control_destroy(app_control);
714 }else if(!strcmp(package_name,TIZEN_ACCOUNT_APPID)){
716 _myaccount_common_launch_tizen_account(ad);
718 app_control_destroy(app_control);
719 _myaccount_common_launch_timer_start(ad);
721 MA_MEMFREE(package_name);
723 } else if(strcmp(package_name,"email-setting-efl") == 0 ||
724 strcmp(package_name,"com.samsung.google-service-account") == 0 ||
725 strcmp(package_name,"activesync-ui") == 0){
728 MYACCOUNT_DBUG("package_name[%s] check max count\n");
729 if( _myaccount_common_is_email_count_max() == TRUE ){
730 MA_SNPRINTF(buf, sizeof(buf), dgettext(MA_UG_NAME, "IDS_EMAIL_BODY_MAXIMUM_NUMBER_OF_EMAIL_ACCOUNTS_REACHED"));
731 _myaccount_common_add_popup(ad->layout_main, buf, NULL);
732 myaccount_common_set_item_selected_state(FALSE);
734 app_control_destroy(app_control);
740 app_control_set_operation(app_control, ACCOUNT_OPERATION_SIGNIN);
741 if(email_sp && strlen(email_sp) > 0) {
742 app_control_add_extra_data(app_control, "http://tizen.org/account/data/service_provider", email_sp);
745 if(sp_type == MYACCOUNT_TYPE_CSC) {
746 app_control_add_extra_data(app_control, "http://tizen.org/account/data/csc", email_sp);
750 case MYACCOUNT_REQUEST_VIEW :
752 MYACCOUNT_ERROR("myaccount_common_launch_application: username=%p !!!\n",
754 MA_MEMFREE(package_name);
756 app_control_destroy(app_control);
760 MA_SNPRINTF(id_buf, sizeof(id_buf), "%d", account_id);
761 ret = app_control_add_extra_data(app_control, ACCOUNT_DATA_ID, id_buf);
762 if ( ret != APP_CONTROL_ERROR_NONE ) {
763 MYACCOUNT_ERROR("app_control_add_extra_data fail, ret = %d\n", ret);
766 ret = app_control_set_operation(app_control, ACCOUNT_OPERATION_VIEW);
767 if ( ret != APP_CONTROL_ERROR_NONE ) {
768 MYACCOUNT_ERROR("app_control_set_operation fail, ret = %d\n", ret);
771 ret = app_control_add_extra_data(app_control, ACCOUNT_DATA_USERNAME,username);
772 if ( ret != APP_CONTROL_ERROR_NONE ) {
773 MYACCOUNT_ERROR("app_control_add_extra_data fail, ret = %d\n", ret);
777 MA_MEMFREE(username);
778 MA_MEMFREE(package_name);
779 app_control_destroy(app_control);
782 MYACCOUNT_SLOGD("myaccount_common_launch_application request type=%d, package name = %s\n",
783 request_type, package_name);
785 ret = app_control_add_extra_data(app_control, "XWINDOW_ID", win_id_buf);
786 if ( ret != APP_CONTROL_ERROR_NONE ) {
787 MYACCOUNT_ERROR("app_control_add_extra_data fail, ret = %d\n", ret);
790 ret = app_control_send_launch_request(app_control, NULL, NULL);
791 if ( ret != APP_CONTROL_ERROR_NONE ) {
792 MYACCOUNT_ERROR("app_control_send_launch_request fail, ret = %d\n", ret);
796 MA_MEMFREE(username);
797 MA_MEMFREE(package_name);
799 if(ret != APP_CONTROL_ERROR_NONE) {
800 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", package_name, ret);
801 // char buf[64]={0,};
802 // MA_SNPRINTF(buf, sizeof(buf), "Launch fail (%x)", ret);
803 // _myaccount_common_add_popup(ad->win_main, buf, "Error");
804 // ad->item_selected_state = FALSE;
805 _myaccount_common_try_relaunch(ad, app_control);
809 app_control_destroy(app_control);
810 _myaccount_common_launch_timer_start(ad);
816 Evas_Object *myaccount_common_progress_add(Evas_Object *parent)
819 MYACCOUNT_ERROR("myaccount_common_progress_add: parent is NULL \n");
822 Evas_Object *progressbar = NULL;
823 progressbar = elm_progressbar_add(parent);
824 elm_object_style_set(progressbar, "list_process");
825 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
826 evas_object_size_hint_weight_set(progressbar,
829 evas_object_show(progressbar);
830 elm_progressbar_pulse(progressbar, EINA_TRUE);
834 void myaccount_common_delete_modal_popup(Evas_Object *popup)
837 MYACCOUNT_ERROR("myaccount_common_delete_modal_popup: popup is NULL \n");
840 evas_object_del(popup);
843 Eina_Bool myaccount_common_modal_popup_timer_cb(gpointer data)
846 MYACCOUNT_ERROR("myaccount_common_modal_popup_timer_cb: data is NULL \n");
849 myaccount_appdata *global_data = NULL;
850 global_data = (myaccount_appdata*)data;
851 if (global_data->modal_popup) {
852 myaccount_common_delete_modal_popup(global_data->modal_popup);
853 global_data->modal_popup = NULL;
855 if (global_data->progress_timer) {
856 ecore_timer_del(global_data->progress_timer);
857 global_data->progress_timer = NULL;
862 int myaccount_common_get_all_account_cnt(int *count, bool include_secret)
867 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: count ptr is NULL \n");
870 if( include_secret ) {
871 error_code = account_get_total_count_from_db(&account_cnt);
873 error_code = account_get_total_count_from_db_ex(&account_cnt);
875 if (error_code != ACCOUNT_ERROR_NONE) {
878 *count = account_cnt;
880 return ACCOUNT_ERROR_NONE;
883 static bool _myaccount_common_query_cb(account_h account, void *user_data)
885 int* tmp_count = (int*)user_data;
887 *tmp_count = *tmp_count + 1;
892 int myaccount_common_get_account_cnt_by_capability(const char* capability_type, int *count)
897 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_capability: count ptr is NULL \n");
901 error_code = account_query_account_by_capability_type(_myaccount_common_query_cb, capability_type, &account_cnt);
902 if (error_code != ACCOUNT_ERROR_NONE) {
908 *count = account_cnt;
910 return ACCOUNT_ERROR_NONE;
913 int myaccount_common_get_account_cnt_by_appid(const char* appid, int *count)
918 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: count ptr is NULL \n");
922 error_code = account_query_account_by_package_name(_myaccount_common_query_cb, appid, &account_cnt);
924 if (error_code != ACCOUNT_ERROR_NONE) {
930 *count = account_cnt;
932 return ACCOUNT_ERROR_NONE;
935 static int _myaccount_common_pkmgr_return_cb(int req_id, const char *pkg_type,
936 const char *pkg_name,
942 MYACCOUNT_SLOGD(" _myaccount_common_pkmgr_return_cb: pkg_type = %s, pkg_name = %s, key = %s, val = %s\n", pkg_type, pkg_name,key,val);
946 if( strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
948 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
951 MYACCOUNT_ERROR("App data NULL!!! \n");
954 if(appdata->capability_filter && strlen(appdata->capability_filter)){
955 if(!strcmp(appdata->capability_filter, "http://tizen.org/account/capability/tizen_email")){
959 error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
960 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
961 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt3);
962 count = cnt1+cnt2+cnt3;
964 error_code = myaccount_common_get_account_cnt_by_capability(appdata->capability_filter, &count);
967 if (error_code != ACCOUNT_ERROR_NONE) {
968 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
972 error_code = myaccount_common_get_all_account_cnt(&count, false);
973 if (error_code != ACCOUNT_ERROR_NONE) {
974 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
979 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
981 if (appdata->add_genlist) {
982 evas_object_del(appdata->add_genlist);
983 appdata->add_genlist = NULL;
984 elm_naviframe_item_pop(appdata->navi_bar);
986 if (appdata->account_genlist) {
987 myaccount_list_refresh_item_list(appdata);
989 myaccount_ug_account_list_create((void*)appdata);
992 if (appdata->add_genlist) {
993 evas_object_show(appdata->add_genlist);
995 myaccount_addaccount_create_view(appdata);
998 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
1000 ui_gadget_h ug = appdata->ug;
1001 error_code = ug_destroy_me(ug);
1004 //MYACCOUNT_WARNING("Unknown mode !!!");
1011 void myaccount_common_listen_pkgmgr_for_pkg_uninstall()
1013 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
1016 MYACCOUNT_ERROR("App data NULL!!! \n");
1021 pkgmgr_client *pc = NULL;
1022 pc = pkgmgr_client_new(PC_LISTENING);
1024 MYACCOUNT_ERROR("pc is NULL\n");
1028 result = pkgmgr_client_listen_status(pc, _myaccount_common_pkmgr_return_cb, pc);
1031 MYACCOUNT_ERROR("status listen failed!\n");
1037 int myaccount_common_get_csc_sp_count(const char* capability_filter)
1039 dictionary* dic = NULL;
1042 if(capability_filter) {
1043 // tizen email, email, none case, read csc email provider
1044 // otherwise ignore csc list
1045 if(strcmp(capability_filter, "http://tizen.org/account/capability/tizen_email")
1046 && strcmp(capability_filter, "http://tizen.org/account/capability/email"))
1050 // check ini file /opt/system/csc-default/data/csc-default-data-email-account.ini
1051 dic = iniparser_load(TIZEN_EMAIL_CSC_FILE_PATH);
1053 MYACCOUNT_ERROR("email csc file is not exist\n");
1057 sp_count = iniparser_getint(dic, TIZEN_EMAIL_CSC_SP_COUNT_KEY, 0);
1060 iniparser_freedict(dic);
1061 MYACCOUNT_ERROR("email sp count 0\n");
1065 iniparser_freedict(dic);
1070 bool myaccount_common_account_by_package_name_cb(account_h account,
1077 static bool _myaccount_common_get_account_type_count_cb(account_type_h account_type, void *user_data)
1079 int *count = (int*)user_data;
1080 char* type_buf = NULL;
1083 if(account_type == NULL) {
1084 MYACCOUNT_ERROR(" account type handle is NULL \n");
1088 account_type_get_app_id(account_type, &type_buf);
1090 if(!type_buf) return FALSE;
1092 if(!strcmp(type_buf, "email-setting-efl")) {
1093 *count = *count+3; // predefined email count
1094 MA_MEMFREE(type_buf);
1096 }else if(!strcmp(type_buf, "activesync-ui")) {
1098 MA_MEMFREE(type_buf);
1100 } else if(!strcmp(type_buf, "com.samsung.rcs-im")
1101 || !strcmp(type_buf, "ims-service")) {
1102 MA_MEMFREE(type_buf);
1106 account_type_get_multiple_account_support(account_type, &type_int);
1108 if(type_int == FALSE
1109 && account_query_account_by_package_name(myaccount_common_account_by_package_name_cb, type_buf, NULL) == ACCOUNT_ERROR_NONE) {
1110 MYACCOUNT_SLOGD("Multiple account not support (%s)\n", type_buf);
1111 MA_MEMFREE(type_buf);
1117 MA_MEMFREE(type_buf);
1123 int myaccount_common_get_account_type_count(const char* capability_filter)
1127 if(capability_filter) {
1128 if(!strcmp(capability_filter, "http://tizen.org/account/capability/tizen_email")){
1129 account_type_query_by_provider_feature(_myaccount_common_get_account_type_count_cb, "http://tizen.org/account/capability/email", (void*)&count);
1131 account_type_query_by_provider_feature(_myaccount_common_get_account_type_count_cb, capability_filter, (void*)&count);
1135 account_type_foreach_account_type_from_db(_myaccount_common_get_account_type_count_cb, (void*)&count);
1138 MYACCOUNT_DBUG("count %d\n", count);