1 #include "e_mod_main.h"
3 /* Gadcon function protos */
4 static E_Gadcon_Client *_gc_init(E_Gadcon *gc,
8 static void _gc_shutdown(E_Gadcon_Client *gcc);
9 static const char *_gc_label(E_Gadcon_Client_Class *client_class);
10 static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class,
12 static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
13 static void _gc_id_del(E_Gadcon_Client_Class *client_class,
16 /* Callback function protos */
17 static int _notification_cb_notify(E_Notification_Daemon *daemon,
19 static void _notification_cb_close_notification(E_Notification_Daemon *daemon,
22 /* Config function protos */
23 static Config *_notification_cfg_new(void);
24 static void _notification_cfg_free(Config *cfg);
26 /* Global variables */
27 E_Module *notification_mod = NULL;
28 Config *notification_cfg = NULL;
30 static E_Config_DD *conf_edd = NULL;
31 static E_Config_DD *conf_item_edd = NULL;
33 /* Gadcon Api Functions */
34 const E_Gadcon_Client_Class _gc_class =
36 GADCON_CLIENT_CLASS_VERSION, "notification",
38 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, _gc_id_del,
39 e_gadcon_site_is_not_toolbar
41 E_GADCON_CLIENT_STYLE_PLAIN
44 static E_Gadcon_Client *
45 _gc_init(E_Gadcon *gc,
55 inst = E_NEW(Instance, 1);
56 ci = notification_box_config_item_get(id);
57 b = notification_box_get(ci->id, gc->evas);
63 gcc = e_gadcon_client_new(gc, name, id, style, b->o_box);
67 evas_object_event_callback_add(b->o_box, EVAS_CALLBACK_MOVE,
68 notification_box_cb_obj_moveresize, inst);
69 evas_object_event_callback_add(b->o_box, EVAS_CALLBACK_RESIZE,
70 notification_box_cb_obj_moveresize, inst);
71 notification_cfg->instances = eina_list_append(notification_cfg->instances, inst);
72 _gc_orient(gcc, gc->orient);
77 _gc_shutdown(E_Gadcon_Client *gcc)
82 notification_box_visible_set(inst->n_box, EINA_FALSE);
83 notification_cfg->instances = eina_list_remove(notification_cfg->instances, inst);
88 _gc_orient(E_Gadcon_Client *gcc,
89 E_Gadcon_Orient orient)
96 case E_GADCON_ORIENT_FLOAT:
97 case E_GADCON_ORIENT_HORIZ:
98 case E_GADCON_ORIENT_TOP:
99 case E_GADCON_ORIENT_BOTTOM:
100 case E_GADCON_ORIENT_CORNER_TL:
101 case E_GADCON_ORIENT_CORNER_TR:
102 case E_GADCON_ORIENT_CORNER_BL:
103 case E_GADCON_ORIENT_CORNER_BR:
104 notification_box_orient_set(inst->n_box, 1);
105 e_gadcon_client_aspect_set(gcc, MAX(eina_list_count(inst->n_box->icons), 1) * 16, 16);
108 case E_GADCON_ORIENT_VERT:
109 case E_GADCON_ORIENT_LEFT:
110 case E_GADCON_ORIENT_RIGHT:
111 case E_GADCON_ORIENT_CORNER_LT:
112 case E_GADCON_ORIENT_CORNER_RT:
113 case E_GADCON_ORIENT_CORNER_LB:
114 case E_GADCON_ORIENT_CORNER_RB:
115 notification_box_orient_set(inst->n_box, 0);
116 e_gadcon_client_aspect_set(gcc, 16, MAX(eina_list_count(inst->n_box->icons), 1) * 16);
122 e_gadcon_client_min_size_set(gcc, 16, 16);
126 _gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
128 return _("Notification Box");
132 _gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__,
138 o = edje_object_add(evas);
139 snprintf(buf, sizeof(buf), "%s/e-module-notification.edj",
140 e_module_dir_get(notification_mod));
141 if (!e_theme_edje_object_set(o, "base/theme/modules/notification",
143 edje_object_file_set(o, buf, "icon");
148 _gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
152 ci = notification_box_config_item_get(NULL);
157 _gc_id_del(E_Gadcon_Client_Class *client_class __UNUSED__,
162 notification_box_del(id);
163 ci = notification_box_config_item_get(id);
165 eina_stringshare_del(ci->id);
166 notification_cfg->items = eina_list_remove(notification_cfg->items, ci);
171 _notification_notify(E_Notification *n)
173 const char *appname = e_notification_app_name_get(n);
174 unsigned int replaces_id = e_notification_replaces_id_get(n);
178 if (replaces_id) new_id = replaces_id;
179 else new_id = notification_cfg->next_id++;
181 e_notification_id_set(n, new_id);
183 popuped = notification_popup_notify(n, replaces_id, appname);
184 notification_box_notify(n, replaces_id, new_id);
188 e_notification_hint_urgency_set(n, 4);
189 notification_popup_notify(n, replaces_id, appname);
196 _notification_show_common(const char *summary,
200 E_Notification *n = e_notification_full_new
201 ("enlightenment", replaces_id, "enlightenment", summary, body, -1);
206 _notification_notify(n);
207 e_notification_unref(n);
211 _notification_show_presentation(Eina_Bool enabled)
213 const char *summary, *body;
217 summary = _("Enter Presentation Mode");
218 body = _("Enlightenment is in <b>presentation</b> mode."
219 "<br>During presentation mode, screen saver, lock and "
220 "power saving will be disabled so you are not interrupted.");
224 summary = _("Exited Presentation Mode");
225 body = _("Presentation mode is over."
226 "<br>Now screen saver, lock and "
227 "power saving settings will be restored.");
230 _notification_show_common(summary, body, -1);
234 _notification_show_offline(Eina_Bool enabled)
236 const char *summary, *body;
240 summary = _("Enter Offline Mode");
241 body = _("Enlightenment is in <b>offline</b> mode.<br>"
242 "During offline mode, modules that use network will stop "
243 "polling remote services.");
247 summary = _("Exited Offline Mode");
248 body = _("Now in <b>online</b> mode.<br>"
249 "Now modules that use network will "
250 "resume regular tasks.");
253 _notification_show_common(summary, body, -1);
257 _notification_cb_config_mode_changed(Config *m_cfg,
259 void *event __UNUSED__)
261 if (m_cfg->last_config_mode.presentation != e_config->mode.presentation)
263 m_cfg->last_config_mode.presentation = e_config->mode.presentation;
264 _notification_show_presentation(e_config->mode.presentation);
267 if (m_cfg->last_config_mode.offline != e_config->mode.offline)
269 m_cfg->last_config_mode.offline = e_config->mode.offline;
270 _notification_show_offline(e_config->mode.offline);
277 _notification_cb_initial_mode_timer(Config *m_cfg)
279 if (e_config->mode.presentation)
280 _notification_show_presentation(1);
281 if (e_config->mode.offline)
282 _notification_show_offline(1);
284 m_cfg->initial_mode_timer = NULL;
288 /* Module Api Functions */
289 EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Notification"};
292 e_modapi_init(E_Module *m)
294 E_Notification_Daemon *d;
297 snprintf(buf, sizeof(buf), "%s/e-module-notification.edj", m->dir);
298 /* register config panel entry */
299 e_configure_registry_category_add("extensions", 90, _("Extensions"), NULL,
300 "preferences-extensions");
301 e_configure_registry_item_add("extensions/notification", 30,
302 _("Notification"), NULL,
303 buf, e_int_config_notification_module);
305 conf_item_edd = E_CONFIG_DD_NEW("Notification_Config_Item", Config_Item);
308 #define T Config_Item
309 #define D conf_item_edd
310 E_CONFIG_VAL(D, T, id, STR);
311 E_CONFIG_VAL(D, T, show_label, INT);
312 E_CONFIG_VAL(D, T, show_popup, INT);
313 E_CONFIG_VAL(D, T, focus_window, INT);
314 E_CONFIG_VAL(D, T, store_low, INT);
315 E_CONFIG_VAL(D, T, store_normal, INT);
316 E_CONFIG_VAL(D, T, store_critical, INT);
318 conf_edd = E_CONFIG_DD_NEW("Notification_Config", Config);
323 E_CONFIG_VAL(D, T, version, INT);
324 E_CONFIG_VAL(D, T, show_low, INT);
325 E_CONFIG_VAL(D, T, show_normal, INT);
326 E_CONFIG_VAL(D, T, show_critical, INT);
327 E_CONFIG_VAL(D, T, corner, INT);
328 E_CONFIG_VAL(D, T, timeout, FLOAT);
329 E_CONFIG_VAL(D, T, force_timeout, INT);
330 E_CONFIG_VAL(D, T, ignore_replacement, INT);
331 E_CONFIG_VAL(D, T, dual_screen, INT);
332 E_CONFIG_LIST(D, T, items, conf_item_edd);
334 notification_cfg = e_config_domain_load("module.notification", conf_edd);
335 if (notification_cfg &&
336 !(e_util_module_config_check(_("Notification Module"),
337 notification_cfg->version,
338 MOD_CFG_FILE_VERSION)))
340 _notification_cfg_free(notification_cfg);
343 if (!notification_cfg)
345 notification_cfg = _notification_cfg_new();
348 /* set up the notification daemon */
349 e_notification_daemon_init();
350 d = e_notification_daemon_add("e_notification_module", "Enlightenment");
353 _notification_cfg_free(notification_cfg);
354 notification_cfg = NULL;
355 e_util_dialog_show(_("Error During DBus Init!"),
356 _("Error during DBus init! Please check if "
357 "dbus is correctly installed and running."));
360 notification_cfg->daemon = d;
361 e_notification_daemon_data_set(d, notification_cfg);
362 e_notification_daemon_callback_notify_set(d, _notification_cb_notify);
363 e_notification_daemon_callback_close_notification_set(d, _notification_cb_close_notification);
365 notification_cfg->last_config_mode.presentation = e_config->mode.presentation;
366 notification_cfg->last_config_mode.offline = e_config->mode.offline;
367 notification_cfg->handlers = eina_list_append
368 (notification_cfg->handlers, ecore_event_handler_add
369 (E_EVENT_CONFIG_MODE_CHANGED, (Ecore_Event_Handler_Cb)_notification_cb_config_mode_changed,
371 notification_cfg->initial_mode_timer = ecore_timer_add
372 (0.1, (Ecore_Task_Cb)_notification_cb_initial_mode_timer, notification_cfg);
374 /* set up the borders events callbacks */
375 notification_cfg->handlers = eina_list_append
376 (notification_cfg->handlers, ecore_event_handler_add
377 (E_EVENT_BORDER_REMOVE, (Ecore_Event_Handler_Cb)notification_box_cb_border_remove, NULL));
379 notification_mod = m;
380 e_gadcon_provider_register(&_gc_class);
385 e_modapi_shutdown(E_Module *m __UNUSED__)
387 Ecore_Event_Handler *h;
390 e_gadcon_provider_unregister(&_gc_class);
392 if (notification_cfg->initial_mode_timer)
393 ecore_timer_del(notification_cfg->initial_mode_timer);
395 EINA_LIST_FREE(notification_cfg->handlers, h)
396 ecore_event_handler_del(h);
398 if (notification_cfg->cfd) e_object_del(E_OBJECT(notification_cfg->cfd));
399 e_configure_registry_item_del("extensions/notification");
400 e_configure_registry_category_del("extensions");
402 if (notification_cfg->menu)
404 e_menu_post_deactivate_callback_set(notification_cfg->menu, NULL, NULL);
405 e_object_del(E_OBJECT(notification_cfg->menu));
406 notification_cfg->menu = NULL;
409 EINA_LIST_FREE(notification_cfg->items, ci)
411 eina_stringshare_del(ci->id);
415 notification_box_shutdown();
416 notification_popup_shutdown();
418 e_notification_daemon_free(notification_cfg->daemon);
419 e_notification_daemon_shutdown();
420 _notification_cfg_free(notification_cfg);
421 E_CONFIG_DD_FREE(conf_item_edd);
422 E_CONFIG_DD_FREE(conf_edd);
423 notification_mod = NULL;
429 e_modapi_save(E_Module *m __UNUSED__)
432 ret = e_config_domain_save("module.notification", conf_edd, notification_cfg);
438 _notification_cb_notify(E_Notification_Daemon *daemon __UNUSED__,
441 return _notification_notify(n);
445 _notification_cb_close_notification(E_Notification_Daemon *daemon __UNUSED__,
448 notification_popup_close(id);
452 _notification_cfg_new(void)
456 cfg = E_NEW(Config, 1);
458 cfg->version = MOD_CFG_FILE_VERSION;
460 cfg->show_normal = 1;
461 cfg->show_critical = 1;
463 cfg->force_timeout = 0;
464 cfg->ignore_replacement = 0;
465 cfg->dual_screen = 0;
466 cfg->corner = CORNER_TR;
472 _notification_cfg_free(Config *cfg)