remove unused code
[apps/core/preloaded/quickpanel.git] / daemon / common_uic.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18
19 #include <Elementary.h>
20 #include <sys/utsname.h>
21 #include <Ecore_Input.h>
22
23 #include <app.h>
24 #include <vconf.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>
30
31 #include <tzsh.h>
32 #include <tzsh_quickpanel_service.h>
33 #include <E_DBus.h>
34
35 #include "common.h"
36 #include "quickpanel-ui.h"
37
38
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;
44
45
46 static void _quickpanel_move_data_to_service(const char *key, const char *val, void *data)
47 {
48         retif(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
49
50         app_control_h service = data;
51         app_control_add_extra_data(service, key, val);
52 }
53
54 HAPI Evas_Object *quickpanel_uic_load_edj(Evas_Object * parent, const char *file, const char *group, int is_just_load)
55 {
56         Eina_Bool r;
57         Evas_Object *eo = NULL;
58
59         retif(parent == NULL, NULL, "Invalid parameter!");
60
61         eo = elm_layout_add(parent);
62         retif(eo == NULL, NULL, "Failed to add layout object!");
63
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);
66
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);
69
70         if (is_just_load == 1) {
71                 elm_win_resize_object_add(parent, eo);
72         }
73         evas_object_show(eo);
74
75         return eo;
76 }
77
78 HAPI int quickpanel_uic_is_opened(void)
79 {
80         struct appdata *ad = quickpanel_get_app_data();
81         retif(ad == NULL, 0, "invalid data.");
82
83         return ad->is_opened;
84 }
85
86 HAPI int quickpanel_uic_is_suspended(void)
87 {
88         struct appdata *ad = quickpanel_get_app_data();
89         retif(ad == NULL, 0, "invalid data.");
90
91         return ad->is_suspended;
92 }
93
94 HAPI int quickpanel_uic_is_emul(void)
95 {
96         int is_emul = 0;
97         char *info = NULL;
98
99         if (system_info_get_platform_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
100                 if (info == NULL) {
101                         return 0;
102                 }
103                 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
104                         is_emul = 1;
105                 }
106         }
107
108         free(info);
109
110         return is_emul;
111 }
112
113 HAPI void quickpanel_uic_initial_resize(Evas_Object *obj, int height)
114 {
115         struct appdata *ad = quickpanel_get_app_data();
116         retif(ad == NULL, , "invalid data.");
117
118         height = (height % 2 != 0) ? height + 1 : height;
119
120         if (ad->angle == 90 || ad->angle == 270) {
121                 evas_object_resize(obj, ad->win_height, height * ad->scale);
122         } else  {
123                 evas_object_resize(obj, ad->win_width, height * ad->scale);
124         }
125 }
126
127 HAPI int quickpanel_uic_launch_app(char *app_id, void *data)
128 {
129         int ret = APP_CONTROL_ERROR_NONE;
130         app_control_h service = NULL;
131         char *app_id_from_service = NULL;
132
133         retif(app_id == NULL && data == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "Invialid parameter!");
134
135         ret = app_control_create(&service);
136         if (ret != APP_CONTROL_ERROR_NONE) {
137                 ERR("app_control_create() return error : %d", ret);
138                 return ret;
139         }
140         retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
141
142         if (app_id != NULL) {
143                 app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
144                 app_control_set_app_id(service, app_id);
145
146                 if (data != NULL) {
147                         bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
148                 }
149         } else {
150                 if (data != NULL) {
151                         ret = app_control_import_from_bundle(service, data);
152                         if (ret != APP_CONTROL_ERROR_NONE) {
153                                 ERR("Failed to import[%d]", ret);
154                         }
155                 }
156         }
157
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);
165                 } else {
166                         quickpanel_uic_launch_app_inform_result(app_id, ret);
167                 }
168                 app_control_destroy(service);
169                 return ret;
170         }
171         app_control_destroy(service);
172         return ret;
173 }
174
175 HAPI int quickpanel_uic_launch_ug_by_appcontrol(const char *package, void *data)
176 {
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");
182
183         ret = app_control_create(&service);
184         if (ret != APP_CONTROL_ERROR_NONE) {
185                 ERR("app_control_create() return error : %d", ret);
186                 return ret;
187         }
188         retif(service == NULL, APP_CONTROL_ERROR_INVALID_PARAMETER, "fail to create service handle!");
189
190         app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
191         app_control_set_app_id(service, package);
192
193         if (data != NULL) {
194                 bundle_iterate((bundle *)data, _quickpanel_move_data_to_service, service);
195         }
196
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);
201                 return ret;
202         }
203         app_control_destroy(service);
204         return ret;
205 }
206
207 HAPI void quickpanel_uic_launch_app_inform_result(const char *pkgname, int retcode)
208 {
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!");
211
212         const char *msg = NULL;
213         char *app_label = NULL;
214
215         if (retcode == APP_CONTROL_ERROR_APP_NOT_FOUND) {
216                 notification_status_message_post(_NOT_LOCALIZED("Unable to find application to perform this action."));
217         } else {
218                 Eina_Strbuf *strbuf = eina_strbuf_new();
219                 char *format = _("IDS_QP_TPOP_UNABLE_TO_OPEN_PS");
220
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);
225                                 free(app_label);
226                         } else {
227                                 eina_strbuf_append_printf(strbuf, format, pkgname);
228                         }
229                         eina_strbuf_append_printf(strbuf, "(%x)", retcode);
230                         msg = eina_strbuf_string_get(strbuf);
231
232                         if (msg != NULL) {
233                                 notification_status_message_post(msg);
234                         }
235                         eina_strbuf_free(strbuf);
236                 }
237         }
238 }
239
240 HAPI void quickpanel_uic_open_quickpanel(int reason)
241 {
242         struct appdata *ad = quickpanel_get_app_data();
243
244         DBG("reason:%d", reason);
245
246         retif(ad == NULL, , "Invalid parameter!");
247         retif(ad->win == NULL, , "Invalid parameter!");
248
249         ERR("Not yet implemented");
250
251 }
252
253 HAPI void quickpanel_uic_opened_reason_set(int reason)
254 {
255         struct appdata *ad = quickpanel_get_app_data();
256         retif(ad == NULL, , "Invalid parameter!");
257
258         ad->opening_reason = reason;
259 }
260
261 HAPI int quickpanel_uic_opened_reason_get(void)
262 {
263         struct appdata *ad = quickpanel_get_app_data();
264         retif(ad == NULL, OPENED_NO_REASON, "Invalid parameter!");
265
266         return ad->opening_reason;
267 }
268
269 static void _quickpanel_close(void)
270 {
271         struct appdata *ad = quickpanel_get_app_data();
272
273         DBG("");
274
275         if (!ad || !ad->win) {
276                 ERR("Invalid parameter");
277                 return;
278         }
279
280         int ret = 0;
281         ret = tzsh_quickpanel_service_hide(ad->quickpanel_service);
282         if(ret != 0) {
283                 ERR("failed tzsh_quickpanel_service_hide");
284         }
285
286 }
287
288 static Eina_Bool _quickpanel_close_timer_cb(void *data)
289 {
290         if (_close_timer != NULL) {
291                 _close_timer = NULL;
292         }
293         _quickpanel_close();
294
295         return ECORE_CALLBACK_CANCEL;
296 }
297
298 HAPI void quickpanel_uic_close_quickpanel(bool is_check_lock, int is_delay_needed) {
299         int ret = 0;
300         int is_lock_launched = VCONFKEY_IDLE_UNLOCK;
301
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);
306                                 if (ret == 0) {
307                                         ERR("unlock the lockscreen from quickpanel");
308                                 } else {
309                                         ERR("failed to unlock the lockscreen from quickpanel");
310                                 }
311                         }
312                 }
313         }
314
315         if (is_delay_needed) {
316                 if( _close_timer == NULL ) {
317                         _close_timer = ecore_timer_add(DEL_TIMER_VALUE, _quickpanel_close_timer_cb, NULL);
318                 }
319         } else {
320                 _quickpanel_close();
321         }
322 }
323
324 HAPI void quickpanel_uic_toggle_openning_quickpanel(void)
325 {
326         /* TO DO */
327 }