summaryrefslogtreecommitdiff
path: root/syspopup-app/syspopup-app.c
blob: 8c6d143b8defb6fccb6f8d214d53f9972364b9da (plain)
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
/*
 * syspopup
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
 * Jaeho Lee <jaeho81.lee@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 <stdio.h>
#include <appcore-efl.h>
#include <Ecore_X.h>

#include "syspopup.h"
#include "syspopup-app.h"

/*#include <quickpanel.h> */
#include <time.h>
/*
struct quickpanel {
	int type;
	int priv_id; 
	char *title;
	char *content;
	time_t rtime;
	bundle *args; 
	bundle *args_group;
	int group_id;
};
*/

int myterm(bundle *b, void *data)
{
	/*
	char b_str[QP_BUF_LEN];
	int ret = 0;
	const char* val;

	struct appdata *ad = data;
	struct quickpanel* qp;

	val = bundle_get_val(b,"_INTERNAL_SYSPOPUP_NAME_");
	printf("[SYSTEM POPUP] Popup Name : %s\n", val);

	qp = malloc(sizeof(struct quickpanel));
	memset(qp,0,sizeof(struct quickpanel));

	//qp->type = QP_TYPE_SYSPOPUP;
	qp->type = quickpanel_get_type_id("org.tizen.syspopup-app", NULL, 0);
	qp->priv_id = QP_PRIVID;
	qp->title = ad->title;
	qp->content = ad->content;
	qp->args = b;
	qp->group_id = qp->priv_id;

	ret = quickpanel_insert(qp);
	if (ret < 0)
		printf("[SYSTEM POPUP] Error!! Cannot insert to quickpanel!\n");

	free(qp);
	*/
	return 0;
}

int mytimeout(bundle *b, void* data)
{
	/*
	char b_str[QP_BUF_LEN];
	int ret = 0;
	const char* val;

	struct appdata *ad = data;
	struct quickpanel* qp;

	val = bundle_get_val(b,"_INTERNAL_SYSPOPUP_NAME_");
	printf("[SYSTEM POPUP] Popup Name : %s\n", val);

	qp = malloc(sizeof(struct quickpanel));
	memset(qp,0,sizeof(struct quickpanel));

	//qp->type = QP_TYPE_SYSPOPUP;
	qp->type = quickpanel_get_type_id("org.tizen.syspopup-app", NULL, 0);
	qp->priv_id = QP_PRIVID;
	qp->title = ad->title;
	qp->content = ad->content;
	qp->args = b;
	qp->group_id = qp->priv_id;

	ret = quickpanel_insert(qp);
	if (ret < 0)
		printf("[SYSTEM POPUP] Error!! Cannot insert to quickpanel!\n");

	free(qp);
	*/
	return 0;
}

syspopup_handler handler = {
	.def_term_fn = myterm,
	.def_timeout_fn = mytimeout
};

static void __win_del(void *data, Evas_Object * obj, void *event)
{
	elm_exit();
}


static Evas_Object *__create_win(const char *name)
{
	Evas_Object *eo;
	int w;
	int h;

	eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
	if (eo) {
		elm_win_title_set(eo, name);
		elm_win_borderless_set(eo, EINA_TRUE);

		elm_win_alpha_set(eo, EINA_TRUE);

		evas_object_smart_callback_add(eo, "delete,request",
					       __win_del, NULL);
		ecore_x_window_size_get(ecore_x_window_root_first_get(),
					&w, &h);
		evas_object_resize(eo, w, h);
	}

	return eo;
}

static int __app_create(void *data)
{
	struct appdata *ad = data;
	Evas_Object *win;
	int r;

	/* create window */
	win = __create_win(PACKAGE);
	if (win == NULL)
		return -1;
	ad->win = win;
	/* evas_object_show(win);*/

	/* init internationalization */
	r = appcore_set_i18n(PACKAGE, LOCALEDIR);
	if (r)
		return -1;

	appcore_measure_start();
	return 0;
}

static int __app_terminate(void *data)
{
	struct appdata *ad = data;

	printf("[SYSPOPUP] %s, %d\n", __func__, __LINE__);

	if (ad->win)
		evas_object_del(ad->win);

	return 0;
}

static int __app_pause(void *data)
{
	struct appdata *ad = data;

	return 0;
}

static int __app_resume(void *data)
{
	struct appdata *ad = data;

	return 0;
}

static void __prt_recvd_bundle(const char *key, const char *value, void *d)
{
	printf("recvd - key: %s, value: %s\n", key, value);
}

static void __response_cb(void *data, Evas_Object * obj, void *event_info)
{
	if ((int)event_info != 5)
		evas_object_del(obj);
	elm_exit();
}

static int __app_reset(bundle *b, void *data)
{
	struct appdata *ad = data;
	Evas_Object *popup;
	const char *val;
	int ret = 0;

	ad->b = bundle_dup(b);

	bundle_iterate(b, __prt_recvd_bundle, NULL);

	if (syspopup_has_popup(b)) {
		syspopup_reset(b);
	} else {
		popup = elm_popup_add(ad->win);
		if (popup != NULL) {
			ret = syspopup_create(b, &handler, ad->win, ad);
			evas_object_show(ad->win);

			if (ret == 0) {
				val = bundle_get_val(b,
						   "_INTERNAL_SYSPOPUP_NAME_");

				val = bundle_get_val(b, "_SYSPOPUP_TITLE_");
				if (val) {
					snprintf(ad->title, TITLE_BUF_LEN, "%s",
						 val);
				} else {
					snprintf(ad->title, TITLE_BUF_LEN, "%s",
						 "Unknown Title");
				}

				val = bundle_get_val(b, "_SYSPOPUP_CONTENT_");
				if (val) {
					snprintf(ad->content, CONTENT_BUF_LEN,
						 "%s", val);
				} else {
					snprintf(ad->content, CONTENT_BUF_LEN,
						 "%s", "Unknown Content");
				}

				elm_object_style_set(popup, "char_wrap_style");
				evas_object_size_hint_weight_set(popup,
							EVAS_HINT_EXPAND,
							EVAS_HINT_EXPAND);
				elm_popup_mode_set(popup, ELM_POPUP_TYPE_ALERT);
				elm_popup_title_label_set(popup, ad->title);
				elm_popup_desc_set(popup, ad->content);
				evas_object_smart_callback_add(popup,
							       "response",
							       __response_cb,
							       NULL);

				evas_object_show(popup);
			}
		}
	}

	return 0;
}

int main(int argc, char *argv[])
{
	struct appdata ad;
	struct appcore_ops ops = {
		.create = __app_create,
		.terminate = __app_terminate,
		.pause = __app_pause,
		.resume = __app_resume,
		.reset = __app_reset,
	};

//	unsetenv("ELM_SCALE");

	/* appcore measure time example */
	printf("from AUL to %s(): %d msec\n", __func__,
	       appcore_measure_time_from("APP_START_TIME"));

	memset(&ad, 0x0, sizeof(struct appdata));
	ops.data = &ad;

	return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
}