2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.0 (the License);
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://floralicense.org/license/
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an AS IS BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "myaccount_ug.h"
\r
18 #include "myaccount_ug_common.h"
\r
19 #include "myaccount_ug_addaccount.h"
\r
20 #include "myaccount_ug_account_list.h"
\r
22 static myaccount_appdata *g_myaccount_appdata = NULL;
\r
24 void *myaccount_init_appdata()
\r
26 if (g_myaccount_appdata == NULL) {
\r
27 g_myaccount_appdata = calloc(1, sizeof(myaccount_appdata));
\r
28 g_myaccount_appdata->item_selected_state = false;
\r
30 return g_myaccount_appdata;
\r
33 void myaccount_destroy_appdata()
\r
35 MYACCOUNT_INFO("myaccount_destroy_appdata START \n");
\r
37 if (g_myaccount_appdata == NULL) {
\r
38 MYACCOUNT_WARNING("myaccount_destroy_appdata: appdata NULL \n");
\r
43 /* fix by sungchan,kim.
\r
44 sudden crash on account list view destroyed.
\r
45 tempolarily blocked below codes. */
\r
46 if (g_myaccount_appdata->base) {
\r
47 evas_object_del(g_myaccount_appdata->base);
\r
48 g_myaccount_appdata->base = NULL;
\r
50 MA_MEMFREE(g_myaccount_appdata->capability_filter)
\r
52 /* For accounts list */
\r
53 if (g_myaccount_appdata->ug_called) {
\r
54 ug_destroy(g_myaccount_appdata->ug_called);
\r
55 g_myaccount_appdata->ug_called = NULL;
\r
57 if (g_myaccount_appdata->layout_main) {
\r
58 evas_object_del(g_myaccount_appdata->layout_main);
\r
59 g_myaccount_appdata->layout_main = NULL;
\r
61 if (g_myaccount_appdata->layout_addaccount) {
\r
62 evas_object_del(g_myaccount_appdata->layout_addaccount);
\r
63 g_myaccount_appdata->layout_addaccount = NULL;
\r
65 if (g_myaccount_appdata->navi_bar) {
\r
66 evas_object_del(g_myaccount_appdata->navi_bar);
\r
67 g_myaccount_appdata->navi_bar = NULL;
\r
69 if (g_myaccount_appdata->account_genlist) {
\r
70 evas_object_del(g_myaccount_appdata->account_genlist);
\r
71 g_myaccount_appdata->account_genlist = NULL;
\r
73 if (g_myaccount_appdata->help_label) {
\r
74 evas_object_del(g_myaccount_appdata->help_label);
\r
75 g_myaccount_appdata->help_label = NULL;
\r
77 if (g_myaccount_appdata->refresh_btn) {
\r
78 evas_object_del(g_myaccount_appdata->refresh_btn);
\r
79 g_myaccount_appdata->refresh_btn = NULL;
\r
81 if (g_myaccount_appdata->refresh_icon) {
\r
82 evas_object_del(g_myaccount_appdata->refresh_icon);
\r
83 g_myaccount_appdata->refresh_icon = NULL;
\r
85 if (g_myaccount_appdata->cancel_sync_icon) {
\r
86 evas_object_del(g_myaccount_appdata->cancel_sync_icon);
\r
87 g_myaccount_appdata->cancel_sync_icon = NULL;
\r
89 if (g_myaccount_appdata->auto_sync_check) {
\r
90 evas_object_del(g_myaccount_appdata->auto_sync_check);
\r
91 g_myaccount_appdata->auto_sync_check = NULL;
\r
93 if (g_myaccount_appdata->bg) {
\r
94 evas_object_del(g_myaccount_appdata->bg);
\r
95 g_myaccount_appdata->bg = NULL;
\r
97 if (g_myaccount_appdata->ly) {
\r
98 elm_object_part_content_unset(g_myaccount_appdata->ly, "elm.swallow.content");
\r
99 evas_object_del(g_myaccount_appdata->ly);
\r
100 g_myaccount_appdata->ly = NULL;
\r
102 if (g_myaccount_appdata->modal_popup) {
\r
103 evas_object_del(g_myaccount_appdata->modal_popup);
\r
104 g_myaccount_appdata->modal_popup = NULL;
\r
106 if (g_myaccount_appdata->r_title_sk) {
\r
107 evas_object_del(g_myaccount_appdata->r_title_sk);
\r
108 g_myaccount_appdata->r_title_sk = NULL;
\r
110 if (g_myaccount_appdata->l_title_sk) {
\r
111 evas_object_del(g_myaccount_appdata->l_title_sk);
\r
112 g_myaccount_appdata->l_title_sk = NULL;
\r
114 if (g_myaccount_appdata->progress_timer) {
\r
115 ecore_timer_del(g_myaccount_appdata->progress_timer);
\r
116 g_myaccount_appdata->progress_timer = NULL;
\r
118 if (g_myaccount_appdata->add_genlist) {
\r
119 evas_object_del(g_myaccount_appdata->add_genlist);
\r
120 g_myaccount_appdata->add_genlist = NULL;
\r
122 if (g_myaccount_appdata->pc) {
\r
123 pkgmgr_client_free(g_myaccount_appdata->pc);
\r
124 g_myaccount_appdata->pc = NULL;
\r
126 MA_MEMFREE(g_myaccount_appdata->caller_userdata);
\r
127 MA_MEMFREE(g_myaccount_appdata);
\r
129 MYACCOUNT_VERBOSE("myaccount_destroy_appdata END \n");
\r
132 void * myaccount_get_appdata()
\r
134 return g_myaccount_appdata;
\r
137 void myaccount_common_get_icon_by_name(char *domain_name,
\r
140 if (!domain_name) {
\r
141 MYACCOUNT_ERROR("\n !!! domain_name is NULL \n");
\r
144 char tmp_domain_name[64] = {0,};
\r
145 myaccount_common_lowercase(domain_name, tmp_domain_name);
\r
146 MYACCOUNT_VERBOSE("\n !!! myaccount_common_get_icon_by_name = %s \n",
\r
150 MYACCOUNT_ERROR("\n !!! icon_path is NULL \n");
\r
154 MYACCOUNT_VERBOSE("Default icon\n");
\r
155 MA_SNPRINTF(icon_path, BUFSIZE, "%s", "99_email.png");
\r
158 void myaccount_common_lowercase(char *src, char *dest)
\r
163 if (!src || !dest) {
\r
164 MYACCOUNT_ERROR("myaccount_common_lowercase src=%p, dest=%p\n",
\r
168 src_len = strlen(src);
\r
169 for(i=0;i<src_len;i++) {
\r
170 dest[i] = tolower(src[i]);
\r
175 void myaccount_common_vconf_notification_cb(keynode_t *key, void *user_data)
\r
177 MYACCOUNT_VERBOSE("myaccount_common_vconf_notification_cb START \n ");
\r
178 myaccount_common_handle_notification();
\r
179 MYACCOUNT_VERBOSE("myaccount_common_vconf_notification_cb END \n ");
\r
182 extern addaccount_list_priv* service_info;
\r
183 void myaccount_common_handle_notification()
\r
185 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
188 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
191 int error_code = -1;
\r
193 char *noti_name = NULL;
\r
195 appdata->item_selected_state = false;
\r
197 noti_name = vconf_get_str(VCONFKEY_ACCOUNT_MSG_STR);
\r
199 MYACCOUNT_FATAL("myaccount_common_handle_notification: vconf_get_str() Failed!\n");
\r
202 MYACCOUNT_VERBOSE("myaccount_common_handle_notification: noti_name = %s\n",
\r
205 error_code = myaccount_common_get_all_account_cnt(&count);
\r
206 if (error_code != ACCOUNT_ERROR_NONE) {
\r
207 MYACCOUNT_ERROR("myaccount_common_handle_notification: myaccount_common_get_all_account_cnt fail(%d) \n",
\r
211 MYACCOUNT_VERBOSE("myaccount_common_handle_notification account count =%d\n",
\r
214 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
\r
216 if (appdata->add_genlist && strcmp(noti_name, ACCOUNT_NOTI_NAME_SYNC_UPDATE)) {
\r
217 evas_object_del(appdata->add_genlist);
\r
218 appdata->add_genlist = NULL;
\r
219 elm_naviframe_item_pop(appdata->navi_bar);
\r
220 MA_MEMFREE(service_info);
\r
222 if (appdata->account_genlist) {
\r
223 myaccount_check_syncall_finish(appdata);
\r
224 myaccount_list_refresh_item_list(appdata);
\r
226 myaccount_ug_account_list_create((void*)appdata);
\r
229 if (appdata->add_genlist) {
\r
230 evas_object_show(appdata->add_genlist);
\r
232 myaccount_addaccount_create_view(appdata);
\r
235 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
\r
237 if (!appdata->add_genlist)
\r
238 MA_MEMFREE(service_info);
\r
239 error_code = ug_destroy_me(appdata->ug);
\r
240 MYACCOUNT_DBUG("myaccount_common_handle_notification callback : return = %d!!!\n",
\r
244 MYACCOUNT_DBUG("Unknown mode !!!");
\r
248 int myaccount_common_launch_application(MyAccountRequestViewType
\r
250 char *package_name,
\r
256 int ret = SERVICE_ERROR_NONE;
\r
258 myaccount_appdata *ad = (myaccount_appdata *) data;
\r
259 char id_buf[64] = {0,};
\r
261 if (!ad || !package_name) {
\r
262 MYACCOUNT_DBUG("myaccount_common_launch_application: App data=%p, package_name=%p\n",
\r
267 ret = service_create(&service);
\r
268 ret = service_set_package(service, package_name);
\r
269 ret = service_set_window(service, ad->win_id);
\r
270 if(ad->caller_userdata) {
\r
271 MYACCOUNT_DBUG("myaccount_common_launch_application: caller userdata exist!\n");
\r
272 ret = service_add_extra_data(service, "myaccount_userdata", ad->caller_userdata);
\r
275 if (ret != SERVICE_ERROR_NONE)
\r
276 MYACCOUNT_ERROR("myaccount_common_launch_application: service_set_package failed\n");
\r
278 switch (request_type) {
\r
279 case MYACCOUNT_REQUEST_SIGNIN :
\r
280 service_set_operation(service, ACCOUNT_OPERATION_SIGNIN);
\r
281 if(email_sp && strlen(email_sp) > 0)
\r
282 service_add_extra_data(service, ACCOUNT_DATA_SERVICE_PROVIDER, email_sp);
\r
284 case MYACCOUNT_REQUEST_VIEW :
\r
286 MYACCOUNT_ERROR("myaccount_common_launch_application: username=%p !!!\n",
\r
288 MA_MEMFREE(package_name);
\r
289 service_destroy(service);
\r
293 MA_SNPRINTF(id_buf, sizeof(id_buf), "%d", account_id);
\r
294 ret = service_add_extra_data(service, ACCOUNT_DATA_ID, id_buf);
\r
295 ret = service_set_operation(service, ACCOUNT_OPERATION_VIEW);
\r
296 MYACCOUNT_DBUG("###### USERNAME = %s\n", username);
\r
297 ret = service_add_extra_data(service, ACCOUNT_DATA_USERNAME,username);
\r
300 MYACCOUNT_DBUG("myaccount_common_launch_application: Invalid request type=%d\n",
\r
302 MA_MEMFREE(username);
\r
303 MA_MEMFREE(package_name);
\r
304 service_destroy(service);
\r
307 MYACCOUNT_VERBOSE("myaccount_common_launch_application request type=%d, package name = %s\n",
\r
308 request_type, package_name);
\r
310 ret = service_send_launch_request(service, NULL, NULL);
\r
311 MA_MEMFREE(username);
\r
312 MA_MEMFREE(package_name);
\r
313 service_destroy(service);
\r
314 if(ret != SERVICE_ERROR_NONE){
\r
322 Evas_Object *myaccount_common_progress_add(Evas_Object *parent)
\r
325 MYACCOUNT_ERROR("myaccount_common_progress_add: parent is NULL \n");
\r
328 Evas_Object *progressbar = NULL;
\r
329 progressbar = elm_progressbar_add(parent);
\r
330 elm_object_style_set(progressbar, "list_process");
\r
331 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
\r
332 evas_object_size_hint_weight_set(progressbar,
\r
335 evas_object_show(progressbar);
\r
336 elm_progressbar_pulse(progressbar, EINA_TRUE);
\r
337 return progressbar;
\r
340 Evas_Object *myaccount_common_create_modal_popup(Evas_Object *parent)
\r
343 MYACCOUNT_ERROR("myaccount_common_create_modal_popup: parent is NULL \n");
\r
346 Evas_Object *popup = NULL;
\r
347 Evas_Object *progressbar = NULL;
\r
348 popup = elm_popup_add(parent);
\r
349 progressbar = myaccount_common_progress_add(popup);
\r
350 elm_object_content_set(popup, progressbar);
\r
351 evas_object_show(popup);
\r
355 void myaccount_common_delete_modal_popup(Evas_Object *popup)
\r
358 MYACCOUNT_ERROR("myaccount_common_delete_modal_popup: popup is NULL \n");
\r
361 evas_object_del(popup);
\r
364 Eina_Bool myaccount_common_modal_popup_timer_cb(gpointer data)
\r
367 MYACCOUNT_ERROR("myaccount_common_modal_popup_timer_cb: data is NULL \n");
\r
370 myaccount_appdata *global_data = NULL;
\r
371 global_data = (myaccount_appdata*)data;
\r
372 if (global_data->modal_popup) {
\r
373 myaccount_common_delete_modal_popup(global_data->modal_popup);
\r
374 global_data->modal_popup = NULL;
\r
376 if (global_data->progress_timer) {
\r
377 ecore_timer_del(global_data->progress_timer);
\r
378 global_data->progress_timer = NULL;
\r
383 int myaccount_common_get_all_account_cnt(int *count)
\r
385 int error_code = -1;
\r
386 int account_cnt = 0;
\r
388 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: count ptr is NULL \n");
\r
391 error_code = account_connect();
\r
392 if (error_code != ACCOUNT_ERROR_NONE) {
\r
393 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: fail to connect account DB \n");
\r
396 error_code = account_get_total_count_from_db(&account_cnt);
\r
397 if (error_code != ACCOUNT_ERROR_NONE) {
\r
398 int ret = ACCOUNT_ERROR_NONE;
\r
399 MYACCOUNT_VERBOSE("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
\r
401 ret = account_disconnect();
\r
402 if (ret != ACCOUNT_ERROR_NONE) {
\r
403 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_disconnect fail(%d) \n",
\r
408 *count = account_cnt;
\r
409 error_code = account_disconnect();
\r
410 if (error_code != ACCOUNT_ERROR_NONE) {
\r
411 MYACCOUNT_ERROR("myaccount_common_get_all_account_cnt: account_svc_get_count fail(%d) \n",
\r
415 return ACCOUNT_ERROR_NONE;
\r
418 static int _myaccount_common_pkmgr_return_cb(int req_id, const char *pkg_type,
\r
419 const char *pkg_name,
\r
425 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
427 int error_code = -1;
\r
429 if( strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) {
\r
430 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
433 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
436 error_code = myaccount_common_get_all_account_cnt(&count);
\r
437 if (error_code != ACCOUNT_ERROR_NONE) {
\r
438 MYACCOUNT_ERROR("_myaccount_common_pkmgr_return_cb: myaccount_common_get_all_account_cnt fail(%d) \n",
\r
442 MYACCOUNT_VERBOSE("_myaccount_common_pkmgr_return_cb account count =%d\n",
\r
444 if (appdata->eMode == eMYACCOUNT_ACCOUNT_LIST) {
\r
446 if (appdata->add_genlist) {
\r
447 evas_object_del(appdata->add_genlist);
\r
448 appdata->add_genlist = NULL;
\r
449 elm_naviframe_item_pop(appdata->navi_bar);
\r
450 MA_MEMFREE(service_info);
\r
452 if (appdata->account_genlist) {
\r
453 myaccount_check_syncall_finish(appdata);
\r
454 myaccount_list_refresh_item_list(appdata);
\r
456 myaccount_ug_account_list_create((void*)appdata);
\r
459 if (appdata->add_genlist) {
\r
460 evas_object_show(appdata->add_genlist);
\r
462 myaccount_addaccount_create_view(appdata);
\r
465 } else if (appdata->eMode == eMYACCOUNT_ADD_ACCOUNT) {
\r
467 if (!appdata->add_genlist)
\r
468 MA_MEMFREE(service_info);
\r
469 error_code = ug_destroy_me(appdata->ug);
\r
470 MYACCOUNT_VERBOSE("myaccount_common_handle_notification callback : return = %d!!!\n",
\r
474 MYACCOUNT_WARNING("Unknown mode !!!");
\r
481 void myaccount_common_listen_pkgmgr_for_pkg_uninstall()
\r
483 myaccount_appdata *appdata = (myaccount_appdata*)myaccount_get_appdata();
\r
486 MYACCOUNT_FATAL("App data NULL!!! \n");
\r
491 pkgmgr_client *pc = NULL;
\r
492 pc = pkgmgr_client_new(PC_LISTENING);
\r
494 MYACCOUNT_ERROR("pc is NULL\n");
\r
498 result = pkgmgr_client_listen_status(pc, _myaccount_common_pkmgr_return_cb, pc);
\r
501 MYACCOUNT_ERROR("status listen failed!\n");
\r