[tizen_2.1] merge with private
[apps/core/preloaded/my-account.git] / src / myaccount_ug_account_list.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <Ecore_X.h>
18 #include <vconf.h>
19 #include "myaccount_ug_account_list.h"
20 #include "myaccount_ug_addaccount.h"
21 #include "myaccount_ug_common.h"
22
23 typedef struct __capability_data {
24         char* type;
25         int state;
26 }myaccount_capability_data;
27
28 typedef struct __account_list_priv {
29         int account_id;
30         char username[256];
31         char display_name[256];
32         char email_address[256];
33         char package_name[256];
34         char domain_name[60];
35         char icon_path[PATH_MAX];
36         char capability[128];
37         int secret;
38         int list_index;
39         int sync_status;
40         GSList *capablity_list;
41 }myaccount_list_priv;
42
43 static Elm_Genlist_Item_Class account_list_itc;
44 static Elm_Genlist_Item_Class account_list_title_itc;
45 static Elm_Genlist_Item_Class account_list_itc_sep;
46 static Elm_Genlist_Item_Class account_list_itc_sep_end;
47 static myaccount_list_priv *account_info;
48 static int account_index = 0;
49
50 static void __myaccount_account_list_addaccount_cb( void *data,
51                                                                                         Evas_Object *obj, void* event_info );
52 static void _myaccount_ug_account_list_layout_cb(ui_gadget_h ug,
53                                                                                         enum ug_mode mode, void *priv);
54 static void _myaccount_ug_account_list_result_cb(ui_gadget_h ug,
55                                                                                         service_h service, void *priv);
56 static void _myaccount_ug_account_list_destroy_cb(ui_gadget_h ug,
57                                                                                 void *priv);
58 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
59                                                                                 int count);
60
61 static char *__myaccount_account_list_get_capablity_string_value(const char* capability_type)
62 {
63         if (!strcmp(capability_type, ACCOUNT_SUPPORTS_CAPABILITY_CONTACT))
64                 return dgettext(MA_UG_NAME, "IDS_MA_BODY_CONTACT");
65         else if (!strcmp(capability_type, ACCOUNT_SUPPORTS_CAPABILITY_CALENDAR))
66                 return dgettext("sys_string", "IDS_COM_BODY_S_PLANNER");
67         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_PHOTO))
68                 return dgettext(MA_UG_NAME, "IDS_PB_BODY_PHOTO");
69         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_VIDEO))
70                 return dgettext(MA_UG_NAME, "IDS_ST_BODY_VIDEOS");
71         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_EMAIL))
72                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_EMAIL");
73         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_POST))
74                 return dgettext(MA_UG_NAME, "IDS_TW_BODY_POST_TWITTER");
75         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_VOIP))
76                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_VOIP_CALL");
77         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_SAMSUNG_APPS))
78                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_SAMSUNG_APPS_T_MAINMENU");
79         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_MOBILE_TRACKER))
80                 return dgettext(MA_UG_NAME, "IDS_ST_BODY_MOBILE_TRACKER");
81         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_TASK))
82                 return dgettext(MA_UG_NAME, "IDS_COM_BODY_TASK");
83         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_MEMO))
84                 return dgettext("sys_string", "IDS_COM_BODY_S_NOTE");
85         else if (!strcmp(capability_type ,ACCOUNT_SUPPORTS_CAPABILITY_MUSIC))
86                 return dgettext("sys_string", "IDS_COM_BODY_MUSIC");
87         else
88                 return NULL;//return dgettext(MA_UG_NAME, "IDS_COM_POP_UNKNOWN");
89 }
90
91 bool _myaccount_account_list_get_capablity_text(const char* capability_type,
92                                                                                 account_capability_state_e capability_state,
93                                                                                 void *user_data)
94 {
95         /* get capabilities of the account*/
96         char *capability_string = NULL;
97         myaccount_list_priv *account_info = (myaccount_list_priv*)user_data;
98         char *capability_textbuf = account_info->capability;
99
100         myaccount_capability_data *cap_data = (myaccount_capability_data*)malloc(sizeof(myaccount_capability_data));
101         if (!cap_data) {
102                 MYACCOUNT_FATAL("malloc failed\n");
103                 return true;
104         }
105         memset(cap_data, 0, sizeof(myaccount_capability_data));
106
107         cap_data->type = strdup(capability_type);
108         cap_data->state = capability_state;
109
110         account_info->capablity_list = g_slist_append(account_info->capablity_list, (gpointer)cap_data);
111
112         if (capability_state == ACCOUNT_CAPABILITY_ENABLED) {
113                 capability_string = __myaccount_account_list_get_capablity_string_value(
114                                                                                                                         capability_type);
115
116                 if (capability_string != NULL) {
117                         MYACCOUNT_VERBOSE("capability_string = %s\n",   capability_string);
118                         if(strlen(capability_textbuf) > 0) {
119                                 char *temp2 = strdup(capability_textbuf);
120                                 if (!temp2) {
121                                         MYACCOUNT_FATAL("strdup returns NULL\n");
122                                         return false;
123                                 }
124                                 MA_SNPRINTF(capability_textbuf, 127, "%s, %s", temp2, capability_string);
125                                 MA_MEMFREE(temp2);
126                         } else {
127                                 MA_SNPRINTF(capability_textbuf, 127, "%s%s", capability_textbuf,
128                                                                                                                         capability_string);
129                         }
130                 }
131         }
132
133         MYACCOUNT_VERBOSE("capability_textbuf = %s \n",         capability_textbuf);
134         return true;
135 }
136
137 bool _myaccount_account_list_account_info_cb(account_h account,
138                                                                                                                 void *user_data)
139 {
140         int error_code = -1;
141         int j = account_index;
142
143         if (!account) {
144                 MYACCOUNT_ERROR("_myaccount_account_list_account_info_cb:account handle is NULL\n");
145                 return false;
146         } else {
147                 char *temptxt = NULL;
148                 int id = -1;
149                 account_secrecy_state_e secret;
150
151                 error_code = account_get_user_name(account, &temptxt);
152                 if (error_code != ACCOUNT_ERROR_NONE) {
153                         MYACCOUNT_ERROR("account_get_user_name: Failed \n");
154                 } else if (temptxt && strlen(temptxt)) {
155                         MA_STRNCPY(account_info[j].username, temptxt,
156                                                                         sizeof(account_info[j].username));
157                 } else {
158                         MYACCOUNT_DBUG("account_get_user_name: returned NULL \n");
159                 }
160                 MA_MEMFREE(temptxt);
161                 error_code = account_get_display_name(account, &temptxt);
162                 if (error_code != ACCOUNT_ERROR_NONE) {
163                         MYACCOUNT_ERROR("account_get_display_name: Failed \n");
164                 } else if (temptxt && strlen(temptxt)) {
165                         MA_STRNCPY(account_info[j].display_name, temptxt,
166                                                                         sizeof(account_info[j].display_name));
167                 } else {
168                         MYACCOUNT_DBUG("account_get_display_name: returned NULL \n");
169                 }
170                 MA_MEMFREE(temptxt);
171                 error_code = account_get_email_address(account, &temptxt);
172                 if (error_code != ACCOUNT_ERROR_NONE) {
173                         MYACCOUNT_ERROR("account_get_email_address: Failed \n");
174                 } else if (temptxt && strlen(temptxt)) {
175                         MA_STRNCPY(account_info[j].email_address, temptxt,
176                                                                         sizeof(account_info[j].email_address));
177                 } else {
178                         MYACCOUNT_DBUG("account_get_email_address: returned NULL \n");
179                 }
180                 MA_MEMFREE(temptxt);
181                 error_code = account_get_package_name(account, &temptxt);
182                 if (error_code != ACCOUNT_ERROR_NONE) {
183                         MYACCOUNT_ERROR("account_get_package_name: Failed \n");
184                 } else if (temptxt && strlen(temptxt)) {
185                         MA_STRNCPY(account_info[j].package_name, temptxt,
186                                                                         sizeof(account_info[j].package_name));
187                 } else {
188                         MYACCOUNT_DBUG("account_get_package_name: returned NULL \n");
189                 }
190                 MA_MEMFREE(temptxt);
191                 error_code = account_get_account_id(account, &id);
192                 if (error_code != ACCOUNT_ERROR_NONE) {
193                         MYACCOUNT_ERROR("account_get_account_id: Failed \n");
194                 } else if (id > 0) {
195                         account_info[j].account_id = id;
196                 } else {
197                         MYACCOUNT_DBUG("account_get_account_id: returned 0 or -ve \n");
198                 }
199                 error_code = account_get_secret(account, &secret);
200                 if (error_code != ACCOUNT_ERROR_NONE) {
201                         MYACCOUNT_ERROR("account_get_secret: Failed \n");
202                 } else {
203                         account_info[j].secret = secret;
204                 }
205                 error_code = account_get_domain_name(account, &temptxt);
206                 if (error_code != ACCOUNT_ERROR_NONE) {
207                         MYACCOUNT_ERROR("account_get_domain_name: Failed \n");
208                 } else if (temptxt && strlen(temptxt)) {
209                         MA_STRNCPY(account_info[j].domain_name, temptxt,
210                                                                         sizeof(account_info[j].domain_name));
211                 } else {
212                         MYACCOUNT_DBUG("account_get_domain_name: returned NULL \n");
213                 }
214                 MA_MEMFREE(temptxt);
215                 error_code = account_get_icon_path(account, &temptxt);
216                 if (error_code != ACCOUNT_ERROR_NONE) {
217                                 MYACCOUNT_ERROR("account_get_icon_path: Failed \n");
218                 } else if (temptxt && strlen(temptxt)) {
219                         MA_STRNCPY(account_info[j].icon_path, temptxt,
220                                                                         sizeof(account_info[j].icon_path));
221                 } else {
222                         MYACCOUNT_DBUG("account_get_icon_path: returned NULL \n");
223                 }
224                 MA_MEMFREE(temptxt);
225                 if(!strlen(account_info[j].icon_path))
226                         myaccount_common_get_icon_by_name(account_info[j].domain_name ,
227                                                                                                         account_info[j].icon_path);
228
229                 error_code = account_get_sync_support(account,
230                                                 (account_sync_state_e *)&(account_info[j].sync_status));
231                 if (error_code != ACCOUNT_ERROR_NONE) {
232                         MYACCOUNT_ERROR("account_get_sync_support: Failed \n");
233                 }
234
235                 error_code = account_get_capability_all(account,
236                                                                         _myaccount_account_list_get_capablity_text,
237                                                                         (void *)&account_info[j]);
238                 if (error_code != ACCOUNT_ERROR_NONE)
239                         MYACCOUNT_ERROR("account_get_capability: Failed \n");
240
241                 account_index++;
242         }
243         return true;
244 }
245
246 static int __myaccount_account_list_populate_account_info()
247 {
248         MYACCOUNT_VERBOSE("\n Inside __myaccount_account_list_populate_account_info !! \n");
249         int error_code = -1;
250         int count=0;
251
252         error_code = account_connect();
253         if (error_code != ACCOUNT_ERROR_NONE)
254                 MYACCOUNT_ERROR("account_connect: Failed \n");
255
256         error_code = account_get_total_count_from_db(&count);
257         if (error_code != ACCOUNT_ERROR_NONE)
258                 MYACCOUNT_ERROR("account_get_total_count_from_db: Failed \n");
259
260         MYACCOUNT_DBUG("CURRENT account count is %d\n", count);
261         account_info = calloc(count, sizeof(myaccount_list_priv));
262         account_foreach_account_from_db(_myaccount_account_list_account_info_cb,
263                                                                                         NULL);
264         error_code = account_disconnect();
265         if (error_code != ACCOUNT_ERROR_NONE)
266                 MYACCOUNT_ERROR("account_disconnect: Failed \n");
267
268         MYACCOUNT_VERBOSE("populate myacconut data END\n");
269         return count;
270 }
271
272 void myaccount_account_list_quit_cb( void *data,
273                                                                         Evas_Object *obj, void *event_info )
274 {
275         int error_code=0;
276         myaccount_appdata *priv = (myaccount_appdata*)data;
277
278         MYACCOUNT_VERBOSE("myaccount_account_list_quit_cb START\n");
279
280         if (!priv) {
281                 MYACCOUNT_ERROR("myaccount_account_list_quit_cb callback user data is null!!!\n");
282                 return;
283         }
284
285         if(account_info){
286                 if (account_info->capablity_list) {
287                         g_slist_free(account_info->capablity_list);
288                         account_info->capablity_list = NULL;
289                 }
290         }
291         MA_MEMFREE(account_info);
292         account_index = 0;
293         if (priv->ug) {
294                 error_code = ug_destroy_me(priv->ug);
295                 MYACCOUNT_INFO("myaccount_account_list_quit_cb callback : return = %d!!!\n",
296                                                                                                 error_code);
297         }
298         MYACCOUNT_VERBOSE("myaccount_account_list_quit_cb END\n");
299 }
300
301 static void __myaccount_account_list_addaccount_cb( void *data,
302                                                                                         Evas_Object *obj, void *event_info )
303 {
304         myaccount_appdata *priv = (myaccount_appdata*)data;
305         myaccount_addaccount_create_view(priv);
306 }
307
308 static char *__myaccount_account_list_gl_label_get(void *data,
309                                                                                 Evas_Object *obj, const char *part)
310 {
311         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
312         char domain_name_lower[128] = {0,};
313         MYACCOUNT_VERBOSE("__myaccount_account_list_gl_label_get START data=%p, part=%s\n",
314                                                                                         data, part);
315
316         if (!account_info_item) {
317                 MYACCOUNT_ERROR(" __myaccount_account_list_gl_label_get: Data is NULL\n");
318                 return NULL;
319         }
320
321         if (!strcmp(part, "elm.text") || !strcmp(part, "elm.text.1")) {
322                 myaccount_common_lowercase(account_info_item->domain_name,
323                                                                                                 domain_name_lower);
324
325                 if (strlen(account_info_item->display_name) > 0)
326                         return strdup(account_info_item->display_name);
327                 else if (strlen(account_info_item->email_address) > 0)
328                         return strdup(account_info_item->email_address);
329                 else if (strlen(account_info_item->username) > 0)
330                         return strdup(account_info_item->username);
331                 else
332                         return strdup("Unknown");
333         } else if (!strcmp(part, "elm.text.sub") || !strcmp(part, "elm.text.2")) {
334                 if (strlen(account_info_item->capability) <=0 )
335                         return strdup("Signed In");
336                 else
337                         return strdup(account_info_item->capability);
338         } else {
339                 MYACCOUNT_DBUG("__myaccount_account_list_gl_label_get : UNKNOWN part name");
340                 return strdup(account_info_item->domain_name);
341         }
342
343         MYACCOUNT_VERBOSE("END of __myaccount_account_list_gl_label_get \n");
344         return NULL;
345 }
346
347 static char *__myaccount_account_list_title_get(void *data,
348                                                                                 Evas_Object *obj, const char *part)
349 {
350         if (!strcmp(part, "elm.text"))
351                 return (strdup(dgettext(MA_UG_NAME, "IDS_EMAIL_SK3_ACCOUNT_LIST")));
352
353         return NULL;
354 }
355
356 static Evas_Object *__myaccount_account_list_gl_icon_get(void *data,
357                                                                                         Evas_Object *obj, const char *part)
358 {
359         char tempbuf[PATH_MAX];
360         Evas_Object *icon = NULL;
361         myaccount_list_priv *account_info_item = (myaccount_list_priv*)data;
362
363         MYACCOUNT_VERBOSE("__myaccount_account_list_gl_icon_get START data=%p, obj = %p, part=%s\n",
364                                                                         data, obj, part);
365
366         if (!account_info_item) {
367                 MYACCOUNT_ERROR("__myaccount_account_list_gl_icon_get: Data is NULL\n");
368                 return NULL;
369         }
370         memset(tempbuf, 0, sizeof(char)*PATH_MAX);
371         if (!strcmp(part, "elm.icon.1")) {
372                 MYACCOUNT_VERBOSE("__myaccount_account_list_gl_icon_get : current path %s\n",
373                                                                 account_info_item->icon_path);
374                 if (strlen(account_info_item->icon_path) > 0) {
375                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", account_info_item->icon_path);
376                 } else {
377                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s", "99_email.png");
378                 }
379
380                 icon = elm_icon_add(obj);
381                 if (strstr(tempbuf, "/"))
382                         elm_image_file_set(icon, tempbuf, NULL);
383                 else
384                         elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
385
386                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_NONE, 1, 1);
387         }
388         if (!strcmp(part, "elm.icon.2")) {
389                 if (account_info_item->sync_status == ACCOUNT_SYNC_NOT_SUPPORT)
390                         return NULL;
391
392                 if (account_info_item->sync_status == ACCOUNT_SYNC_STATUS_IDLE
393                         || account_info_item->sync_status == ACCOUNT_SYNC_STATUS_OFF ) {
394                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s",
395                                 "66_myaccount_icon_push_deactivated.png");
396                 } else if  (account_info_item->sync_status == ACCOUNT_SYNC_STATUS_RUNNING){
397                         MA_SNPRINTF(tempbuf, sizeof(tempbuf), "%s",
398                                 "66_myaccount_icon_push_press.png");
399                 }
400
401                 MYACCOUNT_DBUG("## icon path (%s)\n", tempbuf);
402
403                 if(strlen(tempbuf) > 0) {
404                 icon = elm_icon_add(obj);
405                 if (strstr(tempbuf, "/"))
406                         elm_image_file_set(icon, tempbuf, NULL);
407                 else
408                         elm_image_file_set(icon, MA_IMAGE_EDJ_NAME, tempbuf);
409
410                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_NONE, 1, 1);
411         }
412         }
413         MYACCOUNT_VERBOSE("__myaccount_account_list_gl_icon_get :: END :: icon = %p\n",
414                                                         icon);
415         return icon;
416 }
417
418 static void _myaccount_ug_account_list_layout_cb(ui_gadget_h ug,
419                                                                                 enum ug_mode mode, void *priv)
420 {
421         Evas_Object *base;
422         myaccount_appdata *ad;
423
424         if (!ug||!priv) {
425                 MYACCOUNT_FATAL("layout cb error ug=%p, priv=%p\n", ug, priv);
426                 return;
427         }
428         ad = (myaccount_appdata*)priv;
429         base = ug_get_layout(ug);
430         if (!base)
431                 MYACCOUNT_FATAL("layout cb base is null\n");
432
433         switch (mode) {
434         case UG_MODE_FRAMEVIEW:
435                         elm_object_part_content_set (ad->layout_main, "content", base);
436                         break;
437         case UG_MODE_FULLVIEW:
438                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
439                                          EVAS_HINT_EXPAND);
440                         elm_win_resize_object_add(ad->win_main, base);
441                         evas_object_show(base);
442                         break;
443         default:
444                         break;
445         }
446 }
447
448 static void _myaccount_ug_account_list_result_cb(ui_gadget_h ug,
449                                                                                 service_h service, void *priv)
450 {
451         MYACCOUNT_VERBOSE("_myaccount_ug_account_list_result_cb\n");
452 }
453
454 static void _myaccount_ug_account_list_destroy_cb(ui_gadget_h ug,
455                                                                                                         void *priv)
456 {
457         MYACCOUNT_VERBOSE("_myaccount_ug_account_list_destroy_cb\n");
458         myaccount_appdata *mydata = (myaccount_appdata*)priv;
459
460         if (!ug||!mydata) {
461                 MYACCOUNT_ERROR("destroy cb error ug=%p, priv=%p\n", ug, mydata);
462                 return;
463         }
464         mydata->item_selected_state = false;
465
466         ug_destroy(ug);
467         MYACCOUNT_VERBOSE("_myaccount_ug_account_list_destroy_cb : ug callee request kill layout_addaccount=%p\n",
468                                                                                         mydata->layout_addaccount);
469 #ifndef ENABLE_NOTI
470         myaccount_common_handle_notification(NULL);
471 #endif
472 }
473
474 static void __myaccount_ug_launch_signin_view(void *data, myaccount_list_priv *account)
475 {
476         myaccount_appdata *ad = (myaccount_appdata*)data;
477         service_h service;
478         int ret;
479
480         if(!account) {
481                 MYACCOUNT_ERROR("__myaccount_ug_launch_signin_view : account info NULL\n");
482                 return;
483         }
484
485         ret = service_create(&service);
486
487         ret = myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
488                                                                 strdup(account->package_name),
489                                                                 strdup(account->username),
490                                                                 "",
491                                                                 account->account_id,
492                                                                 0,
493                                                                 ad);
494
495         service_destroy(service);
496 }
497
498 static void __myaccount_account_list_gl_sel(void *data,
499                                                                                 Evas_Object *obj, void *event_info)
500 {
501         myaccount_appdata *ad = myaccount_get_appdata();
502         if(ad->item_selected_state) {
503                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
504                 return;
505         }
506         ad->item_selected_state = true;
507         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
508
509         MYACCOUNT_VERBOSE("__myaccount_account_list_gl_sel data=%p, obj=%p, event_info=%p\n",
510                                                                         data, obj, event_info);
511         myaccount_list_priv *account = (myaccount_list_priv*)data;
512         MYACCOUNT_DBUG("__myaccount_account_list_gl_sel : account name : %s\n",
513                                                                         account->domain_name);
514
515         if (item != NULL)
516                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
517
518         __myaccount_ug_launch_signin_view((myaccount_appdata*)ad, account);
519
520         MYACCOUNT_VERBOSE("END of __myaccount_account_list_gl_sel\n");
521
522         return;
523 }
524
525 static void __myaccount_account_list_item_selected(void *data,
526                                                                                 Evas_Object *obj, void *event_info)
527 {
528         MYACCOUNT_VERBOSE("__myaccount_account_list_item_selected \n");
529 }
530
531 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
532                                                                                                                 int count)
533 {
534         MYACCOUNT_DBUG ("\n count received in __myaccount_account_list_append_genlist = %d \n",
535                                                                                 count);
536         int index = 0;
537         Elm_Object_Item *it;
538         bool supported = false;
539
540         if (count > 0) {
541                 it = elm_genlist_item_append(ad->account_genlist,
542                                                                 &account_list_itc_sep, NULL, NULL,
543                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
544                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
545                 it = elm_genlist_item_append(ad->account_genlist,
546                                                                 &account_list_title_itc, NULL, NULL,
547                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
548                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
549
550                 for (index = 0; index < count; index++) {
551                         supported = false;
552                         if (account_info[index].secret == ACCOUNT_SECRECY_VISIBLE) {
553                                 if (ad->capability_filter) {
554                                         GSList* iter;
555                                         myaccount_list_priv *acc_info = NULL;
556                                         acc_info = &account_info[index];
557                                         for (iter = acc_info->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
558                                                 myaccount_capability_data *cap_data = (myaccount_capability_data*)iter->data;
559                                                 if (!strcmp(cap_data->type, ad->capability_filter)) {
560                                                         supported = true;
561                                                         break;
562                                                 }
563                                         }
564                                         if (supported) {
565                                                 it = elm_genlist_item_append(ad->account_genlist,
566                                                                                 &account_list_itc,
567                                                                                 (void *)&account_info[index], NULL,
568                                                                                 ELM_GENLIST_ITEM_NONE,
569                                                                                 __myaccount_account_list_gl_sel,
570                                                                                 (void *)&account_info[index]);
571
572                                                 MYACCOUNT_VERBOSE("genlist item(%p)\n", it);
573                                         }
574                                 } else {
575                                         it = elm_genlist_item_append(ad->account_genlist,
576                                                                         &account_list_itc,
577                                                                         (void *)&account_info[index], NULL,
578                                                                         ELM_GENLIST_ITEM_NONE,
579                                                                         __myaccount_account_list_gl_sel,
580                                                                         (void *)&account_info[index]);
581                                         MYACCOUNT_VERBOSE("genlist item(%p)\n", it);
582                                 }
583                         }
584                 }
585
586                 it = elm_genlist_item_append(ad->account_genlist,
587                                                                 &account_list_itc_sep_end, NULL, NULL,
588                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
589                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
590         } else {
591                 myaccount_addaccount_create_view(ad);
592         }
593         return;
594 }
595
596
597 static void _myaccount_ug_account_gl_realized(void *data, Evas_Object *obj, void *ei)
598 {
599         Elm_Object_Item *it = NULL;
600         int total_count = 0;
601         int index = 0;
602         Evas_Object *ao;
603         char buf[2048]={0,};
604         char bufdomain[2048]={0,};
605
606         if(!ei) {
607                 MYACCOUNT_ERROR("Realized event info is NULL!!! \n");
608                 return;
609         }
610
611         it = (Elm_Object_Item *)ei;
612
613         total_count = elm_genlist_items_count(obj);
614         index = elm_genlist_item_index_get(it);
615
616         MYACCOUNT_VERBOSE("Total genlist item count(%d)!!! \n", total_count);
617         if(index > 2 && index < total_count)
618         {
619         /*Add account items. index 1 and last are the seperators*/
620                 myaccount_list_priv *account_info_item = (myaccount_list_priv*)elm_object_item_data_get(it);
621
622                 if(account_info_item){
623                 memset(buf, 0, 2048);
624                 memset(bufdomain, 0, 2048);
625
626                         if (strlen(account_info_item->domain_name) > 0)
627                                 g_snprintf(bufdomain, 1024, "Logged into %s with user id ", account_info_item->domain_name);
628                         else
629                                 g_snprintf(bufdomain, 1024, "Service unknown user id ");
630
631                         if (strlen(account_info_item->display_name) > 0)
632                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->display_name);
633                         else if (strlen(account_info_item->email_address) > 0)
634                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->email_address);
635                         else if (strlen(account_info_item->username) > 0)
636                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->username);
637                         else
638                                 g_snprintf(buf, 1024, "%sUnknown", account_info_item->domain_name);
639
640                 ao = elm_object_item_access_object_get(it);
641                 elm_access_info_set(ao, ELM_ACCESS_INFO, buf);
642                 }
643         }else {
644                 /*Remove access for seperators*/
645                 elm_object_item_access_unregister(ei);
646         }
647
648         if(total_count <= 4)
649         {
650                 MYACCOUNT_INFO("DO NOTHING only one account exist, total_count(%d) index(%d) !!! \n", total_count, index);
651         } else {
652                 if (index == 1) {
653                         MYACCOUNT_VERBOSE("DO NOTHING realized (%d) !!! \n", index);
654                 } else if (index == 2) {
655                         MYACCOUNT_VERBOSE("TOP realized (%d) !!! \n", index);
656                         elm_object_item_signal_emit(ei, "elm,state,top", "");
657                 } else if (index == (total_count-2)) {
658                         MYACCOUNT_VERBOSE("BOTTOM realized (%d) item count (%d) !!! \n", index, total_count);
659                         elm_object_item_signal_emit(ei, "elm,state,bottom", "");
660                 } else  {
661                         MYACCOUNT_VERBOSE("CENTER realized (%d) !!! \n", index);
662                         elm_object_item_signal_emit(ei, "elm,state,center", "");
663                 }
664         }
665 }
666
667 static Evas_Object *__myaccount_account_list_create_genlist(
668                                                                                                         myaccount_appdata *ad)
669 {
670         Evas_Object *genlist;
671
672         if (ad == NULL) {
673                 MYACCOUNT_ERROR("__myaccount_account_list_create_genlist returns NULL\n");
674                 return NULL;
675         }
676
677         int account_count = 0;
678         account_count = __myaccount_account_list_populate_account_info();
679
680         account_list_itc.item_style = "dialogue/2text.2icon.3";
681         account_list_itc.func.text_get = __myaccount_account_list_gl_label_get;
682         account_list_itc.func.content_get = __myaccount_account_list_gl_icon_get;
683         account_list_itc.func.state_get = NULL;
684         account_list_itc.func.del = NULL;
685
686         account_list_title_itc.item_style = "dialogue/title";
687         account_list_title_itc.func.text_get = __myaccount_account_list_title_get;
688         account_list_title_itc.func.content_get = NULL;
689         account_list_title_itc.func.state_get = NULL;
690         account_list_title_itc.func.del = NULL;
691
692         /*to add 40 pixel separator*/
693         account_list_itc_sep.item_style = "dialogue/separator";
694         account_list_itc_sep.func.text_get = NULL;
695         account_list_itc_sep.func.content_get = NULL;
696         account_list_itc_sep.func.state_get = NULL;
697         account_list_itc_sep.func.del = NULL;
698
699         /*to add 40 pixel list end separator*/
700         account_list_itc_sep_end.item_style = "dialogue/separator/end";
701         account_list_itc_sep_end.func.text_get = NULL;
702         account_list_itc_sep_end.func.content_get = NULL;
703         account_list_itc_sep_end.func.state_get = NULL;
704         account_list_itc_sep_end.func.del = NULL;
705
706         ad->account_genlist = genlist = elm_genlist_add(ad->navi_bar);
707         evas_object_smart_callback_add(genlist, "realized", _myaccount_ug_account_gl_realized, NULL);
708         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
709         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
710         elm_genlist_mode_set(genlist, EINA_TRUE);
711
712         evas_object_smart_callback_add(genlist, "selected",
713                                         __myaccount_account_list_item_selected,
714                                         (myaccount_appdata*) ad);
715
716         MYACCOUNT_VERBOSE("\n account count = %d\n", account_count);
717
718         __myaccount_account_list_append_genlist(ad, account_count);
719
720         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_genlist\n");
721         return genlist;
722 }
723
724 void myaccount_ug_account_list_create(void *data)
725 {
726         MYACCOUNT_VERBOSE("\n myaccount_ug_account_list_create called !!\n");
727         myaccount_appdata *ad = data;
728         Evas_Object *genlist = NULL;
729         Evas_Object *layout;
730         Evas_Object *l_button;
731         Evas_Object *btn;
732
733         if (ad == NULL) {
734                 MYACCOUNT_ERROR("myaccount_ug_account_list_create myaccount_appdata is null\n");
735                 return;
736         }
737
738         layout = elm_layout_add(ad->navi_bar);
739         elm_layout_file_set(layout,
740                                         "/usr/ug/res/edje/ug-setting-myaccount-efl/myaccount.edj",
741                                         "account_list");
742         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
743         evas_object_size_hint_align_set( layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
744         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
745         //edje_object_signal_emit(_EDJ(layout), "elm,bg,show,group_list", "elm");
746         elm_object_style_set(ad->bg, "group_list");
747         evas_object_show(layout);
748
749         genlist = __myaccount_account_list_create_genlist(ad);
750
751         elm_object_part_content_set (layout, "accountlist.genlist", genlist);
752         ad->l_title_sk = l_button = elm_button_add(ad->navi_bar);
753         evas_object_smart_callback_add(l_button, "clicked",
754                                         myaccount_account_list_quit_cb,
755                                         ad);
756         elm_object_style_set(l_button , "naviframe/back_btn/default");
757         ad->navi_it = elm_naviframe_item_push(ad->navi_bar,
758                                                         dgettext(MA_UG_NAME,
759                                                         "IDS_ST_HEADER_ACCOUNTS_AND_SYNC"),
760                                                         l_button, NULL, layout, NULL);
761         btn = elm_button_add(ad->navi_bar);
762         if (!btn) {
763                 MYACCOUNT_ERROR("myaccount_ug_account_list_create elm_button_add FAIL\n");
764                 return;
765         }
766         elm_object_style_set(btn, "naviframe/toolbar/default");
767         elm_object_text_set(btn, dgettext(MA_UG_NAME,
768                                         "IDS_COM_SK_ADD_LITE"));
769         evas_object_smart_callback_add(btn, "clicked",
770                                         __myaccount_account_list_addaccount_cb,
771                                         ad);
772
773         elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", btn);
774
775         MYACCOUNT_VERBOSE("END of myaccount_ug_account_list_create\n");
776 }
777
778 static Evas_Object *__myaccount_account_list_create_bg(Evas_Object *parent)
779 {
780         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_bg ");
781         Evas_Object *bg = elm_bg_add(parent);
782         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
783         elm_win_resize_object_add(parent, bg);
784         evas_object_show(bg);
785         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_bg ");
786     return bg;
787 }
788
789 static Evas_Object *__myaccount_account_list_create_main_layout(
790                                                                                                         Evas_Object *parent,
791                                                                                                         Evas_Object *bg)
792 {
793         Evas_Object *layout;
794         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_main_layout ");
795
796         layout = elm_layout_add(parent);
797         elm_layout_theme_set(layout, "layout", "application", "default");
798         evas_object_size_hint_weight_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
799         edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator", "elm");
800         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
801         elm_object_part_content_set ( layout, "elm.swallow.bg", bg);
802         evas_object_show( layout );
803         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_main_layout ");
804
805         return layout;
806 }
807
808 static Evas_Object *__myaccount_account_list_create_navi_layout(
809                                                                                                                         Evas_Object *parent)
810 {
811         Evas_Object *navi_bar;
812         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_navi_layout ");
813
814         navi_bar = elm_naviframe_add(parent);
815         elm_object_part_content_set ( parent, "elm.swallow.content", navi_bar );
816         evas_object_show(navi_bar);
817         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_navi_layout ");
818
819         return navi_bar;
820 }
821
822 static void __myaccount_account_list_init_main_view(myaccount_appdata *ad)
823 {
824         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
825         ad->bg = __myaccount_account_list_create_bg(ad->win_main);
826         ad->layout_main = __myaccount_account_list_create_main_layout(ad->win_main,
827                                                                                                                                 ad->bg);
828         ad->base = ad->layout_main;
829         ad->navi_bar = __myaccount_account_list_create_navi_layout(ad->layout_main);
830
831         MYACCOUNT_VERBOSE("END of __myaccount_account_list_init_main_view : %p\n",
832                                                                                                                                 ad->navi_bar);
833 }
834
835 void myaccount_list_view_create(myaccount_appdata *priv)
836 {
837         /*struct ug_cbs cbs = {0,};*/
838         __attribute__((__unused__)) struct ug_cbs cbs = {0,};
839         cbs.layout_cb = _myaccount_ug_account_list_layout_cb;
840         cbs.result_cb = _myaccount_ug_account_list_result_cb;
841         cbs.destroy_cb = _myaccount_ug_account_list_destroy_cb;
842         cbs.priv = (void *)priv;
843
844         MYACCOUNT_VERBOSE("\n !!!!! myaccount_list_view_create !!!!! \n");
845
846         __myaccount_account_list_init_main_view(priv);
847 }
848
849 void myaccount_list_refresh_item_list(myaccount_appdata *ad)
850 {
851         int count = 0;
852
853         MYACCOUNT_DBUG("START\n");
854
855         if(!ad) {
856                 MYACCOUNT_FATAL("no appdata!\n");
857                 return;
858         }
859
860         elm_genlist_clear(ad->account_genlist);
861
862         MYACCOUNT_DBUG("Account list removed completely!\n");
863         if(account_info) {
864                 if (account_info->capablity_list) {
865                         g_slist_free(account_info->capablity_list);
866                         account_info->capablity_list = NULL;
867                 }
868         }
869         MA_MEMFREE(account_info);
870         account_index = 0;
871         count = __myaccount_account_list_populate_account_info();
872
873         __myaccount_account_list_append_genlist(ad, count);
874
875         return;
876 }
877