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>
32 #include <tzsh_quickpanel_service.h>
36 #include "quickpanel-ui.h"
39 /* binary information */
40 #define QP_EMUL_STR "Emulator"
41 #define DEL_TIMER_VALUE 0.480
42 #define SYSTEM_INFO_KEY_MODEL "http://tizen.org/system/model_name"
43 static Ecore_Timer *_close_timer = NULL;
46 static void _quickpanel_move_data_to_service(const char *key, const char *val, void *data)
48 retif(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
50 app_control_h service = data;
51 app_control_add_extra_data(service, key, val);
54 HAPI Evas_Object *quickpanel_uic_load_edj(Evas_Object * parent, const char *file, const char *group, int is_just_load)
57 Evas_Object *eo = NULL;
59 retif(parent == NULL, NULL, "Invalid parameter!");
61 eo = elm_layout_add(parent);
62 retif(eo == NULL, NULL, "Failed to add layout object!");
64 r = elm_layout_file_set(eo, file, group);
65 retif(r != EINA_TRUE, NULL, "Failed to set edje object file[%s-%s]!", file, group);
67 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
70 if (is_just_load == 1) {
71 elm_win_resize_object_add(parent, eo);
78 HAPI int quickpanel_uic_is_opened(void)
80 struct appdata *ad = quickpanel_get_app_data();
81 retif(ad == NULL, 0, "invalid data.");
86 HAPI int quickpanel_uic_is_suspended(void)
88 struct appdata *ad = quickpanel_get_app_data();
89 retif(ad == NULL, 0, "invalid data.");
91 return ad->is_suspended;
94 HAPI int quickpanel_uic_is_emul(void)
99 if (system_info_get_platform_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
103 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
113 HAPI void quickpanel_uic_initial_resize(Evas_Object *obj, int height)
115 struct appdata *ad = quickpanel_get_app_data();
116 retif(ad == NULL, , "invalid data.");
118 height = (height % 2 != 0) ? height + 1 : height;
120 if (ad->angle == 90 || ad->angle == 270) {
121 evas_object_resize(obj, ad->win_height, height * ad->scale);
123 evas_object_resize(obj, ad->win_width, height * ad->scale);
127 HAPI int quickpanel_uic_launch_app(char *app_id, void *data)
129 int ret = APP_CONTROL_ERROR_NONE;
130 app_control_h service = NULL;
131 char *app_id_from_service = NULL;
133 retif(app_id == NULL && data == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "Invialid parameter!");
135 ret = app_control_create(&service);
136 if (ret != APP_CONTROL_ERROR_NONE) {
137 ERR("app_control_create() return error : %d", ret);
140 retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
142 if (app_id != NULL) {
143 app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
144 app_control_set_app_id(service, app_id);
147 bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
151 ret = app_control_import_from_bundle(service, data);
152 if (ret != APP_CONTROL_ERROR_NONE) {
153 ERR("Failed to import[%d]", ret);
158 ret = app_control_send_launch_request(service, NULL, NULL);
159 if (ret != APP_CONTROL_ERROR_NONE) {
160 ERR("app_control_send_launch_request() is failed : %d", ret);
161 app_control_get_app_id(service, &app_id_from_service);
162 if (app_id_from_service != NULL) {
163 quickpanel_uic_launch_app_inform_result(app_id_from_service, ret);
164 free(app_id_from_service);
166 quickpanel_uic_launch_app_inform_result(app_id, ret);
168 app_control_destroy(service);
171 app_control_destroy(service);
175 HAPI int quickpanel_uic_launch_ug_by_appcontrol(const char *package, void *data)
177 int ret = APP_CONTROL_ERROR_NONE;
178 app_control_h service = NULL;
179 struct appdata *ad = quickpanel_get_app_data();
180 retif(ad == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "ad null");
181 retif(package == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "package null");
183 ret = app_control_create(&service);
184 if (ret != APP_CONTROL_ERROR_NONE) {
185 ERR("app_control_create() return error : %d", ret);
188 retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
190 app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
191 app_control_set_app_id(service, package);
194 bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
197 ret = app_control_send_launch_request(service, NULL, NULL);
198 if (ret != APP_CONTROL_ERROR_NONE) {
199 ERR("app_control_send_launch_request() is failed : %d", ret);
200 app_control_destroy(service);
203 app_control_destroy(service);
207 HAPI void quickpanel_uic_launch_app_inform_result(const char *pkgname, int retcode)
209 retif(retcode == APP_CONTROL_ERROR_NONE, , "retcode = APP_CONTROL_ERROR_NONE!");
210 retif(pkgname == NULL && retcode != APP_CONTROL_ERROR_APP_NOT_FOUND, , "Invialid parameter!");
212 const char *msg = NULL;
213 char *app_label = NULL;
215 if (retcode == APP_CONTROL_ERROR_APP_NOT_FOUND) {
216 notification_status_message_post(_NOT_LOCALIZED("Unable to find application to perform this action."));
218 Eina_Strbuf *strbuf = eina_strbuf_new();
219 char *format = _("IDS_QP_TPOP_UNABLE_TO_OPEN_PS");
221 if (strbuf != NULL) {
222 app_label = quickpanel_common_ui_get_pkginfo_label(pkgname);
223 if (app_label != NULL) {
224 eina_strbuf_append_printf(strbuf, format, app_label);
227 eina_strbuf_append_printf(strbuf, format, pkgname);
229 eina_strbuf_append_printf(strbuf, "(%x)", retcode);
230 msg = eina_strbuf_string_get(strbuf);
233 notification_status_message_post(msg);
235 eina_strbuf_free(strbuf);
240 HAPI void quickpanel_uic_open_quickpanel(int reason)
242 struct appdata *ad = quickpanel_get_app_data();
244 DBG("reason:%d", reason);
246 retif(ad == NULL, , "Invalid parameter!");
247 retif(ad->win == NULL, , "Invalid parameter!");
249 ERR("Not yet implemented");
253 HAPI void quickpanel_uic_opened_reason_set(int reason)
255 struct appdata *ad = quickpanel_get_app_data();
256 retif(ad == NULL, , "Invalid parameter!");
258 ad->opening_reason = reason;
261 HAPI int quickpanel_uic_opened_reason_get(void)
263 struct appdata *ad = quickpanel_get_app_data();
264 retif(ad == NULL, OPENED_NO_REASON, "Invalid parameter!");
266 return ad->opening_reason;
269 static void _quickpanel_close(void)
271 struct appdata *ad = quickpanel_get_app_data();
275 if (!ad || !ad->win) {
276 ERR("Invalid parameter");
281 ret = tzsh_quickpanel_service_hide(ad->quickpanel_service);
283 ERR("failed tzsh_quickpanel_service_hide");
288 static Eina_Bool _quickpanel_close_timer_cb(void *data)
290 if (_close_timer != NULL) {
295 return ECORE_CALLBACK_CANCEL;
298 HAPI void quickpanel_uic_close_quickpanel(bool is_check_lock, int is_delay_needed) {
300 int is_lock_launched = VCONFKEY_IDLE_UNLOCK;
302 if (is_check_lock == true) {
303 if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &is_lock_launched) == 0) {
304 if (is_lock_launched == VCONFKEY_IDLE_LOCK) {
305 ret = vconf_set_int(VCONFKEY_IDLE_LOCK_STATE, VCONFKEY_IDLE_UNLOCK);
307 ERR("unlock the lockscreen from quickpanel");
309 ERR("failed to unlock the lockscreen from quickpanel");
315 if (is_delay_needed) {
316 if( _close_timer == NULL ) {
317 _close_timer = ecore_timer_add(DEL_TIMER_VALUE, _quickpanel_close_timer_cb, NULL);
324 HAPI void quickpanel_uic_toggle_openning_quickpanel(void)