NotificationDevelopmentGuidelines
Attachment 'icon-summary.c'
Download 1 /*******************************************************************************
2 **3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
3 ** 10 20 30 40 50 60 70 80
4 **
5 ** Info:
6 ** Example of how to use libnotify correctly and at the same time comply to
7 ** the new jaunty notification spec (read: visual guidelines)
8 **
9 ** Compile:
10 ** gcc -O0 -ggdb -Wall -Werror `pkg-config --cflags --libs libnotify \
11 ** glib-2.0` icon-summary.c -o icon-summary
12 **
13 ** Copyright 2009 Canonical Ltd.
14 **
15 ** Author:
16 ** Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
17 **
18 ** This program is free software: you can redistribute it and/or modify it
19 ** under the terms of the GNU General Public License version 3, as published
20 ** by the Free Software Foundation.
21 **
22 ** This program is distributed in the hope that it will be useful, but
23 ** WITHOUT ANY WARRANTY; without even the implied warranties of
24 ** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
25 ** PURPOSE. See the GNU General Public License for more details.
26 **
27 ** You should have received a copy of the GNU General Public License along
28 ** with this program. If not, see <http://www.gnu.org/licenses/>.
29 **
30 *******************************************************************************/
31
32 #include <glib.h>
33 #include <unistd.h>
34 #include <libnotify/notify.h>
35
36 typedef enum _Capability {
37 CAP_ACTIONS = 0,
38 CAP_BODY,
39 CAP_BODY_HYPERLINKS,
40 CAP_BODY_IMAGES,
41 CAP_BODY_MARKUP,
42 CAP_ICON_MULTI,
43 CAP_ICON_STATIC,
44 CAP_SOUND,
45 CAP_IMAGE_SVG,
46 CAP_SYNCHRONOUS,
47 CAP_APPEND,
48 CAP_LAYOUT_ICON_ONLY,
49 CAP_MAX
50 } Capability;
51
52 #define ACTIONS "actions"
53 #define BODY "body"
54 #define BODY_HYPERLINKS "body-hyperlinks"
55 #define BODY_IMAGES "body-images"
56 #define BODY_MARKUP "body-markup"
57 #define ICON_MULTI "icon-multi"
58 #define ICON_STATIC "icon-static"
59 #define SOUND "sound"
60 #define IMAGE_SVG "image/svg+xml"
61 #define SYNCHRONOUS "private-synchronous"
62 #define APPEND "append"
63 #define LAYOUT_ICON_ONLY "private-icon-only"
64
65 /* this is globally nasty :), do something nicer in your own code */
66 gboolean g_capabilities[CAP_MAX] = {FALSE, /* actions */
67 FALSE, /* body */
68 FALSE, /* body-hyperlinks */
69 FALSE, /* body-imges */
70 FALSE, /* body-markup */
71 FALSE, /* icon-multi */
72 FALSE, /* icon-static */
73 FALSE, /* sound */
74 FALSE, /* image/svg+xml */
75 FALSE, /* synchronous-hint */
76 FALSE, /* append-hint */
77 FALSE /* icon-only-hint */};
78
79 void
80 closed_handler (NotifyNotification* notification,
81 gpointer data)
82 {
83 g_print ("closed_handler() called");
84
85 return;
86 }
87
88 void
89 set_cap (gpointer data,
90 gpointer user_data)
91 {
92 /* test for "actions" */
93 if (!g_strcmp0 (ACTIONS, (gchar*) data))
94 g_capabilities[CAP_ACTIONS] = TRUE;
95
96 /* test for "body" */
97 if (!g_strcmp0 (BODY, (gchar*) data))
98 g_capabilities[CAP_BODY] = TRUE;
99
100 /* test for "body-hyperlinks" */
101 if (!g_strcmp0 (BODY_HYPERLINKS, (gchar*) data))
102 g_capabilities[CAP_BODY_HYPERLINKS] = TRUE;
103
104 /* test for "body-images" */
105 if (!g_strcmp0 (BODY_IMAGES, (gchar*) data))
106 g_capabilities[CAP_BODY_IMAGES] = TRUE;
107
108 /* test for "body-markup" */
109 if (!g_strcmp0 (BODY_MARKUP, (gchar*) data))
110 g_capabilities[CAP_BODY_MARKUP] = TRUE;
111
112 /* test for "icon-multi" */
113 if (!g_strcmp0 (ICON_MULTI, (gchar*) data))
114 g_capabilities[CAP_ICON_MULTI] = TRUE;
115
116 /* test for "icon-static" */
117 if (!g_strcmp0 (ICON_STATIC, (gchar*) data))
118 g_capabilities[CAP_ICON_STATIC] = TRUE;
119
120 /* test for "sound" */
121 if (!g_strcmp0 (SOUND, (gchar*) data))
122 g_capabilities[CAP_SOUND] = TRUE;
123
124 /* test for "image/svg+xml" */
125 if (!g_strcmp0 (IMAGE_SVG, (gchar*) data))
126 g_capabilities[CAP_IMAGE_SVG] = TRUE;
127
128 /* test for "canonical-private-1" */
129 if (!g_strcmp0 (SYNCHRONOUS, (gchar*) data))
130 g_capabilities[CAP_SYNCHRONOUS] = TRUE;
131
132 /* test for "canonical-private-2" */
133 if (!g_strcmp0 (APPEND, (gchar*) data))
134 g_capabilities[CAP_APPEND] = TRUE;
135
136 /* test for "canonical-private-3" */
137 if (!g_strcmp0 (LAYOUT_ICON_ONLY, (gchar*) data))
138 g_capabilities[CAP_LAYOUT_ICON_ONLY] = TRUE;
139 }
140
141 void
142 init_caps (void)
143 {
144 GList* caps_list;
145
146 caps_list = notify_get_server_caps ();
147 if (caps_list)
148 {
149 g_list_foreach (caps_list, set_cap, NULL);
150 g_list_foreach (caps_list, (GFunc) g_free, NULL);
151 g_list_free (caps_list);
152 }
153 }
154
155 gboolean
156 has_cap (Capability cap)
157 {
158 return g_capabilities[cap];
159 }
160
161 void
162 print_caps (void)
163 {
164 gchar* name;
165 gchar* vendor;
166 gchar* version;
167 gchar* spec_version;
168
169 notify_get_server_info (&name, &vendor, &version, &spec_version);
170
171 g_print ("Name: %s\n"
172 "Vendor: %s\n"
173 "Version: %s\n"
174 "Spec. Version: %s\n",
175 name,
176 vendor,
177 version,
178 spec_version);
179
180 g_print ("Supported capabilities/hints:\n");
181
182 if (has_cap (CAP_ACTIONS))
183 g_print ("\tactions\n");
184
185 if (has_cap (CAP_BODY))
186 g_print ("\tbody\n");
187
188 if (has_cap (CAP_BODY_HYPERLINKS))
189 g_print ("\tbody-hyperlinks\n");
190
191 if (has_cap (CAP_BODY_IMAGES))
192 g_print ("\tbody-images\n");
193
194 if (has_cap (CAP_BODY_MARKUP))
195 g_print ("\tbody-markup\n");
196
197 if (has_cap (CAP_ICON_MULTI))
198 g_print ("\ticon-multi\n");
199
200 if (has_cap (CAP_ICON_STATIC))
201 g_print ("\ticon-static\n");
202
203 if (has_cap (CAP_SOUND))
204 g_print ("\tsound\n");
205
206 if (has_cap (CAP_IMAGE_SVG))
207 g_print ("\timage/svg+xml\n");
208
209 if (has_cap (CAP_SYNCHRONOUS))
210 g_print ("\tprivate-synchronous\n");
211
212 if (has_cap (CAP_APPEND))
213 g_print ("\tappend\n");
214
215 if (has_cap (CAP_LAYOUT_ICON_ONLY))
216 g_print ("\tprivate-icon-only\n");
217
218 g_print ("Notes:\n");
219 if (!g_strcmp0 ("notify-osd", name))
220 {
221 g_print ("\tx- and y-coordinates hints are ignored\n");
222 g_print ("\texpire-timeout is ignored\n");
223 g_print ("\tbody-markup is accepted but filtered\n");
224 }
225 else
226 g_print ("\tnone");
227
228 g_free ((gpointer) name);
229 g_free ((gpointer) vendor);
230 g_free ((gpointer) version);
231 g_free ((gpointer) spec_version);
232 }
233
234 int
235 main (int argc,
236 char** argv)
237 {
238 NotifyNotification* notification;
239 gboolean success;
240 GError* error = NULL;
241
242 if (!notify_init ("icon-summary"))
243 return 1;
244
245 /* call this so we can savely use has_cap(CAP_SOMETHING) later */
246 init_caps ();
247
248 /* show what's supported */
249 print_caps ();
250
251 /* try the icon-summary case */
252 notification = notify_notification_new (
253 "WiFi connection lost",
254 NULL,
255 "notification-network-wireless-disconnected",
256 NULL);
257 error = NULL;
258 success = notify_notification_show (notification, &error);
259 if (!success)
260 {
261 g_print ("That did not work ... \"%s\".\n",
262 error->message);
263 }
264 g_signal_connect (G_OBJECT (notification),
265 "closed",
266 G_CALLBACK (closed_handler),
267 NULL);
268
269 notify_uninit ();
270
271 return 0;
272 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.