4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@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 <setting-applications.h>
28 #include <setting-cfg.h>
30 #define SETTING_BRIGHTNESS_DEFAULT_LEVEL 60
33 #define UG_MODULE_API __attribute__ ((visibility("default")))
37 * view selection by service variable
39 * viewtype == 'brightness' --> setting_view_applications_brightness
40 * viewtype != NULL && viewtype --> setting_view_applications_main
42 setting_view *__get_applications_view_to_load(void *data, app_control_h service)
45 setting_retvm_if((!data), NULL, "!data");
47 SettingApplicationsUG *applicationsUG = (SettingApplicationsUG *)data;
48 char *viewtype = NULL;
51 setting_view_node_table_register(&setting_view_applications_main, NULL);
52 setting_view_node_table_register(&setting_view_applications_defaultapp, &setting_view_applications_main);
53 return &setting_view_applications_main;
59 * viewtype != 'wallpaper' --> ly_main
61 Evas_Object *__get_applications_layout_to_return(app_control_h service, void *priv)
64 SettingApplicationsUG *applicationsUG = priv;
65 return applicationsUG->ly_main;
70 static void setting_applications_ug_cb_resize(void *data, Evas *e,
71 Evas_Object *obj, void *event_info)
73 SettingApplicationsUG *ad = (SettingApplicationsUG *) data;
74 setting_view_update(ad->view_to_load, ad);
77 static void *setting_applications_ug_on_create(ui_gadget_h ug,
78 enum ug_mode mode, app_control_h service,
81 setting_retvm_if((!priv), NULL, "!priv");
84 SettingApplicationsUG *applicationsUG = priv;
85 applicationsUG->ug = ug;
86 setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
88 applicationsUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
89 applicationsUG->win_get = (Evas_Object *) ug_get_window();
91 /*evas_object_show(applicationsUG->win_main_layout); */
92 applicationsUG->evas = evas_object_evas_get(applicationsUG->win_main_layout);
94 setting_retvm_if(applicationsUG->win_main_layout == NULL, NULL,
95 "cannot get main window ");
97 /* register view node table */
98 setting_view_node_table_intialize();
100 setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(applicationsUG->itc_2text_2));
101 setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(applicationsUG->itc_1text_1icon));
103 setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(applicationsUG->itc_1icon_1text_sub));
105 setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(applicationsUG->itc_1text));
106 setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(applicationsUG->itc_2text_3));
107 setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(applicationsUG->itc_1text_1icon_divider));
109 /* creating a view. */
110 applicationsUG->view_to_load = __get_applications_view_to_load(applicationsUG, service);
111 setting_retvm_if(NULL == applicationsUG->view_to_load, NULL, "NULL == applicationsUG->view_to_load");
113 setting_view_node_set_cur_view(applicationsUG->view_to_load);
114 setting_view_create(applicationsUG->view_to_load, (void *)applicationsUG);
115 evas_object_event_callback_add(applicationsUG->win_main_layout,
116 EVAS_CALLBACK_RESIZE,
117 setting_applications_ug_cb_resize, applicationsUG);
118 return __get_applications_layout_to_return(service, applicationsUG);
121 static void setting_applications_ug_on_start(ui_gadget_h ug, app_control_h service,
126 static void setting_applications_ug_on_pause(ui_gadget_h ug, app_control_h service,
130 setting_retm_if((!priv), "!priv");
131 SettingApplicationsUG *applicationsUG = priv;
134 static void setting_applications_ug_on_resume(ui_gadget_h ug, app_control_h service,
138 setting_retvm_if((!priv), NULL, "!priv");
140 SettingApplicationsUG *applicationsUG = priv;
143 if (applicationsUG->data_home) {
144 char *appid = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME);
145 char *sub_desc = setting_application_get_defaultapp_name(appid);
147 applicationsUG->data_home->sub_desc = (char *)strdup(sub_desc);
148 elm_object_item_data_set(applicationsUG->data_home->item, applicationsUG->data_home);
149 elm_genlist_item_update(applicationsUG->data_home->item);
155 static void setting_applications_ug_on_destroy(ui_gadget_h ug, app_control_h service,
159 setting_retm_if((!priv), "!priv");
160 SettingApplicationsUG *applicationsUG = priv;
162 /* fix flash issue for gallery */
163 evas_object_event_callback_del(applicationsUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_applications_ug_cb_resize);
164 applicationsUG->ug = ug;
166 FREE(applicationsUG->uri);
168 /* called when this shared gadget is terminated. similar with app_exit */
169 if (&setting_view_applications_main == applicationsUG->view_to_load) {
170 setting_view_destroy(&setting_view_applications_main, applicationsUG);
175 if (NULL != ug_get_layout(applicationsUG->ug)) {
176 evas_object_hide((Evas_Object *) ug_get_layout(applicationsUG->ug));
177 evas_object_del((Evas_Object *) ug_get_layout(applicationsUG->ug));
183 static void setting_applications_ug_on_message(ui_gadget_h ug, app_control_h msg,
184 app_control_h service, void *priv)
189 static void setting_applications_ug_on_event(ui_gadget_h ug,
190 enum ug_event event, app_control_h service,
194 SettingApplicationsUG *ad = priv;
195 setting_retm_if(NULL == ad, "ad is NULL");
197 case UG_EVENT_LOW_MEMORY:
199 case UG_EVENT_LOW_BATTERY:
201 case UG_EVENT_LANG_CHANGE:
202 setting_navi_items_update(ad->navi_bar);
204 case UG_EVENT_ROTATE_PORTRAIT:
206 case UG_EVENT_ROTATE_LANDSCAPE:
207 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
209 case UG_EVENT_REGION_CHANGE:
216 static void setting_applications_ug_on_key_event(ui_gadget_h ug,
217 enum ug_key_event event,
218 app_control_h service, void *priv)
221 SettingApplicationsUG *ad = (SettingApplicationsUG *) priv;
224 case UG_KEY_EVENT_END: {
225 if (elm_naviframe_top_item_get(ad->navi_bar) ==
226 elm_naviframe_bottom_item_get(ad->navi_bar)) {
229 setting_view_cb_at_endKey(ad);
238 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
241 SettingApplicationsUG *applicationsUG = calloc(1, sizeof(SettingApplicationsUG));
242 setting_retvm_if(!applicationsUG, -1, "Create SettingApplicationsUG obj failed");
244 memset(applicationsUG, 0x00, sizeof(SettingApplicationsUG));
246 ops->create = setting_applications_ug_on_create;
247 ops->start = setting_applications_ug_on_start;
248 ops->pause = setting_applications_ug_on_pause;
249 ops->resume = setting_applications_ug_on_resume;
250 ops->destroy = setting_applications_ug_on_destroy;
251 ops->message = setting_applications_ug_on_message;
252 ops->event = setting_applications_ug_on_event;
253 ops->key_event = setting_applications_ug_on_key_event;
254 ops->priv = applicationsUG;
255 ops->opt = UG_OPT_INDICATOR_ENABLE;
260 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
263 struct SettingApplicationsUG *applicationsUG;
264 setting_retm_if(!ops, "ops == NULL");
266 applicationsUG = ops->priv;
267 if (applicationsUG) {
268 FREE(applicationsUG);
272 /* ***************************************************
276 ***************************************************/
278 #define BUS_NAME "org.tizen.system.deviced"
279 #define INTERFACE_NAME BUS_NAME
280 #define OBJECT_PATH "/Org/Tizen/System/DeviceD"
281 #define DEVICED_PATH_DISPLAY OBJECT_PATH"/Applications"
282 #define DEVICED_INTERFACE_DISPLAY INTERFACE_NAME".applications"
283 #define DBUS_REPLY_TIMEOUT (120 * 1000)
285 static int __append_param(DBusMessage *msg, const char *sig, char *param[])
287 DBusMessageIter iter;
288 /*DBusMessageIter cont_iter; */
293 if (sig == NULL || param == NULL) {
297 dbus_message_iter_init_append(msg, &iter);
298 for (ch = (char *)sig, i = 0; *ch != '\0'; ++i, ++ch) {
299 SETTING_TRACE_DEBUG("sig : %c", *ch);
302 int_type = atoi(param[i]);
303 SETTING_TRACE_DEBUG("param[%2d] : %d", i, int_type);
304 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &int_type);
308 SETTING_TRACE_DEBUG("param[%2d] : %s", i, str_type);
309 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &str_type);
318 static DBusMessage *__invoke_dbus_method(const char *dest, const char *path,
319 const char *interface, const char *method,
320 const char *sig, char *param[])
323 DBusConnection *conn;
328 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
330 SETTING_TRACE_DEBUG("dbus_bus_get error");
333 msg = dbus_message_new_method_call(dest, path, interface, method);
335 SETTING_TRACE_DEBUG("dbus_message_new_method_call error");
338 r = __append_param(msg, sig, param);
340 SETTING_TRACE_DEBUG("append_param error");
343 dbus_error_init(&err);
344 reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
345 dbus_message_unref(msg);
346 if (dbus_error_is_set(&err)) {
347 SETTING_TRACE_DEBUG("dbus_connection_send_with_reply_and_block error");
348 SETTING_TRACE_DEBUG("error [%s:%s]", err.name, err.message);
349 dbus_error_free(&err);
355 int setting_applications_set_auto_adjust_tone(int value)
358 if (value < 0 || value > 1) {
359 SETTING_TRACE_DEBUG("value has invalid range. [0 or 1]");
360 return SETTING_RETURN_FAIL;
371 dbus_error_init(&err);
373 snprintf(temp, 2, "%1d", value);
375 SETTING_TRACE_DEBUG("set as [%s]", temp);
377 msg = __invoke_dbus_method(BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, "setautotone", "i", arr);
379 if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID)) {
380 SETTING_TRACE_DEBUG("no message : [%s:%s]", err.name, err.message);
381 ret = SETTING_RETURN_FAIL;
383 SETTING_TRACE_DEBUG("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, "setautotone", state);
385 dbus_message_unref(msg);
392 void setting_applications_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
395 /*SettingApplicationsUG *ad = (SettingApplicationsUG *) priv; */
403 base = (Evas_Object *) ug_get_layout(ug);
409 case UG_MODE_FULLVIEW:
410 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
412 evas_object_show(base);