ab9f69dac174ae5a1812ee961276ba35fc9dabb2
[apps/home/my-account.git] / src / myaccount_ug_account_list.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 <Ecore_X.h>
23 #include <vconf.h>
24 #include "myaccount_ug_account_list.h"
25 #include "myaccount_ug_addaccount.h"
26 #include "myaccount_ug_common.h"
27
28 #define SORT_PRIOR_1 "1_"
29 #define SORT_PRIOR_2 "2_"
30 #define SORT_PRIOR_3 "3_"
31
32 static Elm_Genlist_Item_Class account_list_itc;
33
34 static int account_index = 0;
35
36 #define TOOLBAR_HEIGHT          0
37
38 //static void _myaccount_account_list_free_capdata(gpointer data,       gpointer user_data);
39 static void __myaccount_account_list_addaccount_cb( void *data,
40                                                                                         Evas_Object *obj, void* event_info );
41 static void _myaccount_ug_account_list_layout_cb(ui_gadget_h ug,
42                                                                                         enum ug_mode mode, void *priv);
43 static void _myaccount_ug_account_list_result_cb(ui_gadget_h ug,
44                                                                                         app_control_h app_control, void *priv);
45 static void _myaccount_ug_account_list_destroy_cb(ui_gadget_h ug,
46                                                                                 void *priv);
47 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
48                                                                                 int count);
49 static void __rotate_more_ctxpopup_cb(void *data, Evas_Object *obj, void *event_info);
50
51 static char *__myaccount_account_list_get_capablity_string_value(const char* capability_type)
52 {
53         if (!strcmp(capability_type, "http://tizen.org/account/capability/contact"))
54                 return dgettext(MA_UG_NAME, "IDS_PB_TAB_CONTACTS");
55         else if (!strcmp(capability_type, "http://tizen.org/account/capability/calendar"))
56                 return dgettext("sys_string", "IDS_COM_BODY_S_PLANNER");
57         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/photo"))
58                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_GALLERY");
59         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/video"))
60                 return dgettext(MA_UG_NAME, "IDS_ST_BODY_VIDEOS");
61         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/email"))
62                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_EMAIL");
63         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/post"))
64                 return dgettext(MA_UG_NAME, "IDS_TW_BODY_POST_TWITTER");
65         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/voip"))
66                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_VOIP_CALL");
67         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/samsungapps"))
68                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_SAMSUNG_APPS_T_MAINMENU");
69         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/mobiletracker"))
70                 return dgettext(MA_UG_NAME, "IDS_ST_BODY_MOBILE_TRACKER");
71         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/task"))
72                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_TASK");
73 #ifdef _FEATURE_SMEMO_ENABLE
74         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/memo"))
75                 return dgettext(MA_UG_NAME, "IDS_COM_OPT_S_MEMO");
76 #else
77         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/memo"))
78                 return NULL;
79 #endif
80         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/synchronise"))
81                 return dgettext(MA_UG_NAME, "IDS_SYNCML_BODY_SYNC_SERVER");
82         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/docomo"))
83                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_CALENDAR_T_MAINMENU_ABB2");
84         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/music"))
85                 return dgettext("sys_string", "IDS_COM_BODY_MUSIC");
86         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/internet"))
87                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_INTERNET");
88         else if (!strcmp(capability_type ,"http://tizen.org/account/capability/message"))
89                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_MESSAGES");
90         else
91                 return NULL;//return dgettext(MA_UG_NAME, "IDS_COM_POP_UNKNOWN");
92 }
93
94 /*
95 static void _myaccount_account_list_free_capdata(gpointer data, gpointer user_data)
96 {
97         if(data == NULL)
98                 return;
99         myaccount_capability_data * cap_data= (myaccount_capability_data*)data;
100
101         MA_MEMFREE(cap_data->type);
102         MA_MEMFREE(cap_data);
103 }
104 */
105
106 bool _myaccount_account_list_get_capablity_text(const char* capability_type,
107                                                                                 account_capability_state_e capability_state,
108                                                                                 void *user_data)
109 {
110         /* get capabilities of the account*/
111         char *capability_string = NULL;
112         myaccount_list_priv *account_info = (myaccount_list_priv*)user_data;
113         char *capability_textbuf = account_info->capability;
114
115         if(!account_info) {
116                 return false;
117         }
118
119         myaccount_capability_data *cap_data = (myaccount_capability_data*)malloc(sizeof(myaccount_capability_data));
120         if (!cap_data) {
121                 MYACCOUNT_ERROR("malloc failed\n");
122                 return true;
123         }
124         memset(cap_data, 0, sizeof(myaccount_capability_data));
125
126         cap_data->type = strdup(capability_type);
127         cap_data->state = capability_state;
128
129         account_info->capablity_list = g_slist_append(account_info->capablity_list, (gpointer)cap_data);
130
131         if (capability_state == ACCOUNT_CAPABILITY_ENABLED) {
132                 capability_string = __myaccount_account_list_get_capablity_string_value(
133                                                                                                                         capability_type);
134
135                 /* Synchronise capability string exception, wylee */
136                 if(!strcmp(account_info->package_name, "setting-synchronise-efl")){
137                         MA_SNPRINTF(capability_textbuf, 127, "%s", dgettext(MA_UG_NAME, "IDS_SYNCML_BODY_SYNC_SERVER"));
138                 } else {
139                         if (capability_string != NULL) {
140                                 if(strlen(capability_textbuf) > 0) {
141                                         char *temp2 = strdup(capability_textbuf);
142                                         if (!temp2) {
143                                                 MYACCOUNT_ERROR("strdup returns NULL\n");
144                                                 return false;
145                                         }
146                                         MA_SNPRINTF(capability_textbuf, 127, "%s, %s", temp2, capability_string);
147                                         MA_MEMFREE(temp2);
148                                 } else {
149                                         MA_SNPRINTF(capability_textbuf, 127, "%s%s", capability_textbuf,
150                                                                                                                                 capability_string);
151                                 }
152                         }
153                 }
154         }
155
156         return true;
157 }
158
159 void myaccount_account_list_free_priv_data(myaccount_appdata *appdata)
160 {
161         GList* it = NULL;
162         myaccount_appdata *ad = (myaccount_appdata *)appdata;
163
164         if(!ad) {
165                 MYACCOUNT_ERROR("No appdata!!\n");
166                 return;
167         }
168
169         for(it=ad->sorted_account_list;it!=NULL;it=g_list_next(it)) {
170                 myaccount_list_priv* tmp = (myaccount_list_priv*)it->data;
171                 MA_MEMFREE(tmp);
172         }
173
174         if(ad->account_info_list) {
175                 g_list_free(ad->account_info_list);
176                 ad->account_info_list = NULL;
177         }
178
179         ad->sorted_account_list = NULL;
180
181 }
182
183 static myaccount_list_priv*
184 _myaccount_account_list_create_priv_item()
185 {
186         myaccount_list_priv* account_info = NULL;
187         account_info = (myaccount_list_priv*)calloc(1,sizeof(myaccount_list_priv));
188         if(!account_info) {
189                 MYACCOUNT_ERROR("memory allocation fail\n");
190         }
191         return account_info;
192 }
193
194
195 bool _myaccount_account_list_account_info_cb(account_h account,
196                                                                                                                 void *user_data)
197 {
198         GList **account_info_list = (GList **)user_data;
199         int error_code = -1;
200         myaccount_list_priv* account_info = NULL;
201
202         if (!account) {
203                 MYACCOUNT_ERROR("_myaccount_account_list_account_info_cb:account handle is NULL\n");
204                 return false;
205         } else {
206
207                 account_info = _myaccount_account_list_create_priv_item();
208                 if( account_info == NULL ) {
209                         MYACCOUNT_ERROR("_myaccount_account_list_create_priv_item fail\n");
210                         return false;
211                 }
212
213                 char *temptxt = NULL;
214                 int id = -1;
215                 account_secrecy_state_e secret;
216
217                 error_code = account_get_user_name(account, &temptxt);
218                 if (error_code != ACCOUNT_ERROR_NONE) {
219                         MYACCOUNT_ERROR("account_get_user_name: Failed \n");
220                 } else if (temptxt && strlen(temptxt)) {
221                         MA_STRNCPY(account_info->username, temptxt,
222                                                                         sizeof(account_info->username));
223                 }
224                 MA_MEMFREE(temptxt);
225                 error_code = account_get_display_name(account, &temptxt);
226                 if (error_code != ACCOUNT_ERROR_NONE) {
227                         MYACCOUNT_ERROR("account_get_display_name: Failed \n");
228                 } else if (temptxt && strlen(temptxt)) {
229                         MA_STRNCPY(account_info->display_name, temptxt,
230                                                                         sizeof(account_info->display_name));
231                 }
232                 MA_MEMFREE(temptxt);
233                 error_code = account_get_email_address(account, &temptxt);
234                 if (error_code != ACCOUNT_ERROR_NONE) {
235                         MYACCOUNT_ERROR("account_get_email_address: Failed \n");
236                 } else if (temptxt && strlen(temptxt)) {
237                         MA_STRNCPY(account_info->email_address, temptxt,
238                                                                         sizeof(account_info->email_address));
239                 }
240
241                 MA_MEMFREE(temptxt);
242                 error_code = account_get_package_name(account, &temptxt);
243                 if (error_code != ACCOUNT_ERROR_NONE) {
244                         MYACCOUNT_ERROR("account_get_package_name: Failed \n");
245                 } else if (temptxt && strlen(temptxt)) {
246                         MA_STRNCPY(account_info->package_name, temptxt,
247                                                                         sizeof(account_info->package_name));
248                         if(!strcmp(temptxt, TIZEN_EMAIL_APPID) || !strcmp(temptxt, EXCHANGE_UI_APPID) ||!strcmp(temptxt, GOOGLE_ACCOUNT_APPID)){
249                                 account_info->b_tizen_email = TRUE;
250                         } else {
251                                 account_info->b_tizen_email = FALSE;
252                         }
253
254                 }
255                 MA_MEMFREE(temptxt);
256                 error_code = account_get_account_id(account, &id);
257                 if (error_code != ACCOUNT_ERROR_NONE) {
258                         MYACCOUNT_ERROR("account_get_account_id: Failed \n");
259                 } else if (id > 0) {
260                         account_info->account_id = id;
261                 }
262                 error_code = account_get_secret(account, &secret);
263                 if (error_code != ACCOUNT_ERROR_NONE) {
264                         MYACCOUNT_ERROR("account_get_secret: Failed \n");
265                 } else {
266                         account_info->secret = secret;
267                 }
268                 error_code = account_get_domain_name(account, &temptxt);
269                 if (error_code != ACCOUNT_ERROR_NONE) {
270                         MYACCOUNT_ERROR("account_get_domain_name: Failed \n");
271                 } else if (temptxt && strlen(temptxt)) {
272                         MA_STRNCPY(account_info->domain_name, temptxt,
273                                                                         sizeof(account_info->domain_name));
274                 }
275
276                 MA_MEMFREE(temptxt);
277                 error_code = account_get_icon_path(account, &temptxt);
278                 if (error_code != ACCOUNT_ERROR_NONE) {
279                                 MYACCOUNT_ERROR("account_get_icon_path: Failed \n");
280                 } else if (temptxt && strlen(temptxt)) {
281                         MA_STRNCPY(account_info->icon_path, temptxt, sizeof(account_info->icon_path));
282                 } else {
283
284                         account_type_h account_type = NULL;
285
286                         error_code = account_type_create(&account_type);
287
288                         if(error_code == ACCOUNT_ERROR_NONE){
289
290                                 error_code = account_type_query_by_app_id((const char*)account_info->package_name, &account_type);
291
292                                 if(error_code == ACCOUNT_ERROR_NONE){
293                                         char* provider_icon = NULL;
294                                         error_code = account_type_get_icon_path(account_type, &provider_icon);
295
296                                         if(error_code != ACCOUNT_ERROR_NONE){
297                                                 MYACCOUNT_ERROR("account provider icon get Failed \n");
298                                         } else if (provider_icon && strlen(provider_icon)) {
299                                                 MA_STRNCPY(account_info->icon_path, provider_icon, sizeof(account_info->icon_path));
300                                         } else {
301                                                 MYACCOUNT_DBUG("account provider icon is not set \n");
302                                         }
303                                         MA_MEMFREE(provider_icon);
304                                 }
305
306                                 error_code = account_type_destroy(account_type);
307                                 if(error_code != ACCOUNT_ERROR_NONE){
308                                         MYACCOUNT_ERROR("type_destroy destroy Failed \n");
309                                 }
310                         }
311                 }
312
313                 MA_MEMFREE(temptxt);
314                 if(!strlen(account_info->icon_path))
315                         myaccount_common_get_icon_by_name(account_info->domain_name ,
316                                                                                                         account_info->icon_path);
317
318                 error_code = account_get_sync_support(account,
319                                                 (account_sync_state_e *)&(account_info->sync_status));
320                 if (error_code != ACCOUNT_ERROR_NONE) {
321                         MYACCOUNT_ERROR("account_get_sync_support: Failed \n");
322                 }
323
324                 error_code = account_get_capability_all(account,
325                                                                         _myaccount_account_list_get_capablity_text,
326                                                                         (void *)account_info);
327                 if (error_code != ACCOUNT_ERROR_NONE)
328                         MYACCOUNT_ERROR("account_get_capability: Failed \n");
329
330                 /* for SA(01), TA(02) sorting */
331                 MYACCOUNT_DBUG("(%s)\n", strchr(account_info->package_name, '.'));
332                 if(!strcmp(account_info->package_name, SAMSUNG_ACCOUNT_APPID)) {
333                         MA_SNPRINTF(account_info->service_sname,
334                                                                 sizeof(account_info->service_sname), "%s%s", SORT_PRIOR_1, strchr(account_info->package_name, '.'));
335                 } else if(!strcmp(account_info->package_name, TIZEN_ACCOUNT_APPID)){
336                         MA_SNPRINTF(account_info->service_sname,
337                                                                 sizeof(account_info->service_sname), "%s%s", SORT_PRIOR_1, strchr(account_info->package_name, '.'));
338                 } else {
339                         /* No need to sort, sort as the order user register */
340                         MA_SNPRINTF(account_info->service_sname,
341                                                                 sizeof(account_info->service_sname), "%s", SORT_PRIOR_3);
342                 }
343
344                 *account_info_list = g_list_append(*account_info_list, (void*)account_info);
345                 account_index++;
346         }
347         return true;
348 }
349
350 static int _myaccount_ug_account_list_compare(gconstpointer a, gconstpointer b)
351 {
352         myaccount_list_priv* account_info_a = (myaccount_list_priv*)a;
353         myaccount_list_priv* account_info_b = (myaccount_list_priv*)b;
354
355         return g_ascii_strcasecmp(account_info_a->service_sname, account_info_b->service_sname);
356 }
357
358 static int __myaccount_account_list_populate_account_info(myaccount_appdata *ad)
359 {
360         int error_code = -1;
361         int count=0;
362
363         error_code = account_connect();
364         if (error_code != ACCOUNT_ERROR_NONE)
365                 MYACCOUNT_ERROR("account_connect: Failed \n");
366
367         account_foreach_account_from_db(_myaccount_account_list_account_info_cb,
368                                                                                         &ad->account_info_list);
369         error_code = account_disconnect();
370         if (error_code != ACCOUNT_ERROR_NONE)
371                 MYACCOUNT_ERROR("account_disconnect: Failed \n");
372
373         ad->sorted_account_list = g_list_sort(ad->account_info_list, (GCompareFunc)_myaccount_ug_account_list_compare);
374         count = g_list_length(ad->sorted_account_list);
375
376         return count;
377 }
378
379 Eina_Bool myaccount_account_list_quit_cb(void *data, Elm_Object_Item *it)
380 {
381         int error_code=0;
382         myaccount_appdata *priv = (myaccount_appdata*)data;
383
384         MYACCOUNT_DBUG("account list view quit\n");
385
386         if (!priv) {
387                 MYACCOUNT_ERROR("myaccount_account_list_quit_cb callback user data is null!!!\n");
388                 return EINA_TRUE;
389         }
390
391         if(priv->popup != NULL)
392         {
393                 evas_object_del(priv->popup);
394                 priv->popup = NULL;
395         }
396
397         myaccount_account_list_free_priv_data(priv);
398
399         account_index = 0;
400
401         if (priv->ug) {
402                 ui_gadget_h ug = priv->ug;
403                 error_code = ug_destroy_me(ug);
404                 MYACCOUNT_SLOGD("myaccount_account_list_quit_cb callback : return = %d!!!\n",
405                                                                                                 error_code);
406                 return EINA_FALSE;
407         }
408         return EINA_TRUE;
409 }
410
411 void myaccount_account_list_back_key_cb(void *data, Evas_Object *obj, void *event_info)
412 {
413         elm_naviframe_item_pop(obj);
414 }
415
416 static void __myaccount_account_list_addaccount_cb( void *data,
417                                                                                         Evas_Object *obj, void *event_info )
418 {
419         myaccount_appdata *priv = (myaccount_appdata*)data;
420         myaccount_addaccount_create_view(priv);
421         if(priv->popup != NULL)
422         {
423                 evas_object_del(priv->popup);
424                 priv->popup = NULL;
425         }
426 }
427
428 static char *__myaccount_account_list_gl_label_get(void *data,
429                                                                                 Evas_Object *obj, const char *part)
430 {
431         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
432         char domain_name_lower[128] = {0,};
433
434         if (!account_info_item) {
435                 MYACCOUNT_ERROR(" __myaccount_account_list_gl_label_get: Data is NULL\n");
436                 return NULL;
437         }
438
439         if (!strcmp(part, "elm.text.main.left.top")) {
440                 myaccount_common_lowercase(account_info_item->domain_name,
441                                                                                                 domain_name_lower);
442
443                 if (strlen(account_info_item->display_name) > 0)
444                         return strdup(account_info_item->display_name);
445                 else if (strlen(account_info_item->email_address) > 0)
446                         return strdup(account_info_item->email_address);
447                 else if (strlen(account_info_item->username) > 0)
448                         return strdup(account_info_item->username);
449                 else
450                         return strdup("Unknown");
451         } else if (!strcmp(part, "elm.text.sub.left.bottom")) {
452                 if (strlen(account_info_item->capability) <=0 )
453                         return strdup(dgettext(MA_UG_NAME, "IDS_MA_BODY_SIGNED_IN"));
454                 else
455                         return strdup(account_info_item->capability);
456         }
457
458         return NULL;
459 }
460
461
462 static Evas_Object *__myaccount_account_list_gl_icon_get(void *data,
463                                                                                         Evas_Object *obj, const char *part)
464 {
465         char tempbuf[PATH_MAX];
466         Evas_Object *icon = NULL;
467         int auto_sync_status = -1;
468         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
469         char *color = NULL;
470         Evas_Object *ic = NULL;
471
472         if (!account_info_item) {
473                 MYACCOUNT_ERROR("__myaccount_account_list_gl_icon_get: Data is NULL\n");
474                 return NULL;
475         }
476         memset(tempbuf, 0, sizeof(char)*PATH_MAX);
477
478         if (!strcmp(part, "elm.icon.1")) {
479                 if (strlen(account_info_item->icon_path) > 0) {
480                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", account_info_item->icon_path);
481                 } else {
482                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", "A01_2_Icon_default.png");
483                 }
484
485                 ic = elm_layout_add(obj);
486                 elm_layout_theme_set(ic, "layout", "list/B/type.2", "default");
487
488                 icon = elm_image_add(obj);
489                 if (strstr(tempbuf, "/"))
490                         elm_image_file_set(icon, tempbuf, NULL);
491                 else
492                         elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
493
494                 elm_layout_content_set(ic, "elm.swallow.content", icon);
495         }
496
497         if (!strcmp(part, "elm.icon.2")) {
498                 if (account_info_item->sync_status == ACCOUNT_SYNC_NOT_SUPPORT)
499                         return NULL;
500                 if (vconf_get_int(VCONFKEY_ACCOUNT_AUTO_SYNC_STATUS_INT,
501                                                 &auto_sync_status) < 0) {
502                         MYACCOUNT_ERROR("Fail to getVCONFKEY_ACCOUNT_AUTO_SYNC_STATUS_INT\n");
503                 }
504                 MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", "account_icon_syncing.png");
505                 color = "AO001";
506
507                 MYACCOUNT_DBUG("color:[%s]",color);
508                 if(strlen(tempbuf) > 0) {
509                         ic = elm_layout_add(obj);
510                         elm_layout_theme_set(ic, "layout", "list/C/type.3", "default");
511
512                         icon = elm_image_add(obj);
513                         if (strstr(tempbuf, "/"))
514                                 elm_image_file_set(icon, tempbuf, NULL);
515                         else
516                                 elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
517
518                         int ret = 0;
519                         if (color) {
520                                 ret = ea_theme_object_color_set(icon, color);
521                                 MYACCOUNT_DBUG("ret[%d]", ret);
522                         }
523                         elm_layout_content_set(ic, "elm.swallow.content", icon);
524                 }
525         }
526
527         return ic;
528 }
529
530 static void _myaccount_ug_account_list_layout_cb(ui_gadget_h ug,
531                                                                                 enum ug_mode mode, void *priv)
532 {
533         Evas_Object *base;
534         myaccount_appdata *ad;
535
536         if (!ug||!priv) {
537                 MYACCOUNT_ERROR("layout cb error ug=%p, priv=%p\n", ug, priv);
538                 return;
539         }
540         ad = (myaccount_appdata*)priv;
541         base = ug_get_layout(ug);
542         if (!base)
543                 MYACCOUNT_ERROR("layout cb base is null\n");
544
545         switch (mode) {
546         case UG_MODE_FRAMEVIEW:
547                         elm_object_part_content_set (ad->layout_main, "content", base);
548                         break;
549         case UG_MODE_FULLVIEW:
550                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
551                                          EVAS_HINT_EXPAND);
552                         //elm_win_resize_object_add(ad->win_main, base);
553                         evas_object_show(base);
554                         break;
555         default:
556                         break;
557         }
558 }
559
560 static void _myaccount_ug_account_list_result_cb(ui_gadget_h ug,
561                                                                                 app_control_h app_control, void *priv)
562 {
563         //MYACCOUNT_VERBOSE("_myaccount_ug_account_list_result_cb\n");
564 }
565
566 static void _myaccount_ug_account_list_destroy_cb(ui_gadget_h ug,
567                                                                                                         void *priv)
568 {
569         myaccount_appdata *mydata = (myaccount_appdata*)priv;
570
571         if (!ug||!mydata) {
572                 MYACCOUNT_ERROR("destroy cb error ug=%p, priv=%p\n", ug, mydata);
573                 return;
574         }
575         myaccount_common_set_item_selected_state(false);
576
577         ug_destroy(ug);
578         MYACCOUNT_SLOGD("_myaccount_ug_account_list_destroy_cb");
579 #ifndef ENABLE_NOTI
580         myaccount_common_handle_notification(NULL);
581 #endif
582 }
583
584 static void __myaccount_accountlist_set_ug_cbs(struct ug_cbs *cbs,
585                                                                                                 myaccount_appdata *priv)
586 {
587         if (!cbs || !priv) {
588                 MYACCOUNT_ERROR("__myaccount_addaccount_ug_create_email: Invalid param cbs=%p, priv=%p\n",
589                                                                 cbs, priv);
590                 return;
591         }
592         cbs->layout_cb = _myaccount_ug_account_list_layout_cb;
593         cbs->result_cb = _myaccount_ug_account_list_result_cb;
594         cbs->destroy_cb = _myaccount_ug_account_list_destroy_cb;
595         cbs->priv = (void *)priv;
596 }
597
598 static void __myaccount_ug_list_call_ug(void *data, myaccount_list_priv *account)
599 {
600         myaccount_appdata *ad = (myaccount_appdata*)data;
601         MyAccountProviderType sp_type;
602         ui_gadget_h ug = NULL;
603         struct ug_cbs cbs = {0,};
604         app_control_h app_control;
605         __attribute__((__unused__)) int ret = APP_CONTROL_ERROR_NONE;
606
607         if (!account) {
608                 MYACCOUNT_ERROR("__myaccount_ug_list_call_ug : account info NULL\n");
609                 return;
610         }
611
612         __myaccount_accountlist_set_ug_cbs(&cbs, ad);
613
614         sp_type = myaccount_common_get_provider_type(account->package_name);
615         ret = app_control_create(&app_control);
616
617         switch (sp_type) {
618 //      case MYACCOUNT_TYPE_MSN :
619         case MYACCOUNT_TYPE_GOOGLE :
620         case MYACCOUNT_TYPE_OTHER :
621 //      case MYACCOUNT_TYPE_FACEBOOK :
622                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
623                                                                         strdup(account->package_name),
624                                                                         strdup(account->username),
625                                                                         "",
626                                                                         account->account_id,
627                                                                         sp_type,
628                                                                         ad);
629                 break;
630         case MYACCOUNT_TYPE_EXCHANGE :
631                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
632                                                                         strdup("activesync-ui"),
633                                                                         strdup(account->username),
634                                                                         "",
635                                                                         account->account_id,
636                                                                         sp_type,
637                                                                         ad);
638                 break;
639         case MYACCOUNT_TYPE_SAMSUNG :
640                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
641                                                                         strdup("com.samsung.samsung-account-front"),
642                                                                         strdup(account->username),
643                                                                         "",
644                                                                         account->account_id,
645                                                                         sp_type,
646                                                                         ad);
647                 break;
648         case MYACCOUNT_TYPE_PICASA :
649         case MYACCOUNT_TYPE_YOUTUBE :
650         default :
651                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
652                                                                         strdup(account->package_name),
653                                                                         strdup(account->username),
654                                                                         "",
655                                                                         account->account_id,
656                                                                         sp_type,
657                                                                         ad);
658                 break;
659         }
660
661         ad->ug_called = ug;
662         app_control_destroy(app_control);
663
664 }
665
666 static void __myaccount_account_list_gl_sel(void *data,
667                                                                                 Evas_Object *obj, void *event_info)
668 {
669         myaccount_appdata *ad = myaccount_get_appdata();
670         if( myaccount_common_get_item_selected_state() ) {
671                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
672                 return;
673         }
674         myaccount_common_set_item_selected_state(true);
675         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
676
677         MYACCOUNT_SLOGD("__myaccount_account_list_gl_sel data=%p, obj=%p, event_info=%p\n",
678                                                                         data, obj, event_info);
679         myaccount_list_priv *account = (myaccount_list_priv*)data;
680         MYACCOUNT_SLOGD("__myaccount_account_list_gl_sel : account name : %s\n",
681                                                                         account->domain_name);
682
683         if (item != NULL)
684                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
685
686         __myaccount_ug_list_call_ug((myaccount_appdata*)ad, account);
687         return;
688 }
689
690 static void __myaccount_account_list_item_selected(void *data,
691                                                                                 Evas_Object *obj, void *event_info)
692 {
693         //MYACCOUNT_VERBOSE("__myaccount_account_list_item_selected \n");
694 }
695
696 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
697                                                                                                                 int count)
698 {
699         MYACCOUNT_SLOGD ("\n count received in __myaccount_account_list_append_genlist = %d \n",
700                                                                                 count);
701         bool supported = false;
702
703         if (count > 0) {
704                 GList* iter;
705                 for(iter=ad->sorted_account_list;iter!=NULL;iter=g_list_next(iter)) {
706                         myaccount_list_priv* tmp = (myaccount_list_priv*)iter->data;
707                         supported = false;
708                         if (tmp->secret == ACCOUNT_SECRECY_VISIBLE) {
709                                 if (ad->capability_filter) {
710                                         GSList* siter;
711                                         myaccount_list_priv *acc_info = NULL;
712                                         acc_info = tmp;
713
714                                         /* Tizen email exception */
715                                         if(!strcmp("http://tizen.org/account/capability/tizen_email", ad->capability_filter)){
716                                                 if(tmp->b_tizen_email) {
717                                                         supported = true;
718                                                 }
719                                         } else {
720                                                 for (siter = acc_info->capablity_list; siter != NULL; siter = g_slist_next(siter)) {
721                                                         myaccount_capability_data *cap_data = (myaccount_capability_data*)siter->data;
722
723                                                         if (!strcmp(cap_data->type, ad->capability_filter)) {
724                                                                 supported = true;
725                                                                 break;
726                                                         }
727                                                 }
728                                         }
729
730                                         if (supported) {
731                                                 elm_genlist_item_append(ad->account_genlist,
732                                                                                 &account_list_itc,
733                                                                                 (void *)tmp, NULL,
734                                                                                 ELM_GENLIST_ITEM_NONE,
735                                                                                 __myaccount_account_list_gl_sel,
736                                                                                 (void *)tmp);
737
738                                         }
739                                 } else {
740                                         elm_genlist_item_append(ad->account_genlist,
741                                                                         &account_list_itc,
742                                                                         (void *)tmp, NULL,
743                                                                         ELM_GENLIST_ITEM_NONE,
744                                                                         __myaccount_account_list_gl_sel,
745                                                                         (void *)tmp);
746                                 }
747                         }
748                 }
749
750         } else {
751                 myaccount_addaccount_create_view(ad);
752         }
753         return;
754 }
755
756 static void _myaccount_ug_account_gl_realized(void *data, Evas_Object *obj, void *ei)
757 {
758         Elm_Object_Item *it = NULL;
759         int total_count = 0;
760         int index = 0;
761 //      Evas_Object *ao;
762 //      char buf[2048]={0,};
763 //      char bufdomain[2048]={0,};
764
765         if(!ei) {
766                 MYACCOUNT_ERROR("Realized event info is NULL!!! \n");
767                 return;
768         }
769
770         it = (Elm_Object_Item *)ei;
771
772         total_count = elm_genlist_items_count(obj);
773         index = elm_genlist_item_index_get(it);
774
775         if(index > 2 && index < total_count)
776         {
777         /*Add account items. index 1 and last are the seperators*/
778                 /*
779                 myaccount_list_priv *account_info_item = (myaccount_list_priv*)elm_object_item_data_get(it);
780
781                 if(account_info_item){
782                 memset(buf, 0, 2048);
783                 memset(bufdomain, 0, 2048);
784
785                         if (strlen(account_info_item->domain_name) > 0)
786                                 g_snprintf(bufdomain, 1024, "Logged into %s with user id ", account_info_item->domain_name);
787                         else
788                                 g_snprintf(bufdomain, 1024, "Service unknown user id ");
789
790                         if (strlen(account_info_item->display_name) > 0)
791                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->display_name);
792                         else if (strlen(account_info_item->email_address) > 0)
793                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->email_address);
794                         else if (strlen(account_info_item->username) > 0)
795                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->username);
796                         else
797                                 g_snprintf(buf, 1024, "%sUnknown", account_info_item->domain_name);
798
799                 ao = elm_object_item_access_object_get(it);
800                 elm_access_info_set(ao, ELM_ACCESS_INFO, buf);
801
802                 }
803                 */
804         } else if (index == 2) {
805                 //ao = elm_object_item_access_object_get(it);
806                 //elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Turn Auto Sync on or off");
807     } else if (index == 3) {
808                 //ao = elm_object_item_access_object_get(it);
809                 //elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Below is the list of all logged in accounts");
810         } else {
811                 /*Remove access for seperators*/
812                 //elm_object_item_access_unregister(ei);
813         }
814
815         if(total_count <= 4)
816         {
817                 //MYACCOUNT_INFO("DO NOTHING only one account exist, total_count(%d) index(%d) !!! \n", total_count, index);
818         } else {
819                 if (index == 1) {
820                 } else if (index == 2) {
821                         elm_object_item_signal_emit(ei, "elm,state,top", "");
822                 } else if (index == (total_count-2)) {
823                         elm_object_item_signal_emit(ei, "elm,state,bottom", "");
824                 } else  {
825                         elm_object_item_signal_emit(ei, "elm,state,center", "");
826                 }
827         }
828 }
829
830 static Evas_Object *__myaccount_account_list_create_genlist(
831                                                                                                         myaccount_appdata *ad)
832 {
833         Evas_Object *genlist;
834
835         if (ad == NULL) {
836                 MYACCOUNT_ERROR("__myaccount_account_list_create_genlist returns NULL\n");
837                 return NULL;
838         }
839
840         int account_count = 0;
841         account_count = __myaccount_account_list_populate_account_info(ad);
842
843         account_list_itc.item_style = "2line.top";
844         account_list_itc.func.text_get = __myaccount_account_list_gl_label_get;
845         account_list_itc.func.content_get = __myaccount_account_list_gl_icon_get;
846         account_list_itc.func.state_get = NULL;
847         account_list_itc.func.del = NULL;
848
849         ad->account_genlist = genlist = elm_genlist_add(ad->navi_bar);
850         evas_object_smart_callback_add(genlist, "realized", _myaccount_ug_account_gl_realized, NULL);
851         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
852         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
853         elm_genlist_mode_set(genlist, EINA_TRUE);
854
855         evas_object_smart_callback_add(genlist, "selected",
856                                         __myaccount_account_list_item_selected,
857                                         (myaccount_appdata*) ad);
858
859         __myaccount_account_list_append_genlist(ad, account_count);
860
861         return genlist;
862 }
863
864 static void __move_more_ctxpopup(myaccount_appdata *ad)
865 {
866         MYACCOUNT_DBUG("__move_more_ctxpopup");
867
868         Evas_Coord w = 0;
869         Evas_Coord h = 0;
870
871         elm_win_screen_size_get(ad->win_main, NULL, NULL, &w, &h);
872         int pos = elm_win_rotation_get(ad->win_main);
873
874         switch (pos) {
875                 case 0:
876                 case 180:
877                          evas_object_move(ad->popup, (w / 2), h);
878                         break;
879                 case 90:
880                         evas_object_move(ad->popup,  (h / 2), w);
881                         break;
882                 case 270:
883                         evas_object_move(ad->popup, (h / 2), w);
884                         break;
885         }
886
887
888 }
889
890 static void __rotate_more_ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
891 {
892         MYACCOUNT_DBUG("__rotate_more_ctxpopup_cb");
893         myaccount_appdata *ad = data;
894
895         __move_more_ctxpopup(ad);
896 }
897 static void _delete_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
898 {
899         MYACCOUNT_DBUG("_delete_toolbar_ctxpopup_cb");
900         myaccount_appdata *ad = data;
901         if (elm_win_wm_rotation_supported_get(ad->win_main)) {
902                 if (ad->popup) {
903                         evas_object_smart_callback_del(elm_object_top_widget_get(ad->popup), "wm,rotation,changed", __rotate_more_ctxpopup_cb);
904                 }
905         }
906         if (ad->popup) {
907                 ea_object_event_callback_del(ad->popup, EA_CALLBACK_BACK, ea_ctxpopup_back_cb);
908                 ea_object_event_callback_del(ad->popup, EA_CALLBACK_MORE, ea_ctxpopup_back_cb);
909                 evas_object_event_callback_del(ad->popup, EVAS_CALLBACK_DEL, _delete_ctxpopup_cb);
910         }
911 }
912
913 static void __create_more_ctxpopup(myaccount_appdata *ad)
914 {
915         MYACCOUNT_DBUG("__create_more_ctxpopup");
916
917         Evas_Object *popup = elm_ctxpopup_add(ad->navi_bar);
918         ad->popup = popup;
919
920         elm_object_style_set(popup, "more/default");
921         elm_ctxpopup_auto_hide_disabled_set(popup, EINA_TRUE);
922         if (elm_win_wm_rotation_supported_get(ad->win_main)) {
923                 evas_object_smart_callback_add(elm_object_top_widget_get(popup), "wm,rotation,changed", __rotate_more_ctxpopup_cb, ad);
924         }
925         evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _delete_ctxpopup_cb, ad);
926         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, ea_ctxpopup_back_cb, popup);
927     ea_object_event_callback_add(popup, EA_CALLBACK_MORE, ea_ctxpopup_back_cb, popup);
928
929         elm_ctxpopup_item_append(popup, dgettext(MA_UG_NAME,"IDS_PB_BODY_ADD_ACCOUNT"), NULL, __myaccount_account_list_addaccount_cb, ad);
930
931         elm_ctxpopup_direction_priority_set(popup, ELM_CTXPOPUP_DIRECTION_UP,
932                                                 ELM_CTXPOPUP_DIRECTION_LEFT,
933                                                 ELM_CTXPOPUP_DIRECTION_RIGHT,
934                                                 ELM_CTXPOPUP_DIRECTION_DOWN);
935
936         __move_more_ctxpopup(ad);
937         evas_object_show(popup);
938 }
939
940 static void __delete_more_cb(void *data)
941 {
942         MYACCOUNT_DBUG("__delete_more_cb");
943         myaccount_appdata *ad = data;
944         if (ad->popup) {
945                 evas_object_del(ad->popup);
946                 ad->popup = NULL;
947         }
948 }
949
950 static void __more_cb(void *data, Elm_Object_Item *it, const char *emission, const char *source)
951 {
952         MYACCOUNT_DBUG("__more_cb");
953         myaccount_appdata *ad = data;
954         __delete_more_cb(data);
955         __create_more_ctxpopup(ad);
956 }
957
958 void myaccount_ug_account_list_create(void *data)
959 {
960         myaccount_appdata *ad = data;
961         Evas_Object *genlist = NULL;
962         Evas_Object *layout;
963
964         if (ad == NULL) {
965                 MYACCOUNT_ERROR("myaccount_ug_account_list_create myaccount_appdata is null\n");
966                 return;
967         }
968
969         layout = elm_layout_add(ad->navi_bar);
970         elm_layout_file_set(layout,
971                                         "/usr/apps/setting-myaccount-efl/res/edje/setting-myaccount-efl/myaccount.edj",
972                                         "account_list");
973         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
974         evas_object_size_hint_align_set( layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
975         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
976         elm_object_style_set(ad->bg, "group_list");
977
978         evas_object_show(layout);
979
980         genlist = __myaccount_account_list_create_genlist(ad);
981
982         elm_object_part_content_set (layout, "accountlist.genlist", genlist);
983
984         ad->nf_it = elm_naviframe_item_push(ad->navi_bar,
985                                                         dgettext(MA_UG_NAME,
986                                                         "IDS_ST_BODY_ACCOUNT_LIST"),
987                                                         NULL, NULL, layout, NULL);
988         elm_naviframe_item_pop_cb_set(ad->nf_it, myaccount_account_list_quit_cb, (void*)ad);
989
990         int count = 0;
991         count = myaccount_common_get_account_type_count(ad->capability_filter);
992
993         MYACCOUNT_DBUG("TOTAL avaiable sp count %d\n", count);
994
995         ea_object_event_callback_add(ad->navi_bar, EA_CALLBACK_MORE, ea_naviframe_more_cb, NULL);
996         elm_object_item_signal_callback_add(ad->nf_it, "elm,action,more_event", "", __more_cb, ad);
997
998 }
999
1000 static Evas_Object *__myaccount_account_list_create_bg(Evas_Object *parent)
1001 {
1002         Evas_Object *bg = elm_bg_add(parent);
1003         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1004         //elm_win_resize_object_add(parent, bg);
1005         evas_object_show(bg);
1006     return bg;
1007 }
1008
1009 static Evas_Object *__myaccount_account_list_create_main_layout(
1010                                                                                                         Evas_Object *parent,
1011                                                                                                         Evas_Object *bg)
1012 {
1013         Evas_Object *layout;
1014
1015         layout = elm_layout_add(parent);
1016         elm_layout_theme_set(layout, "layout", "application", "default");
1017         evas_object_size_hint_weight_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1018         edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator", "elm");
1019         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
1020         elm_object_part_content_set ( layout, "elm.swallow.bg", bg);
1021
1022         evas_object_show( layout );
1023
1024         return layout;
1025 }
1026
1027 static Evas_Object *__myaccount_account_list_create_navi_layout(
1028                                                                                                                         Evas_Object *parent)
1029 {
1030         Evas_Object *navi_bar;
1031
1032         navi_bar = elm_naviframe_add(parent);
1033         elm_object_part_content_set ( parent, "elm.swallow.content", navi_bar );
1034         evas_object_show(navi_bar);
1035
1036         return navi_bar;
1037 }
1038
1039 static void __myaccount_account_list_init_main_view(myaccount_appdata *ad)
1040 {
1041         //elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
1042         ad->bg = __myaccount_account_list_create_bg(ad->win_main);
1043         ad->layout_main = __myaccount_account_list_create_main_layout(ad->win_main, ad->bg);
1044 //      ea_theme_object_style_set(ad->layout_main, EA_THEME_STYLE_DARK);
1045 //      ea_theme_object_style_set(ad->layout_main, EA_THEME_STYLE_LIGHT);
1046
1047         ad->base = ad->layout_main;
1048 }
1049
1050 void myaccount_list_navi_create(myaccount_appdata *ad)
1051 {
1052         ad->navi_bar = __myaccount_account_list_create_navi_layout(ad->layout_main);
1053
1054         ea_object_event_callback_add(ad->navi_bar, EA_CALLBACK_BACK, myaccount_account_list_back_key_cb, (void*)ad);
1055 }
1056
1057 void myaccount_list_view_create(myaccount_appdata *priv)
1058 {
1059         /*struct ug_cbs cbs = {0,};*/
1060         __attribute__((__unused__)) struct ug_cbs cbs = {0,};
1061         cbs.layout_cb = _myaccount_ug_account_list_layout_cb;
1062         cbs.result_cb = _myaccount_ug_account_list_result_cb;
1063         cbs.destroy_cb = _myaccount_ug_account_list_destroy_cb;
1064         cbs.priv = (void *)priv;
1065
1066         MYACCOUNT_DBUG("Account list start\n");
1067         __myaccount_account_list_init_main_view(priv);
1068 }
1069
1070 void myaccount_list_refresh_item_list(myaccount_appdata *ad)
1071 {
1072         int count = 0;
1073
1074         if(!ad) {
1075                 MYACCOUNT_ERROR("no appdata!\n");
1076                 return;
1077         }
1078
1079         if(!ad->account_genlist) {
1080                 MYACCOUNT_ERROR("no genlist!\n");
1081                 return;
1082         }
1083
1084         MYACCOUNT_DBUG("Account list start\n");
1085
1086         elm_genlist_clear(ad->account_genlist);
1087
1088         myaccount_account_list_free_priv_data(ad);
1089
1090         account_index = 0;
1091         count = __myaccount_account_list_populate_account_info(ad);
1092
1093         __myaccount_account_list_append_genlist(ad, count);
1094
1095         return;
1096 }
1097