4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Tarun Kumar <tarun.kr@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "myaccount_ug_account_list.h"
23 #include "myaccount_ug_addaccount.h"
24 #include "myaccount_ug_common.h"
27 #include <account_internal.h>
30 #define UG_MODULE_API __attribute__ ((visibility("default")))
33 static myaccount_appdata *g_appdata = NULL;
34 static int g_handle_noti = 0;
36 int myaccount_subscribe_to_account_notification_vconfkey();
37 static void __reset_indicator(myaccount_appdata *ugd);
39 static void lang_changed(void * priv)
42 MYACCOUNT_SLOGE("lang_changed ### priv=%p\n", priv);
46 myaccount_appdata *ugd;
47 ugd = (myaccount_appdata*)priv;
49 char* language = NULL;
50 language = vconf_get_str(VCONFKEY_LANGSET);
54 MA_STRNCPY(tmp_buf, language, 6);
55 ugd->current_language = strdup(tmp_buf);
59 elm_object_item_text_set (ugd->nf_it, dgettext(MA_UG_NAME, "IDS_MA_HEADER_ACCOUNTS"));
60 myaccount_list_refresh_item_list(ugd);
62 if( ugd->add_genlist ) {
64 elm_object_item_text_set (ugd->add_nf_it, dgettext(MA_UG_NAME, "IDS_MA_HEADER_ADD_ACCOUNT"));
65 myaccount_addaccount_refresh_item_list(ugd);
67 MYACCOUNT_SLOGE("lang_changed ### ugd->add_genlist is NULL\n");
72 static gboolean __myaccount_account_list_parse_param(myaccount_mode_e
75 myaccount_appdata *ad)
80 char *extracted = NULL;
81 ad->capability_filter = NULL;
82 app_control_get_extra_data(data, "mode", &extracted);
83 app_control_get_extra_data(data, "capability_filter", &ad->capability_filter);
84 app_control_get_extra_data(data, "myaccount_userdata", &ad->caller_userdata);
85 app_control_get_extra_data(data, "from", &ad->called_from);
87 MYACCOUNT_SLOGD("view_account_list = %s\n", extracted);
89 if (!strcmp(extracted, "account_list"))
90 *mode = eMYACCOUNT_ACCOUNT_LIST;
91 else if (!strcmp(extracted, "add_account"))
92 *mode = eMYACCOUNT_ADD_ACCOUNT;
94 *mode = eMYACCOUNT_ACCOUNT_LIST;
96 *mode = eMYACCOUNT_ACCOUNT_LIST;
99 MA_MEMFREE(extracted);
104 static void __save_indicator_state(myaccount_appdata *ugd)
106 /* Save old view's indicator values */
107 ugd->indi_mode = elm_win_indicator_mode_get(ugd->win_main);
108 ugd->indi_o_mode = elm_win_indicator_opacity_get(ugd->win_main);
109 /* Save old view's overlap mode */
110 ugd->overlap_mode = (int)evas_object_data_get(ugd->conformant, "overlap");
111 MYACCOUNT_DBUG("indi_o_mode: %d, indi_mode: %d", ugd->indi_o_mode, ugd->indi_mode);
112 MYACCOUNT_DBUG("overlap_mode: %d", ugd->overlap_mode);
115 void *myaccount_account_list_create(ui_gadget_h ug,
117 app_control_h data, void *priv)
120 myaccount_appdata *ugd;
129 bindtextdomain("setting-myaccount-efl", "/usr/apps/setting-myaccount-efl/res/locale");
130 ugd = (myaccount_appdata*)priv;
133 parent = (Evas_Object *)ug_get_window();
139 ugd->win_main = parent;
140 Evas_Object *conformant = (Evas_Object *)ug_get_conformant();
141 __save_indicator_state(ugd);
143 Evas_Object *indi_bg = elm_bg_add(conformant);
144 elm_object_style_set(indi_bg, "indicator/headerbg");
145 elm_object_part_content_set(conformant, "elm.swallow.indicator_bg", indi_bg);
146 evas_object_show(indi_bg);
147 ugd->conformant = conformant;
148 __reset_indicator(ugd);
150 /*sbscribe to vconf noti key which will recevie notification about account update, delete and insert*/
152 myaccount_subscribe_to_account_notification_vconfkey();
154 /*listen to pkgmgr for uninstall of pkg*/
155 myaccount_common_listen_pkgmgr_for_pkg_uninstall();
157 __myaccount_account_list_parse_param(&ugd->eMode, data, ugd);
159 if( ugd->capability_filter
160 && strlen(ugd->capability_filter) > 0 ) {
162 if(!strcmp(ugd->capability_filter, "http://tizen.org/account/capability/tizen_email")){
166 error_code = myaccount_common_get_account_cnt_by_appid(TIZEN_EMAIL_APPID, &cnt1);
167 error_code = myaccount_common_get_account_cnt_by_appid(EXCHANGE_UI_APPID, &cnt2);
168 error_code = myaccount_common_get_account_cnt_by_appid(GOOGLE_ACCOUNT_APPID, &cnt3);
169 count = cnt1+cnt2+cnt3;
171 error_code = myaccount_common_get_account_cnt_by_capability(ugd->capability_filter, &count);
174 if (error_code != ACCOUNT_ERROR_NONE) {
175 MYACCOUNT_SLOGE("myaccount_account_list_create: myaccount_common_get_all_account_cnt fail(%d) \n",
180 error_code = myaccount_common_get_all_account_cnt(&count, false);
181 if (error_code != ACCOUNT_ERROR_NONE) {
182 MYACCOUNT_SLOGE("myaccount_account_list_create: myaccount_common_get_all_account_cnt fail(%d) \n",
187 char* language = NULL;
188 language = vconf_get_str(VCONFKEY_LANGSET);
191 char tmp_buf[6]={0,};
193 MA_STRNCPY(tmp_buf, language, 6);
195 ugd->current_language = strdup(tmp_buf);
197 MA_MEMFREE(language);
199 myaccount_list_view_create(ugd);
201 myaccount_list_navi_create(ugd);
203 if (ugd->eMode == eMYACCOUNT_ACCOUNT_LIST) {
205 myaccount_ug_account_list_create((void*)priv);
206 } else if (count == 0) {
207 myaccount_addaccount_create_view(ugd);
209 MYACCOUNT_ERROR("add list count(%d)", count);
211 } else if (ugd->eMode == eMYACCOUNT_ADD_ACCOUNT) {
212 myaccount_addaccount_create_view(ugd);
218 bool myaccount_subscribe_callback(const char* event_type, int account_id, void* user_data)
220 myaccount_common_handle_notification(event_type);
225 int myaccount_subscribe_to_account_notification_vconfkey()
227 myaccount_appdata* ad = (myaccount_appdata*)myaccount_get_appdata();
232 ret = account_subscribe_create(&ad->account_subscribe);
233 if(ret != ACCOUNT_ERROR_NONE){
234 MYACCOUNT_ERROR("account_subscribe_create fail");
237 ret = account_subscribe_notification_ex(ad->account_subscribe, myaccount_subscribe_callback, NULL);
238 if(ret != ACCOUNT_ERROR_NONE){
239 MYACCOUNT_ERROR("account_subscribe_notification_ex fail");
246 static void myaccount_account_list_start(ui_gadget_h ug, app_control_h data, void *priv)
248 //MYACCOUNT_DBUG("ug start\n");
251 static void myaccount_account_list_pause(ui_gadget_h ug, app_control_h data, void *priv)
253 __attribute__((__unused__)) myaccount_appdata *ugd;
254 ugd = (myaccount_appdata*)priv;
256 MYACCOUNT_DBUG("My account ug goes to pause state\n");
259 static void myaccount_account_list_resume(ui_gadget_h ug, app_control_h data, void *priv)
261 myaccount_appdata *ugd;
262 ugd = (myaccount_appdata*)priv;
263 MYACCOUNT_DBUG("Myaccount ug resume\n");
264 myaccount_common_set_item_selected_state(false);
266 myaccount_common_handle_notification(NULL);
269 char* language = NULL;
270 language = vconf_get_str(VCONFKEY_LANGSET);
272 if(language && (strcmp(language, ugd->current_language) == 0)) {
275 /* refresh item to update font size */
276 myaccount_list_refresh_item_list(ugd);
277 if( ugd->add_genlist ) {
278 myaccount_addaccount_refresh_item_list(ugd);
281 MA_MEMFREE(language);
284 static void __reset_indicator(myaccount_appdata *ugd)
287 MYACCOUNT_SLOGE("__reset_indicator ### ugd=%p\n",ugd);
290 MYACCOUNT_DBUG("indi_o_mode: %d, indi_mode: %d", ugd->indi_o_mode, ugd->indi_mode);
291 MYACCOUNT_DBUG("overlap_mode: %d", ugd->overlap_mode);
292 /* Set old view's indicator */
293 elm_win_indicator_mode_set(ugd->win_main, ugd->indi_mode);
294 elm_win_indicator_opacity_set(ugd->win_main, ugd->indi_o_mode);
295 /* set old view's conformant overlap mode
296 if layout is different with new view and needs starts from (0,60) */
297 if (!ugd->overlap_mode) {
298 elm_object_signal_emit(ugd->conformant,
299 "elm,state,indicator,nooverlap", "");
300 evas_object_data_set(ugd->conformant, "overlap", NULL);
302 elm_object_signal_emit(ugd->conformant, "elm,state,indicator,overlap", "");
303 evas_object_data_set(ugd->conformant, "overlap", (void *)EINA_TRUE);
305 MYACCOUNT_DBUG("__reset_indicator\n");
308 void myaccount_destroy_data()
311 MYACCOUNT_SLOGE("myaccount_account_ug_destroy ### g_appdata=%p\n", g_appdata);
315 myaccount_appdata *ugd = g_appdata;
316 account_unsubscribe_notification_ex(ugd->account_subscribe);
317 ugd->account_subscribe = NULL;
319 myaccount_destroy_appdata();
321 if (g_handle_noti > 0) {
322 g_source_remove(g_handle_noti);
326 MYACCOUNT_DBUG("Terminate Myaccount_ug_main[%s]", __func__);
330 static void myaccount_account_list_destroy(ui_gadget_h ug, app_control_h data, void *priv)
332 myaccount_destroy_data();
335 static void myaccount_account_list_message(ui_gadget_h ug,
343 static void myaccount_account_list_event(ui_gadget_h ug,
349 case UG_EVENT_LOW_MEMORY:
350 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_LOW_MEMORY \n");
352 case UG_EVENT_LOW_BATTERY:
353 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_LOW_BATTERY \n");
355 case UG_EVENT_LANG_CHANGE: /* old : SG_BINDTEXTDOMAIN_NOTIFY*/
357 MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_LANG_CHANGE \n");
359 case UG_EVENT_ROTATE_PORTRAIT:
360 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_ROTATE_PORTRAIT \n");
362 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
363 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN \n");
365 case UG_EVENT_ROTATE_LANDSCAPE:
366 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_ROTATE_LANDSCAPE \n");
368 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
369 // MYACCOUNT_DBUG("myaccount_account_list_event: UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN \n");
372 // MYACCOUNT_DBUG("myaccount_account_list_event: default !!! \n");
377 static void myaccount_on_key_event(ui_gadget_h ug,
378 enum ug_key_event event ,
383 MYACCOUNT_DBUG("myaccount_on_key_event ug is NULL !!!");
387 case UG_KEY_EVENT_END: {
388 ui_gadget_h ug = ((myaccount_appdata *)priv)->ug;
397 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
399 myaccount_appdata *ugd;
401 MYACCOUNT_DBUG("UG_MODULE_INIT ops is NULL !!!");
404 ugd = (myaccount_appdata*)myaccount_init_appdata();
406 MYACCOUNT_DBUG("myaccount_init_appdata failed!\n");
409 ops->create = myaccount_account_list_create;
410 ops->start = myaccount_account_list_start;
411 ops->pause = myaccount_account_list_pause;
412 ops->resume = myaccount_account_list_resume;
413 ops->destroy = myaccount_account_list_destroy;
414 ops->message = myaccount_account_list_message;
415 ops->event = myaccount_account_list_event;
416 ops->key_event= myaccount_on_key_event;/*to handle BACK(END)key Event recently added in UG*/
418 ops->opt = UG_OPT_INDICATOR_ENABLE;/*UG_OPT_INDICATOR_ENABLE;*/
423 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
425 MYACCOUNT_DBUG("myaccount UG_MODULE_EXIT!\n");
429 MYACCOUNT_RESET_FAILED = -1,
430 MYACCOUNT_UNDEFINED_LIB_SYMBOL = -2,
431 MYACCOUNT_OPERATE_LIB_SUCCESS = 0
432 }MyAccountResetErrorCode_e;
434 static MyAccountResetErrorCode_e
435 __myaccount_account_exchange_reset(app_control_h data, void *priv)
437 int (*reset) (app_control_h pair, void *ptr);
438 MyAccountResetErrorCode_e ret = MYACCOUNT_OPERATE_LIB_SUCCESS;
440 void *handle = dlopen("/usr/ug/lib/libug-activesync-efl.so", RTLD_LAZY);
442 return MYACCOUNT_RESET_FAILED;
445 reset = dlsym(handle, "setting_plugin_reset");
446 // if (dlerror() != NULL){
448 MYACCOUNT_ERROR("dlsym return value is NULL : dlsym() error or setting_plugin_reset symbol is NULL");
450 return MYACCOUNT_UNDEFINED_LIB_SYMBOL;
453 ret = (*reset) (data, priv);
455 if (ret < 0) ret = MYACCOUNT_RESET_FAILED;
461 UG_MODULE_API int setting_plugin_reset(app_control_h data, void *priv)
463 /*reset exchange account information first*/
464 #ifdef TIZEN_ENGINEER_MODE
467 MyAccountResetErrorCode_e ret = MYACCOUNT_OPERATE_LIB_SUCCESS;
469 ret = __myaccount_account_exchange_reset(data, priv);
470 if(ret != MYACCOUNT_OPERATE_LIB_SUCCESS) {
471 #ifdef TIZEN_ENGINEER_MODE
472 MYACCOUNT_SLOGE("__myaccount_account_exchange_reset returns %d\n",
477 return (int)MYACCOUNT_OPERATE_LIB_SUCCESS;