summaryrefslogtreecommitdiff
path: root/syspopup-app/src/syspopup-app.c
blob: 4f2e4543e7501705a50627764640ca353cb4f671 (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
/*
 * syspopup-app
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * 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 <app.h>
#include <app_control.h>
#include <app_control_internal.h>
#include <Elementary.h>
#include <system_settings.h>
#include <bundle_internal.h>

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

typedef struct appdata {
	Evas_Object *win;
	Evas_Object *popup;
} appdata_s;

syspopup_handler syspopup_h = {
	.def_term_fn = NULL,
	.def_timeout_fn = NULL,
};

static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
	ui_app_exit();
}

static Evas_Object *create_win(const char *name)
{
	Evas_Object *win;

	win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
	if (win == NULL)
		return NULL;

	elm_win_title_set(win, name);
	elm_win_borderless_set(win, EINA_TRUE);
	elm_win_alpha_set(win, EINA_TRUE);

	evas_object_smart_callback_add(win, "delete,request",
					win_delete_request_cb, NULL);

	return win;
}

static bool app_create(void *data)
{
	appdata_s *ad = data;

	ad->win = create_win(PACKAGE);
	if (ad->win == NULL)
		return false;

	return true;
}

static void response_cb(void *data, Evas_Object *obj, void *event_info)
{
	ui_app_exit();
}

static void block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;

	if (ad == NULL)
		return;

	if (ad->popup) {
		evas_object_del(ad->popup);
		ad->popup = NULL;
	}
}

static void set_popup_text(Evas_Object *popup, bundle *b)
{
	const char *value;
	const char *title = "Unknown Title";
	const char *content = "Unknown Content";

	value = bundle_get_val(b, KEY_SYSPOPUP_TITLE);
	if (value)
		title = value;

	elm_object_part_text_set(popup, "title,text", title);

	value = bundle_get_val(b, KEY_SYSPOPUP_CONTENT);
	if (value)
		content = value;

	elm_object_text_set(popup, content);
}

static void create_popup(appdata_s *ad, bundle *b)
{
	int ret;

	ad->popup = elm_popup_add(ad->win);
	if (ad->popup == NULL)
		return;

	ret = syspopup_create(b, &syspopup_h, ad->win, ad);
	if (ret < 0)
		return;

	evas_object_show(ad->win);

	elm_object_style_set(ad->popup, "char_wrap_style");
	evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_smart_callback_add(ad->popup, "block,clicked", block_clicked_cb, ad);
	set_popup_text(ad->popup, b);
	evas_object_smart_callback_add(ad->popup, "response", response_cb, ad);

	evas_object_show(ad->popup);
}

static void app_control(app_control_h app_control, void *data)
{
	int ret;
	bundle *b = NULL;
	appdata_s *ad = data;

	ret = app_control_to_bundle(app_control, &b);
	if (ret != APP_CONTROL_ERROR_NONE)
		return;

	if (syspopup_has_popup(b)) {
		syspopup_reset(b);
		return;
	}

	create_popup(ad, b);
}

static void app_terminate(void *data)
{
	appdata_s *ad = data;

	if (ad == NULL)
		return;

	if (ad->popup) {
		evas_object_del(ad->popup);
		ad->popup = NULL;
	}

	if (ad->win) {
		evas_object_del(ad->win);
		ad->win = NULL;
	}
}

static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
{
	char *locale = NULL;
	system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
	elm_language_set(locale);
	free(locale);

	return;
}

int main(int argc, char *argv[])
{
	appdata_s ad = {0,};
	int ret = 0;
	ui_app_lifecycle_callback_s event_callback = {0,};
	app_event_handler_h handlers;

	event_callback.create = app_create;
	event_callback.terminate = app_terminate;
	event_callback.app_control = app_control;

	ui_app_add_event_handler(&handlers, APP_EVENT_LANGUAGE_CHANGED,
					ui_app_lang_changed, &ad);

	ret = ui_app_main(argc, argv, &event_callback, &ad);
	if (ret != APP_ERROR_NONE)
		dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);

	return ret;
}