1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "message-dialog.h"
#include "app_service.h"
static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info);
static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info);
static int __msg_ui_dialog_create_always_ask_popup(void *data);
static void __msg_ui_dialog_rotation_changed_cb(void *data, Evas_Object *obj, void *event);
static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event);
static Evas_Object *__msg_ui_dialog_create_win(const char *name);
static int parse_opt(int argc, char **argv, struct appdata *ad);
void msg_ui_dialog_exit(void *data)
{
struct appdata *ad = data;
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ");
if (ad->msg) {
g_free(ad->msg);
ad->msg = NULL;
}
if (ad->url) {
g_free(ad->url);
ad->url = NULL;
}
if (ad->popup != NULL) {
evas_object_del(ad->popup);
ad->popup = NULL;
}
if (ad->main_window != NULL) {
evas_object_del(ad->main_window);
ad->main_window = NULL;
}
elm_exit();
}
static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data);
struct appdata *ad = data;
service_h svc_h;
int ret = SERVICE_ERROR_NONE;
ret = service_create(&svc_h);
if (ret != SERVICE_ERROR_NONE) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_create() is failed : %d", ret);
return;
}
ret = service_set_operation(svc_h, SERVICE_OPERATION_VIEW);
if (ret != SERVICE_ERROR_NONE) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_operation() is failed : %d", ret);
goto DESTROY;
}
ret = service_set_uri(svc_h, ad->url);
if (ret != SERVICE_ERROR_NONE) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_uri() is failed : %d", ret);
goto DESTROY;
}
ret = service_send_launch_request(svc_h, NULL, NULL);
if (ret != SERVICE_ERROR_NONE) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_send_launch_request() is failed : %d", ret);
}
DESTROY:
ret = service_destroy(svc_h);
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "service_destroy() returns : %d", ret);
msg_ui_dialog_exit(ad);
}
static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data);
struct appdata *ad = data;
msg_ui_dialog_exit(ad);
}
static int __msg_ui_dialog_create_always_ask_popup(void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
struct appdata *ad = data;
char display_msg[100] = { 0, };
Evas_Object *btn1;
Evas_Object *btn2;
const char *str = dgettext(MESSAGE_PKGNAME, "IDS_MSGF_POP_ABOUT_TO_GO_ONLINE_CONTINUE_Q");
snprintf(display_msg, sizeof(display_msg), str, ad->url);
ad->popup = elm_popup_add(ad->main_window);
if (ad->popup == NULL) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Cannot add popup object !!");
return MSG_UI_RET_ERR;
}
evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_text_set(ad->popup, display_msg);
elm_popup_orient_set(ad->popup, ELM_POPUP_ORIENT_CENTER);
btn1 = elm_button_add(ad->popup);
elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_YES"));
elm_object_part_content_set(ad->popup, "button1", btn1);
evas_object_smart_callback_add(btn1, "clicked", __msg_ui_dialog_always_ask_left_btn_cb, ad);
btn2 = elm_button_add(ad->popup);
elm_object_text_set(btn2, dgettext("sys_string", "IDS_COM_SK_NO"));
elm_object_part_content_set(ad->popup, "button2", btn2);
evas_object_smart_callback_add(btn2, "clicked", __msg_ui_dialog_always_ask_right_btn_cb, ad);
evas_object_show(ad->popup);
MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG);
return MSG_UI_RET_SUCCESS;
}
static void __msg_ui_dialog_rotation_changed_cb(void *data, Evas_Object *obj, void *event)
{
struct appdata *ad = data;
if (ad == NULL || ad->main_window == NULL)
return;
int changed_rotation = elm_win_rotation_get(obj);
if(changed_rotation != ad->cur_rotation) {
D_MSG("current rotation [%d], changed rotation [%d]", ad->cur_rotation, changed_rotation);
ad->cur_rotation = changed_rotation;
}
}
static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event)
{
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ");
elm_exit();
}
static Evas_Object *__msg_ui_dialog_create_win(const char *name)
{
Evas_Object *eo = NULL;
int w, h;
eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
if (eo) {
elm_win_alpha_set(eo, EINA_TRUE);
elm_win_title_set(eo, name);
elm_win_raise(eo);
evas_object_smart_callback_add(eo, "delete,request", __msg_ui_dialog_win_del, NULL);
ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
evas_object_resize(eo, w, h);
evas_object_show(eo);
}
return eo;
}
static bool app_create(void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
struct appdata *ad = data;
if (ad->dialog_mode != MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK) {
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Invalid mode !!");
return FALSE;
}
/* init internationalization */
if (bindtextdomain(MESSAGE_PKGNAME, LOCALEDIR) == NULL) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "bindtextdomain() is failed !!");
return FALSE;
}
if (textdomain(MESSAGE_PKGNAME) == NULL) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "textdomain() is failed !!");
return FALSE;
}
/* Create main window */
ad->main_window = __msg_ui_dialog_create_win(PACKAGE);
if (ad->main_window == NULL) {
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_win() is failed !!");
return FALSE;
}
if (__msg_ui_dialog_create_always_ask_popup(ad) < 0) {
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_always_ask_popup() is failed !!");
return FALSE;
}
if(elm_win_wm_rotation_supported_get(ad->main_window)) {
int rotation[4] = {0, 90, 180, 270};
elm_win_wm_rotation_available_rotations_set(ad->main_window, rotation, 4);
ad->cur_rotation = elm_win_rotation_get(ad->main_window);
D_MSG("current rotation %d", ad->cur_rotation);
evas_object_smart_callback_add(ad->main_window, "wm,rotation,changed", __msg_ui_dialog_rotation_changed_cb, ad);
}
return TRUE;
}
static void app_terminate(void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
}
static void app_pause(void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
}
static void app_resume(void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
}
static void app_service(service_h service, void *data)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
}
static int parse_opt(int argc, char **argv, struct appdata *ad)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
int opt;
if (ad == NULL) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid argument: application data is NULL");
return MSG_UI_RET_ERR;
}
while ((opt = getopt(argc, argv, "m:o:u:h")) != -1) {
switch (opt) {
case 'o':
ad->msg = strdup(optarg);
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "optarg = %s", ad->msg);
break;
case 'm':
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "m = %s", optarg);
if (g_strcmp0(optarg, "PUSH_MSG_ALWAYS_ASK") == 0) {
ad->dialog_mode = MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK;
} else {
MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid mode: %s", optarg);
return MSG_UI_RET_ERR;
}
break;
case 'u':
ad->url = strdup(optarg);
MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ad->url = %s", ad->url);
break;
case 'h':
default:
fprintf(stderr, "Usage: %s [-h] [-m PUSH_MSG_ALWAYS_ASK] [-u LaunchURL] \n", argv[0]);
fprintf(stderr, "ex) %s -m PUSH_MSG_ALWAYS_ASK -u www.google.com \n", argv[0]);
return MSG_UI_RET_ERR;
}
}
return MSG_UI_RET_SUCCESS;
}
int main(int argc, char **argv)
{
MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
struct appdata ad;
memset(&ad, 0x0, sizeof(struct appdata));
app_event_callback_s event_callback;
event_callback.create = app_create;
event_callback.terminate = app_terminate;
event_callback.pause = app_pause;
event_callback.resume = app_resume;
event_callback.service = app_service;
event_callback.low_memory = NULL;
event_callback.low_battery = NULL;
event_callback.device_orientation = NULL;
event_callback.language_changed = NULL;
event_callback.region_format_changed = NULL;
if (parse_opt(argc, argv, &ad) == -1) {
MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "parse_opt() is failed !!");
return MSG_UI_RET_ERR;
}
return app_efl_main(&argc, &argv, &event_callback, &ad);
}
|