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>
28 static myaccount_appdata *g_myaccount_appdata = NULL;
30 #define MYACCOUNT_MAX_EMAIL_COUNT 10
31 #define MYACCOUNT_LAUNCH_TIME_OUT 0.7
32 #define MYACCOUNT_RELAUNCH_INTERVAL 0.3
33 #define MYACCOUNT_MAX_TOUCH_BLOCK_INTERVAL 2.5
36 void *myaccount_init_appdata()
38 if (g_myaccount_appdata == NULL) {
39 g_myaccount_appdata = calloc(1, sizeof(myaccount_appdata));
40 g_myaccount_appdata->item_selected_state = false;
42 return g_myaccount_appdata;
45 void myaccount_destroy_appdata()
47 if (g_myaccount_appdata == NULL) {
48 MYACCOUNT_ERROR("myaccount_destroy_appdata: appdata NULL \n");
52 if (g_myaccount_appdata->base) {
53 evas_object_del(g_myaccount_appdata->base);
54 g_myaccount_appdata->base = NULL;
57 MA_MEMFREE(g_myaccount_appdata->capability_filter)
59 /* For accounts list */
60 if (g_myaccount_appdata->ug_called) {
61 ug_destroy(g_myaccount_appdata->ug_called);
62 g_myaccount_appdata->ug_called = NULL;
64 if (g_myaccount_appdata->layout_main) {
65 evas_object_del(g_myaccount_appdata->layout_main);
66 g_myaccount_appdata->layout_main = NULL;
68 if (g_myaccount_appdata->layout_addaccount) {
69 evas_object_del(g_myaccount_appdata->layout_addaccount);
70 g_myaccount_appdata->layout_addaccount = NULL;
72 if (g_myaccount_appdata->navi_bar) {
73 evas_object_del(g_myaccount_appdata->navi_bar);
74 g_myaccount_appdata->navi_bar = NULL;
76 if (g_myaccount_appdata->help_label) {
77 evas_object_del(g_myaccount_appdata->help_label);
78 g_myaccount_appdata->help_label = NULL;
80 if (g_myaccount_appdata->refresh_btn) {
81 evas_object_del(g_myaccount_appdata->refresh_btn);
82 g_myaccount_appdata->refresh_btn = NULL;
84 if (g_myaccount_appdata->refresh_icon) {
85 evas_object_del(g_myaccount_appdata->refresh_icon);
86 g_myaccount_appdata->refresh_icon = NULL;
88 if (g_myaccount_appdata->cancel_sync_icon) {
89 evas_object_del(g_myaccount_appdata->cancel_sync_icon);
90 g_myaccount_appdata->cancel_sync_icon = NULL;
92 if (g_myaccount_appdata->auto_sync_check) {
93 evas_object_del(g_myaccount_appdata->auto_sync_check);
94 g_myaccount_appdata->auto_sync_check = NULL;
96 if (g_myaccount_appdata->bg) {
97 evas_object_del(g_myaccount_appdata->bg);
98 g_myaccount_appdata->bg = NULL;
100 if (g_myaccount_appdata->ly) {
101 elm_object_part_content_unset(g_myaccount_appdata->ly, "elm.swallow.content");
102 evas_object_del(g_myaccount_appdata->ly);
103 g_myaccount_appdata->ly = NULL;
105 if (g_myaccount_appdata->modal_popup) {
106 evas_object_del(g_myaccount_appdata->modal_popup);
107 g_myaccount_appdata->modal_popup = NULL;
109 if (g_myaccount_appdata->r_title_sk) {
110 evas_object_del(g_myaccount_appdata->r_title_sk);
111 g_myaccount_appdata->r_title_sk = NULL;
114 if (g_myaccount_appdata->progress_timer) {
115 ecore_timer_del(g_myaccount_appdata->progress_timer);
116 g_myaccount_appdata->progress_timer = NULL;
118 if (g_myaccount_appdata->relaunch_timer) {
119 ecore_timer_del(g_myaccount_appdata->relaunch_timer);
120 g_myaccount_appdata->relaunch_timer = NULL;
122 if (g_myaccount_appdata->pc) {
123 pkgmgr_client_free(g_myaccount_appdata->pc);
124 g_myaccount_appdata->pc = NULL;
127 if(g_myaccount_appdata->theme) {
128 elm_theme_free(g_myaccount_appdata->theme);
129 g_myaccount_appdata->theme = NULL;
132 if(g_myaccount_appdata->clickblock_timer){
133 ecore_timer_del(g_myaccount_appdata->clickblock_timer);
134 g_myaccount_appdata->clickblock_timer = NULL;
137 g_myaccount_appdata->sorted_sp_list= NULL;
138 g_myaccount_appdata->sorted_account_list= NULL;
140 MA_MEMFREE(g_myaccount_appdata->caller_userdata);
141 MA_MEMFREE(g_myaccount_appdata->called_from);
142 MA_MEMFREE(g_myaccount_appdata);
146 void * myaccount_get_appdata()
148 return g_myaccount_appdata;
151 static Eina_Bool _myaccount_common_click_block_timer_cb(void *data)
153 myaccount_appdata *ad = (myaccount_appdata *)data;
156 return ECORE_CALLBACK_CANCEL;
159 if(ad->clickblock_timer){
160 ecore_timer_del(ad->clickblock_timer);
161 ad->clickblock_timer = NULL;
164 MYACCOUNT_DBUG("_myaccount_common_click_block_timer_cb: ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
165 myaccount_common_set_item_selected_state(FALSE);
167 return ECORE_CALLBACK_CANCEL;
171 void myaccount_common_set_item_selected_state(bool val)
173 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
175 MYACCOUNT_DBUG("myaccount_common_set_item_selected_state[%s]", val ? "true":"false");
177 MYACCOUNT_ERROR("appdata is NULL");
181 appdata->item_selected_state = val;
183 if(appdata->clickblock_timer){
184 ecore_timer_del(appdata->clickblock_timer);
185 appdata->clickblock_timer = NULL;
189 appdata->clickblock_timer = ecore_timer_add(MYACCOUNT_MAX_TOUCH_BLOCK_INTERVAL, _myaccount_common_click_block_timer_cb, appdata);
193 bool myaccount_common_get_item_selected_state()
195 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
197 return (appdata->item_selected_state);
200 void myaccount_common_get_icon_by_name(char *domain_name,
204 MYACCOUNT_ERROR("\n !!! domain_name is NULL \n");
207 char tmp_domain_name[64] = {0,};
208 myaccount_common_lowercase(domain_name, tmp_domain_name);
211 MYACCOUNT_ERROR("\n !!! icon_path is NULL \n");
215 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "A01_2_Icon_default.png");
218 MyAccountProviderType myaccount_common_get_provider_type(
221 MyAccountProviderType sp_type = MYACCOUNT_TYPE_UNKNOWN;
224 MYACCOUNT_ERROR("myaccount_common_get_provider_type : package name is NULL\n");
228 if (!strcmp(package_name, "com.samsung.picasa"))
229 sp_type = MYACCOUNT_TYPE_PICASA;
230 else if (!strcmp(package_name, "com.samsung.youtube"))
231 sp_type = MYACCOUNT_TYPE_YOUTUBE;
232 else if (!strcmp(package_name, "email-setting-efl"))
233 sp_type = MYACCOUNT_TYPE_GOOGLE;
234 else if (!strcmp(package_name, "activesync-ui") || !strcmp(package_name, "activesync-efl"))
235 sp_type = MYACCOUNT_TYPE_EXCHANGE;
236 // else if (!strcmp(package_name, "com.samsung.facebook"))
237 // sp_type = MYACCOUNT_TYPE_FACEBOOK;
238 else if (!strcmp(package_name, SAMSUNG_ACCOUNT_APPID))
239 sp_type = MYACCOUNT_TYPE_SAMSUNG;
241 sp_type = MYACCOUNT_TYPE_UNKNOWN;
246 void myaccount_common_lowercase(char *src, char *dest)
252 MYACCOUNT_ERROR("myaccount_common_lowercase src=%p, dest=%p\n",
256 src_len = strlen(src);
257 for(i=0;i<src_len;i++) {
258 dest[i] = tolower(src[i]);
263 void myaccount_common_handle_notification(const char* event_type)
265 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
268 MYACCOUNT_ERROR("App data NULL!!! \n");
275 myaccount_common_set_item_selected_state(false);
277 MYACCOUNT_DBUG("called_from[%s],eMode(%d),event_type(%s), capability_filter(%s)\n", appdata->called_from, appdata->eMode,event_type, appdata->capability_filter);
278 if(appdata->capability_filter && strlen(appdata->capability_filter)) {
279 if(!strcmp(appdata->capability_filter, "http://tizen.org/account/capability/tizen_email")){
283 error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
284 if (error_code != ACCOUNT_ERROR_NONE) {
285 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID) code(%d)cnt1(%d) \n", error_code, cnt1);
288 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
289 if (error_code != ACCOUNT_ERROR_NONE) {
290 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID) code(%d)cnt2(%d) \n", error_code, cnt2);
293 error_code = myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID, &cnt3);
294 if (error_code != ACCOUNT_ERROR_NONE) {
295 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID) code(%d)cnt3(%d) \n", error_code, cnt3);
297 count = cnt1+cnt2+cnt3;
300 error_code = myaccount_common_get_account_cnt_by_capability(appdata->capability_filter, &count);
301 if (error_code != ACCOUNT_ERROR_NONE) {
302 MYACCOUNT_DBUG(": myaccount_common_get_account_cnt_by_capability code(%d)count(%d) \n", error_code, count);
308 error_code = myaccount_common_get_all_account_cnt(&count);
309 if (error_code != ACCOUNT_ERROR_NONE) {
310 MYACCOUNT_ERROR("myaccount_common_handle_notification: myaccount_common_get_all_account_cnt code(%d) \n",
314 MYACCOUNT_DBUG("count[%d],appdata->add_genlist[%p],appdata->account_genlist[%p]", count,appdata->add_genlist,appdata->account_genlist);
316 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
318 if (appdata->add_genlist) {
319 if( strcmp(event_type, ACCOUNT_NOTI_NAME_SYNC_UPDATE)){ // not sync update -> insert, update, delete
320 MYACCOUNT_DBUG("# recved noti-event(%s) -> elm_naviframe_item_pop / quit_cb should be called.", (event_type != NULL) ? event_type : "null");
321 elm_naviframe_item_pop(appdata->navi_bar);
322 appdata->add_genlist = NULL;
323 MYACCOUNT_DBUG("elm_naviframe_item_pop func finished.\n");
325 // if sync update received, do nothing.
326 MYACCOUNT_DBUG("recved noti-event(%s) -> do nothing.", (event_type != NULL) ? event_type : "null");
330 if (appdata->account_genlist) {
331 myaccount_list_refresh_item_list(appdata);
333 myaccount_ug_account_list_create((void*)appdata);
336 if (appdata->add_genlist) {
337 evas_object_show(appdata->add_genlist);
339 MYACCOUNT_DBUG("eMYACCOUNT_ACCOUNT_LIST mode, count=0, add_genlist=NULL, event_type must be delete.");
340 myaccount_addaccount_create_view(appdata); // event_type=delete, fix duplicate elm_naviframe_item_push happening.
343 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
344 MYACCOUNT_SLOGD("myaccount_common_handle_notification: ADD_ACCOUNT, event_type = %s\n", event_type);
346 if (appdata->ug && count > 0) {
347 if (!g_strcmp0(event_type, ACCOUNT_NOTI_NAME_INSERT) || !g_strcmp0(event_type, ACCOUNT_NOTI_NAME_SYNC_UPDATE)) {
348 app_control_h app_control = NULL;
349 app_control_create(&app_control);
350 app_control_add_extra_data(app_control, "account_noti", event_type);
351 error_code = ug_send_result(appdata->ug, app_control);
352 ui_gadget_h ug = appdata->ug;
353 error_code = ug_destroy_me(ug);
354 app_control_destroy(app_control);
361 bool myaccount_samsung_callback(char* result_code, char* user_id, void *user_data)
363 MYACCOUNT_SLOGD("Result Code = %s\n", result_code);
364 MYACCOUNT_SLOGD("User Id = %s\n", user_id);
367 int* test = (int*)user_data;
375 static void _myaccount_common_popup_cb(void *data, Evas_Object *obj, void *event_info)
377 myaccount_appdata *ad = (myaccount_appdata *)data;
380 evas_object_del(ad->modal_popup);
381 ad->modal_popup = NULL;
384 Evas_Object* _myaccount_common_add_popup(Evas_Object* parent, const char* text, const char* title)
386 myaccount_appdata *ad = (myaccount_appdata*)myaccount_get_appdata();
388 /* multi window >>> */
389 #ifdef _MULTI_WINDOW_ENABLE_
390 MYACCOUNT_DBUG("multi window enabled.\n");
391 ad->modal_popup = ea_center_popup_add(parent);
393 MYACCOUNT_DBUG("multi window not enabled.\n");
394 ad->modal_popup = elm_popup_add(parent);
396 evas_object_size_hint_weight_set(ad->modal_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
398 elm_object_text_set(ad->modal_popup, text);
400 elm_object_part_text_set(ad->modal_popup, "title,text", title);
401 evas_object_smart_callback_add(ad->modal_popup, "block,clicked", _myaccount_common_popup_cb, (void*)ad);
402 // elm_popup_timeout_set(ad->modal_popup, 3);
403 // evas_object_smart_callback_add(ad->modal_popup, "timeout", _myaccount_common_popup_cb, NULL);
405 Evas_Object *ok_btn = elm_button_add(ad->modal_popup);
406 elm_object_text_set(ok_btn, dgettext(MA_UG_NAME, "IDS_MA_BUTTON_OK"));
407 elm_object_part_content_set(ad->modal_popup, "button1", ok_btn);
408 evas_object_smart_callback_add(ok_btn, "clicked", _myaccount_common_popup_cb, (void*)ad);
409 elm_object_style_set(ok_btn, "popup_button/default");
411 evas_object_show(ad->modal_popup);
412 return ad->modal_popup;
415 static bool _myaccount_common_synchronise_query_cb(account_h account, void *user_data)
417 int ret = ACCOUNT_ERROR_NONE;
418 char** tmp_count = (char**)user_data;
421 MYACCOUNT_ERROR("account handle is NULL\n");
425 ret = account_get_custom(account, "profile_count", tmp_count);
426 if(ret != ACCOUNT_ERROR_NONE) {
427 MYACCOUNT_ERROR("account_get_custom fail(%x)\n", ret);
434 static Eina_Bool _myaccount_common_relaunch_application_timer_cb(void *data)
436 myaccount_appdata *ad = (myaccount_appdata *)data;
439 return ECORE_CALLBACK_CANCEL;
442 if(ad->relaunch_timer){
443 ecore_timer_del(ad->relaunch_timer);
444 ad->relaunch_timer = NULL;
447 app_control_send_launch_request(ad->appsvc_handle, NULL, NULL);
449 MYACCOUNT_DBUG("ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
450 myaccount_common_set_item_selected_state(FALSE);
452 app_control_destroy(ad->appsvc_handle);
453 ad->appsvc_handle = NULL;
455 return ECORE_CALLBACK_CANCEL;
458 static void _myaccount_common_try_relaunch(myaccount_appdata* ad, app_control_h app_control)
460 if(ad->relaunch_timer){
461 ecore_timer_del(ad->relaunch_timer);
462 ad->relaunch_timer = NULL;
465 ad->appsvc_handle = app_control;
467 ad->relaunch_timer = ecore_timer_add(MYACCOUNT_RELAUNCH_INTERVAL, _myaccount_common_relaunch_application_timer_cb, ad);
471 static int _myaccount_common_launch_samsung_account(myaccount_appdata *ad)
474 app_control_h app_control = NULL;
476 ret = app_control_create(&app_control);
477 if ( ret != APP_CONTROL_ERROR_NONE ) {
478 MYACCOUNT_SLOGE("app_control_cteate() fail, ret = %d\n", ret);
481 ret = app_control_set_app_id(app_control,SAMSUNG_ACCOUNT_APPID);
482 if ( ret != APP_CONTROL_ERROR_NONE ) {
483 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
486 ret = app_control_set_operation(app_control,ACCOUNT_OPERATION_SIGNIN);
487 if ( ret != APP_CONTROL_ERROR_NONE ) {
488 MYACCOUNT_SLOGE("app_control_set_operation() fail, ret = %d\n", ret);
491 Ecore_X_Window win_id = elm_win_xwindow_get(ad->win_main);
492 ret = app_control_set_window(app_control, win_id);
493 if ( ret != APP_CONTROL_ERROR_NONE ) {
494 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
497 ret = app_control_add_extra_data (app_control, "service_category", "from_myaccounts");
498 if ( ret != APP_CONTROL_ERROR_NONE ) {
499 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
502 ret = app_control_add_extra_data (app_control, "client_id", "gr47by21a5");
503 if ( ret != APP_CONTROL_ERROR_NONE ) {
504 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
507 ret = app_control_add_extra_data (app_control, "client_secret", "BD1F21218D46C1C082651EA0B8026721");
508 if ( ret != APP_CONTROL_ERROR_NONE ) {
509 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
512 ret = app_control_send_launch_request(app_control, NULL, NULL);
514 if(ret != APP_CONTROL_ERROR_NONE) {
515 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", SAMSUNG_ACCOUNT_APPID, ret);
516 _myaccount_common_try_relaunch(ad, app_control);
520 ret = app_control_destroy(app_control);
521 if ( ret != APP_CONTROL_ERROR_NONE ) {
522 MYACCOUNT_SLOGE("app_control_destroy() fail, ret = %d\n", ret);
528 static int _myaccount_common_launch_tizen_account(myaccount_appdata *ad)
531 app_control_h app_control = NULL;
533 ret = app_control_create(&app_control);
534 if ( ret != APP_CONTROL_ERROR_NONE ) {
535 MYACCOUNT_SLOGE("app_control_create() fail, ret = %d\n", ret);
538 ret = app_control_set_app_id(app_control,TIZEN_ACCOUNT_APPID);
539 if ( ret != APP_CONTROL_ERROR_NONE ) {
540 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
543 ret = app_control_set_operation(app_control,ACCOUNT_OPERATION_SIGNIN);
544 if ( ret != APP_CONTROL_ERROR_NONE ) {
545 MYACCOUNT_SLOGE("app_control_set_operation() fail, ret = %d\n", ret);
549 Ecore_X_Window win_id = elm_win_xwindow_get(ad->win_main);
550 ret = app_control_set_window(app_control, win_id);
551 if ( ret != APP_CONTROL_ERROR_NONE ) {
552 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
555 ret = app_control_add_extra_data (app_control, "client_id", "j5p7llxxxx");
556 if ( ret != APP_CONTROL_ERROR_NONE ) {
557 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
560 ret = app_control_add_extra_data (app_control, "client_secret", "5113D0052DC14XXXXX751F753384E9XX");
561 if ( ret != APP_CONTROL_ERROR_NONE ) {
562 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
565 ret = app_control_add_extra_data (app_control, "service_category", "from_myaccounts");
566 if ( ret != APP_CONTROL_ERROR_NONE ) {
567 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
570 ret = app_control_send_launch_request(app_control, NULL, NULL);
572 if(ret != APP_CONTROL_ERROR_NONE) {
573 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", TIZEN_ACCOUNT_APPID, ret);
574 _myaccount_common_try_relaunch(ad, app_control);
578 ret = app_control_destroy(app_control);
579 if ( ret != APP_CONTROL_ERROR_NONE ) {
580 MYACCOUNT_SLOGE("app_control_destroy() fail, ret = %d\n", ret);
586 static Eina_Bool _myaccount_common_launch_application_timer_cb(void *data)
588 myaccount_appdata *ad = (myaccount_appdata *)data;
591 return ECORE_CALLBACK_CANCEL;
594 if(ad->progress_timer){
595 ecore_timer_del(ad->progress_timer);
596 ad->progress_timer = NULL;
599 MYACCOUNT_DBUG("ad->item_selected_state=%d\n", myaccount_common_get_item_selected_state());
601 return ECORE_CALLBACK_CANCEL;
604 static void _myaccount_common_launch_timer_start(myaccount_appdata *ad)
606 if(ad->progress_timer){
607 ecore_timer_del(ad->progress_timer);
608 ad->progress_timer = NULL;
611 ad->progress_timer = ecore_timer_add(MYACCOUNT_LAUNCH_TIME_OUT, _myaccount_common_launch_application_timer_cb, ad);
614 static bool _myaccount_common_is_email_count_max()
616 int cnt1 = 0, cnt2 = 0, cnt3 = 0, count = 0;
618 myaccount_common_get_account_cnt_by_appid("email-setting-efl", &cnt1);
619 myaccount_common_get_account_cnt_by_appid("com.samsung.google-service-account", &cnt2);
620 myaccount_common_get_account_cnt_by_appid("activesync-ui", &cnt3);
621 count = cnt1 + cnt2 + cnt3;
623 MYACCOUNT_DBUG("count(%d)cnt1(%d)cnt2(%d)cnt3(%d)", count, cnt1, cnt2, cnt3);
624 if(count >= MYACCOUNT_MAX_EMAIL_COUNT){
630 int myaccount_common_launch_application(MyAccountRequestViewType
636 MyAccountProviderType sp_type,
639 int ret = APP_CONTROL_ERROR_NONE;
640 app_control_h app_control = NULL;
641 myaccount_appdata *ad = (myaccount_appdata *) data;
642 char win_id_buf[64]={0,};
643 char id_buf[64] = {0,};
645 if (!ad || !package_name) {
646 MYACCOUNT_SLOGE("myaccount_common_launch_application: App data=%p, package_name=%p\n",
651 MYACCOUNT_SLOGD("trying to launch (%s)\n", package_name);
653 ad->win_id = elm_win_xwindow_get(ad->win_main);
654 MA_SNPRINTF(win_id_buf, sizeof(win_id_buf)-1, "%d", ad->win_id);
656 if(!strcmp(package_name,SAMSUNG_ACCOUNT_APPID)){
658 _myaccount_common_launch_samsung_account(ad);
659 _myaccount_common_launch_timer_start(ad);
661 MA_MEMFREE(package_name);
664 ret = app_control_create(&app_control);
665 if ( ret != APP_CONTROL_ERROR_NONE ) {
666 MYACCOUNT_SLOGE("app_control_create() fail, ret = %d\n", ret);
669 ret = app_control_set_window(app_control, ad->win_id);
670 if ( ret != APP_CONTROL_ERROR_NONE ) {
671 MYACCOUNT_SLOGE("app_control_set_window() fail, ret = %d\n", ret);
674 ret = app_control_set_app_id(app_control, package_name);
675 if ( ret != APP_CONTROL_ERROR_NONE ) {
676 MYACCOUNT_SLOGE("app_control_set_app_id() fail, ret = %d\n", ret);
679 if(ad->caller_userdata) {
680 ret = app_control_add_extra_data(app_control, "myaccount_userdata", ad->caller_userdata);
681 if ( ret != APP_CONTROL_ERROR_NONE ) {
682 MYACCOUNT_SLOGE("app_control_add_extra_data() fail, ret = %d\n", ret);
688 if (ret != APP_CONTROL_ERROR_NONE)
689 MYACCOUNT_ERROR("myaccount_common_launch_application: service_set_package failed\n");
691 switch (request_type) {
692 case MYACCOUNT_REQUEST_SIGNIN :
693 //Check MAX synchronise count
694 if(strcmp(package_name,"setting-synchronise-efl") == 0){
695 int ret = -1, sync_cnt = 0;
696 char* synchronise_count = NULL;
697 ret = account_connect();
698 if(ret != ACCOUNT_ERROR_NONE) {
699 MYACCOUNT_ERROR("Account connect fail (%x)\n", ret);
701 ret = account_query_account_by_package_name(_myaccount_common_synchronise_query_cb, "setting-synchronise-efl", (void*)&synchronise_count);
702 if(ret != ACCOUNT_ERROR_NONE) {
703 MYACCOUNT_ERROR("account_query_account_by_package_name fail (%x)\n", ret);
706 if(synchronise_count)
707 sync_cnt = atoi(synchronise_count);
710 // draw popup and return
713 MA_SNPRINTF(buf, sizeof(buf), "Synchronise profile is full");
714 _myaccount_common_add_popup(ad->layout_main, buf, "Error");
715 myaccount_common_set_item_selected_state(FALSE);
716 MA_MEMFREE(synchronise_count);
718 app_control_destroy(app_control);
721 }else if(!strcmp(package_name,TIZEN_ACCOUNT_APPID)){
723 _myaccount_common_launch_tizen_account(ad);
725 app_control_destroy(app_control);
726 _myaccount_common_launch_timer_start(ad);
728 MA_MEMFREE(package_name);
730 } else if(strcmp(package_name,"email-setting-efl") == 0 ||
731 strcmp(package_name,"com.samsung.google-service-account") == 0 ||
732 strcmp(package_name,"activesync-ui") == 0){
735 MYACCOUNT_DBUG("package_name[%s] check max count\n");
736 if( _myaccount_common_is_email_count_max() == TRUE ){
737 MA_SNPRINTF(buf, sizeof(buf), dgettext(MA_UG_NAME, "IDS_EMAIL_BODY_MAXIMUM_NUMBER_OF_EMAIL_ACCOUNTS_REACHED"));
738 _myaccount_common_add_popup(ad->layout_main, buf, NULL);
739 myaccount_common_set_item_selected_state(FALSE);
741 app_control_destroy(app_control);
745 #ifdef _MULTI_WINDOW_ENABLE_
746 unsigned int layout = 0;
747 if( ecore_x_window_prop_card32_get( elm_win_xwindow_get( (Evas_Object*)ad->win_main ),
748 ECORE_X_ATOM_E_WINDOW_DESKTOP_LAYOUT, &layout, 1 ) != -1 )
750 if( layout == 0 || layout == 1)
752 app_control_add_extra_data( app_control, "window_startup_type", "2");
753 char temp[10] = {0,};
754 snprintf( temp, sizeof(temp), "%d", (int)layout );
755 app_control_add_extra_data( app_control, "window_layout_id", temp);
758 MYACCOUNT_SLOGD("### MULTI WINDOW: call with multi win params");
764 app_control_set_operation(app_control, ACCOUNT_OPERATION_SIGNIN);
765 if(email_sp && strlen(email_sp) > 0) {
766 app_control_add_extra_data(app_control, "http://tizen.org/account/data/service_provider", email_sp);
769 if(sp_type == MYACCOUNT_TYPE_CSC) {
770 app_control_add_extra_data(app_control, "http://tizen.org/account/data/csc", email_sp);
774 case MYACCOUNT_REQUEST_VIEW :
776 MYACCOUNT_ERROR("myaccount_common_launch_application: username=%p !!!\n",
778 MA_MEMFREE(package_name);
780 app_control_destroy(app_control);
784 MA_SNPRINTF(id_buf, sizeof(id_buf), "%d", account_id);
785 ret = app_control_add_extra_data(app_control, ACCOUNT_DATA_ID, 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_set_operation(app_control, ACCOUNT_OPERATION_VIEW);
791 if ( ret != APP_CONTROL_ERROR_NONE ) {
792 MYACCOUNT_ERROR("app_control_set_operation fail, ret = %d\n", ret);
795 ret = app_control_add_extra_data(app_control, ACCOUNT_DATA_USERNAME,username);
796 if ( ret != APP_CONTROL_ERROR_NONE ) {
797 MYACCOUNT_ERROR("app_control_add_extra_data fail, ret = %d\n", ret);
801 MA_MEMFREE(username);
802 MA_MEMFREE(package_name);
803 app_control_destroy(app_control);
806 MYACCOUNT_SLOGD("myaccount_common_launch_application request type=%d, package name = %s\n",
807 request_type, package_name);
809 ret = app_control_add_extra_data(app_control, "XWINDOW_ID", win_id_buf);
810 if ( ret != APP_CONTROL_ERROR_NONE ) {
811 MYACCOUNT_ERROR("app_control_add_extra_data fail, ret = %d\n", ret);
814 ret = app_control_send_launch_request(app_control, NULL, NULL);
815 if ( ret != APP_CONTROL_ERROR_NONE ) {
816 MYACCOUNT_ERROR("app_control_send_launch_request fail, ret = %d\n", ret);
820 MA_MEMFREE(username);
821 MA_MEMFREE(package_name);
823 if(ret != APP_CONTROL_ERROR_NONE) {
824 MYACCOUNT_SLOGE("(%s) launch fail. ret(%x)\n", package_name, ret);
825 // char buf[64]={0,};
826 // MA_SNPRINTF(buf, sizeof(buf), "Launch fail (%x)", ret);
827 // _myaccount_common_add_popup(ad->win_main, buf, "Error");
828 // ad->item_selected_state = FALSE;
829 _myaccount_common_try_relaunch(ad, app_control);
833 app_control_destroy(app_control);
834 _myaccount_common_launch_timer_start(ad);
840 Evas_Object *myaccount_common_progress_add(Evas_Object *parent)
843 MYACCOUNT_ERROR("myaccount_common_progress_add: parent is NULL \n");
846 Evas_Object *progressbar = NULL;
847 progressbar = elm_progressbar_add(parent);
848 elm_object_style_set(progressbar, "list_process");
849 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
850 evas_object_size_hint_weight_set(progressbar,
853 evas_object_show(progressbar);
854 elm_progressbar_pulse(progressbar, EINA_TRUE);
858 void myaccount_common_delete_modal_popup(Evas_Object *popup)
861 MYACCOUNT_ERROR("myaccount_common_delete_modal_popup: popup is NULL \n");
864 evas_object_del(popup);
867 Eina_Bool myaccount_common_modal_popup_timer_cb(gpointer data)
870 MYACCOUNT_ERROR("myaccount_common_modal_popup_timer_cb: data is NULL \n");
873 myaccount_appdata *global_data = NULL;
874 global_data = (myaccount_appdata*)data;
875 if (global_data->modal_popup) {
876 myaccount_common_delete_modal_popup(global_data->modal_popup);
877 global_data->modal_popup = NULL;
879 if (global_data->progress_timer) {
880 ecore_timer_del(global_data->progress_timer);
881 global_data->progress_timer = NULL;
886 int myaccount_common_get_all_account_cnt(int *count)
891 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: count ptr is NULL \n");
894 error_code = account_connect();
895 if (error_code != ACCOUNT_ERROR_NONE) {
896 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: fail to connect account DB \n");
899 error_code = account_get_total_count_from_db(&account_cnt);
900 if (error_code != ACCOUNT_ERROR_NONE) {
901 int ret = ACCOUNT_ERROR_NONE;
902 ret = account_disconnect();
903 if (ret != ACCOUNT_ERROR_NONE) {
904 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_disconnect fail(%d) \n",
909 *count = account_cnt;
910 error_code = account_disconnect();
911 if (error_code != ACCOUNT_ERROR_NONE) {
912 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
916 return ACCOUNT_ERROR_NONE;
919 static bool _myaccount_common_query_cb(account_h account, void *user_data)
921 int* tmp_count = (int*)user_data;
923 *tmp_count = *tmp_count + 1;
928 int myaccount_common_get_account_cnt_by_capability(const char* capability_type, int *count)
933 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_capability: count ptr is NULL \n");
936 error_code = account_connect();
937 if (error_code != ACCOUNT_ERROR_NONE) {
938 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_capability: fail to connect account DB \n");
942 error_code = account_query_account_by_capability_type(_myaccount_common_query_cb, capability_type, &account_cnt);
943 if (error_code != ACCOUNT_ERROR_NONE) {
947 int ret = ACCOUNT_ERROR_NONE;
948 ret = account_disconnect();
949 if (ret != ACCOUNT_ERROR_NONE) {
950 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_capability: account_svc_disconnect fail(%d) \n",
955 *count = account_cnt;
956 error_code = account_disconnect();
957 if (error_code != ACCOUNT_ERROR_NONE) {
958 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
962 return ACCOUNT_ERROR_NONE;
965 int myaccount_common_get_account_cnt_by_appid(const char* appid, int *count)
970 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: count ptr is NULL \n");
973 error_code = account_connect();
974 if (error_code != ACCOUNT_ERROR_NONE) {
975 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: fail to connect account DB \n");
979 error_code = account_query_account_by_package_name(_myaccount_common_query_cb, appid, &account_cnt);
981 if (error_code != ACCOUNT_ERROR_NONE) {
985 int ret = ACCOUNT_ERROR_NONE;
986 ret = account_disconnect();
987 if (ret != ACCOUNT_ERROR_NONE) {
988 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: account_svc_disconnect fail(%d) \n",
993 *count = account_cnt;
994 error_code = account_disconnect();
995 if (error_code != ACCOUNT_ERROR_NONE) {
996 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: account_svc_get_count fail(%d) \n",
1000 return ACCOUNT_ERROR_NONE;
1003 static int _myaccount_common_pkmgr_return_cb(int req_id, const char *pkg_type,
1004 const char *pkg_name,
1010 MYACCOUNT_SLOGD(" _myaccount_common_pkmgr_return_cb: pkg_type = %s, pkg_name = %s, key = %s, val = %s\n", pkg_type, pkg_name,key,val);
1012 int error_code = -1;
1014 if( strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
1016 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
1019 MYACCOUNT_ERROR("App data NULL!!! \n");
1022 if(appdata->capability_filter && strlen(appdata->capability_filter)){
1023 if(!strcmp(appdata->capability_filter, "http://tizen.org/account/capability/tizen_email")){
1027 error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
1028 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
1029 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt3);
1030 count = cnt1+cnt2+cnt3;
1032 error_code = myaccount_common_get_account_cnt_by_capability(appdata->capability_filter, &count);
1035 if (error_code != ACCOUNT_ERROR_NONE) {
1036 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
1040 error_code = myaccount_common_get_all_account_cnt(&count);
1041 if (error_code != ACCOUNT_ERROR_NONE) {
1042 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
1047 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
1049 if (appdata->add_genlist) {
1050 evas_object_del(appdata->add_genlist);
1051 appdata->add_genlist = NULL;
1052 elm_naviframe_item_pop(appdata->navi_bar);
1054 if (appdata->account_genlist) {
1055 myaccount_list_refresh_item_list(appdata);
1057 myaccount_ug_account_list_create((void*)appdata);
1060 if (appdata->add_genlist) {
1061 evas_object_show(appdata->add_genlist);
1063 myaccount_addaccount_create_view(appdata);
1066 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
1068 ui_gadget_h ug = appdata->ug;
1069 error_code = ug_destroy_me(ug);
1072 //MYACCOUNT_WARNING("Unknown mode !!!");
1079 void myaccount_common_listen_pkgmgr_for_pkg_uninstall()
1081 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
1084 MYACCOUNT_ERROR("App data NULL!!! \n");
1089 pkgmgr_client *pc = NULL;
1090 pc = pkgmgr_client_new(PC_LISTENING);
1092 MYACCOUNT_ERROR("pc is NULL\n");
1096 result = pkgmgr_client_listen_status(pc, _myaccount_common_pkmgr_return_cb, pc);
1099 MYACCOUNT_ERROR("status listen failed!\n");
1105 int myaccount_common_get_csc_sp_count(const char* capability_filter)
1107 dictionary* dic = NULL;
1110 if(capability_filter) {
1111 // tizen email, email, none case, read csc email provider
1112 // otherwise ignore csc list
1113 if(strcmp(capability_filter, "http://tizen.org/account/capability/tizen_email")
1114 && strcmp(capability_filter, "http://tizen.org/account/capability/email"))
1118 // check ini file /opt/system/csc-default/data/csc-default-data-email-account.ini
1119 dic = iniparser_load(TIZEN_EMAIL_CSC_FILE_PATH);
1121 MYACCOUNT_ERROR("email csc file is not exist\n");
1125 sp_count = iniparser_getint(dic, TIZEN_EMAIL_CSC_SP_COUNT_KEY, 0);
1128 iniparser_freedict(dic);
1129 MYACCOUNT_ERROR("email sp count 0\n");
1133 iniparser_freedict(dic);
1138 bool myaccount_common_account_by_package_name_cb(account_h account,
1145 static bool _myaccount_common_get_account_type_count_cb(account_type_h account_type, void *user_data)
1147 int *count = (int*)user_data;
1148 char* type_buf = NULL;
1151 if(account_type == NULL) {
1152 MYACCOUNT_ERROR(" account type handle is NULL \n");
1156 account_type_get_app_id(account_type, &type_buf);
1158 if(!type_buf) return FALSE;
1160 if(!strcmp(type_buf, "email-setting-efl")) {
1161 *count = *count+3; // predefined email count
1162 MA_MEMFREE(type_buf);
1164 }else if(!strcmp(type_buf, "activesync-ui")) {
1166 MA_MEMFREE(type_buf);
1168 } else if(!strcmp(type_buf, "com.samsung.rcs-im")
1169 || !strcmp(type_buf, "ims-service")) {
1170 MA_MEMFREE(type_buf);
1174 account_type_get_multiple_account_support(account_type, &type_int);
1176 if(type_int == FALSE
1177 && account_query_account_by_package_name(myaccount_common_account_by_package_name_cb, type_buf, NULL) == ACCOUNT_ERROR_NONE) {
1178 MYACCOUNT_SLOGD("Multiple account not support (%s)\n", type_buf);
1179 MA_MEMFREE(type_buf);
1185 MA_MEMFREE(type_buf);
1191 int myaccount_common_get_account_type_count(const char* capability_filter)
1196 ret = account_connect();
1197 if(ret != ACCOUNT_ERROR_NONE){
1198 MYACCOUNT_ERROR("account database cannot be connected\n");
1202 if(capability_filter) {
1203 if(!strcmp(capability_filter, "http://tizen.org/account/capability/tizen_email")){
1204 account_type_query_by_provider_feature(_myaccount_common_get_account_type_count_cb, "http://tizen.org/account/capability/email", (void*)&count);
1206 account_type_query_by_provider_feature(_myaccount_common_get_account_type_count_cb, capability_filter, (void*)&count);
1210 account_type_foreach_account_type_from_db(_myaccount_common_get_account_type_count_cb, (void*)&count);
1213 MYACCOUNT_DBUG("count %d\n", count);
1215 ret = account_disconnect();
1216 if(ret != ACCOUNT_ERROR_NONE){
1217 MYACCOUNT_ERROR("account database cannot be connected\n");