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