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>
30 #include "ug-client.h"
32 #define POPUP_TITLE_MAX (128)
38 #define LOG_TAG "UGClient"
40 static void prt_usage(const char *cmd)
42 fprintf(stderr, "Usage: %s [-f] [-F] -n <UG NAME> [-d <Arguments>]\n",
44 fprintf(stderr, " Options:\n");
45 fprintf(stderr, " -d argument\n");
46 fprintf(stderr, " -F Fullview mode (Default)\n");
47 fprintf(stderr, " -f Frameview mode\n");
48 fprintf(stderr, " Example:\n");
50 " %s -F -n helloUG-efl -d \"name,John Doe\" -d \"age,30\"\n",
55 static void win_del(void *data, Evas_Object *obj, void *event)
60 static void main_quit_cb(void *data, Evas_Object *obj,
61 const char *emission, const char *source)
66 static int rotate(enum appcore_rm m, void *data)
68 struct appdata *ad = data;
71 if (ad == NULL || ad->win == NULL)
75 case APPCORE_RM_PORTRAIT_NORMAL:
76 ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
79 case APPCORE_RM_PORTRAIT_REVERSE:
81 ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
83 case APPCORE_RM_LANDSCAPE_NORMAL:
84 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
87 case APPCORE_RM_LANDSCAPE_REVERSE:
88 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
97 elm_win_rotation_with_resize_set(ad->win, r);
102 static void close_popup(void *data, Evas_Object *obj, void *event_info)
104 evas_object_del(obj);
108 static void show_popup(Evas_Object *win, const char *name)
111 char buf[POPUP_TITLE_MAX];
116 pu = elm_popup_add(win);
120 evas_object_size_hint_weight_set(pu, EVAS_HINT_EXPAND,
123 elm_popup_mode_set(pu, ELM_POPUP_TYPE_ALERT);
124 elm_popup_timeout_set(pu, 2);
125 snprintf(buf, POPUP_TITLE_MAX, "Received result from %s", name);
126 elm_popup_title_label_set(pu, buf);
127 evas_object_smart_callback_add(pu, "response", close_popup, NULL);
129 evas_object_show(pu);
132 void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
142 base = ug_get_layout(ug);
147 case UG_MODE_FULLVIEW:
148 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
150 elm_win_resize_object_add(ad->win, base);
151 ug_disable_effect(ug);
152 evas_object_show(base);
154 case UG_MODE_FRAMEVIEW:
155 elm_object_part_content_set(ad->ly_main, "content", base);
162 void result_cb(ui_gadget_h ug, service_h result, void *priv)
171 ret = service_reply_to_launch_request(result, ad->request, SERVICE_RESULT_SUCCEEDED);
172 if (ret != SERVICE_ERROR_NONE)
173 LOGE("service_reply_to_launch_request failed, %d\n", ret);
176 void destroy_cb(ui_gadget_h ug, void *priv)
185 static Evas_Object *create_win(const char *name)
190 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
192 elm_win_title_set(eo, name);
193 elm_win_borderless_set(eo, EINA_TRUE);
194 evas_object_smart_callback_add(eo, "delete,request",
196 ecore_x_window_size_get(ecore_x_window_root_first_get(),
198 evas_object_resize(eo, w, h);
204 static Evas_Object *load_edj(Evas_Object *parent, const char *file,
210 eo = elm_layout_add(parent);
212 r = elm_layout_file_set(eo, file, group);
218 evas_object_size_hint_weight_set(eo,
226 static int low_memory(void *data)
228 return ug_send_event(UG_EVENT_LOW_MEMORY);
231 static int low_battery(void *data)
233 return ug_send_event(UG_EVENT_LOW_BATTERY);
236 static int lang_changed(void *data)
238 return ug_send_event(UG_EVENT_LANG_CHANGE);
241 static int app_create(void *data)
243 struct appdata *ad = data;
248 win = create_win(PACKAGE);
252 UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
255 ly = load_edj(win, EDJ_FILE, GRP_MAIN);
258 elm_win_resize_object_add(win, ly);
259 edje_object_signal_callback_add(elm_layout_edje_get(ly),
260 "EXIT", "*", main_quit_cb, NULL);
265 appcore_set_rotation_cb(rotate, ad);
266 appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, low_memory, ad);
267 appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, low_battery, ad);
268 appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, lang_changed, ad);
273 static int app_terminate(void *data)
275 struct appdata *ad = data;
279 evas_object_del(ad->ly_main);
282 evas_object_del(ad->win);
287 static int app_pause(void *data)
293 static int app_resume(void *data)
299 static int svc_cb(void *data)
301 LOGD("svc_cb called\n");
305 extern int service_create_event(bundle *data, service_h *service);
306 extern int appsvc_request_transient_app(bundle *b, Ecore_X_Window callee_id, appsvc_host_res_fn cbfunc, void *data);
308 static int app_reset(bundle *b, void *data)
310 struct appdata *ad = data;
311 struct ug_cbs cbs = { 0, };
313 enum ug_mode mode = UG_MODE_FULLVIEW;
315 Ecore_X_Window id2 = elm_win_xwindow_get(ad->win);
316 appsvc_request_transient_app(b, id2, svc_cb, "svc test");
319 elm_win_activate(ad->win);
320 evas_object_show(ad->win);
323 if (ad->data) /* ug-launcher */
324 service_create_event(ad->data, &service);
326 service_create_event(b, &service);
328 service_clone(&ad->request, service);
330 cbs.layout_cb = layout_cb;
331 cbs.destroy_cb = destroy_cb;
332 cbs.result_cb = result_cb;
335 ad->ug = ug_create(NULL, ad->name, mode, service, &cbs);
340 static int update_argument(const char *optarg, struct appdata *ad)
344 key = strtok((char *)optarg, ",");
348 val = optarg + strlen(key) + 1;
353 ad->data = bundle_create();
356 bundle_add(ad->data, key, val);
360 int main(int argc, char *argv[])
364 struct appcore_ops ops = {
365 .create = app_create,
366 .terminate = app_terminate,
368 .resume = app_resume,
373 setenv("ELM_ENGINE", "gl", 1); //enabling the OpenGL as the backend of the EFL.
375 memset(&ad, 0x0, sizeof(struct appdata));
378 cmdlen = strlen(argv[0]);
379 if (strncmp(argv[0], "ug-launcher", cmdlen) == 0
380 || strncmp(argv[0], "/usr/bin/ug-launcher", cmdlen) == 0) {
381 while ((opt = getopt(argc, argv, "n:d:")) != -1) {
385 ad.name = strdup(optarg);
388 if (update_argument(optarg, &ad)) {
390 bundle_free(ad.data);
405 argc = 1; // remove appsvc bundle
406 } else { /* ug-client */
408 name = strrchr(argv[0], '/');
412 ad.name = strdup(&name[1]);
414 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);