2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license
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.
18 #include "message-dialog.h"
19 #include "app_service.h"
22 static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info);
23 static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info);
24 static int __msg_ui_dialog_create_always_ask_popup(void *data);
25 static void __msg_ui_dialog_rotate(app_device_orientation_e orientation, void *data);
26 static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event);
27 static Evas_Object *__msg_ui_dialog_create_win(const char *name);
28 static int parse_opt(int argc, char **argv, struct appdata *ad);
31 void msg_ui_dialog_exit(void *data)
33 struct appdata *ad = data;
35 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ");
47 if (ad->popup != NULL) {
48 evas_object_del(ad->popup);
52 if (ad->main_window != NULL) {
53 evas_object_del(ad->main_window);
54 ad->main_window = NULL;
60 static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info)
62 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
63 MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data);
65 struct appdata *ad = data;
67 int ret = SERVICE_ERROR_NONE;
69 ret = service_create(&svc_h);
70 if (ret != SERVICE_ERROR_NONE) {
71 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_create() is failed : %d", ret);
75 ret = service_set_operation(svc_h, SERVICE_OPERATION_VIEW);
76 if (ret != SERVICE_ERROR_NONE) {
77 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_operation() is failed : %d", ret);
81 ret = service_set_uri(svc_h, ad->url);
82 if (ret != SERVICE_ERROR_NONE) {
83 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_uri() is failed : %d", ret);
87 ret = service_send_launch_request(svc_h, NULL, NULL);
88 if (ret != SERVICE_ERROR_NONE) {
89 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_send_launch_request() is failed : %d", ret);
93 ret = service_destroy(svc_h);
94 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "service_destroy() returns : %d", ret);
96 msg_ui_dialog_exit(ad);
99 static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info)
101 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
102 MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data);
104 struct appdata *ad = data;
106 msg_ui_dialog_exit(ad);
109 static int __msg_ui_dialog_create_always_ask_popup(void *data)
111 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
113 struct appdata *ad = data;
114 char display_msg[100] = { 0, };
118 const char *str = dgettext(MESSAGE_PKGNAME, "IDS_MSGF_POP_ABOUT_TO_GO_ONLINE_CONTINUE_Q");
119 snprintf(display_msg, sizeof(display_msg), str, ad->url);
121 ad->popup = elm_popup_add(ad->main_window);
122 if (ad->popup == NULL) {
123 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Cannot add popup object !!");
124 return MSG_UI_RET_ERR;
127 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128 elm_object_text_set(ad->popup, display_msg);
129 elm_popup_orient_set(ad->popup, ELM_POPUP_ORIENT_CENTER);
131 btn1 = elm_button_add(ad->popup);
132 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_YES"));
133 elm_object_part_content_set(ad->popup, "button1", btn1);
134 evas_object_smart_callback_add(btn1, "clicked", __msg_ui_dialog_always_ask_left_btn_cb, ad);
136 btn2 = elm_button_add(ad->popup);
137 elm_object_text_set(btn2, dgettext("sys_string", "IDS_COM_SK_NO"));
138 elm_object_part_content_set(ad->popup, "button2", btn2);
139 evas_object_smart_callback_add(btn2, "clicked", __msg_ui_dialog_always_ask_right_btn_cb, ad);
141 evas_object_show(ad->popup);
143 MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG);
145 return MSG_UI_RET_SUCCESS;
148 static void __msg_ui_dialog_rotate(app_device_orientation_e orientation, void *data)
150 struct appdata *ad = data;
153 if (ad == NULL || ad->main_window == NULL)
156 switch (orientation) {
157 case APP_DEVICE_ORIENTATION_0:
160 case APP_DEVICE_ORIENTATION_180:
163 case APP_DEVICE_ORIENTATION_270:
166 case APP_DEVICE_ORIENTATION_90:
175 if (ad->main_window) {
176 elm_win_rotation_with_resize_set(ad->main_window, r);
178 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid case !!");
183 static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event)
185 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ");
190 static Evas_Object *__msg_ui_dialog_create_win(const char *name)
192 Evas_Object *eo = NULL;
195 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
197 elm_win_alpha_set(eo, EINA_TRUE);
198 elm_win_title_set(eo, name);
200 evas_object_smart_callback_add(eo, "delete,request", __msg_ui_dialog_win_del, NULL);
201 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
202 evas_object_resize(eo, w, h);
203 evas_object_show(eo);
209 static bool app_create(void *data)
211 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
213 struct appdata *ad = data;
215 if (ad->dialog_mode != MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK) {
216 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Invalid mode !!");
220 /* init internationalization */
221 if (bindtextdomain(MESSAGE_PKGNAME, LOCALEDIR) == NULL) {
222 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "bindtextdomain() is failed !!");
226 if (textdomain(MESSAGE_PKGNAME) == NULL) {
227 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "textdomain() is failed !!");
231 /* Create main window */
232 ad->main_window = __msg_ui_dialog_create_win(PACKAGE);
233 if (ad->main_window == NULL) {
234 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_win() is failed !!");
238 if (__msg_ui_dialog_create_always_ask_popup(ad) < 0) {
239 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_always_ask_popup() is failed !!");
246 static void app_terminate(void *data)
248 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
251 static void app_pause(void *data)
253 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
256 static void app_resume(void *data)
258 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
261 static void app_service(service_h service, void *data)
263 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
266 static int parse_opt(int argc, char **argv, struct appdata *ad)
268 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
273 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid argument: application data is NULL");
274 return MSG_UI_RET_ERR;
277 while ((opt = getopt(argc, argv, "m:o:u:h")) != -1) {
280 ad->msg = strdup(optarg);
281 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "optarg = %s", ad->msg);
285 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "m = %s", optarg);
286 if (g_strcmp0(optarg, "PUSH_MSG_ALWAYS_ASK") == 0) {
287 ad->dialog_mode = MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK;
289 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid mode: %s", optarg);
290 return MSG_UI_RET_ERR;
294 ad->url = strdup(optarg);
295 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ad->url = %s", ad->url);
299 fprintf(stderr, "Usage: %s [-h] [-m PUSH_MSG_ALWAYS_ASK] [-u LaunchURL] \n", argv[0]);
300 fprintf(stderr, "ex) %s -m PUSH_MSG_ALWAYS_ASK -u www.google.com \n", argv[0]);
301 return MSG_UI_RET_ERR;
305 return MSG_UI_RET_SUCCESS;
308 int main(int argc, char **argv)
310 MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
313 memset(&ad, 0x0, sizeof(struct appdata));
315 app_event_callback_s event_callback;
317 event_callback.create = app_create;
318 event_callback.terminate = app_terminate;
319 event_callback.pause = app_pause;
320 event_callback.resume = app_resume;
321 event_callback.service = app_service;
322 event_callback.low_memory = NULL;
323 event_callback.low_battery = NULL;
324 event_callback.device_orientation = __msg_ui_dialog_rotate;
325 event_callback.language_changed = NULL;
326 event_callback.region_format_changed = NULL;
328 if (parse_opt(argc, argv, &ad) == -1) {
329 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "parse_opt() is failed !!");
330 return MSG_UI_RET_ERR;
333 return app_efl_main(&argc, &argv, &event_callback, &ad);