new enotify test which showcases 1) our ability to break e_dbus 2) enotify's continue...
[framework/uifw/edbus.git] / src / bin / notify.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <stdio.h>
6
7 #include <Evas.h>
8 #include <Ecore.h>
9 #include <Ecore_Evas.h>
10 #include <E_DBus.h>
11 #include <E_Notify.h>
12
13 #define LOGO PACKAGE_DATA_DIR "/logo.png"
14
15 void
16 cb_sent(void *data __UNUSED__, void *ret, DBusError *err)
17 {
18   E_Notification_Return_Notify *notify;
19   notify = ret;
20   if (notify) 
21   {
22     printf("id: %d\n", notify->notification_id);
23   }
24   else if (dbus_error_is_set(err))
25   {
26     printf("Error: %s\n", err->message);
27   }
28 }
29
30 Eina_Bool
31 cb_timer(void *data __UNUSED__)
32 {
33   E_Notification *n;
34   char buf[1024];
35   static int num = 0;
36   static const char *icons[] = {
37     "xterm",
38     "firefox",
39     "gvim",
40     "e"
41   };
42
43   snprintf(buf, sizeof(buf), "<i>%s</i> says <b>Hello</b> #%d", icons[num % 4], num % 4); 
44   n = e_notification_full_new(icons[num % 4], 0, (icons[num % 4][0] != 'e') ? icons[num % 4] : NULL, "Summary", buf, -1);
45
46   if (!e_notification_app_icon_get(n))
47     {
48        Ecore_Evas *ee;
49        Evas_Object *img;
50        E_Notification_Image *i;
51        ee = ecore_evas_buffer_new(1, 1);
52        if (ee)
53          {
54             img = evas_object_image_add(ecore_evas_get(ee));
55             evas_object_image_file_set(img, LOGO, NULL);
56             if (evas_object_image_load_error_get(img) != EVAS_LOAD_ERROR_NONE)
57               evas_object_image_file_set(img, "logo.png", NULL);
58             if (evas_object_image_load_error_get(img) != EVAS_LOAD_ERROR_NONE)
59               {
60                  fprintf(stderr, "ERROR LOADING IMAGE: %s\n", LOGO);
61                  evas_object_del(img);
62                  img = NULL;
63               }
64             else
65               ecore_evas_manual_render(ee);
66
67             i = e_notification_image_new();
68             if (e_notification_image_init(i, img))
69               e_notification_hint_image_data_set(n, i);
70            evas_object_del(img);
71            ecore_evas_free(ee);
72          }
73     }
74
75   e_notification_send(n, cb_sent, NULL);
76   e_notification_unref(n);
77   num++;
78
79   return ECORE_CALLBACK_RENEW;
80 }
81
82 void
83 cb_action_invoked(void *data __UNUSED__, int type __UNUSED__, void *event)
84 {
85   E_Notification_Event_Action_Invoked *ev;
86
87   ev = event;
88   printf("Action (%d): %s\n", ev->notification_id, ev->action_id);
89   free(ev);
90 }
91
92 void
93 cb_note_closed(void *data __UNUSED__, int type __UNUSED__, void *event)
94 {
95   E_Notification_Event_Notification_Closed *ev;
96   static const char *reasons[] = {
97     "Expired",
98     "Dismissed",
99     "Requested",
100     "Undefined"
101   };
102
103   ev = event;
104   printf("Note %d closed: %s\n", ev->notification_id, reasons[ev->reason]);
105   free(ev);
106 }
107
108 int
109 main()
110 {
111   int ret = 0;
112   ecore_init();
113   ecore_evas_init();
114   if (e_notification_init())
115   {
116     ecore_timer_add(1, cb_timer, NULL);
117     ecore_main_loop_begin();
118     e_notification_shutdown();
119   }
120
121   ecore_evas_shutdown();
122   ecore_shutdown();
123   return ret;
124 }