4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@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.
23 #include <appcore-efl.h>
24 #include <ui-gadget.h>
29 #include <runtime_info.h>
31 #include "ug-client.h"
37 #define LOG_TAG "UGClient"
39 static void prt_usage(const char *cmd)
41 fprintf(stderr, "Usage: %s [-f] [-F] -n <UG NAME> [-d <Arguments>]\n",
43 fprintf(stderr, " Options:\n");
44 fprintf(stderr, " -d argument\n");
45 fprintf(stderr, " -F Fullview mode (Default)\n");
46 fprintf(stderr, " -f Frameview mode\n");
47 fprintf(stderr, " Example:\n");
49 " %s -F -n helloUG-efl -d \"name,John Doe\" -d \"age,30\"\n",
54 static void win_del(void *data, Evas_Object *obj, void *event)
59 static void main_quit_cb(void *data, Evas_Object *obj,
60 const char *emission, const char *source)
65 static int rotate(enum appcore_rm m, void *data)
67 struct appdata *ad = data;
69 bool is_rotation_lock = false;
71 if (ad == NULL || ad->win == NULL)
75 r = runtime_info_get_value_bool(RUNTIME_INFO_KEY_ROTATION_LOCK_ENABLED, &is_rotation_lock);
76 if ( !r && is_rotation_lock)
77 m = APPCORE_RM_PORTRAIT_NORMAL;
80 case APPCORE_RM_PORTRAIT_NORMAL:
81 ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
84 case APPCORE_RM_PORTRAIT_REVERSE:
86 ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
88 case APPCORE_RM_LANDSCAPE_NORMAL:
89 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
92 case APPCORE_RM_LANDSCAPE_REVERSE:
93 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
104 void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
114 base = ug_get_layout(ug);
119 case UG_MODE_FULLVIEW:
120 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
122 elm_win_resize_object_add(ad->win, base);
123 ug_disable_effect(ug);
124 evas_object_show(base);
126 case UG_MODE_FRAMEVIEW:
127 elm_object_part_content_set(ad->ly_main, "content", base);
134 void result_cb(ui_gadget_h ug, service_h result, void *priv)
143 ret = service_reply_to_launch_request(result, ad->request, SERVICE_RESULT_SUCCEEDED);
144 if (ret != SERVICE_ERROR_NONE)
145 LOGE("service_reply_to_launch_request failed, %d\n", ret);
148 void destroy_cb(ui_gadget_h ug, void *priv)
157 static Evas_Object *create_win(const char *name)
162 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
164 elm_win_title_set(eo, name);
165 elm_win_borderless_set(eo, EINA_TRUE);
166 evas_object_smart_callback_add(eo, "delete,request",
168 ecore_x_window_size_get(ecore_x_window_root_first_get(),
170 evas_object_resize(eo, w, h);
176 static Evas_Object *load_edj(Evas_Object *parent, const char *file,
182 eo = elm_layout_add(parent);
184 r = elm_layout_file_set(eo, file, group);
190 evas_object_size_hint_weight_set(eo,
198 static int low_memory(void *data)
200 return ug_send_event(UG_EVENT_LOW_MEMORY);
203 static int low_battery(void *data)
205 return ug_send_event(UG_EVENT_LOW_BATTERY);
208 static int lang_changed(void *data)
210 return ug_send_event(UG_EVENT_LANG_CHANGE);
213 static int app_create(void *data)
215 struct appdata *ad = data;
221 win = create_win(PACKAGE);
225 UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
228 ly = load_edj(win, EDJ_FILE, GRP_MAIN);
231 elm_win_resize_object_add(win, ly);
232 edje_object_signal_callback_add(elm_layout_edje_get(ly),
233 "EXIT", "*", main_quit_cb, NULL);
238 appcore_set_rotation_cb(rotate, ad);
239 appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, low_memory, ad);
240 appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, low_battery, ad);
241 appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, lang_changed, ad);
243 if (appcore_get_rotation_state(&rm) == 0)
249 static int app_terminate(void *data)
251 struct appdata *ad = data;
255 evas_object_del(ad->ly_main);
258 evas_object_del(ad->win);
263 static int app_pause(void *data)
269 static int app_resume(void *data)
275 static int svc_cb(void *data)
277 LOGD("svc_cb called\n");
281 extern int service_create_event(bundle *data, service_h *service);
282 extern int appsvc_request_transient_app(bundle *b, Ecore_X_Window callee_id, appsvc_host_res_fn cbfunc, void *data);
284 static int app_reset(bundle *b, void *data)
286 struct appdata *ad = data;
287 struct ug_cbs cbs = { 0, };
289 enum ug_mode mode = UG_MODE_FULLVIEW;
291 Ecore_X_Window id2 = elm_win_xwindow_get(ad->win);
292 appsvc_request_transient_app(b, id2, svc_cb, "svc test");
295 elm_win_activate(ad->win);
296 evas_object_show(ad->win);
299 if (ad->data) /* ug-launcher */
300 service_create_event(ad->data, &service);
302 service_create_event(b, &service);
304 service_clone(&ad->request, service);
306 cbs.layout_cb = layout_cb;
307 cbs.destroy_cb = destroy_cb;
308 cbs.result_cb = result_cb;
311 ad->ug = ug_create(NULL, ad->name, mode, service, &cbs);
312 if (ad->ug == NULL) {
313 LOGE("ug_create fail: %s\n", ad->name);
320 static int update_argument(const char *optarg, struct appdata *ad)
324 key = strtok((char *)optarg, ",");
328 val = optarg + strlen(key) + 1;
333 ad->data = bundle_create();
336 bundle_add(ad->data, key, val);
340 int main(int argc, char *argv[])
344 struct appcore_ops ops = {
345 .create = app_create,
346 .terminate = app_terminate,
348 .resume = app_resume,
353 setenv("ELM_ENGINE", "gl", 1); //enabling the OpenGL as the backend of the EFL.
355 memset(&ad, 0x0, sizeof(struct appdata));
358 cmdlen = strlen(argv[0]);
359 if (strncmp(argv[0], "ug-launcher", cmdlen) == 0
360 || strncmp(argv[0], "/usr/bin/ug-launcher", cmdlen) == 0) {
361 while ((opt = getopt(argc, argv, "n:d:")) != -1) {
365 ad.name = strdup(optarg);
368 if (update_argument(optarg, &ad)) {
370 bundle_free(ad.data);
385 argc = 1; // remove appsvc bundle
386 } else { /* ug-client */
388 name = strrchr(argv[0], '/');
392 ad.name = strdup(&name[1]);
394 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);