3 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "popup-common.h"
20 #define SYSPOPUP_CONTENT "_SYSPOPUP_CONTENT_"
22 static syspopup_handler handler;
23 static GList *popup_list = NULL;
24 static int feedback_init_processed;
26 extern int reset_window_priority(int priority);
28 GList *get_popup_list(void)
33 void register_popup(const struct popup_ops *ops)
35 struct object_ops *obj;
38 _E("Invalid parameter.");
42 obj = (struct object_ops *)calloc(1, sizeof(struct object_ops));
44 _E("Failed to calloc().");
50 popup_list = g_list_append(popup_list, obj);
53 static void free_obj(gpointer data)
55 struct object_ops *obj = data;
59 void unregister_all_popup(void)
62 g_list_free_full(popup_list, free_obj);
67 void terminate_if_no_popup(void)
70 struct object_ops *obj;
72 for (l = popup_list ; l ; l = g_list_next(l)) {
73 obj = (struct object_ops *)(l->data);
75 _I("Popup(%s) exists.", obj->ops->name);
82 static int load_popup_by_type(bundle *b)
86 struct object_ops *obj;
92 type = (char *)bundle_get_val(b, SYSPOPUP_CONTENT);
94 _E("Failed to bundle_get_val().");
98 for (l = popup_list ; l ; l = g_list_next(l)) {
99 obj = (struct object_ops *)(l->data);
100 if (!obj || !(obj->ops) || !(obj->ops->name) || !(obj->ops->show))
102 if (strncmp(type, obj->ops->name, strlen(type) + 1))
105 if (obj->ops->skip && obj->ops->skip(b, obj->ops)) {
106 terminate_if_no_popup();
110 if (obj->ops->pattern)
111 play_multi_feedback(obj->ops->pattern);
113 if (obj->ops->change)
114 obj->ops->change(b, obj->ops);
117 obj->ops->pre(b, obj->ops);
119 ret = obj->ops->show(b, obj->ops);
122 obj->ops->post(b, obj->ops);
129 static int release_all_handlers(void *data)
132 struct object_ops *obj;
133 static bool already = false;
139 for (l = popup_list ; l ; l = g_list_next(l)) {
140 obj = (struct object_ops *)(l->data);
141 if (obj && obj->popup) {
142 if (obj->ops->terminate)
143 obj->ops->terminate(obj->ops);
144 release_evas_object(&(obj->popup));
148 unset_dbus_connection();
150 unregister_all_popup();
154 static int terminate_by_syspopup(bundle *b, void *data)
156 return release_all_handlers(data);
159 static int app_create(void *data)
163 handler.def_term_fn = terminate_by_syspopup;
164 handler.def_timeout_fn = NULL;
167 ret = create_window(PACKAGE);
171 app_info = (appdata_s *)data;
173 if (appcore_set_i18n(LANG_DOMAIN, LOCALE_DIR) != 0)
174 _E("Failed to appcore_set_i18n().");
176 ret = set_dbus_connection();
178 _E("Failed to set dbus connection: %d", ret);
180 if (!feedback_init_processed) {
181 init_multi_feedback();
182 feedback_init_processed = 1;
188 static int app_terminate(void *data)
190 stop_multi_feedback();
191 feedback_init_processed = 0;
192 return release_all_handlers(data);
195 static int app_pause(void *data)
198 struct object_ops *obj;
200 for (l = popup_list ; l ; l = g_list_next(l)) {
201 obj = (struct object_ops *)(l->data);
202 if (obj && obj->ops) {
203 if (obj->ops->term_pause == NULL
204 || obj->ops->term_pause(obj->ops)) {
205 unload_simple_popup(obj->ops);
209 terminate_if_no_popup();
213 static int app_resume(void *data)
218 static int app_reset(bundle *b, void *data)
228 if (syspopup_has_popup(b)) {
235 ret = syspopup_create(b, &handler, win, NULL);
237 _E("Failed to syspopup_create(): %d", ret);
241 /* change window priority to normal */
242 (void)reset_window_priority(WIN_PRIORITY_HIGH);
245 ret = load_popup_by_type(b);
256 int main(int argc, char *argv[])
260 struct appcore_ops ops = {
261 .create = app_create,
262 .terminate = app_terminate,
264 .resume = app_resume,
268 memset(&ad, 0x0, sizeof(appdata_s));
271 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);