2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <Elementary.h>
20 #include <sys/utsname.h>
21 #include <Ecore_Input.h>
25 #include <notification.h>
26 #include <app_control_internal.h>
27 #include <bundle_internal.h>
28 #include <system_info.h>
29 #include <common_uic.h>
31 #if defined(WINSYS_X11)
38 #include <tzsh_quickpanel_service.h>
41 #include "quickpanel-ui.h"
44 /* binary information */
45 #define QP_EMUL_STR "Emulator"
46 #define DEL_TIMER_VALUE 0.480
47 #define SYSTEM_INFO_KEY_MODEL "http://tizen.org/system/model_name"
48 static Ecore_Timer *_close_timer = NULL;
51 static void _quickpanel_move_data_to_service(const char *key, const char *val, void *data)
53 retif(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
55 app_control_h service = data;
56 app_control_add_extra_data(service, key, val);
59 HAPI Evas_Object *quickpanel_uic_load_edj(Evas_Object * parent, const char *file, const char *group, int is_just_load)
62 Evas_Object *eo = NULL;
64 retif(parent == NULL, NULL, "Invalid parameter!");
66 eo = elm_layout_add(parent);
67 retif(eo == NULL, NULL, "Failed to add layout object!");
69 r = elm_layout_file_set(eo, file, group);
70 retif(r != EINA_TRUE, NULL, "Failed to set edje object file[%s-%s]!", file, group);
72 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
75 if (is_just_load == 1) {
76 elm_win_resize_object_add(parent, eo);
83 HAPI int quickpanel_uic_is_opened(void)
85 struct appdata *ad = quickpanel_get_app_data();
86 retif(ad == NULL, 0, "invalid data.");
91 HAPI int quickpanel_uic_is_suspended(void)
93 struct appdata *ad = quickpanel_get_app_data();
94 retif(ad == NULL, 0, "invalid data.");
96 return ad->is_suspended;
99 HAPI int quickpanel_uic_is_emul(void)
104 if (system_info_get_platform_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
108 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
118 HAPI void quickpanel_uic_initial_resize(Evas_Object *obj, int height)
120 struct appdata *ad = quickpanel_get_app_data();
121 retif(ad == NULL, , "invalid data.");
123 height = (height % 2 != 0) ? height + 1 : height;
125 if (ad->angle == 90 || ad->angle == 270) {
126 evas_object_resize(obj, ad->win_height, height * ad->scale);
128 evas_object_resize(obj, ad->win_width, height * ad->scale);
132 HAPI int quickpanel_uic_launch_app(char *app_id, void *data)
134 int ret = APP_CONTROL_ERROR_NONE;
135 app_control_h service = NULL;
136 char *app_id_from_service = NULL;
138 retif(app_id == NULL && data == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "Invialid parameter!");
140 ret = app_control_create(&service);
141 if (ret != APP_CONTROL_ERROR_NONE) {
142 ERR("app_control_create() return error : %d", ret);
145 retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
147 if (app_id != NULL) {
148 app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
149 app_control_set_app_id(service, app_id);
152 bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
156 ret = app_control_import_from_bundle(service, data);
157 if (ret != APP_CONTROL_ERROR_NONE) {
158 ERR("Failed to import[%d]", ret);
163 ret = app_control_send_launch_request(service, NULL, NULL);
164 if (ret != APP_CONTROL_ERROR_NONE) {
165 ERR("app_control_send_launch_request() is failed : %d", ret);
166 app_control_get_app_id(service, &app_id_from_service);
167 if (app_id_from_service != NULL) {
168 quickpanel_uic_launch_app_inform_result(app_id_from_service, ret);
169 free(app_id_from_service);
171 quickpanel_uic_launch_app_inform_result(app_id, ret);
173 app_control_destroy(service);
176 app_control_destroy(service);
180 HAPI int quickpanel_uic_launch_ug_by_appcontrol(const char *package, void *data)
182 int ret = APP_CONTROL_ERROR_NONE;
183 app_control_h service = NULL;
184 struct appdata *ad = quickpanel_get_app_data();
185 retif(ad == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "ad null");
186 retif(package == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "package null");
188 ret = app_control_create(&service);
189 if (ret != APP_CONTROL_ERROR_NONE) {
190 ERR("app_control_create() return error : %d", ret);
193 retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
195 app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
196 app_control_set_app_id(service, package);
199 bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
202 ret = app_control_send_launch_request(service, NULL, NULL);
203 if (ret != APP_CONTROL_ERROR_NONE) {
204 ERR("app_control_send_launch_request() is failed : %d", ret);
205 app_control_destroy(service);
208 app_control_destroy(service);
212 HAPI void quickpanel_uic_launch_app_inform_result(const char *pkgname, int retcode)
214 retif(retcode == APP_CONTROL_ERROR_NONE, , "retcode = APP_CONTROL_ERROR_NONE!");
215 retif(pkgname == NULL && retcode != APP_CONTROL_ERROR_APP_NOT_FOUND, , "Invialid parameter!");
217 const char *msg = NULL;
218 char *app_label = NULL;
220 if (retcode == APP_CONTROL_ERROR_APP_NOT_FOUND) {
221 notification_status_message_post(_NOT_LOCALIZED("Unable to find application to perform this action."));
223 Eina_Strbuf *strbuf = eina_strbuf_new();
224 char *format = _("IDS_QP_TPOP_UNABLE_TO_OPEN_PS");
226 if (strbuf != NULL) {
227 app_label = quickpanel_common_ui_get_pkginfo_label(pkgname);
228 if (app_label != NULL) {
229 eina_strbuf_append_printf(strbuf, format, app_label);
232 eina_strbuf_append_printf(strbuf, format, pkgname);
234 eina_strbuf_append_printf(strbuf, "(%x)", retcode);
235 msg = eina_strbuf_string_get(strbuf);
238 notification_status_message_post(msg);
240 eina_strbuf_free(strbuf);
245 HAPI void quickpanel_uic_open_quickpanel(int reason)
247 struct appdata *ad = quickpanel_get_app_data();
249 DBG("reason:%d", reason);
251 retif(ad == NULL, , "Invalid parameter!");
252 retif(ad->win == NULL, , "Invalid parameter!");
254 #if defined(WINSYS_X11)
257 xwin = elm_win_xwindow_get(ad->win);
259 if ((zone = ecore_x_e_illume_zone_get(xwin)) != 0) {
260 if (ecore_x_e_illume_quickpanel_state_get(zone) == ECORE_X_ILLUME_QUICKPANEL_STATE_OFF) {
261 ecore_x_e_illume_quickpanel_state_send(zone, ECORE_X_ILLUME_QUICKPANEL_STATE_ON);
262 quickpanel_uic_opened_reason_set(reason);
265 ERR("failed to get zone");
268 ERR("failed to get xwin");
271 ERR("Not yet implemented");
275 HAPI void quickpanel_uic_opened_reason_set(int reason)
277 struct appdata *ad = quickpanel_get_app_data();
278 retif(ad == NULL, , "Invalid parameter!");
280 ad->opening_reason = reason;
283 HAPI int quickpanel_uic_opened_reason_get(void)
285 struct appdata *ad = quickpanel_get_app_data();
286 retif(ad == NULL, OPENED_NO_REASON, "Invalid parameter!");
288 return ad->opening_reason;
291 static void _quickpanel_close(void)
293 struct appdata *ad = quickpanel_get_app_data();
297 if (!ad || !ad->win) {
298 ERR("Invalid parameter");
302 #if defined(WINSYS_X11)
305 xwin = elm_win_xwindow_get(ad->win);
307 if ((zone = ecore_x_e_illume_zone_get(xwin)) != 0) {
308 if (ecore_x_e_illume_quickpanel_state_get(zone) == ECORE_X_ILLUME_QUICKPANEL_STATE_ON) {
309 ecore_x_e_illume_quickpanel_state_send(zone, ECORE_X_ILLUME_QUICKPANEL_STATE_OFF);
312 ERR("failed to get zone");
315 ERR("failed to get xwin");
318 ERR("Not yet implemented");
322 static Eina_Bool _quickpanel_close_timer_cb(void *data)
324 if (_close_timer != NULL) {
329 return ECORE_CALLBACK_CANCEL;
332 HAPI void quickpanel_uic_close_quickpanel(bool is_check_lock, int is_delay_needed) {
334 int is_lock_launched = VCONFKEY_IDLE_UNLOCK;
336 if (is_check_lock == true) {
337 if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &is_lock_launched) == 0) {
338 if (is_lock_launched == VCONFKEY_IDLE_LOCK) {
339 ret = vconf_set_int(VCONFKEY_IDLE_LOCK_STATE, VCONFKEY_IDLE_UNLOCK);
341 ERR("unlock the lockscreen from quickpanel");
343 ERR("failed to unlock the lockscreen from quickpanel");
349 if (is_delay_needed) {
350 if( _close_timer == NULL ) {
351 _close_timer = ecore_timer_add(DEL_TIMER_VALUE, _quickpanel_close_timer_cb, NULL);
358 HAPI void quickpanel_uic_toggle_openning_quickpanel(void)
362 struct appdata *ad = quickpanel_get_app_data();
366 if (!ad || !ad->win) {
367 ERR("Invalid parameters");
371 xwin = elm_win_xwindow_get(ad->win);
373 if ((zone = ecore_x_e_illume_zone_get(xwin)) != 0) {
374 if (ecore_x_e_illume_quickpanel_state_get(zone) == ECORE_X_ILLUME_QUICKPANEL_STATE_ON) {
375 ecore_x_e_illume_quickpanel_state_send(zone, ECORE_X_ILLUME_QUICKPANEL_STATE_OFF);
377 ecore_x_e_illume_quickpanel_state_send(zone, ECORE_X_ILLUME_QUICKPANEL_STATE_ON);
380 ERR("failed to get zone");
383 ERR("failed to get xwin");