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;
25 extern int reset_window_priority(int priority);
27 GList *get_popup_list(void)
32 void register_popup(const struct popup_ops *ops)
34 struct object_ops *obj;
37 _E("Invalid parameter");
41 obj = (struct object_ops *)calloc(1, sizeof(struct object_ops));
43 _E("calloc() fialed");
49 popup_list = g_list_append(popup_list, obj);
52 static void free_obj(gpointer data)
54 struct object_ops *obj = data;
58 void unregister_all_popup(void)
61 g_list_free_full(popup_list, free_obj);
64 void terminate_if_no_popup(void)
67 struct object_ops *obj;
69 for (l = popup_list ; l ; l = g_list_next(l)) {
70 obj = (struct object_ops *)(l->data);
72 _I("popup exists(%s)", obj->ops->name);
79 static int load_popup_by_type(bundle *b)
83 struct object_ops *obj;
89 type = (char *)bundle_get_val(b, SYSPOPUP_CONTENT);
91 _E("FAIL: bundle_get_val()");
95 for (l = popup_list ; l ; l = g_list_next(l)) {
96 obj = (struct object_ops *)(l->data);
97 if (!obj || !(obj->ops) || !(obj->ops->name) || !(obj->ops->show))
99 if (strncmp(type, obj->ops->name, strlen(type) + 1))
102 if (obj->ops->skip && obj->ops->skip(b, obj->ops)) {
103 terminate_if_no_popup();
107 if (obj->ops->change)
108 obj->ops->change(b, obj->ops);
111 obj->ops->pre(b, obj->ops);
113 ret = obj->ops->show(b, obj->ops);
116 obj->ops->post(b, obj->ops);
123 static int release_all_handlers(void *data)
126 struct object_ops *obj;
127 static bool already = false;
133 for (l = popup_list ; l ; l = g_list_next(l)) {
134 obj = (struct object_ops *)(l->data);
135 if (obj && obj->popup) {
136 if (obj->ops->terminate)
137 obj->ops->terminate(obj->ops);
138 release_evas_object(&(obj->popup));
142 unset_dbus_connection();
144 unregister_all_popup();
148 static int terminate_by_syspopup(bundle *b, void *data)
150 return release_all_handlers(data);
153 static int app_create(void *data)
157 handler.def_term_fn = terminate_by_syspopup;
158 handler.def_timeout_fn = NULL;
161 ret = create_window(PACKAGE);
165 if (appcore_set_i18n(LANG_DOMAIN, LOCALE_DIR) != 0)
166 _E("FAIL: appcore_set_i18n()");
168 ret = set_dbus_connection();
170 _E("Failed to set dbus connection (%d)", ret);
175 static int app_terminate(void *data)
177 return release_all_handlers(data);
180 static int app_pause(void *data)
183 struct object_ops *obj;
185 for (l = popup_list ; l ; l = g_list_next(l)) {
186 obj = (struct object_ops *)(l->data);
187 if (obj && obj->ops) {
188 if (obj->ops->term_pause == NULL
189 || obj->ops->term_pause(obj->ops)) {
190 unload_simple_popup(obj->ops);
194 terminate_if_no_popup();
198 static int app_resume(void *data)
203 static int app_reset(bundle *b, void *data)
213 if (syspopup_has_popup(b)) {
220 ret = syspopup_create(b, &handler, win, NULL);
222 _E("FAIL: syspopup_create(): %d", ret);
226 /* change window priority to normal */
227 (void)reset_window_priority(WIN_PRIORITY_HIGH);
230 ret = load_popup_by_type(b);
241 int main(int argc, char *argv[])
243 struct appcore_ops ops = {
244 .create = app_create,
245 .terminate = app_terminate,
247 .resume = app_resume,
251 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);