tizen 2.4 release
[apps/home/my-account.git] / src / myaccount_ug_addaccount.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 #ifndef UG_MODULE_API
23 #define UG_MODULE_API __attribute__ ((visibility("default")))
24 #endif
25 #include <Ecore_X.h>
26 #include "myaccount_ug_common.h"
27 #include "myaccount_ug_addaccount.h"
28 #include "myaccount_ug_account_list.h"
29 #include <app.h>
30 #include <app_manager.h>
31 #include <system_settings.h>
32 #include <iniparser.h>
33
34 #define SORT_PRIOR_1 "1_"
35 #define SORT_PRIOR_2 "2_"
36 #define SORT_PRIOR_3 "3_"
37
38 static Elm_Genlist_Item_Class addacc_list_itc;
39
40 static bool _myaccount_addaccount_get_account_type_info_cb(account_type_h account_type, void *user_data);
41
42 static char *__myaccount_addaccount_gl_label_get(void *data,
43                                                                                         Evas_Object *obj, const char *part)
44 {
45         addaccount_list_priv *service = (addaccount_list_priv*)data;
46         char buf[2048]={0,};
47
48         if (!strcmp(part, "elm.text")) {
49                 int value = -1;
50                 int rc = -1;
51                 char *tmp_sp_name = NULL;
52
53                 rc = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &value);
54                 if ( rc != SYSTEM_SETTINGS_ERROR_NONE ) {
55                         MYACCOUNT_DBUG("system_settings_get_value_int fail, rc=%d, value=%d", rc, value);
56                 }
57
58                 tmp_sp_name = elm_entry_utf8_to_markup(service->service_name);
59
60                 if(!strcmp(service->service_name, dgettext(MA_UG_NAME, "IDS_EMAIL_BODY_MICROSOFT_EXCHANGE_ACTIVESYNC"))
61                         && value == SYSTEM_SETTINGS_FONT_SIZE_NORMAL) {
62
63                         if(tmp_sp_name){
64                                 MA_SNPRINTF(buf, sizeof(buf), "<font_size=%d>%s</font_size>", 37, tmp_sp_name);
65                                 MA_MEMFREE(tmp_sp_name);
66                         }
67                         return strdup(buf);
68                 } else {
69                         return tmp_sp_name;
70                 }
71         }
72
73         return NULL;
74 }
75
76 bool myaccount_add_account_by_package_name_cb(account_h account,
77                                                                                                         void *user_data)
78 {
79         return false;
80 }
81
82 static void __myaccount_addaccount_gl_sel(void *data,
83                                                                 Evas_Object *obj, void *event_info)
84 {
85         myaccount_appdata *ad = myaccount_get_appdata();
86         addaccount_list_priv *service = (addaccount_list_priv*)data;
87         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
88         char email_sp[64] = {0,};
89
90         if(!ad) {
91                 MYACCOUNT_ERROR("__myaccount_account_list_gl_sel appdata is NULL\n");
92                 return;
93         }
94
95         MYACCOUNT_DBUG("ad->item_selected_state=%d\n",  myaccount_common_get_item_selected_state());
96
97         if( myaccount_common_get_item_selected_state() ) {
98                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
99                 return;
100         }
101
102         myaccount_common_set_item_selected_state(true);
103
104         if (item != NULL) {
105                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
106
107                 switch(service->sp_type) {
108                         case MYACCOUNT_TYPE_PICASA :
109                         case MYACCOUNT_TYPE_YOUTUBE :
110                         case MYACCOUNT_TYPE_EXCHANGE :
111                                 myaccount_common_launch_application(
112                                                 MYACCOUNT_REQUEST_SIGNIN,
113                                                 strdup(service->package_name),
114                                                 NULL,
115                                                 email_sp,
116                                                 -1,
117                                                 service->sp_type,
118                                                 ad);
119                                 break;
120                         case MYACCOUNT_TYPE_GOOGLE :
121                                 MA_SNPRINTF(email_sp, sizeof(email_sp), "%s", "gmail");
122                                 myaccount_common_launch_application(
123                                                 MYACCOUNT_REQUEST_SIGNIN,
124                                                 strdup(service->package_name),
125                                                 NULL,
126                                                 email_sp,
127                                                 -1,
128                                                 service->sp_type,
129                                                 ad);
130                                 break;
131                         case MYACCOUNT_TYPE_OTHER:
132                                 MA_SNPRINTF(email_sp, sizeof(email_sp), "%s", "others");
133                                 myaccount_common_launch_application(
134                                                 MYACCOUNT_REQUEST_SIGNIN,
135                                                 strdup(service->package_name),
136                                                 NULL,
137                                                 email_sp,
138                                                 service->sp_type,
139                                                 -1,
140                                                 ad);
141                                 break;
142                         case MYACCOUNT_TYPE_CSC:
143                                 MA_SNPRINTF(email_sp, sizeof(email_sp), "%s", service->service_name);
144                                 myaccount_common_launch_application(
145                                                 MYACCOUNT_REQUEST_SIGNIN,
146                                                 strdup(service->package_name),
147                                                 NULL,
148                                                 email_sp,
149                                                 -1,
150                                                 service->sp_type,
151                                                 ad);
152                                 break;
153                         default:
154                                 if(myaccount_common_launch_application(
155                                                         MYACCOUNT_REQUEST_SIGNIN,
156                                                         strdup(service->package_name),
157                                                         NULL,
158                                                         "",
159                                                         -1,
160                                                         service->sp_type,
161                                                         ad) != APP_CONTROL_ERROR_NONE ) {
162                                         MYACCOUNT_ERROR("__myaccount_addaccount_gl_sel : Failed to launch application\n");
163                                         myaccount_common_set_item_selected_state(false);
164
165                                 }
166                                 break;
167                 }
168         }
169         return;
170 }
171
172
173 static Evas_Object *__myaccount_addaccount_icon_get( void *data,
174                                                                                         Evas_Object *obj, const char *part)
175 {
176         char tempbuf[PATH_MAX];
177         Evas_Object *icon = NULL;
178         addaccount_list_priv *service_item = (addaccount_list_priv*)data;
179         Evas_Object *ic = NULL;
180
181         if (!service_item) {
182                 MYACCOUNT_ERROR(" __myaccount_addaccount_icon_get: Data is NULL\n");
183                 return NULL;
184         }
185         memset(tempbuf, 0, sizeof(char)*PATH_MAX);
186
187         if (!strcmp(part, "elm.swallow.icon")) {
188                 if (strlen(service_item->icon_path) > 0) {
189                         MA_STRNCPY(tempbuf, service_item->icon_path, sizeof(tempbuf));
190                 } else {
191                         MA_STRNCPY(tempbuf, "A01_2_Icon_default.png", sizeof(tempbuf));
192                 }
193                 ic = elm_layout_add(obj);
194                 elm_layout_theme_set(ic, "layout", "list/B/type.2", "default");
195
196                 icon = elm_image_add(obj);
197                 if (strstr(tempbuf, "/"))
198                         elm_image_file_set(icon, tempbuf, NULL);
199                 else
200                         elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
201
202                 elm_layout_content_set(ic, "elm.swallow.content", icon);
203         }
204         return ic;
205 }
206
207 void myaccount_addaccount_free_priv_data(myaccount_appdata *appdata)
208 {
209         GList* it = NULL;
210         myaccount_appdata *ad = (myaccount_appdata *)appdata;
211
212         if(!ad) {
213                 MYACCOUNT_ERROR("No appdata!!\n");
214                 return;
215         }
216
217         for(it=ad->sorted_sp_list;it!=NULL;it=g_list_next(it)) {
218                 addaccount_list_priv* tmp = (addaccount_list_priv*)it->data;
219                 MA_MEMFREE(tmp);
220         }
221
222         ad->sorted_sp_list = NULL;
223 }
224
225 static addaccount_list_priv*
226 _myaccount_addaccount_create_priv_item()
227 {
228         addaccount_list_priv* sp_info = NULL;
229         sp_info = (addaccount_list_priv*)calloc(1,sizeof(addaccount_list_priv));
230         if(!sp_info) {
231                 MYACCOUNT_ERROR("memory allocation fail\n");
232                 return NULL;
233         }
234         memset(sp_info, 0x00, sizeof(addaccount_list_priv));
235         return sp_info;
236 }
237
238 static bool _myaccount_addaccount_get_account_type_info_cb(account_type_h account_type, void *user_data)
239 {
240         GList **service_info_list = (GList **)user_data;
241         char* type_buf = NULL;
242         int type_int = -1, ret = -1;
243         addaccount_list_priv* sp_info = NULL;
244
245         if(account_type == NULL) {
246                 MYACCOUNT_ERROR(" account type handle is NULL \n");
247                 return FALSE;
248         }
249
250         sp_info = _myaccount_addaccount_create_priv_item();
251
252         if(sp_info == NULL) {
253                 MYACCOUNT_ERROR(" sp_info is NULL \n");
254                 return FALSE;
255         }
256
257         ret = account_type_get_app_id(account_type, &type_buf);
258         if(ret == ACCOUNT_ERROR_NONE ) {
259                 if(type_buf) {
260                         MA_STRNCPY(sp_info->package_name, type_buf,
261                                                                 sizeof(sp_info->package_name));
262                 } else {
263                         MYACCOUNT_ERROR("No appid available\n");
264                 }
265         } else {
266                 MYACCOUNT_ERROR("account_type_get_app_id return(%x)\n", ret);
267         }
268         MA_MEMFREE(type_buf);
269
270         myaccount_appdata* ad = NULL;
271         ad = myaccount_get_appdata();
272
273         if(ad) {
274                 if(ad->called_from && !strcmp(ad->called_from, "setup_wizard")){
275                         MYACCOUNT_ERROR("FROM SETUP WIZARD\n");
276                         if(!strcmp(sp_info->package_name, SAMSUNG_ACCOUNT_APPID)) {
277                                 MA_MEMFREE(sp_info);
278                                 return TRUE;
279                         } else if(!strcmp(sp_info->package_name, TIZEN_ACCOUNT_APPID)) {
280                                 MA_MEMFREE(sp_info);
281                                 return TRUE;
282                         }
283                 }
284         } else {
285                 MYACCOUNT_ERROR("app data is null\n");
286         }
287
288         if(!strcmp(sp_info->package_name, "email-setting-efl")) {
289                 MA_MEMFREE(sp_info);
290                 /* SLP email */
291                 sp_info = _myaccount_addaccount_create_priv_item();
292                 if ( sp_info == NULL ) {
293                         MYACCOUNT_ERROR("sp_info is NULL\n");
294                         return FALSE;
295                 }
296
297                 MA_STRNCPY(sp_info->service_name,
298                                         dgettext(MA_UG_NAME, "IDS_COM_BODY_EMAIL"),
299                                         sizeof(sp_info->service_name));
300                 MA_SNPRINTF(sp_info->service_sname, sizeof(sp_info->service_sname), "%s%s", SORT_PRIOR_3, sp_info->service_name);
301                 MA_STRNCPY(sp_info->package_name,
302                                         "email-setting-efl",
303                                         sizeof(sp_info->package_name));
304                 //myaccount_common_get_icon_by_name("email",
305                 //                      sp_info->icon_path);
306
307                 ret = account_type_get_icon_path(account_type, &type_buf);
308                 if(ret == ACCOUNT_ERROR_NONE ) {
309                         if(type_buf) {
310                                 MA_STRNCPY(sp_info->icon_path, type_buf,
311                                                                         sizeof(sp_info->icon_path));
312                         } else {
313                                 MYACCOUNT_ERROR("No icon path available\n");
314                         }
315                 } else {
316                         MYACCOUNT_ERROR("account_type_get_app_id return(%x)\n", ret);
317                 }
318                 MA_MEMFREE(type_buf);
319
320                 sp_info->sp_type = MYACCOUNT_TYPE_OTHER;
321                 sp_info->b_tizen_email = TRUE;
322                 *service_info_list = g_list_append(*service_info_list, (void*)sp_info);
323                 return TRUE;
324
325         } else if(!strcmp(sp_info->package_name, "activesync-ui")) {
326                 sp_info->b_tizen_email = TRUE;
327         } else if(!strcmp(sp_info->package_name, "com.samsung.rcs-im")
328                                 || !strcmp(sp_info->package_name, "ims-service")) {
329                 MA_MEMFREE(sp_info);
330                 return TRUE;
331         } else if(!strcmp(sp_info->package_name, GOOGLE_ACCOUNT_APPID)) {
332                 sp_info->b_tizen_email = TRUE;
333         }
334
335         ret = account_type_get_icon_path(account_type, &type_buf);
336         if(ret == ACCOUNT_ERROR_NONE ) {
337                 if(type_buf) {
338                         MA_STRNCPY(sp_info->icon_path, type_buf,
339                                                                 sizeof(sp_info->icon_path));
340                 } else {
341                         MYACCOUNT_ERROR("No icon path available\n");
342                 }
343         } else {
344                 MYACCOUNT_ERROR("account_type_get_app_id return(%x)\n", ret);
345         }
346         MA_MEMFREE(type_buf);
347
348         char* provider_name = NULL;
349
350         if(ad && ad->current_language){
351
352                 if(!strcmp(ad->current_language, "en_US")){
353                         ret = account_type_get_label_by_locale(account_type, "en_GB", &provider_name);
354                 }else{
355                         ret = account_type_get_label_by_locale(account_type, ad->current_language, &provider_name);
356                 }
357         }
358
359         if(ret != ACCOUNT_ERROR_NONE){
360                 /* fallback scenario */
361                 ret = account_type_get_label_by_locale(account_type, "default", &provider_name);
362                 if(ret != ACCOUNT_ERROR_NONE){
363                         MYACCOUNT_SLOGE("No service name(%s)\n", sp_info->package_name);
364                         MA_MEMFREE(sp_info);
365                         return TRUE;
366                 }
367         }
368
369         MA_STRNCPY(sp_info->service_name, provider_name,
370                                                 sizeof(sp_info->service_name));
371
372         MA_MEMFREE(provider_name);
373
374         if(!strcmp(sp_info->package_name, SAMSUNG_ACCOUNT_APPID)) {
375                 MA_SNPRINTF(sp_info->service_sname,
376                                                         sizeof(sp_info->service_sname), "%s%s", SORT_PRIOR_1, sp_info->service_name);
377         } else if(!strcmp(sp_info->package_name, TIZEN_ACCOUNT_APPID)){
378                 MA_SNPRINTF(sp_info->service_sname,
379                                                         sizeof(sp_info->service_sname), "%s%s", SORT_PRIOR_1, sp_info->service_name);
380         } else {
381                 MA_SNPRINTF(sp_info->service_sname,
382                                                         sizeof(sp_info->service_sname), "%s%s", SORT_PRIOR_3, sp_info->service_name);
383         }
384
385         account_type_get_multiple_account_support(account_type, &type_int);
386         sp_info->multiple_account_support = type_int;
387
388         if(type_int == FALSE
389                 && account_query_account_by_package_name(myaccount_add_account_by_package_name_cb, sp_info->package_name, NULL) == ACCOUNT_ERROR_NONE) {
390                 MA_MEMFREE(sp_info);
391                 return TRUE;
392         }
393
394         *service_info_list = g_list_append(*service_info_list, (void*)sp_info);
395
396         return TRUE;
397 }
398
399 static void _myaccount_addaccount_get_account_type_info(const char* capability_filter, GList** sp_info_list)
400 {
401         if(!sp_info_list) {
402                 MYACCOUNT_ERROR("sp_info_list is null\n");
403                 return;
404         }
405
406         if(capability_filter) {
407                 if(!strcmp(capability_filter, "http://tizen.org/account/capability/tizen_email")){
408                         account_type_query_by_provider_feature(_myaccount_addaccount_get_account_type_info_cb, "http://tizen.org/account/capability/email", (void*)sp_info_list);
409                 }else {
410                         account_type_query_by_provider_feature(_myaccount_addaccount_get_account_type_info_cb, capability_filter, (void*)sp_info_list);
411                 }
412         }
413         else {
414                 account_type_foreach_account_type_from_db(_myaccount_addaccount_get_account_type_info_cb, (void*)sp_info_list);
415         }
416 }
417
418 static int _myaccount_ug_addaccount_compare(gconstpointer a, gconstpointer b)
419 {
420         addaccount_list_priv* sp_info_a = (addaccount_list_priv*)a;
421         addaccount_list_priv* sp_info_b = (addaccount_list_priv*)b;
422
423         return g_ascii_strcasecmp(sp_info_a->service_sname, sp_info_b->service_sname);
424 }
425
426 static int __myaccount_addaccount_populate_service_info(myaccount_appdata *ad)
427 {
428         int pkg_count = 0;
429
430         //_myaccount_addaccount_get_csc_sp_list(ad->capability_filter, &ad->sp_info_list);
431         _myaccount_addaccount_get_account_type_info(ad->capability_filter, &ad->sorted_sp_list);
432
433         ad->sorted_sp_list = g_list_sort(ad->sorted_sp_list, (GCompareFunc)_myaccount_ug_addaccount_compare);
434         pkg_count = g_list_length(ad->sorted_sp_list);
435
436         return pkg_count;
437 }
438
439 static void _myaccount_ug_addaccount_gl_realized(void *data, Evas_Object *obj, void *ei)
440 {
441         Elm_Object_Item *it = NULL;
442         int total_count = 0;
443         int index = 0;
444
445         if(!ei) {
446                 MYACCOUNT_ERROR("Realized event info is NULL!!! \n");
447                 return;
448         }
449
450         it = (Elm_Object_Item *)ei;
451
452         total_count = elm_genlist_items_count(obj);
453         index = elm_genlist_item_index_get(it);
454
455         if(index != 0 && index != total_count) {
456                 /*Add account items. index 1 and last are the seperators*/
457                 /* but you don't need to do something. winset support accessibility for default item */
458         } else {
459                 /*Remove access for seperators*/
460                 elm_object_item_access_unregister(ei);
461         }
462
463         if(total_count <= 3) {
464                 //MYACCOUNT_VERBOSE("DO NOTHING only one add account item, total_count(%d) index(%d) !!! \n", total_count, index);
465         } else {
466                 if (index == 1) {
467                         elm_object_item_signal_emit(ei, "elm,state,top", "");
468                 } else if (index == (total_count-2)) {
469                         elm_object_item_signal_emit(ei, "elm,state,bottom", "");
470                 } else  {
471                         elm_object_item_signal_emit(ei, "elm,state,center", "");
472                 }
473         }
474 }
475
476 static void _myaccount_ug_addaccount_gl_deleted(void *data, Evas_Object *obj, void *ei)
477 {
478         MYACCOUNT_ERROR("# _myaccount_ug_addaccount_gl_deleted\n");
479         myaccount_appdata *ad = myaccount_get_appdata();
480         myaccount_addaccount_free_priv_data(ad);
481 }
482
483 static Evas_Object * __myaccount_addaccount_create_genlist_layout(
484                                                                                                 Evas_Object *navi_bar)
485 {
486         Evas_Object *genlist;
487
488         addacc_list_itc.item_style = "type1";
489         addacc_list_itc.func.text_get = __myaccount_addaccount_gl_label_get;
490         addacc_list_itc.func.content_get = __myaccount_addaccount_icon_get;
491         addacc_list_itc.func.state_get = NULL;
492         addacc_list_itc.func.del = NULL;
493
494         genlist = elm_genlist_add(navi_bar);
495         evas_object_smart_callback_add(genlist, "realized", _myaccount_ug_addaccount_gl_realized, NULL);
496         evas_object_smart_callback_add(genlist, "delete", _myaccount_ug_addaccount_gl_deleted, NULL);
497         return genlist;
498 }
499
500 static Evas_Object *__myaccount_addaccount_append_genlist_item(
501                                                                                         myaccount_appdata *ad, Evas_Object *genlist, int count)
502 {
503         if (ad == NULL) {
504                 MYACCOUNT_ERROR("__myaccount_addaccount_create_genlist returns NULL\n");
505                 return NULL;
506         }
507
508         GList* iter;
509
510         for(iter=ad->sorted_sp_list;iter!=NULL;iter=g_list_next(iter)) {
511                 addaccount_list_priv* tmp = (addaccount_list_priv*)iter->data;
512
513                 if(ad->capability_filter) {
514                         /* Samsung account exception */
515                         if(tmp->sp_type == MYACCOUNT_TYPE_SAMSUNG
516                                 && (!strcmp(ad->capability_filter, "http://tizen.org/account/capability/memo")
517                                         || !strcmp(ad->capability_filter, "http://tizen.org/account/capability/contact")
518                                         || !strcmp(ad->capability_filter, "http://tizen.org/account/capability/calendar"))) {
519                                 elm_genlist_item_append(genlist, &addacc_list_itc,
520                                                 (void *)tmp, NULL,
521                                                 ELM_GENLIST_ITEM_NONE,
522                                                 __myaccount_addaccount_gl_sel,
523                                                 (void *)tmp);
524                         } else if( !strcmp(ad->capability_filter, "http://tizen.org/account/capability/tizen_email")) { /* Tizen email exception */
525                                 if(tmp->b_tizen_email) {
526                                         elm_genlist_item_append(genlist, &addacc_list_itc,
527                                                         (void *)tmp, NULL,
528                                                         ELM_GENLIST_ITEM_NONE,
529                                                         __myaccount_addaccount_gl_sel,
530                                                         (void *)tmp);
531                                 }
532                         } else {
533                                 elm_genlist_item_append(genlist, &addacc_list_itc,
534                                                 (void *)tmp, NULL,
535                                                 ELM_GENLIST_ITEM_NONE,
536                                                 __myaccount_addaccount_gl_sel,
537                                                 (void *)tmp);
538                         }
539                 } else {
540                         elm_genlist_item_append(genlist, &addacc_list_itc,
541                                         (void *)tmp, NULL,
542                                         ELM_GENLIST_ITEM_NONE,
543                                         __myaccount_addaccount_gl_sel,
544                                         (void *)tmp);
545                 }
546
547         }
548
549         elm_genlist_block_count_set(genlist, count);
550
551         return genlist;
552 }
553
554 static Evas_Object *__myaccount_addaccount_create_genlist(
555                                                                                         myaccount_appdata *ad, int count)
556 {
557         Evas_Object *genlist;
558
559         if (ad == NULL) {
560                 MYACCOUNT_ERROR("__myaccount_addaccount_create_genlist returns NULL\n");
561                 return NULL;
562         }
563
564         genlist = __myaccount_addaccount_create_genlist_layout(ad->navi_bar);
565
566         return __myaccount_addaccount_append_genlist_item(ad, genlist, count);
567 }
568
569 static Evas_Object *__myaccount_addaccount_no_account(myaccount_appdata *ad, int count)
570 {
571         Evas_Object *no_account;
572         char no_content_text[100] = {0,};
573
574         if (ad == NULL) {
575                 MYACCOUNT_ERROR("__myaccount_addaccount_no_account returns NULL\n");
576                 return NULL;
577         }
578         no_account = elm_layout_add(ad->navi_bar);
579         elm_layout_file_set(no_account, MA_NO_ACCOUNT_EDJ_NAME, "nocontents_layout");
580
581         elm_layout_theme_set(no_account, "layout", "nocontents", "default");
582         evas_object_size_hint_weight_set(no_account, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
583         evas_object_size_hint_align_set(no_account, EVAS_HINT_FILL, EVAS_HINT_FILL);
584
585         MA_SNPRINTF(no_content_text, sizeof(no_content_text), "<font=Sans:style=Regular color=#000000>%s</font>", dgettext(MA_UG_NAME, "IDS_MA_NPBODY_NO_ACCOUNT_PROVIDER_APPS_INSTALLED"));
586         elm_object_part_text_set(no_account, "elm.text", no_content_text);
587
588         /* left below line to future use */
589         //elm_object_part_text_set(no_account, "elm.help.text", "Please install account app to add account");
590         elm_layout_signal_emit(no_account, "text,disabled", "");
591         elm_layout_signal_emit(no_account, "align.center", "elm");
592
593         return no_account;
594 }
595
596 Eina_Bool __myaccount_addaccount_quit_cb( void *data,
597                                                         Elm_Object_Item *it )
598 {
599         int error_code = 0;
600         myaccount_appdata *priv = (myaccount_appdata*)data;
601         int count = -1;
602
603         MYACCOUNT_DBUG("Add account list quit\n");
604
605         if (!priv) {
606                 MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb callback user data is null!!!\n");
607                 return EINA_TRUE;
608         }
609
610         if(priv->capability_filter && strlen(priv->capability_filter)){
611
612                 if(!strcmp(priv->capability_filter, "http://tizen.org/account/capability/tizen_email")){
613                         int cnt1 = 0;
614                         int cnt2 = 0;
615                         int cnt3 = 0;
616                         error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
617                         error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
618                         error_code = myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID, &cnt3);
619                         count = cnt1+cnt2+cnt3;
620                 } else {
621                         error_code = myaccount_common_get_account_cnt_by_capability(priv->capability_filter, &count);
622                 }
623
624                 if (error_code != ACCOUNT_ERROR_NONE) {
625                         MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
626                                                                                 error_code);
627                 }
628         } else {
629                 error_code = myaccount_common_get_all_account_cnt(&count, false);
630                 if (error_code != ACCOUNT_ERROR_NONE) {
631                         MYACCOUNT_ERROR("__myaccount_addaccount_quit_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
632                                                                                 error_code);
633                 }
634         }
635
636         /*destroy add genlist before pop it*/
637
638         if ((count > 0) && (priv->eMode == eMYACCOUNT_ACCOUNT_LIST)) {
639                 MYACCOUNT_DBUG("# count > 0, elm_naviframe_item_pop return EINA_TRUE\n");
640                 if (priv->add_genlist) {
641                         evas_object_del(priv->add_genlist);
642                         priv->add_genlist = NULL;
643                 }
644                 priv->prev_app_cnt = 0;
645
646                 return EINA_TRUE;
647         }
648
649         if (priv->ug) {
650                 ui_gadget_h ug = priv->ug;
651                 ug_destroy_me(ug);
652                 return EINA_FALSE;
653         }
654
655         if (priv->add_genlist) {
656                 evas_object_del(priv->add_genlist);
657                 priv->add_genlist = NULL;
658         }
659         priv->prev_app_cnt = 0;
660         MYACCOUNT_DBUG("Add account list quit end\n");
661
662         return EINA_TRUE;
663 }
664
665 void myaccount_addaccount_back_key_cb(void *data, Evas_Object *obj, void *event_info)
666 {
667         myaccount_appdata *ad = (myaccount_appdata*)data;
668         elm_naviframe_item_pop(ad->navi_bar);
669 }
670
671 void myaccount_addaccount_genlist_create(void *data)
672 {
673         myaccount_appdata *ad = data;
674         Evas_Object *genlist;
675         Evas_Object *l_button;
676         int service_cnt=0;
677
678         if (ad == NULL) {
679                 MYACCOUNT_ERROR("myaccount_addaccount_genlist_create myaccount_appdata is null\n");
680                 return;
681         }
682
683         service_cnt = __myaccount_addaccount_populate_service_info(ad);
684         ad->prev_app_cnt = service_cnt;
685         if(service_cnt > 0){
686                 ad->add_genlist = genlist = __myaccount_addaccount_create_genlist(ad, service_cnt);
687         }else{
688                 /* If there's no account provider, display no account view */
689                 ad->add_genlist = genlist = __myaccount_addaccount_no_account(ad, service_cnt);
690         }
691
692         l_button = elm_button_add(ad->navi_bar);
693         elm_object_style_set(l_button , "naviframe/back_btn/default");
694         evas_object_smart_callback_add(l_button, "clicked", myaccount_addaccount_back_key_cb, ad);
695
696         ad->add_nf_it = elm_naviframe_item_push(ad->navi_bar,
697                                         dgettext(MA_UG_NAME, "IDS_MA_HEADER_ADD_ACCOUNT"),
698                                         l_button, NULL, genlist, NULL);
699         MYACCOUNT_DBUG("#elm_naviframe_item_pushed..");
700         elm_naviframe_item_pop_cb_set(ad->add_nf_it, __myaccount_addaccount_quit_cb, (void*)ad);
701 }
702
703 void myaccount_addaccount_create_view(myaccount_appdata *ad)
704 {
705         MYACCOUNT_DBUG("myaccount_addaccount_create_view start\n");
706         if (ad->add_genlist == NULL) {
707                 MYACCOUNT_DBUG("Add account list start\n");
708                 myaccount_addaccount_free_priv_data(ad);
709                 myaccount_addaccount_genlist_create(ad);
710         }
711 }
712
713 void myaccount_addaccount_refresh_item_list(myaccount_appdata *ad)
714 {
715         int count = 0;
716
717         if(!ad) {
718                 MYACCOUNT_ERROR("no appdata!\n");
719                 return;
720         }
721
722         if(!ad->add_genlist) {
723                 MYACCOUNT_ERROR("no genlist!\n");
724                 return;
725         }
726
727         /*check if app count changed or not, if not changed, then do not refresh current view*/
728         int curr_cnt = 0;
729         GList *sp_list = NULL;
730         _myaccount_addaccount_get_account_type_info(ad->capability_filter, &sp_list);
731         curr_cnt = g_list_length(sp_list);
732         int valid_cnt = 0;
733         if (ad->prev_app_cnt == curr_cnt) {
734                 int i = 0;
735                 for (i = 0; i < curr_cnt; i++) {
736                         addaccount_list_priv *info = g_list_nth_data(sp_list, i);
737                         if (!info)
738                                 continue;
739                         int j = 0;
740                         for (j = 0; j < curr_cnt; j++) {
741                                 addaccount_list_priv *prev_info = g_list_nth_data(ad->sorted_sp_list, j);
742                                 if (!prev_info)
743                                         continue;
744                                 if (!g_strcmp0(prev_info->service_name, info->service_name)) {
745                                         valid_cnt++;
746                                         //MYACCOUNT_DBUG("info->service_name[%s]", info->service_name);
747                                 }
748                         }
749                 }
750         }
751         /*free temp data*/
752         GList* it = NULL;
753         for(it=sp_list;it!=NULL;it=g_list_next(it)) {
754                 addaccount_list_priv* tmp = (addaccount_list_priv*)it->data;
755                 MA_MEMFREE(tmp);
756         }
757         MYACCOUNT_DBUG("ad->prev_app_cnt[%d], valid_cnt[%d]", ad->prev_app_cnt, valid_cnt);
758         if (ad->prev_app_cnt == valid_cnt) {
759                 MYACCOUNT_DBUG("no change, no need to refresh genlist items!\n");
760                 return;
761         }
762
763         elm_genlist_clear(ad->add_genlist);
764         myaccount_addaccount_free_priv_data(ad);
765         count = __myaccount_addaccount_populate_service_info(ad);
766         ad->prev_app_cnt = count;
767         __myaccount_addaccount_append_genlist_item(ad, ad->add_genlist, count);
768
769         return;
770 }
771