Debian Codegraph @

tests/test-action-icons.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or(at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #include <libnotify/notify.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 static GMainLoop *loop;
27
28 static void
29 previous_callback (NotifyNotification *n,
30 const char *action)
31 {
32 g_assert (action != NULL);
33 g_assert (strcmp (action, "media-skip-backward") == 0);
34
35 printf ("You clicked Previous\n");
36
37 notify_notification_close (n, NULL);
38
39 g_main_loop_quit (loop);
40 }
41
42 static void
43 pause_callback (NotifyNotification *n,
44 const char *action)
45 {
46 g_assert (action != NULL);
47 g_assert (strcmp (action, "media-playback-pause") == 0);
48
49 printf ("You clicked Pause\n");
50
51 notify_notification_close (n, NULL);
52
53 g_main_loop_quit (loop);
54 }
55
56 static void
57 next_callback (NotifyNotification *n,
58 const char *action)
59 {
60 g_assert (action != NULL);
61 g_assert (strcmp (action, "media-skip-forward") == 0);
62
63 printf ("You clicked Next\n");
64
65 notify_notification_close (n, NULL);
66
67 g_main_loop_quit (loop);
68 }
69
70
71 int
72 main (int argc, char **argv)
73 {
74 NotifyNotification *n;
75
76 if (!notify_init ("Action Icon Test"))
77 exit (1);
78
79 loop = g_main_loop_new (NULL, FALSE);
80
81 n = notify_notification_new ("Music Player",
82 "Some solid funk",
83 NULL);
84
85 notify_notification_set_hint (n, "action-icons", g_variant_new_boolean (TRUE));
86
87 notify_notification_add_action (n,
88 "media-skip-backward",
89 "Previous",
90 (NotifyActionCallback) previous_callback,
91 NULL,
92 NULL);
93 notify_notification_add_action (n,
94 "media-playback-pause",
95 "Pause",
96 (NotifyActionCallback) pause_callback,
97 NULL,
98 NULL);
99 notify_notification_add_action (n,
100 "media-skip-forward",
101 "Next",
102 (NotifyActionCallback) next_callback,
103 NULL,
104 NULL);
105
106 if (!notify_notification_show (n, NULL)) {
107 fprintf (stderr, "failed to send notification\n");
108 return 1;
109 }
110
111
112 n = notify_notification_new ("Music Player",
113 "Shouldn't have icons",
114 NULL);
115
116 notify_notification_set_hint (n, "action-icons", g_variant_new_boolean (FALSE));
117
118 notify_notification_add_action (n,
119 "media-skip-backward",
120 "Previous",
121 (NotifyActionCallback) previous_callback,
122 NULL,
123 NULL);
124
125 if (!notify_notification_show (n, NULL)) {
126 fprintf (stderr, "failed to send notification\n");
127 return 1;
128 }
129
130 g_main_loop_run (loop);
131
132 return 0;
133 }