Enable build with iniparser v 3.1
[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.1 (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
479         if(!account) {
480                 MYACCOUNT_ERROR("__myaccount_ug_launch_signin_view : account info NULL\n");
481                 return;
482         }
483
484         service_create(&service);
485
486         myaccount_common_launch_application(MYACCOUNT_REQUEST_VIEW,
487                                                 strdup(account->package_name),
488                                                 strdup(account->username),
489                                                 "",
490                                                 account->account_id,
491                                                 0,
492                                                 ad);
493
494         service_destroy(service);
495 }
496
497 static void __myaccount_account_list_gl_sel(void *data,
498                                                                                 Evas_Object *obj, void *event_info)
499 {
500         myaccount_appdata *ad = myaccount_get_appdata();
501         if(ad->item_selected_state) {
502                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
503                 return;
504         }
505         ad->item_selected_state = true;
506         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
507
508         MYACCOUNT_VERBOSE("__myaccount_account_list_gl_sel data=%p, obj=%p, event_info=%p\n",
509                                                                         data, obj, event_info);
510         myaccount_list_priv *account = (myaccount_list_priv*)data;
511         MYACCOUNT_DBUG("__myaccount_account_list_gl_sel : account name : %s\n",
512                                                                         account->domain_name);
513
514         if (item != NULL)
515                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
516
517         __myaccount_ug_launch_signin_view((myaccount_appdata*)ad, account);
518
519         MYACCOUNT_VERBOSE("END of __myaccount_account_list_gl_sel\n");
520
521         return;
522 }
523
524 static void __myaccount_account_list_item_selected(void *data,
525                                                                                 Evas_Object *obj, void *event_info)
526 {
527         MYACCOUNT_VERBOSE("__myaccount_account_list_item_selected \n");
528 }
529
530 static void __myaccount_account_list_append_genlist(myaccount_appdata *ad,
531                                                                                                                 int count)
532 {
533         MYACCOUNT_DBUG ("\n count received in __myaccount_account_list_append_genlist = %d \n",
534                                                                                 count);
535         int index = 0;
536         Elm_Object_Item *it;
537         bool supported = false;
538
539         if (count > 0) {
540                 it = elm_genlist_item_append(ad->account_genlist,
541                                                                 &account_list_itc_sep, NULL, NULL,
542                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
543                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
544                 it = elm_genlist_item_append(ad->account_genlist,
545                                                                 &account_list_title_itc, NULL, NULL,
546                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
547                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
548
549                 for (index = 0; index < count; index++) {
550                         supported = false;
551                         if (account_info[index].secret == ACCOUNT_SECRECY_VISIBLE) {
552                                 if (ad->capability_filter) {
553                                         GSList* iter;
554                                         myaccount_list_priv *acc_info = NULL;
555                                         acc_info = &account_info[index];
556                                         for (iter = acc_info->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
557                                                 myaccount_capability_data *cap_data = (myaccount_capability_data*)iter->data;
558                                                 if (!strcmp(cap_data->type, ad->capability_filter)) {
559                                                         supported = true;
560                                                         break;
561                                                 }
562                                         }
563                                         if (supported) {
564                                                 it = elm_genlist_item_append(ad->account_genlist,
565                                                                                 &account_list_itc,
566                                                                                 (void *)&account_info[index], NULL,
567                                                                                 ELM_GENLIST_ITEM_NONE,
568                                                                                 __myaccount_account_list_gl_sel,
569                                                                                 (void *)&account_info[index]);
570
571                                                 MYACCOUNT_VERBOSE("genlist item(%p)\n", it);
572                                         }
573                                 } else {
574                                         it = elm_genlist_item_append(ad->account_genlist,
575                                                                         &account_list_itc,
576                                                                         (void *)&account_info[index], NULL,
577                                                                         ELM_GENLIST_ITEM_NONE,
578                                                                         __myaccount_account_list_gl_sel,
579                                                                         (void *)&account_info[index]);
580                                         MYACCOUNT_VERBOSE("genlist item(%p)\n", it);
581                                 }
582                         }
583                 }
584
585                 it = elm_genlist_item_append(ad->account_genlist,
586                                                                 &account_list_itc_sep_end, NULL, NULL,
587                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
588                 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
589         } else {
590                 myaccount_addaccount_create_view(ad);
591         }
592         return;
593 }
594
595
596 static void _myaccount_ug_account_gl_realized(void *data, Evas_Object *obj, void *ei)
597 {
598         Elm_Object_Item *it = NULL;
599         int total_count = 0;
600         int index = 0;
601         Evas_Object *ao;
602         char buf[2048]={0,};
603         char bufdomain[2048]={0,};
604
605         if(!ei) {
606                 MYACCOUNT_ERROR("Realized event info is NULL!!! \n");
607                 return;
608         }
609
610         it = (Elm_Object_Item *)ei;
611
612         total_count = elm_genlist_items_count(obj);
613         index = elm_genlist_item_index_get(it);
614
615         MYACCOUNT_VERBOSE("Total genlist item count(%d)!!! \n", total_count);
616         if(index > 2 && index < total_count)
617         {
618         /*Add account items. index 1 and last are the seperators*/
619                 myaccount_list_priv *account_info_item = (myaccount_list_priv*)elm_object_item_data_get(it);
620
621                 if(account_info_item){
622                 memset(buf, 0, 2048);
623                 memset(bufdomain, 0, 2048);
624
625                         if (strlen(account_info_item->domain_name) > 0)
626                                 g_snprintf(bufdomain, 1024, "Logged into %s with user id ", account_info_item->domain_name);
627                         else
628                                 g_snprintf(bufdomain, 1024, "Service unknown user id ");
629
630                         if (strlen(account_info_item->display_name) > 0)
631                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->display_name);
632                         else if (strlen(account_info_item->email_address) > 0)
633                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->email_address);
634                         else if (strlen(account_info_item->username) > 0)
635                                 g_snprintf(buf, 1024, "%s%s", bufdomain, account_info_item->username);
636                         else
637                                 g_snprintf(buf, 1024, "%sUnknown", account_info_item->domain_name);
638
639                 ao = elm_object_item_access_object_get(it);
640                 elm_access_info_set(ao, ELM_ACCESS_INFO, buf);
641                 }
642         }else {
643                 /*Remove access for seperators*/
644                 elm_object_item_access_unregister(ei);
645         }
646
647         if(total_count <= 4)
648         {
649                 MYACCOUNT_INFO("DO NOTHING only one account exist, total_count(%d) index(%d) !!! \n", total_count, index);
650         } else {
651                 if (index == 1) {
652                         MYACCOUNT_VERBOSE("DO NOTHING realized (%d) !!! \n", index);
653                 } else if (index == 2) {
654                         MYACCOUNT_VERBOSE("TOP realized (%d) !!! \n", index);
655                         elm_object_item_signal_emit(ei, "elm,state,top", "");
656                 } else if (index == (total_count-2)) {
657                         MYACCOUNT_VERBOSE("BOTTOM realized (%d) item count (%d) !!! \n", index, total_count);
658                         elm_object_item_signal_emit(ei, "elm,state,bottom", "");
659                 } else  {
660                         MYACCOUNT_VERBOSE("CENTER realized (%d) !!! \n", index);
661                         elm_object_item_signal_emit(ei, "elm,state,center", "");
662                 }
663         }
664 }
665
666 static Evas_Object *__myaccount_account_list_create_genlist(
667                                                                                                         myaccount_appdata *ad)
668 {
669         Evas_Object *genlist;
670
671         if (ad == NULL) {
672                 MYACCOUNT_ERROR("__myaccount_account_list_create_genlist returns NULL\n");
673                 return NULL;
674         }
675
676         int account_count = 0;
677         account_count = __myaccount_account_list_populate_account_info();
678
679         account_list_itc.item_style = "dialogue/2text.2icon.3";
680         account_list_itc.func.text_get = __myaccount_account_list_gl_label_get;
681         account_list_itc.func.content_get = __myaccount_account_list_gl_icon_get;
682         account_list_itc.func.state_get = NULL;
683         account_list_itc.func.del = NULL;
684
685         account_list_title_itc.item_style = "dialogue/title";
686         account_list_title_itc.func.text_get = __myaccount_account_list_title_get;
687         account_list_title_itc.func.content_get = NULL;
688         account_list_title_itc.func.state_get = NULL;
689         account_list_title_itc.func.del = NULL;
690
691         /*to add 40 pixel separator*/
692         account_list_itc_sep.item_style = "dialogue/separator";
693         account_list_itc_sep.func.text_get = NULL;
694         account_list_itc_sep.func.content_get = NULL;
695         account_list_itc_sep.func.state_get = NULL;
696         account_list_itc_sep.func.del = NULL;
697
698         /*to add 40 pixel list end separator*/
699         account_list_itc_sep_end.item_style = "dialogue/separator/end";
700         account_list_itc_sep_end.func.text_get = NULL;
701         account_list_itc_sep_end.func.content_get = NULL;
702         account_list_itc_sep_end.func.state_get = NULL;
703         account_list_itc_sep_end.func.del = NULL;
704
705         ad->account_genlist = genlist = elm_genlist_add(ad->navi_bar);
706         evas_object_smart_callback_add(genlist, "realized", _myaccount_ug_account_gl_realized, NULL);
707         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
708         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
709         elm_genlist_mode_set(genlist, EINA_TRUE);
710
711         evas_object_smart_callback_add(genlist, "selected",
712                                         __myaccount_account_list_item_selected,
713                                         (myaccount_appdata*) ad);
714
715         MYACCOUNT_VERBOSE("\n account count = %d\n", account_count);
716
717         __myaccount_account_list_append_genlist(ad, account_count);
718
719         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_genlist\n");
720         return genlist;
721 }
722
723 void myaccount_ug_account_list_create(void *data)
724 {
725         MYACCOUNT_VERBOSE("\n myaccount_ug_account_list_create called !!\n");
726         myaccount_appdata *ad = data;
727         Evas_Object *genlist = NULL;
728         Evas_Object *layout;
729         Evas_Object *l_button;
730         Evas_Object *btn;
731
732         if (ad == NULL) {
733                 MYACCOUNT_ERROR("myaccount_ug_account_list_create myaccount_appdata is null\n");
734                 return;
735         }
736
737         layout = elm_layout_add(ad->navi_bar);
738         elm_layout_file_set(layout,
739                                         "/usr/ug/res/edje/ug-setting-myaccount-efl/myaccount.edj",
740                                         "account_list");
741         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
742         evas_object_size_hint_align_set( layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
743         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
744         //edje_object_signal_emit(_EDJ(layout), "elm,bg,show,group_list", "elm");
745         elm_object_style_set(ad->bg, "group_list");
746         evas_object_show(layout);
747
748         genlist = __myaccount_account_list_create_genlist(ad);
749
750         elm_object_part_content_set (layout, "accountlist.genlist", genlist);
751         ad->l_title_sk = l_button = elm_button_add(ad->navi_bar);
752         evas_object_smart_callback_add(l_button, "clicked",
753                                         myaccount_account_list_quit_cb,
754                                         ad);
755         elm_object_style_set(l_button , "naviframe/back_btn/default");
756         ad->navi_it = elm_naviframe_item_push(ad->navi_bar,
757                                                         dgettext(MA_UG_NAME,
758                                                         "IDS_ST_HEADER_ACCOUNTS_AND_SYNC"),
759                                                         l_button, NULL, layout, NULL);
760         btn = elm_button_add(ad->navi_bar);
761         if (!btn) {
762                 MYACCOUNT_ERROR("myaccount_ug_account_list_create elm_button_add FAIL\n");
763                 return;
764         }
765         elm_object_style_set(btn, "naviframe/toolbar/default");
766         elm_object_text_set(btn, dgettext(MA_UG_NAME,
767                                         "IDS_COM_SK_ADD_LITE"));
768         evas_object_smart_callback_add(btn, "clicked",
769                                         __myaccount_account_list_addaccount_cb,
770                                         ad);
771
772         elm_object_item_part_content_set(ad->navi_it, "toolbar_button1", btn);
773
774         MYACCOUNT_VERBOSE("END of myaccount_ug_account_list_create\n");
775 }
776
777 static Evas_Object *__myaccount_account_list_create_bg(Evas_Object *parent)
778 {
779         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_bg ");
780         Evas_Object *bg = elm_bg_add(parent);
781         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
782         elm_win_resize_object_add(parent, bg);
783         evas_object_show(bg);
784         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_bg ");
785     return bg;
786 }
787
788 static Evas_Object *__myaccount_account_list_create_main_layout(
789                                                                                                         Evas_Object *parent,
790                                                                                                         Evas_Object *bg)
791 {
792         Evas_Object *layout;
793         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_main_layout ");
794
795         layout = elm_layout_add(parent);
796         elm_layout_theme_set(layout, "layout", "application", "default");
797         evas_object_size_hint_weight_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
798         edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator", "elm");
799         edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
800         elm_object_part_content_set ( layout, "elm.swallow.bg", bg);
801         evas_object_show( layout );
802         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_main_layout ");
803
804         return layout;
805 }
806
807 static Evas_Object *__myaccount_account_list_create_navi_layout(
808                                                                                                                         Evas_Object *parent)
809 {
810         Evas_Object *navi_bar;
811         MYACCOUNT_VERBOSE("START of __myaccount_account_list_create_navi_layout ");
812
813         navi_bar = elm_naviframe_add(parent);
814         elm_object_part_content_set ( parent, "elm.swallow.content", navi_bar );
815         evas_object_show(navi_bar);
816         MYACCOUNT_VERBOSE("END of __myaccount_account_list_create_navi_layout ");
817
818         return navi_bar;
819 }
820
821 static void __myaccount_account_list_init_main_view(myaccount_appdata *ad)
822 {
823         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
824         ad->bg = __myaccount_account_list_create_bg(ad->win_main);
825         ad->layout_main = __myaccount_account_list_create_main_layout(ad->win_main,
826                                                                                                                                 ad->bg);
827         ad->base = ad->layout_main;
828         ad->navi_bar = __myaccount_account_list_create_navi_layout(ad->layout_main);
829
830         MYACCOUNT_VERBOSE("END of __myaccount_account_list_init_main_view : %p\n",
831                                                                                                                                 ad->navi_bar);
832 }
833
834 void myaccount_list_view_create(myaccount_appdata *priv)
835 {
836         /*struct ug_cbs cbs = {0,};*/
837         __attribute__((__unused__)) struct ug_cbs cbs = {0,};
838         cbs.layout_cb = _myaccount_ug_account_list_layout_cb;
839         cbs.result_cb = _myaccount_ug_account_list_result_cb;
840         cbs.destroy_cb = _myaccount_ug_account_list_destroy_cb;
841         cbs.priv = (void *)priv;
842
843         MYACCOUNT_VERBOSE("\n !!!!! myaccount_list_view_create !!!!! \n");
844
845         __myaccount_account_list_init_main_view(priv);
846 }
847
848 void myaccount_list_refresh_item_list(myaccount_appdata *ad)
849 {
850         int count = 0;
851
852         MYACCOUNT_DBUG("START\n");
853
854         if(!ad) {
855                 MYACCOUNT_FATAL("no appdata!\n");
856                 return;
857         }
858
859         elm_genlist_clear(ad->account_genlist);
860
861         MYACCOUNT_DBUG("Account list removed completely!\n");
862         if(account_info) {
863                 if (account_info->capablity_list) {
864                         g_slist_free(account_info->capablity_list);
865                         account_info->capablity_list = NULL;
866                 }
867         }
868         MA_MEMFREE(account_info);
869         account_index = 0;
870         count = __myaccount_account_list_populate_account_info();
871
872         __myaccount_account_list_append_genlist(ad, count);
873
874         return;
875 }
876