f885d7c1a246458ef6da624f086bb76496743979
[apps/home/my-account.git] / src / myaccount_ug_common.c
1 /*
2  *  my-account
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Tarun Kumar <tarun.kr@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
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
28 static myaccount_appdata *g_myaccount_appdata = NULL;
29
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
34
35
36 void *myaccount_init_appdata()
37 {
38         if (g_myaccount_appdata == NULL) {
39                 g_myaccount_appdata = calloc(1, sizeof(myaccount_appdata));
40                 g_myaccount_appdata->item_selected_state = false;
41         }
42         return g_myaccount_appdata;
43 }
44
45 void myaccount_destroy_appdata()
46 {
47         if (g_myaccount_appdata == NULL) {
48                 MYACCOUNT_ERROR("myaccount_destroy_appdata: appdata NULL \n");
49                 return;
50         }
51
52         if (g_myaccount_appdata->base) {
53                 evas_object_del(g_myaccount_appdata->base);
54                 g_myaccount_appdata->base = NULL;
55         }
56
57         MA_MEMFREE(g_myaccount_appdata->capability_filter)
58
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;
63         }
64         if (g_myaccount_appdata->layout_main) {
65                 evas_object_del(g_myaccount_appdata->layout_main);
66                 g_myaccount_appdata->layout_main = NULL;
67         }
68         if (g_myaccount_appdata->layout_addaccount) {
69                 evas_object_del(g_myaccount_appdata->layout_addaccount);
70                 g_myaccount_appdata->layout_addaccount = NULL;
71         }
72         if (g_myaccount_appdata->navi_bar) {
73                 evas_object_del(g_myaccount_appdata->navi_bar);
74                 g_myaccount_appdata->navi_bar = NULL;
75         }
76         if (g_myaccount_appdata->help_label) {
77                 evas_object_del(g_myaccount_appdata->help_label);
78                 g_myaccount_appdata->help_label = NULL;
79         }
80         if (g_myaccount_appdata->refresh_btn) {
81                 evas_object_del(g_myaccount_appdata->refresh_btn);
82                 g_myaccount_appdata->refresh_btn = NULL;
83         }
84         if (g_myaccount_appdata->refresh_icon) {
85                 evas_object_del(g_myaccount_appdata->refresh_icon);
86                 g_myaccount_appdata->refresh_icon = NULL;
87         }
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;
91         }
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;
95         }
96         if (g_myaccount_appdata->bg) {
97                 evas_object_del(g_myaccount_appdata->bg);
98                 g_myaccount_appdata->bg = NULL;
99         }
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;
104         }
105         if (g_myaccount_appdata->modal_popup) {
106                 evas_object_del(g_myaccount_appdata->modal_popup);
107                 g_myaccount_appdata->modal_popup = NULL;
108         }
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;
112         }
113
114         if (g_myaccount_appdata->progress_timer) {
115                 ecore_timer_del(g_myaccount_appdata->progress_timer);
116                 g_myaccount_appdata->progress_timer = NULL;
117         }
118         if (g_myaccount_appdata->relaunch_timer) {
119                 ecore_timer_del(g_myaccount_appdata->relaunch_timer);
120                 g_myaccount_appdata->relaunch_timer = NULL;
121         }
122         if (g_myaccount_appdata->pc) {
123                 pkgmgr_client_free(g_myaccount_appdata->pc);
124                 g_myaccount_appdata->pc = NULL;
125         }
126
127         if(g_myaccount_appdata->theme) {
128                 elm_theme_free(g_myaccount_appdata->theme);
129                 g_myaccount_appdata->theme = NULL;
130         }
131
132         if(g_myaccount_appdata->clickblock_timer){
133                 ecore_timer_del(g_myaccount_appdata->clickblock_timer);
134                 g_myaccount_appdata->clickblock_timer = NULL;
135         }
136
137         g_myaccount_appdata->sorted_sp_list= NULL;
138         g_myaccount_appdata->sorted_account_list= NULL;
139
140         MA_MEMFREE(g_myaccount_appdata->caller_userdata);
141         MA_MEMFREE(g_myaccount_appdata->called_from);
142         MA_MEMFREE(g_myaccount_appdata);
143
144 }
145
146 void * myaccount_get_appdata()
147 {
148         return g_myaccount_appdata;
149 }
150
151 static Eina_Bool _myaccount_common_click_block_timer_cb(void *data)
152 {
153         myaccount_appdata *ad = (myaccount_appdata *)data;
154
155         if(!ad){
156                 return ECORE_CALLBACK_CANCEL;
157         }
158
159         if(ad->clickblock_timer){
160                 ecore_timer_del(ad->clickblock_timer);
161                 ad->clickblock_timer = NULL;
162         }
163
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);
166
167         return ECORE_CALLBACK_CANCEL;
168 }
169
170
171 void myaccount_common_set_item_selected_state(bool val)
172 {
173         myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
174
175         MYACCOUNT_DBUG("myaccount_common_set_item_selected_state[%s]", val ? "true":"false");
176         if (!appdata) {
177                 MYACCOUNT_ERROR("appdata is NULL");
178                 return;
179         }
180
181         appdata->item_selected_state = val;
182
183         if(appdata->clickblock_timer){
184                 ecore_timer_del(appdata->clickblock_timer);
185                 appdata->clickblock_timer = NULL;
186         }
187
188         if( val == true ) {
189                 appdata->clickblock_timer = ecore_timer_add(MYACCOUNT_MAX_TOUCH_BLOCK_INTERVAL, _myaccount_common_click_block_timer_cb, appdata);
190         }
191 }
192
193 bool myaccount_common_get_item_selected_state()
194 {
195         myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
196
197         return (appdata->item_selected_state);
198 }
199
200 void myaccount_common_get_icon_by_name(char *domain_name,
201                                                                                         char *icon_path)
202 {
203         if (!domain_name) {
204                 MYACCOUNT_ERROR("\n !!! domain_name is NULL \n");
205                 return;
206         }
207         char tmp_domain_name[64] = {0,};
208         myaccount_common_lowercase(domain_name, tmp_domain_name);
209
210         if (!icon_path) {
211                 MYACCOUNT_ERROR("\n !!! icon_path is NULL \n");
212                 return;
213         }
214
215         MA_SNPRINTF(icon_path, BUFSIZE, "%s", "A01_2_Icon_default.png");
216 }
217
218 MyAccountProviderType myaccount_common_get_provider_type(
219                                                                                                         char    *package_name)
220 {
221         MyAccountProviderType sp_type = MYACCOUNT_TYPE_UNKNOWN;
222
223         if (!package_name) {
224                 MYACCOUNT_ERROR("myaccount_common_get_provider_type : package name is NULL\n");
225                 return sp_type;
226         }
227
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;
240         else
241                 sp_type = MYACCOUNT_TYPE_UNKNOWN;
242
243         return sp_type;
244 }
245
246 void myaccount_common_lowercase(char *src, char *dest)
247 {
248         int i;
249         int src_len=0;
250
251         if (!src || !dest) {
252                 MYACCOUNT_ERROR("myaccount_common_lowercase src=%p, dest=%p\n",
253                                                 src, dest);
254                 return;
255         }
256         src_len = strlen(src);
257         for(i=0;i<src_len;i++) {
258                 dest[i] = tolower(src[i]);
259         }
260         dest[i] = '\0';
261 }
262
263 void myaccount_common_handle_notification(const char* event_type)
264 {
265         myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
266
267         if (!appdata) {
268                 MYACCOUNT_ERROR("App data NULL!!! \n");
269                 return;
270         }
271
272         int error_code = -1;
273         int count = -1;
274
275         myaccount_common_set_item_selected_state(false);
276
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")){
280                         int cnt1 = 0;
281                         int cnt2 = 0;
282                         int cnt3 = 0;
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);
286                         }
287
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);
291                         }
292
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);
296                         }
297                         count = cnt1+cnt2+cnt3;
298
299                 } else {
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);
303                         }
304                 }
305
306
307         } else {
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",
311                                                                 error_code);
312                 }
313         }
314         MYACCOUNT_DBUG("count[%d],appdata->add_genlist[%p],appdata->account_genlist[%p]", count,appdata->add_genlist,appdata->account_genlist);
315
316         if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
317                 if (count > 0) {
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");
324                                 } else {
325                                         // if sync update received, do nothing.
326                                         MYACCOUNT_DBUG("recved noti-event(%s) -> do nothing.", (event_type != NULL) ? event_type : "null");
327                                 }
328                         }
329
330                         if (appdata->account_genlist) {
331                                 myaccount_list_refresh_item_list(appdata);
332                         } else {
333                                 myaccount_ug_account_list_create((void*)appdata);
334                         }
335                 } else {
336                         if (appdata->add_genlist) {
337                                 evas_object_show(appdata->add_genlist);
338                         } else {
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.
341                         }
342                 }
343         } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
344                 MYACCOUNT_SLOGD("myaccount_common_handle_notification: ADD_ACCOUNT, event_type = %s\n", event_type);
345                 if(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);
355                                 }
356                         }
357                 }
358         }
359 }
360
361 bool myaccount_samsung_callback(char* result_code, char* user_id, void *user_data)
362 {
363         MYACCOUNT_SLOGD("Result Code = %s\n", result_code);
364         MYACCOUNT_SLOGD("User Id = %s\n", user_id);
365
366         if(user_data) {
367                 int* test = (int*)user_data;
368
369                 MA_MEMFREE(test);
370         }
371
372         return TRUE;
373 }
374
375 static void _myaccount_common_popup_cb(void *data, Evas_Object *obj, void *event_info)
376 {
377         myaccount_appdata *ad = (myaccount_appdata *)data;
378
379         if(ad->modal_popup)
380                 evas_object_del(ad->modal_popup);
381         ad->modal_popup = NULL;
382 }
383
384 Evas_Object* _myaccount_common_add_popup(Evas_Object* parent, const char* text, const char* title)
385 {
386         myaccount_appdata *ad = (myaccount_appdata*)myaccount_get_appdata();
387
388         /* multi window >>> */
389 #ifdef _MULTI_WINDOW_ENABLE_
390         MYACCOUNT_DBUG("multi window enabled.\n");
391         ad->modal_popup = ea_center_popup_add(parent);
392 #else
393         MYACCOUNT_DBUG("multi window not enabled.\n");
394         ad->modal_popup = elm_popup_add(parent);
395 #endif
396         evas_object_size_hint_weight_set(ad->modal_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
397
398         elm_object_text_set(ad->modal_popup, text);
399         if(!title)
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);
404
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");
410
411         evas_object_show(ad->modal_popup);
412         return ad->modal_popup;
413 }
414
415 static bool _myaccount_common_synchronise_query_cb(account_h account, void *user_data)
416 {
417         int ret = ACCOUNT_ERROR_NONE;
418         char** tmp_count = (char**)user_data;
419
420         if(!account) {
421                 MYACCOUNT_ERROR("account handle is NULL\n");
422                 return FALSE;
423         }
424
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);
428                 return FALSE;
429         }
430
431         return TRUE;
432 }
433
434 static Eina_Bool _myaccount_common_relaunch_application_timer_cb(void *data)
435 {
436         myaccount_appdata *ad = (myaccount_appdata *)data;
437
438         if(!ad){
439                 return ECORE_CALLBACK_CANCEL;
440         }
441
442         if(ad->relaunch_timer){
443                 ecore_timer_del(ad->relaunch_timer);
444                 ad->relaunch_timer = NULL;
445         }
446
447         app_control_send_launch_request(ad->appsvc_handle, NULL, NULL);
448
449         MYACCOUNT_DBUG("ad->item_selected_state=%d\n",  myaccount_common_get_item_selected_state());
450         myaccount_common_set_item_selected_state(FALSE);
451
452         app_control_destroy(ad->appsvc_handle);
453         ad->appsvc_handle = NULL;
454
455         return ECORE_CALLBACK_CANCEL;
456 }
457
458 static void _myaccount_common_try_relaunch(myaccount_appdata* ad, app_control_h app_control)
459 {
460         if(ad->relaunch_timer){
461                 ecore_timer_del(ad->relaunch_timer);
462                 ad->relaunch_timer = NULL;
463         }
464
465         ad->appsvc_handle = app_control;
466
467         ad->relaunch_timer = ecore_timer_add(MYACCOUNT_RELAUNCH_INTERVAL, _myaccount_common_relaunch_application_timer_cb, ad);
468 }
469
470
471 static int _myaccount_common_launch_samsung_account(myaccount_appdata *ad)
472 {
473         int ret = -1;
474         app_control_h app_control = NULL;
475
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);
479         }
480
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);
484         }
485
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);
489         }
490
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);
495         }
496
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);
500         }
501
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);
505         }
506
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);
510         }
511
512         ret = app_control_send_launch_request(app_control, NULL, NULL);
513
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);
517                 return 0;
518         }
519
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);
523         }
524
525         return ret;
526 }
527
528 static int _myaccount_common_launch_tizen_account(myaccount_appdata *ad)
529 {
530         int ret = -1;
531         app_control_h app_control = NULL;
532
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);
536         }
537
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);
541         }
542
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);
546         }
547
548
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);
553         }
554
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);
558         }
559
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);
563         }
564
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);
568         }
569
570         ret = app_control_send_launch_request(app_control, NULL, NULL);
571
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);
575                 return 0;
576         }
577
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);
581         }
582
583         return ret;
584 }
585
586 static Eina_Bool _myaccount_common_launch_application_timer_cb(void *data)
587 {
588         myaccount_appdata *ad = (myaccount_appdata *)data;
589
590         if(!ad){
591                 return ECORE_CALLBACK_CANCEL;
592         }
593
594         if(ad->progress_timer){
595                 ecore_timer_del(ad->progress_timer);
596                 ad->progress_timer = NULL;
597         }
598
599         MYACCOUNT_DBUG("ad->item_selected_state=%d\n",  myaccount_common_get_item_selected_state());
600
601         return ECORE_CALLBACK_CANCEL;
602 }
603
604 static void _myaccount_common_launch_timer_start(myaccount_appdata *ad)
605 {
606         if(ad->progress_timer){
607                 ecore_timer_del(ad->progress_timer);
608                 ad->progress_timer = NULL;
609         }
610
611         ad->progress_timer = ecore_timer_add(MYACCOUNT_LAUNCH_TIME_OUT, _myaccount_common_launch_application_timer_cb, ad);
612 }
613
614 static bool _myaccount_common_is_email_count_max()
615 {
616         int cnt1 = 0, cnt2 = 0, cnt3 = 0, count = 0;
617
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;
622
623         MYACCOUNT_DBUG("count(%d)cnt1(%d)cnt2(%d)cnt3(%d)", count, cnt1, cnt2, cnt3);
624         if(count >= MYACCOUNT_MAX_EMAIL_COUNT){
625                 return TRUE;
626         }
627         return FALSE;
628 }
629
630 int  myaccount_common_launch_application(MyAccountRequestViewType
631                                                                                                                 request_type,
632                                                                                                                 char *package_name,
633                                                                                                                 char *username,
634                                                                                                                 char *email_sp,
635                                                                                                                 int account_id,
636                                                                                                                 MyAccountProviderType sp_type,
637                                                                                                                 void *data )
638 {
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,};
644
645         if (!ad || !package_name) {
646                 MYACCOUNT_SLOGE("myaccount_common_launch_application: App data=%p, package_name=%p\n",
647                                                         ad, package_name);
648                 return 0;
649         }
650
651         MYACCOUNT_SLOGD("trying to launch (%s)\n", package_name);
652
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);
655
656         if(!strcmp(package_name,SAMSUNG_ACCOUNT_APPID)){
657
658                 _myaccount_common_launch_samsung_account(ad);
659                 _myaccount_common_launch_timer_start(ad);
660
661                 MA_MEMFREE(package_name);
662                 return ret;
663         } else {
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);
667                 }
668
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);
672                 }
673
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);
677                 }
678
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);
683                         }
684
685                 }
686         }
687
688         if (ret != APP_CONTROL_ERROR_NONE)
689                 MYACCOUNT_ERROR("myaccount_common_launch_application: service_set_package failed\n");
690
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);
700                                         }
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);
704                                         }
705
706                                         if(synchronise_count)
707                                                 sync_cnt = atoi(synchronise_count);
708
709                                         if(sync_cnt >= 5) {
710                                                 // draw popup and return
711                                                 char buf[256]={0,};
712
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);
717                                                 if(app_control)
718                                                         app_control_destroy(app_control);
719                                                 return -1;
720                                         }
721                                 }else if(!strcmp(package_name,TIZEN_ACCOUNT_APPID)){
722
723                                         _myaccount_common_launch_tizen_account(ad);
724                                         if(app_control)
725                                                 app_control_destroy(app_control);
726                                         _myaccount_common_launch_timer_start(ad);
727
728                                         MA_MEMFREE(package_name);
729                                         return ret;
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){
733                                         char buf[256]={0,};
734
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);
740                                                 if(app_control)
741                                                         app_control_destroy(app_control);
742                                                 return -1;
743                                         }
744
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 )
749                                         {
750                                                 if( layout == 0 || layout == 1)
751                                                 {
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);
756                                                 }
757                                         }
758                                         MYACCOUNT_SLOGD("### MULTI WINDOW: call with multi win params");
759 #endif
760
761
762                                 }
763
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);
767                                 }
768
769                                 if(sp_type == MYACCOUNT_TYPE_CSC) {
770                                         app_control_add_extra_data(app_control, "http://tizen.org/account/data/csc", email_sp);
771                                 }
772
773                         break;
774                 case MYACCOUNT_REQUEST_VIEW :
775                         if(!username) {
776                                 MYACCOUNT_ERROR("myaccount_common_launch_application: username=%p !!!\n",
777                                                                 username);
778                                 MA_MEMFREE(package_name);
779                                 if(app_control)
780                                         app_control_destroy(app_control);
781                                 return 0;
782                         }
783
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);
788                         }
789
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);
793                         }
794
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);
798                         }
799                         break;
800                 default :
801                         MA_MEMFREE(username);
802                         MA_MEMFREE(package_name);
803                         app_control_destroy(app_control);
804                         return 0;
805         }
806         MYACCOUNT_SLOGD("myaccount_common_launch_application request type=%d, package name = %s\n",
807                                                         request_type, package_name);
808
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);
812         }
813
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);
817         }
818
819
820         MA_MEMFREE(username);
821         MA_MEMFREE(package_name);
822
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);
830                 return 0;
831         }
832
833         app_control_destroy(app_control);
834         _myaccount_common_launch_timer_start(ad);
835
836         return ret;
837 }
838
839
840 Evas_Object *myaccount_common_progress_add(Evas_Object *parent)
841 {
842         if (!parent) {
843                 MYACCOUNT_ERROR("myaccount_common_progress_add: parent is NULL \n");
844                 return NULL;
845         }
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,
851                                                 EVAS_HINT_EXPAND,
852                                                 EVAS_HINT_EXPAND);
853         evas_object_show(progressbar);
854         elm_progressbar_pulse(progressbar, EINA_TRUE);
855         return progressbar;
856 }
857
858 void myaccount_common_delete_modal_popup(Evas_Object *popup)
859 {
860         if (!popup){
861                 MYACCOUNT_ERROR("myaccount_common_delete_modal_popup: popup is NULL \n");
862                 return;
863         }
864         evas_object_del(popup);
865 }
866
867 Eina_Bool myaccount_common_modal_popup_timer_cb(gpointer data)
868 {
869         if (!data) {
870                 MYACCOUNT_ERROR("myaccount_common_modal_popup_timer_cb: data is NULL \n");
871                 return false;
872         }
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;
878         }
879         if (global_data->progress_timer) {
880                 ecore_timer_del(global_data->progress_timer);
881                 global_data->progress_timer = NULL;
882         }
883         return false;
884 }
885
886 int myaccount_common_get_all_account_cnt(int *count)
887 {
888         int error_code = -1;
889         int account_cnt = 0;
890         if (!count) {
891                 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: count ptr is NULL \n");
892                 return error_code;
893         }
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");
897                 return error_code;
898         }
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",
905                                                                 ret);
906                 }
907                 return error_code;
908         }
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",
913                                                 error_code);
914                 return error_code;
915         }
916         return ACCOUNT_ERROR_NONE;
917 }
918
919 static bool _myaccount_common_query_cb(account_h account, void *user_data)
920 {
921         int* tmp_count = (int*)user_data;
922
923         *tmp_count = *tmp_count + 1;
924
925         return TRUE;
926 }
927
928 int myaccount_common_get_account_cnt_by_capability(const char* capability_type, int *count)
929 {
930         int error_code = -1;
931         int account_cnt = 0;
932         if (!count) {
933                 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_capability: count ptr is NULL \n");
934                 return error_code;
935         }
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");
939                 return error_code;
940         }
941
942         error_code = account_query_account_by_capability_type(_myaccount_common_query_cb, capability_type, &account_cnt);
943         if (error_code != ACCOUNT_ERROR_NONE) {
944
945                 *count = 0;
946
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",
951                                                                 ret);
952                 }
953                 return error_code;
954         }
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",
959                                                 error_code);
960                 return error_code;
961         }
962         return ACCOUNT_ERROR_NONE;
963 }
964
965 int myaccount_common_get_account_cnt_by_appid(const char* appid, int *count)
966 {
967         int error_code = -1;
968         int account_cnt = 0;
969         if (!count) {
970                 MYACCOUNT_ERROR("myaccount_common_get_account_cnt_by_appid: count ptr is NULL \n");
971                 return error_code;
972         }
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");
976                 return error_code;
977         }
978
979         error_code = account_query_account_by_package_name(_myaccount_common_query_cb, appid, &account_cnt);
980
981         if (error_code != ACCOUNT_ERROR_NONE) {
982
983                 *count = 0;
984
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",
989                                                                 ret);
990                 }
991                 return error_code;
992         }
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",
997                                                 error_code);
998                 return error_code;
999         }
1000         return ACCOUNT_ERROR_NONE;
1001 }
1002
1003 static int _myaccount_common_pkmgr_return_cb(int req_id, const char *pkg_type,
1004                                         const char *pkg_name,
1005                                         const char *key,
1006                                         const char *val,
1007                                         const void *pmsg,
1008                                         void *data)
1009 {
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);
1011
1012         int error_code = -1;
1013         int count = -1;
1014         if( strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
1015
1016                 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
1017
1018                 if (!appdata) {
1019                         MYACCOUNT_ERROR("App data NULL!!! \n");
1020                         return -1;
1021                 }
1022                 if(appdata->capability_filter && strlen(appdata->capability_filter)){
1023                         if(!strcmp(appdata->capability_filter, "http://tizen.org/account/capability/tizen_email")){
1024                                 int cnt1 = 0;
1025                                 int cnt2 = 0;
1026                                 int cnt3 = 0;
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;
1031                         } else {
1032                                 error_code = myaccount_common_get_account_cnt_by_capability(appdata->capability_filter, &count);
1033                         }
1034
1035                         if (error_code != ACCOUNT_ERROR_NONE) {
1036                                 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
1037                                                                                         error_code);
1038                         }
1039                 } else {
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",
1043                                                                                         error_code);
1044                         }
1045                 }
1046
1047                 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
1048                         if (count > 0) {
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);
1053                                 }
1054                                 if (appdata->account_genlist) {
1055                                         myaccount_list_refresh_item_list(appdata);
1056                                 } else {
1057                                         myaccount_ug_account_list_create((void*)appdata);
1058                                 }
1059                         } else {
1060                                 if (appdata->add_genlist) {
1061                                         evas_object_show(appdata->add_genlist);
1062                                 } else {
1063                                         myaccount_addaccount_create_view(appdata);
1064                                 }
1065                         }
1066                 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
1067                         if (appdata->ug) {
1068                                 ui_gadget_h ug = appdata->ug;
1069                                 error_code = ug_destroy_me(ug);
1070                         }
1071                 } else {
1072                         //MYACCOUNT_WARNING("Unknown mode !!!");
1073                 }
1074                 return 0;
1075         }
1076         return 0;
1077 }
1078
1079 void myaccount_common_listen_pkgmgr_for_pkg_uninstall()
1080 {
1081         myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
1082
1083         if (!appdata) {
1084                 MYACCOUNT_ERROR("App data NULL!!! \n");
1085                 return;
1086         }
1087
1088         int result = 0;
1089         pkgmgr_client *pc = NULL;
1090         pc = pkgmgr_client_new(PC_LISTENING);
1091         if(pc == NULL) {
1092                 MYACCOUNT_ERROR("pc is NULL\n");
1093                 return;
1094         }
1095         appdata->pc = pc;
1096         result = pkgmgr_client_listen_status(pc, _myaccount_common_pkmgr_return_cb, pc);
1097         if(result < 0)
1098         {
1099                 MYACCOUNT_ERROR("status listen failed!\n");
1100                 return;
1101         }
1102 }
1103
1104
1105 int myaccount_common_get_csc_sp_count(const char* capability_filter)
1106 {
1107         dictionary* dic = NULL;
1108         int sp_count = -1;
1109
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"))
1115                         return 0;
1116         }
1117
1118         // check ini file /opt/system/csc-default/data/csc-default-data-email-account.ini
1119         dic = iniparser_load(TIZEN_EMAIL_CSC_FILE_PATH);
1120         if(!dic){
1121                 MYACCOUNT_ERROR("email csc file is not exist\n");
1122                 return FALSE;
1123         }
1124
1125         sp_count = iniparser_getint(dic, TIZEN_EMAIL_CSC_SP_COUNT_KEY, 0);
1126
1127         if(sp_count <= 0) {
1128                 iniparser_freedict(dic);
1129                 MYACCOUNT_ERROR("email sp count 0\n");
1130                 return 0;
1131         }
1132
1133         iniparser_freedict(dic);
1134
1135         return sp_count;
1136 }
1137
1138 bool myaccount_common_account_by_package_name_cb(account_h account,
1139                                                                                                         void *user_data)
1140 {
1141         return false;
1142 }
1143
1144
1145 static bool _myaccount_common_get_account_type_count_cb(account_type_h account_type, void *user_data)
1146 {
1147         int *count = (int*)user_data;
1148         char* type_buf = NULL;
1149         int type_int = -1;
1150
1151         if(account_type == NULL) {
1152                 MYACCOUNT_ERROR(" account type handle is NULL \n");
1153                 return FALSE;
1154         }
1155
1156         account_type_get_app_id(account_type, &type_buf);
1157
1158         if(!type_buf) return FALSE;
1159
1160         if(!strcmp(type_buf, "email-setting-efl")) {
1161                 *count = *count+3; // predefined email count
1162                 MA_MEMFREE(type_buf);
1163                 return TRUE;
1164         }else if(!strcmp(type_buf, "activesync-ui")) {
1165                 *count = *count+1;
1166                 MA_MEMFREE(type_buf);
1167                 return TRUE;
1168         } else if(!strcmp(type_buf, "com.samsung.rcs-im")
1169                                 || !strcmp(type_buf, "ims-service")) {
1170                 MA_MEMFREE(type_buf);
1171                 return TRUE;
1172         }
1173
1174         account_type_get_multiple_account_support(account_type, &type_int);
1175
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);
1180                 return TRUE;
1181         }
1182
1183         *count = *count+1;
1184
1185         MA_MEMFREE(type_buf);
1186
1187         return TRUE;
1188 }
1189
1190
1191 int myaccount_common_get_account_type_count(const char* capability_filter)
1192 {
1193         int ret = -1;
1194         int count = 0;
1195
1196         ret = account_connect();
1197         if(ret != ACCOUNT_ERROR_NONE){
1198                 MYACCOUNT_ERROR("account database cannot be connected\n");
1199                 return 0;
1200         }
1201
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);
1205                 }else {
1206                         account_type_query_by_provider_feature(_myaccount_common_get_account_type_count_cb, capability_filter, (void*)&count);
1207                 }
1208         }
1209         else {
1210                 account_type_foreach_account_type_from_db(_myaccount_common_get_account_type_count_cb, (void*)&count);
1211         }
1212
1213         MYACCOUNT_DBUG("count %d\n", count);
1214
1215         ret = account_disconnect();
1216         if(ret != ACCOUNT_ERROR_NONE){
1217                 MYACCOUNT_ERROR("account database cannot be connected\n");
1218                 return 0;
1219         }
1220
1221         return count;
1222 }
1223