tizen 2.4 release
[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 count=0;
361
362         account_foreach_account_from_db(_myaccount_account_list_account_info_cb,
363                                                                                         &ad->account_info_list);
364
365         ad->sorted_account_list = g_list_sort(ad->account_info_list, (GCompareFunc)_myaccount_ug_account_list_compare);
366         count = g_list_length(ad->sorted_account_list);
367
368         return count;
369 }
370
371 Eina_Bool myaccount_account_list_quit_cb(void *data, Elm_Object_Item *it)
372 {
373         int error_code=0;
374         myaccount_appdata *priv = (myaccount_appdata*)data;
375
376         MYACCOUNT_DBUG("account list view quit\n");
377
378         if (!priv) {
379                 MYACCOUNT_ERROR("myaccount_account_list_quit_cb callback user data is null!!!\n");
380                 return EINA_TRUE;
381         }
382
383         if(priv->popup != NULL)
384         {
385                 evas_object_del(priv->popup);
386                 priv->popup = NULL;
387         }
388
389         myaccount_account_list_free_priv_data(priv);
390
391         account_index = 0;
392
393         if (priv->ug) {
394                 ui_gadget_h ug = priv->ug;
395                 error_code = ug_destroy_me(ug);
396                 MYACCOUNT_SLOGD("myaccount_account_list_quit_cb callback : return = %d!!!\n",
397                                                                                                 error_code);
398                 return EINA_FALSE;
399         }
400         return EINA_TRUE;
401 }
402
403 void myaccount_account_list_back_key_cb(void *data, Evas_Object *obj, void *event_info)
404 {
405         myaccount_appdata *ad = (myaccount_appdata*)data;
406         elm_naviframe_item_pop(ad->navi_bar);
407 }
408
409 static void __myaccount_account_list_addaccount_cb( void *data,
410                                                                                         Evas_Object *obj, void *event_info )
411 {
412         myaccount_appdata *priv = (myaccount_appdata*)data;
413         myaccount_addaccount_create_view(priv);
414         if(priv->popup != NULL)
415         {
416                 evas_object_del(priv->popup);
417                 priv->popup = NULL;
418         }
419 }
420
421 static char *__myaccount_account_list_gl_label_get(void *data,
422                                                                                 Evas_Object *obj, const char *part)
423 {
424         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
425         char domain_name_lower[128] = {0,};
426
427         if (!account_info_item) {
428                 MYACCOUNT_ERROR(" __myaccount_account_list_gl_label_get: Data is NULL\n");
429                 return NULL;
430         }
431
432         if (!strcmp(part, "elm.text")) {
433                 myaccount_common_lowercase(account_info_item->domain_name,
434                                                                                                 domain_name_lower);
435
436                 if (strlen(account_info_item->display_name) > 0)
437                         return strdup(account_info_item->display_name);
438                 else if (strlen(account_info_item->email_address) > 0)
439                         return strdup(account_info_item->email_address);
440                 else if (strlen(account_info_item->username) > 0)
441                         return strdup(account_info_item->username);
442                 else
443                         return strdup("Unknown");
444         } else if (!strcmp(part, "elm.text.sub")) {
445                 if (strlen(account_info_item->capability) <=0 )
446                         return strdup(dgettext(MA_UG_NAME, "IDS_MA_BODY_SIGNED_IN"));
447                 else
448                         return strdup(account_info_item->capability);
449         }
450
451         return NULL;
452 }
453
454
455 static Evas_Object *__myaccount_account_list_gl_icon_get(void *data,
456                                                                                         Evas_Object *obj, const char *part)
457 {
458         char tempbuf[PATH_MAX];
459         Evas_Object *icon = NULL;
460         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
461         Evas_Object *ic = NULL;
462
463         if (!account_info_item) {
464                 MYACCOUNT_ERROR("__myaccount_account_list_gl_icon_get: Data is NULL\n");
465                 return NULL;
466         }
467         memset(tempbuf, 0, sizeof(char)*PATH_MAX);
468
469         if (!strcmp(part, "elm.swallow.icon")) {
470                 if (strlen(account_info_item->icon_path) > 0) {
471                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", account_info_item->icon_path);
472                 } else {
473                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", "A01_2_Icon_default.png");
474                 }
475
476                 ic = elm_layout_add(obj);
477                 elm_layout_theme_set(ic, "layout", "list/B/type.2", "default");
478
479                 icon = elm_image_add(obj);
480                 if (strstr(tempbuf, "/"))
481                         elm_image_file_set(icon, tempbuf, NULL);
482                 else
483                         elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
484
485                 elm_layout_content_set(ic, "elm.swallow.content", icon);
486         }
487
488         if (!strcmp(part, "elm.swallow.end")) {
489                 if (account_info_item->sync_status == ACCOUNT_SYNC_NOT_SUPPORT)
490                         return NULL;
491                 MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", "account_icon_syncing.png");
492
493                 if(strlen(tempbuf) > 0) {
494                         ic = elm_layout_add(obj);
495                         elm_layout_theme_set(ic, "layout", "list/C/type.3", "default");
496
497                         icon = elm_image_add(obj);
498                         if (strstr(tempbuf, "/"))
499                                 elm_image_file_set(icon, tempbuf, NULL);
500                         else
501                                 elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
502
503                         evas_object_color_set(icon, 67, 116, 217, 255);
504                         elm_layout_content_set(ic, "elm.swallow.content", icon);
505                 }
506         }
507
508         return ic;
509 }
510
511 static void _myaccount_ug_account_list_layout_cb(ui_gadget_h ug,
512                                                                                 enum ug_mode mode, void *priv)
513 {
514         Evas_Object *base;
515         myaccount_appdata *ad;
516
517         if (!ug||!priv) {
518                 MYACCOUNT_ERROR("layout cb error ug=%p, priv=%p\n", ug, priv);
519                 return;
520         }
521         ad = (myaccount_appdata*)priv;
522         base = ug_get_layout(ug);
523         if (!base)
524                 MYACCOUNT_ERROR("layout cb base is null\n");
525
526         switch (mode) {
527         case UG_MODE_FRAMEVIEW:
528                         elm_object_part_content_set (ad->layout_main, "content", base);
529                         break;
530         case UG_MODE_FULLVIEW:
531                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
532                                          EVAS_HINT_EXPAND);
533                         //elm_win_resize_object_add(ad->win_main, base);
534                         evas_object_show(base);
535                         break;
536         default:
537                         break;
538         }
539 }
540
541 static void _myaccount_ug_account_list_result_cb(ui_gadget_h ug,
542                                                                                 app_control_h app_control, void *priv)
543 {
544         //MYACCOUNT_VERBOSE("_myaccount_ug_account_list_result_cb\n");
545 }
546
547 static void _myaccount_ug_account_list_destroy_cb(ui_gadget_h ug,
548                                                                                                         void *priv)
549 {
550         myaccount_appdata *mydata = (myaccount_appdata*)priv;
551
552         if (!ug||!mydata) {
553                 MYACCOUNT_ERROR("destroy cb error ug=%p, priv=%p\n", ug, mydata);
554                 return;
555         }
556         myaccount_common_set_item_selected_state(false);
557
558         ug_destroy(ug);
559         MYACCOUNT_SLOGD("_myaccount_ug_account_list_destroy_cb");
560 #ifndef ENABLE_NOTI
561         myaccount_common_handle_notification(NULL);
562 #endif
563 }
564
565 static void __myaccount_accountlist_set_ug_cbs(struct ug_cbs *cbs,
566                                                                                                 myaccount_appdata *priv)
567 {
568         if (!cbs || !priv) {
569                 MYACCOUNT_ERROR("__myaccount_addaccount_ug_create_email: Invalid param cbs=%p, priv=%p\n",
570                                                                 cbs, priv);
571                 return;
572         }
573         cbs->layout_cb = _myaccount_ug_account_list_layout_cb;
574         cbs->result_cb = _myaccount_ug_account_list_result_cb;
575         cbs->destroy_cb = _myaccount_ug_account_list_destroy_cb;
576         cbs->priv = (void *)priv;
577 }
578
579 static void __myaccount_ug_list_call_ug(void *data, myaccount_list_priv *account)
580 {
581         myaccount_appdata *ad = (myaccount_appdata*)data;
582         MyAccountProviderType sp_type;
583         ui_gadget_h ug = NULL;
584         struct ug_cbs cbs = {0,};
585         app_control_h app_control;
586         __attribute__((__unused__)) int ret = APP_CONTROL_ERROR_NONE;
587
588         if (!account) {
589                 MYACCOUNT_ERROR("__myaccount_ug_list_call_ug : account info NULL\n");
590                 return;
591         }
592
593         __myaccount_accountlist_set_ug_cbs(&cbs, ad);
594
595         sp_type = myaccount_common_get_provider_type(account->package_name);
596         ret = app_control_create(&app_control);
597
598         switch (sp_type) {
599 //      case MYACCOUNT_TYPE_MSN :
600         case MYACCOUNT_TYPE_GOOGLE :
601         case MYACCOUNT_TYPE_OTHER :
602 //      case MYACCOUNT_TYPE_FACEBOOK :
603                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
604                                                                         strdup(account->package_name),
605                                                                         strdup(account->username),
606                                                                         "",
607                                                                         account->account_id,
608                                                                         sp_type,
609                                                                         ad);
610                 break;
611         case MYACCOUNT_TYPE_EXCHANGE :
612                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
613                                                                         strdup("activesync-ui"),
614                                                                         strdup(account->username),
615                                                                         "",
616                                                                         account->account_id,
617                                                                         sp_type,
618                                                                         ad);
619                 break;
620         case MYACCOUNT_TYPE_SAMSUNG :
621                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
622                                                                         strdup("com.samsung.samsung-account-front"),
623                                                                         strdup(account->username),
624                                                                         "",
625                                                                         account->account_id,
626                                                                         sp_type,
627                                                                         ad);
628                 break;
629         case MYACCOUNT_TYPE_PICASA :
630         case MYACCOUNT_TYPE_YOUTUBE :
631         default :
632                 ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
633                                                                         strdup(account->package_name),
634                                                                         strdup(account->username),
635                                                                         "",
636                                                                         account->account_id,
637                                                                         sp_type,
638                                                                         ad);
639                 break;
640         }
641
642         ad->ug_called = ug;
643         app_control_destroy(app_control);
644
645 }
646
647 static void __myaccount_account_list_gl_sel(void *data,
648                                                                                 Evas_Object *obj, void *event_info)
649 {
650         myaccount_appdata *ad = myaccount_get_appdata();
651         if( myaccount_common_get_item_selected_state() ) {
652                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
653                 return;
654         }
655         myaccount_common_set_item_selected_state(true);
656         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
657
658         MYACCOUNT_SLOGD("__myaccount_account_list_gl_sel data=%p, obj=%p, event_info=%p\n",
659                                                                         data, obj, event_info);
660         myaccount_list_priv *account = (myaccount_list_priv*)data;
661         MYACCOUNT_SLOGD("__myaccount_account_list_gl_sel : account name : %s\n",
662                                                                         account->domain_name);
663
664         if (item != NULL)
665                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
666
667         __myaccount_ug_list_call_ug((myaccount_appdata*)ad, account);
668         return;
669 }
670
671 static void __myaccount_account_list_item_selected(void *data,
672                                                                                 Evas_Object *obj, void *event_info)
673 {
674         //MYACCOUNT_VERBOSE("__myaccount_account_list_item_selected \n");
675 }
676
677 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
678                                                                                                                 int count)
679 {
680         MYACCOUNT_SLOGD ("\n count received in __myaccount_account_list_append_genlist = %d \n",
681                                                                                 count);
682         bool supported = false;
683
684         if (count > 0) {
685                 GList* iter;
686                 for(iter=ad->sorted_account_list;iter!=NULL;iter=g_list_next(iter)) {
687                         myaccount_list_priv* tmp = (myaccount_list_priv*)iter->data;
688                         supported = false;
689                         if (tmp->secret == ACCOUNT_SECRECY_VISIBLE) {
690                                 if (ad->capability_filter) {
691                                         GSList* siter;
692                                         myaccount_list_priv *acc_info = NULL;
693                                         acc_info = tmp;
694
695                                         /* Tizen email exception */
696                                         if(!strcmp("http://tizen.org/account/capability/tizen_email", ad->capability_filter)){
697                                                 if(tmp->b_tizen_email) {
698                                                         supported = true;
699                                                 }
700                                         } else {
701                                                 for (siter = acc_info->capablity_list; siter != NULL; siter = g_slist_next(siter)) {
702                                                         myaccount_capability_data *cap_data = (myaccount_capability_data*)siter->data;
703
704                                                         if (!strcmp(cap_data->type, ad->capability_filter)) {
705                                                                 supported = true;
706                                                                 break;
707                                                         }
708                                                 }
709                                         }
710
711                                         if (supported) {
712                                                 elm_genlist_item_append(ad->account_genlist,
713                                                                                 &account_list_itc,
714                                                                                 (void *)tmp, NULL,
715                                                                                 ELM_GENLIST_ITEM_NONE,
716                                                                                 __myaccount_account_list_gl_sel,
717                                                                                 (void *)tmp);
718
719                                         }
720                                 } else {
721                                         elm_genlist_item_append(ad->account_genlist,
722                                                                         &account_list_itc,
723                                                                         (void *)tmp, NULL,
724                                                                         ELM_GENLIST_ITEM_NONE,
725                                                                         __myaccount_account_list_gl_sel,
726                                                                         (void *)tmp);
727                                 }
728                         }
729                 }
730
731         } else {
732                 myaccount_addaccount_create_view(ad);
733         }
734         return;
735 }
736
737 static void _myaccount_ug_account_gl_realized(void *data, Evas_Object *obj, void *ei)
738 {
739         Elm_Object_Item *it = NULL;
740         int total_count = 0;
741         int index = 0;
742 //      Evas_Object *ao;
743 //      char buf[2048]={0,};
744 //      char bufdomain[2048]={0,};
745
746         if(!ei) {
747                 MYACCOUNT_ERROR("Realized event info is NULL!!! \n");
748                 return;
749         }
750
751         it = (Elm_Object_Item *)ei;
752
753         total_count = elm_genlist_items_count(obj);
754         index = elm_genlist_item_index_get(it);
755
756         if(index > 2 && index < total_count)
757         {
758         /*Add account items. index 1 and last are the seperators*/
759                 /*
760                 myaccount_list_priv *account_info_item = (myaccount_list_priv*)elm_object_item_data_get(it);
761
762                 if(account_info_item){
763                 memset(buf, 0, 2048);
764                 memset(bufdomain, 0, 2048);
765
766                         if (strlen(account_info_item->domain_name) > 0)
767                                 g_snprintf(bufdomain, 1024, "Logged into %s with user id ", account_info_item->domain_name);
768                         else
769                                 g_snprintf(bufdomain, 1024, "Service unknown user id ");
770
771                         if (strlen(account_info_item->display_name) > 0)
772                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->display_name);
773                         else if (strlen(account_info_item->email_address) > 0)
774                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->email_address);
775                         else if (strlen(account_info_item->username) > 0)
776                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->username);
777                         else
778                                 g_snprintf(buf, 1024, "%sUnknown", account_info_item->domain_name);
779
780                 ao = elm_object_item_access_object_get(it);
781                 elm_access_info_set(ao, ELM_ACCESS_INFO, buf);
782
783                 }
784                 */
785         } else if (index == 2) {
786                 //ao = elm_object_item_access_object_get(it);
787                 //elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Turn Auto Sync on or off");
788     } else if (index == 3) {
789                 //ao = elm_object_item_access_object_get(it);
790                 //elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Below is the list of all logged in accounts");
791         } else {
792                 /*Remove access for seperators*/
793                 //elm_object_item_access_unregister(ei);
794         }
795
796         if(total_count <= 4)
797         {
798                 //MYACCOUNT_INFO("DO NOTHING only one account exist, total_count(%d) index(%d) !!! \n", total_count, index);
799         } else {
800                 if (index == 1) {
801                 } else if (index == 2) {
802                         elm_object_item_signal_emit(ei, "elm,state,top", "");
803                 } else if (index == (total_count-2)) {
804                         elm_object_item_signal_emit(ei, "elm,state,bottom", "");
805                 } else  {
806                         elm_object_item_signal_emit(ei, "elm,state,center", "");
807                 }
808         }
809 }
810
811 static Evas_Object *__myaccount_account_list_create_genlist(
812                                                                                                         myaccount_appdata *ad)
813 {
814         Evas_Object *genlist;
815
816         if (ad == NULL) {
817                 MYACCOUNT_ERROR("__myaccount_account_list_create_genlist returns NULL\n");
818                 return NULL;
819         }
820
821         int account_count = 0;
822         account_count = __myaccount_account_list_populate_account_info(ad);
823
824         account_list_itc.item_style = "type1";
825         account_list_itc.func.text_get = __myaccount_account_list_gl_label_get;
826         account_list_itc.func.content_get = __myaccount_account_list_gl_icon_get;
827         account_list_itc.func.state_get = NULL;
828         account_list_itc.func.del = NULL;
829
830         ad->account_genlist = genlist = elm_genlist_add(ad->navi_bar);
831         evas_object_smart_callback_add(genlist, "realized", _myaccount_ug_account_gl_realized, NULL);
832         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
833         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
834         elm_genlist_mode_set(genlist, EINA_TRUE);
835
836         evas_object_smart_callback_add(genlist, "selected",
837                                         __myaccount_account_list_item_selected,
838                                         (myaccount_appdata*) ad);
839
840         __myaccount_account_list_append_genlist(ad, account_count);
841
842         return genlist;
843 }
844
845 static void __move_more_ctxpopup(myaccount_appdata *ad)
846 {
847         MYACCOUNT_DBUG("__move_more_ctxpopup");
848
849         Evas_Coord w = 0;
850         Evas_Coord h = 0;
851
852         elm_win_screen_size_get(ad->win_main, NULL, NULL, &w, &h);
853         int pos = elm_win_rotation_get(ad->win_main);
854
855         switch (pos) {
856                 case 0:
857                 case 180:
858                          evas_object_move(ad->popup, (w / 2), h);
859                         break;
860                 case 90:
861                         evas_object_move(ad->popup,  (h / 2), w);
862                         break;
863                 case 270:
864                         evas_object_move(ad->popup, (h / 2), w);
865                         break;
866         }
867
868
869 }
870
871 static void __rotate_more_ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
872 {
873         MYACCOUNT_DBUG("__rotate_more_ctxpopup_cb");
874         myaccount_appdata *ad = data;
875
876         __move_more_ctxpopup(ad);
877 }
878 static void _delete_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
879 {
880         MYACCOUNT_DBUG("_delete_toolbar_ctxpopup_cb");
881         myaccount_appdata *ad = data;
882         if (elm_win_wm_rotation_supported_get(ad->win_main)) {
883                 if (ad->popup) {
884                         evas_object_smart_callback_del(elm_object_top_widget_get(ad->popup), "wm,rotation,changed", __rotate_more_ctxpopup_cb);
885                 }
886         }
887         if (ad->popup) {
888                 eext_object_event_callback_del(ad->popup, EEXT_CALLBACK_BACK, eext_ctxpopup_back_cb);
889                 eext_object_event_callback_del(ad->popup, EEXT_CALLBACK_MORE, eext_ctxpopup_back_cb);           
890                 
891                 evas_object_event_callback_del(ad->popup, EVAS_CALLBACK_DEL, _delete_ctxpopup_cb);
892         }
893 }
894
895 static void __create_more_ctxpopup(myaccount_appdata *ad)
896 {
897         MYACCOUNT_DBUG("__create_more_ctxpopup");
898
899         Evas_Object *popup = elm_ctxpopup_add(ad->navi_bar);
900         ad->popup = popup;
901
902         elm_object_style_set(popup, "more/default");
903         elm_ctxpopup_auto_hide_disabled_set(popup, EINA_TRUE);
904         if (elm_win_wm_rotation_supported_get(ad->win_main)) {
905                 evas_object_smart_callback_add(elm_object_top_widget_get(popup), "wm,rotation,changed", __rotate_more_ctxpopup_cb, ad);
906         }
907         evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _delete_ctxpopup_cb, ad);
908
909         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_ctxpopup_back_cb, popup);
910         eext_object_event_callback_add(popup, EEXT_CALLBACK_MORE, eext_ctxpopup_back_cb, popup);
911
912         elm_ctxpopup_item_append(popup, dgettext(MA_UG_NAME,"IDS_PB_BODY_ADD_ACCOUNT"), NULL, __myaccount_account_list_addaccount_cb, ad);
913
914         elm_ctxpopup_direction_priority_set(popup, ELM_CTXPOPUP_DIRECTION_UP,
915                                                 ELM_CTXPOPUP_DIRECTION_LEFT,
916                                                 ELM_CTXPOPUP_DIRECTION_RIGHT,
917                                                 ELM_CTXPOPUP_DIRECTION_DOWN);
918
919         __move_more_ctxpopup(ad);
920         evas_object_show(popup);
921 }
922
923 static void __delete_more_cb(void *data)
924 {
925         MYACCOUNT_DBUG("__delete_more_cb");
926         myaccount_appdata *ad = data;
927         if (ad->popup) {
928                 evas_object_del(ad->popup);
929                 ad->popup = NULL;
930         }
931 }
932
933 static void __more_cb(void *data, Evas_Object *obj, void *event_info)
934 {
935         MYACCOUNT_DBUG("__more_cb");
936         myaccount_appdata *ad = data;
937         __delete_more_cb(data);
938         __create_more_ctxpopup(ad);
939 }
940
941 void myaccount_ug_account_list_create(void *data)
942 {
943         myaccount_appdata *ad = data;
944         Evas_Object *genlist = NULL;
945         Evas_Object *back_btn = NULL;
946         Evas_Object *layout = NULL;
947         Evas_Object *more_button = NULL;        
948
949         if (ad == NULL) {
950                 MYACCOUNT_ERROR("myaccount_ug_account_list_create myaccount_appdata is null\n");
951                 return;
952         }
953
954         layout = elm_layout_add(ad->navi_bar);
955         elm_layout_file_set(layout,
956                                         "/usr/apps/setting-myaccount-efl/res/edje/setting-myaccount-efl/myaccount.edj",
957                                         "account_list");
958         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
959         evas_object_size_hint_align_set( layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
960         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
961         elm_object_style_set(ad->bg, "group_list");
962
963         evas_object_show(layout);
964
965         genlist = __myaccount_account_list_create_genlist(ad);
966
967         elm_object_part_content_set (layout, "accountlist.genlist", genlist);
968
969         back_btn = elm_button_add(ad->navi_bar);
970         elm_object_style_set(back_btn, "naviframe/back_btn/default");
971         evas_object_smart_callback_add(back_btn, "clicked", myaccount_account_list_back_key_cb, ad);
972
973         ad->nf_it = elm_naviframe_item_push(ad->navi_bar,
974                                                         dgettext(MA_UG_NAME,
975                                                         "IDS_ST_BODY_ACCOUNT_LIST"),
976                                                         back_btn, NULL, layout, NULL);
977
978         elm_naviframe_item_pop_cb_set(ad->nf_it, myaccount_account_list_quit_cb, (void*)ad);
979
980         int count = 0;
981         count = myaccount_common_get_account_type_count(ad->capability_filter);
982
983         MYACCOUNT_DBUG("TOTAL avaiable sp count %d\n", count);
984
985         eext_object_event_callback_add(ad->navi_bar, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
986
987         more_button = elm_button_add(ad->navi_bar);
988         elm_object_style_set(more_button, "naviframe/more/default");
989         evas_object_smart_callback_add(more_button, "clicked", __more_cb, ad);
990         elm_object_item_part_content_set(ad->nf_it, "toolbar_more_btn", more_button);   
991         
992
993 }
994
995 static Evas_Object *__myaccount_account_list_create_bg(Evas_Object *parent)
996 {
997         Evas_Object *bg = elm_bg_add(parent);
998         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
999         //elm_win_resize_object_add(parent, bg);
1000         evas_object_show(bg);
1001     return bg;
1002 }
1003
1004 static Evas_Object *__myaccount_account_list_create_main_layout(
1005                                                                                                         Evas_Object *parent,
1006                                                                                                         Evas_Object *bg)
1007 {
1008         Evas_Object *layout;
1009
1010         layout = elm_layout_add(parent);
1011         elm_layout_theme_set(layout, "layout", "application", "default");
1012         evas_object_size_hint_weight_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1013         edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator", "elm");
1014         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
1015         elm_object_part_content_set ( layout, "elm.swallow.bg", bg);
1016
1017         evas_object_show( layout );
1018
1019         return layout;
1020 }
1021
1022 static Evas_Object *__myaccount_account_list_create_navi_layout(
1023                                                                                                                         Evas_Object *parent)
1024 {
1025         Evas_Object *navi_bar;
1026
1027         navi_bar = elm_naviframe_add(parent);
1028         elm_object_part_content_set ( parent, "elm.swallow.content", navi_bar );
1029         evas_object_show(navi_bar);
1030
1031         return navi_bar;
1032 }
1033
1034 static void __myaccount_account_list_init_main_view(myaccount_appdata *ad)
1035 {
1036         //elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
1037         ad->bg = __myaccount_account_list_create_bg(ad->win_main);
1038         ad->layout_main = __myaccount_account_list_create_main_layout(ad->win_main, ad->bg);
1039         ad->base = ad->layout_main;
1040 }
1041
1042 void myaccount_list_navi_create(myaccount_appdata *ad)
1043 {
1044         ad->navi_bar = __myaccount_account_list_create_navi_layout(ad->layout_main);
1045
1046         eext_object_event_callback_add(ad->navi_bar, EEXT_CALLBACK_BACK, myaccount_account_list_back_key_cb, (void*)ad);
1047 }
1048
1049 void myaccount_list_view_create(myaccount_appdata *priv)
1050 {
1051         /*struct ug_cbs cbs = {0,};*/
1052         __attribute__((__unused__)) struct ug_cbs cbs = {0,};
1053         cbs.layout_cb = _myaccount_ug_account_list_layout_cb;
1054         cbs.result_cb = _myaccount_ug_account_list_result_cb;
1055         cbs.destroy_cb = _myaccount_ug_account_list_destroy_cb;
1056         cbs.priv = (void *)priv;
1057
1058         MYACCOUNT_DBUG("Account list start\n");
1059         __myaccount_account_list_init_main_view(priv);
1060 }
1061
1062 void myaccount_list_refresh_item_list(myaccount_appdata *ad)
1063 {
1064         int count = 0;
1065
1066         if(!ad) {
1067                 MYACCOUNT_ERROR("no appdata!\n");
1068                 return;
1069         }
1070
1071         if(!ad->account_genlist) {
1072                 MYACCOUNT_ERROR("no genlist!\n");
1073                 return;
1074         }
1075
1076         MYACCOUNT_DBUG("Account list start\n");
1077
1078         elm_genlist_clear(ad->account_genlist);
1079
1080         myaccount_account_list_free_priv_data(ad);
1081
1082         account_index = 0;
1083         count = __myaccount_account_list_populate_account_info(ad);
1084
1085         __myaccount_account_list_append_genlist(ad, count);
1086
1087         return;
1088 }
1089