Debian Codegraph @

tests/test-resident.c

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