4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Tarun Kumar <tarun.kr@samsung.com>
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
22 #include "myaccount_ug.h"
\r
23 #include "myaccount_ug_common.h"
\r
24 #include "myaccount_ug_addaccount.h"
\r
25 #include "myaccount_ug_account_list.h"
\r
27 static myaccount_appdata *g_myaccount_appdata = NULL;
\r
29 void *myaccount_init_appdata()
\r
31 if (g_myaccount_appdata == NULL) {
\r
32 g_myaccount_appdata = calloc(1, sizeof(myaccount_appdata));
\r
33 g_myaccount_appdata->item_selected_state = false;
\r
35 return g_myaccount_appdata;
\r
38 void myaccount_destroy_appdata()
\r
40 MYACCOUNT_INFO("myaccount_destroy_appdata START \n");
\r
42 if (g_myaccount_appdata == NULL) {
\r
43 MYACCOUNT_WARNING("myaccount_destroy_appdata: appdata NULL \n");
\r
48 /* fix by sungchan,kim.
\r
49 sudden crash on account list view destroyed.
\r
50 tempolarily blocked below codes. */
\r
51 if (g_myaccount_appdata->base) {
\r
52 evas_object_del(g_myaccount_appdata->base);
\r
53 g_myaccount_appdata->base = NULL;
\r
55 MA_MEMFREE(g_myaccount_appdata->capability_filter)
\r
57 /* For accounts list */
\r
58 if (g_myaccount_appdata->ug_called) {
\r
59 ug_destroy(g_myaccount_appdata->ug_called);
\r
60 g_myaccount_appdata->ug_called = NULL;
\r
62 if (g_myaccount_appdata->layout_main) {
\r
63 evas_object_del(g_myaccount_appdata->layout_main);
\r
64 g_myaccount_appdata->layout_main = NULL;
\r
66 if (g_myaccount_appdata->layout_addaccount) {
\r
67 evas_object_del(g_myaccount_appdata->layout_addaccount);
\r
68 g_myaccount_appdata->layout_addaccount = NULL;
\r
70 if (g_myaccount_appdata->navi_bar) {
\r
71 evas_object_del(g_myaccount_appdata->navi_bar);
\r
72 g_myaccount_appdata->navi_bar = NULL;
\r
74 if (g_myaccount_appdata->account_genlist) {
\r
75 evas_object_del(g_myaccount_appdata->account_genlist);
\r
76 g_myaccount_appdata->account_genlist = NULL;
\r
78 if (g_myaccount_appdata->help_label) {
\r
79 evas_object_del(g_myaccount_appdata->help_label);
\r
80 g_myaccount_appdata->help_label = NULL;
\r
82 if (g_myaccount_appdata->refresh_btn) {
\r
83 evas_object_del(g_myaccount_appdata->refresh_btn);
\r
84 g_myaccount_appdata->refresh_btn = NULL;
\r
86 if (g_myaccount_appdata->refresh_icon) {
\r
87 evas_object_del(g_myaccount_appdata->refresh_icon);
\r
88 g_myaccount_appdata->refresh_icon = NULL;
\r
90 if (g_myaccount_appdata->cancel_sync_icon) {
\r
91 evas_object_del(g_myaccount_appdata->cancel_sync_icon);
\r
92 g_myaccount_appdata->cancel_sync_icon = NULL;
\r
94 if (g_myaccount_appdata->auto_sync_check) {
\r
95 evas_object_del(g_myaccount_appdata->auto_sync_check);
\r
96 g_myaccount_appdata->auto_sync_check = NULL;
\r
98 if (g_myaccount_appdata->bg) {
\r
99 evas_object_del(g_myaccount_appdata->bg);
\r
100 g_myaccount_appdata->bg = NULL;
\r
102 if (g_myaccount_appdata->ly) {
\r
103 elm_object_part_content_unset(g_myaccount_appdata->ly, "elm.swallow.content");
\r
104 evas_object_del(g_myaccount_appdata->ly);
\r
105 g_myaccount_appdata->ly = NULL;
\r
107 if (g_myaccount_appdata->modal_popup) {
\r
108 evas_object_del(g_myaccount_appdata->modal_popup);
\r
109 g_myaccount_appdata->modal_popup = NULL;
\r
111 if (g_myaccount_appdata->r_title_sk) {
\r
112 evas_object_del(g_myaccount_appdata->r_title_sk);
\r
113 g_myaccount_appdata->r_title_sk = NULL;
\r
115 if (g_myaccount_appdata->l_title_sk) {
\r
116 evas_object_del(g_myaccount_appdata->l_title_sk);
\r
117 g_myaccount_appdata->l_title_sk = NULL;
\r
119 if (g_myaccount_appdata->progress_timer) {
\r
120 ecore_timer_del(g_myaccount_appdata->progress_timer);
\r
121 g_myaccount_appdata->progress_timer = NULL;
\r
123 if (g_myaccount_appdata->add_genlist) {
\r
124 evas_object_del(g_myaccount_appdata->add_genlist);
\r
125 g_myaccount_appdata->add_genlist = NULL;
\r
127 if (g_myaccount_appdata->pc) {
\r
128 pkgmgr_client_free(g_myaccount_appdata->pc);
\r
129 g_myaccount_appdata->pc = NULL;
\r
132 if(g_myaccount_appdata->sp_info_list) {
\r
133 g_list_free(g_myaccount_appdata->sp_info_list);
\r
134 g_myaccount_appdata->sp_info_list = NULL;
\r
137 g_myaccount_appdata->sorted_sp_list= NULL;
\r
139 MA_MEMFREE(g_myaccount_appdata->caller_userdata);
\r
140 MA_MEMFREE(g_myaccount_appdata->called_from);
\r
141 MA_MEMFREE(g_myaccount_appdata);
\r
143 MYACCOUNT_VERBOSE("myaccount_destroy_appdata END \n");
\r
146 void * myaccount_get_appdata()
\r
148 return g_myaccount_appdata;
\r
151 void myaccount_common_get_icon_by_name(char *domain_name,
\r
154 if (!domain_name) {
\r
155 MYACCOUNT_ERROR("\n !!! domain_name is NULL \n");
\r
158 char tmp_domain_name[64] = {0,};
\r
159 myaccount_common_lowercase(domain_name, tmp_domain_name);
\r
160 MYACCOUNT_VERBOSE("\n !!! myaccount_common_get_icon_by_name = %s \n",
\r
164 MYACCOUNT_ERROR("\n !!! icon_path is NULL \n");
\r
167 if (!strcmp(tmp_domain_name, "google") || !strcmp(tmp_domain_name, "gmail")) {
\r
168 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
169 "66_myaccount_icon_google_50x50.png");
\r
170 } else if (!strcmp(tmp_domain_name, "yahoo")
\r
171 || !strcmp(tmp_domain_name, "ymail")) {
\r
172 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
173 "66_myaccount_icon_yahoo_50x50.png");
\r
174 } else if (!strcmp(tmp_domain_name, "hotmail")) {
\r
175 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
176 "66_myaccount_icon_msn_50x50.png");
\r
177 } else if (!strcmp(tmp_domain_name, "msn")) {
\r
178 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
179 "66_myaccount_icon_windows_live_50x50.png");
\r
180 } else if (!strcmp(tmp_domain_name, "exchange")) {
\r
181 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
183 } else if (!strcmp(tmp_domain_name, "icq")) {
\r
184 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "icq.png");
\r
185 } else if (!strcmp(tmp_domain_name, "facebook")) {
\r
186 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
187 "66_myaccount_icon_facebook_50x50.png");
\r
188 } else if (!strcmp(tmp_domain_name, "twitter")) {
\r
189 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
190 "66_myaccount_icon_twitter_50x50.png");
\r
191 } else if (!strcmp(tmp_domain_name, "myspace")) {
\r
192 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
194 } else if(!strcmp(tmp_domain_name, "picasa")) {
\r
195 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "picasa.png");
\r
196 } else if(!strcmp(tmp_domain_name, "flickr")) {
\r
197 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "flickr.png");
\r
198 } else if (!strcmp(tmp_domain_name, "samsung")) {
\r
199 MA_SNPRINTF(icon_path, BUFSIZE, "%s",
\r
200 "01_samsungaccount.png");
\r
201 } else if (!strcmp(tmp_domain_name, "youtube")) {
\r
202 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "youtube.png");
\r
203 } else if (!strcmp(tmp_domain_name, "others")) {
\r
204 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "A01_2_Icon_others.png");
\r
206 MYACCOUNT_VERBOSE("Default icon\n");
\r
207 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "A01_2_Icon_default.png");
\r
211 void myaccount_common_lowercase(char *src, char *dest)
\r
216 if (!src || !dest) {
\r
217 MYACCOUNT_ERROR("myaccount_common_lowercase src=%p, dest=%p\n",
\r
221 src_len = strlen(src);
\r
222 for(i=0;i<src_len;i++) {
\r
223 dest[i] = tolower(src[i]);
\r
228 void myaccount_common_handle_notification(const char* event_type)
\r
230 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
233 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
237 int error_code = -1;
\r
239 char *noti_name = NULL;
\r
241 appdata->item_selected_state = false;
\r
243 noti_name = vconf_get_str(VCONFKEY_ACCOUNT_MSG_STR);
\r
245 MYACCOUNT_FATAL("myaccount_common_handle_notification: vconf_get_str() Failed!\n");
\r
248 MYACCOUNT_VERBOSE("myaccount_common_handle_notification: noti_name = %s\n",
\r
251 error_code = myaccount_common_get_all_account_cnt(&count);
\r
252 if (error_code != ACCOUNT_ERROR_NONE) {
\r
253 MYACCOUNT_ERROR("myaccount_common_handle_notification: myaccount_common_get_all_account_cnt fail(%d) \n",
\r
257 MYACCOUNT_VERBOSE("myaccount_common_handle_notification account count =%d\n",
\r
260 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
\r
262 if (appdata->add_genlist && strcmp(noti_name, ACCOUNT_NOTI_NAME_SYNC_UPDATE)) {
\r
263 evas_object_del(appdata->add_genlist);
\r
264 appdata->add_genlist = NULL;
\r
265 elm_naviframe_item_pop(appdata->navi_bar);
\r
267 if (appdata->account_genlist) {
\r
268 myaccount_list_refresh_item_list(appdata);
\r
270 myaccount_ug_account_list_create((void*)appdata);
\r
273 if (appdata->add_genlist) {
\r
274 evas_object_show(appdata->add_genlist);
\r
276 myaccount_addaccount_create_view(appdata);
\r
279 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
\r
281 if (!strcmp(event_type, ACCOUNT_NOTI_NAME_INSERT) && appdata->ug) {
\r
282 service_h service = NULL;
\r
285 ret = service_create(&service);
\r
286 MYACCOUNT_VERBOSE("service_create ret (%x)\n", ret);
\r
287 ret = service_add_extra_data(service, "account_noti", noti_name);
\r
288 MYACCOUNT_VERBOSE("service_add_extra_data ret (%x)\n", ret);
\r
289 error_code = ug_send_result(appdata->ug, service);
\r
290 MYACCOUNT_VERBOSE("ug_send_result ret (%x)\n", error_code);
\r
291 error_code = ug_destroy_me(appdata->ug);
\r
292 MYACCOUNT_VERBOSE("myaccount_common_handle_notification callback : return = %d!!!\n",
\r
297 MYACCOUNT_WARNING("Unknown mode !!!");
\r
301 bool myaccount_samsung_callback(char* result_code, char* user_id, void *user_data)
\r
303 MYACCOUNT_VERBOSE("Result Code = %s\n", result_code);
\r
304 MYACCOUNT_VERBOSE("User Id = %s\n", user_id);
\r
307 int* test = (int*)user_data;
\r
309 MYACCOUNT_VERBOSE("TEST user data int = %d\n", *test);
\r
316 static void _myaccount_common_popup_cb(void *data, Evas_Object *obj, void *event_info)
\r
318 MYACCOUNT_VERBOSE("delete popup\n");
\r
321 evas_object_del(obj);
\r
324 Evas_Object* _myaccount_common_add_popup(Evas_Object* parent, const char* text, const char* title)
\r
326 Evas_Object *popup = elm_popup_add(parent);
\r
328 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
\r
330 elm_object_text_set(popup, text);
\r
331 elm_object_part_text_set(popup, "title,text", title);
\r
332 evas_object_smart_callback_add(popup, "block,clicked", _myaccount_common_popup_cb, NULL);
\r
333 elm_popup_timeout_set(popup, 3);
\r
334 evas_object_smart_callback_add(popup, "timeout", _myaccount_common_popup_cb, NULL);
\r
335 evas_object_show(popup);
\r
339 int myaccount_common_launch_application(MyAccountRequestViewType
\r
341 char *package_name,
\r
345 MyAccountProviderType sp_type,
\r
348 int ret = SERVICE_ERROR_NONE;
\r
350 myaccount_appdata *ad = (myaccount_appdata *) data;
\r
351 char win_id_buf[64]={0,};
\r
352 char id_buf[64] = {0,};
\r
354 if (!ad || !package_name) {
\r
355 MYACCOUNT_ERROR("myaccount_common_launch_application: App data=%p, package_name=%p\n",
\r
360 MYACCOUNT_DBUG("trying to launch (%s)\n", package_name);
\r
362 ad->win_id = elm_win_xwindow_get(ad->win_main);
\r
363 MA_SNPRINTF(win_id_buf, sizeof(win_id_buf)-1, "%d", ad->win_id);
\r
365 ret = service_create(&service);
\r
366 ret = service_set_app_id(service, package_name);
\r
367 ret = service_set_window(service, ad->win_id);
\r
368 if(ad->caller_userdata) {
\r
369 MYACCOUNT_DBUG("myaccount_common_launch_application: caller userdata exist!\n");
\r
370 ret = service_add_extra_data(service, "myaccount_userdata", ad->caller_userdata);
\r
373 switch (request_type) {
\r
374 case MYACCOUNT_REQUEST_SIGNIN :
\r
375 service_set_operation(service, ACCOUNT_OPERATION_SIGNIN);
\r
376 if(email_sp && strlen(email_sp) > 0) {
\r
377 MYACCOUNT_DBUG("Tizen email_sp (%s)\n", email_sp);
\r
378 service_add_extra_data(service, ACCOUNT_DATA_SERVICE_PROVIDER, email_sp);
\r
381 case MYACCOUNT_REQUEST_VIEW :
\r
383 MYACCOUNT_ERROR("myaccount_common_launch_application: username=%p !!!\n",
\r
385 MA_MEMFREE(package_name);
\r
386 service_destroy(service);
\r
390 MA_SNPRINTF(id_buf, sizeof(id_buf), "%d", account_id);
\r
391 ret = service_add_extra_data(service, ACCOUNT_DATA_ID, id_buf);
\r
392 ret = service_set_operation(service, ACCOUNT_OPERATION_VIEW);
\r
393 MYACCOUNT_DBUG("###### USERNAME = %s\n", username);
\r
394 ret = service_add_extra_data(service, ACCOUNT_DATA_USERNAME,username);
\r
397 MYACCOUNT_DBUG("myaccount_common_launch_application: Invalid request type=%d\n",
\r
399 MA_MEMFREE(username);
\r
400 MA_MEMFREE(package_name);
\r
401 service_destroy(service);
\r
404 MYACCOUNT_VERBOSE("myaccount_common_launch_application request type=%d, package name = %s\n",
\r
405 request_type, package_name);
\r
407 ret = service_add_extra_data(service, "XWINDOW_ID", win_id_buf);
\r
408 ret = service_send_launch_request(service, NULL, NULL);
\r
410 MA_MEMFREE(username);
\r
411 MA_MEMFREE(package_name);
\r
412 service_destroy(service);
\r
414 if(ret != SERVICE_ERROR_NONE) {
\r
415 MYACCOUNT_ERROR("(%s) launch fail. ret(%x)\n", package_name, ret);
\r
417 MA_SNPRINTF(buf, sizeof(buf), "Launch fail (%x)", ret);
\r
418 _myaccount_common_add_popup(ad->win_main, buf, "Error");
\r
419 ad->item_selected_state = FALSE;
\r
426 Evas_Object *myaccount_common_progress_add(Evas_Object *parent)
\r
429 MYACCOUNT_ERROR("myaccount_common_progress_add: parent is NULL \n");
\r
432 Evas_Object *progressbar = NULL;
\r
433 progressbar = elm_progressbar_add(parent);
\r
434 elm_object_style_set(progressbar, "list_process");
\r
435 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
\r
436 evas_object_size_hint_weight_set(progressbar,
\r
439 evas_object_show(progressbar);
\r
440 elm_progressbar_pulse(progressbar, EINA_TRUE);
\r
441 return progressbar;
\r
444 Evas_Object *myaccount_common_create_modal_popup(Evas_Object *parent)
\r
447 MYACCOUNT_ERROR("myaccount_common_create_modal_popup: parent is NULL \n");
\r
450 Evas_Object *popup = NULL;
\r
451 Evas_Object *progressbar = NULL;
\r
452 popup = elm_popup_add(parent);
\r
453 progressbar = myaccount_common_progress_add(popup);
\r
454 elm_object_content_set(popup, progressbar);
\r
455 evas_object_show(popup);
\r
459 void myaccount_common_delete_modal_popup(Evas_Object *popup)
\r
462 MYACCOUNT_ERROR("myaccount_common_delete_modal_popup: popup is NULL \n");
\r
465 evas_object_del(popup);
\r
468 Eina_Bool myaccount_common_modal_popup_timer_cb(gpointer data)
\r
471 MYACCOUNT_ERROR("myaccount_common_modal_popup_timer_cb: data is NULL \n");
\r
474 myaccount_appdata *global_data = NULL;
\r
475 global_data = (myaccount_appdata*)data;
\r
476 if (global_data->modal_popup) {
\r
477 myaccount_common_delete_modal_popup(global_data->modal_popup);
\r
478 global_data->modal_popup = NULL;
\r
480 if (global_data->progress_timer) {
\r
481 ecore_timer_del(global_data->progress_timer);
\r
482 global_data->progress_timer = NULL;
\r
487 int myaccount_common_get_all_account_cnt(int *count)
\r
489 int error_code = -1;
\r
490 int account_cnt = 0;
\r
492 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: count ptr is NULL \n");
\r
495 error_code = account_connect();
\r
496 if (error_code != ACCOUNT_ERROR_NONE) {
\r
497 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: fail to connect account DB \n");
\r
500 error_code = account_get_total_count_from_db(&account_cnt);
\r
501 if (error_code != ACCOUNT_ERROR_NONE) {
\r
502 int ret = ACCOUNT_ERROR_NONE;
\r
503 MYACCOUNT_VERBOSE("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
\r
505 ret = account_disconnect();
\r
506 if (ret != ACCOUNT_ERROR_NONE) {
\r
507 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_disconnect fail(%d) \n",
\r
512 *count = account_cnt;
\r
513 error_code = account_disconnect();
\r
514 if (error_code != ACCOUNT_ERROR_NONE) {
\r
515 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
\r
519 return ACCOUNT_ERROR_NONE;
\r
522 static int _myaccount_common_pkmgr_return_cb(int req_id, const char *pkg_type,
\r
523 const char *pkg_name,
\r
529 MYACCOUNT_VERBOSE(" _myaccount_common_pkmgr_return_cb: pkg_type = %s, pkg_name = %s, key = %s, val = %s\n", pkg_type, pkg_name,key,val);
\r
531 int error_code = -1;
\r
533 if( strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
\r
534 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
537 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
540 error_code = myaccount_common_get_all_account_cnt(&count);
\r
541 if (error_code != ACCOUNT_ERROR_NONE) {
\r
542 MYACCOUNT_ERROR("_myaccount_common_pkmgr_return_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
\r
546 MYACCOUNT_VERBOSE("_myaccount_common_pkmgr_return_cb account count =%d\n",
\r
548 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
\r
550 if (appdata->add_genlist) {
\r
551 evas_object_del(appdata->add_genlist);
\r
552 appdata->add_genlist = NULL;
\r
553 elm_naviframe_item_pop(appdata->navi_bar);
\r
555 if (appdata->account_genlist) {
\r
556 myaccount_list_refresh_item_list(appdata);
\r
558 myaccount_ug_account_list_create((void*)appdata);
\r
561 if (appdata->add_genlist) {
\r
562 evas_object_show(appdata->add_genlist);
\r
564 myaccount_addaccount_create_view(appdata);
\r
567 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
\r
569 error_code = ug_destroy_me(appdata->ug);
\r
570 MYACCOUNT_VERBOSE("myaccount_common_handle_notification callback : return = %d!!!\n",
\r
574 MYACCOUNT_WARNING("Unknown mode !!!");
\r
581 void myaccount_common_listen_pkgmgr_for_pkg_uninstall()
\r
583 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
586 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
591 pkgmgr_client *pc = NULL;
\r
592 pc = pkgmgr_client_new(PC_LISTENING);
\r
594 MYACCOUNT_ERROR("pc is NULL\n");
\r
598 result = pkgmgr_client_listen_status(pc, _myaccount_common_pkmgr_return_cb, pc);
\r
601 MYACCOUNT_ERROR("status listen failed!\n");
\r