File: test-xy-actions.c

package info (click to toggle)
libnotify 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 840 kB
  • sloc: xml: 8,298; ansic: 3,167; sh: 63; python: 23; makefile: 5
file content (75 lines) | stat: -rw-r--r-- 2,580 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 *
 * @file tests/test-xy-actions.c Unit test: X, Y hints and actions
 *
 * @Copyright (C) 2006 Christian Hammond <chipx86@chipx86.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 */

#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>

static GMainLoop *loop;

static void
action_cb (NotifyNotification *n,
           const char         *action)
{
        printf ("You clicked '%s'\n", action);

        g_main_loop_quit (loop);
}

int
main (int argc, char **argv)
{
        NotifyNotification *n;

        notify_init ("XY");

        loop = g_main_loop_new (NULL, FALSE);

        n = notify_notification_new ("System update available",
                                     "New system updates are available. It is "
                                     "recommended that you install the updates.",
                                     NULL);

        notify_notification_set_hint_int32 (n, "x", 600);
        notify_notification_set_hint_int32 (n, "y", 10);
        notify_notification_add_action (n,
                                        "help",
                                        "Help",
                                        (NotifyActionCallback) action_cb,
                                        NULL,
                                        NULL);
        notify_notification_add_action (n,
                                        "update",
                                        "Update",
                                        (NotifyActionCallback) action_cb,
                                        NULL,
                                        NULL);

        if (!notify_notification_show (n, NULL)) {
                fprintf (stderr, "failed to send notification\n");
                return 1;
        }

        g_main_loop_run (loop);

        return 0;
}