Debian Codegraph @

tests/test-persistence.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 <string.h>
23 #include <glib.h>
24 #include <gtk/gtk.h>
25
26 static gboolean
27 server_has_persistence (void)
28 {
29 gboolean has;
30 GList *caps;
31 GList *l;
32
33 caps = notify_get_server_caps ();
34 if (caps == NULL) {
35 fprintf (stderr, "Failed to receive server caps.\n");
36 return FALSE;
37 }
38
39 l = g_list_find_custom (caps, "persistence", (GCompareFunc)strcmp);
40 has = l != NULL;
41
42 g_list_foreach (caps, (GFunc) g_free, NULL);
43 g_list_free (caps);
44
45 return has;
46 }
47
48 static void
49 install_callback (NotifyNotification *n,
50 const char *action)
51 {
52 g_assert (action != NULL);
53 g_assert (strcmp (action, "install") == 0);
54
55 printf ("You clicked Install\n");
56 }
57
58 int
59 main (int argc, char *argv[])
60 {
61 NotifyNotification *n;
62
63 gtk_init ();
64 notify_init ("Persistence Test");
65
66 n = notify_notification_new ("Software Updates Available",
67 "Important updates for your apps are now available.",
68 "software-update-available-symbolic");
69 notify_notification_add_action (n,
70 "install",
71 "Install now",
72 (NotifyActionCallback) install_callback,
73 NULL,
74 NULL);
75
76 notify_notification_set_timeout (n, 0); //don't timeout
77 notify_notification_show (n, NULL);
78
79 if (!server_has_persistence ()) {
80 g_message ("Server does not support persistence; using a status icon");
81 } else {
82 g_message ("Server supports persistence; status icon not needed");
83 }
84
85 return 0;
86 }