| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* @file tests/test-multi-actions.c Unit test: multiple actions |
| 4 |
* |
| 5 |
* @Copyright(C) 2004 Mike Hearn <[email protected]> |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or(at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the |
| 19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <libnotify/notify.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
static GMainLoop *loop; |
| 30 |
|
| 31 |
static void |
| 32 |
help_callback (NotifyNotification *n, |
| 33 |
const char *action) |
| 34 |
{ |
| 35 |
g_assert (action != NULL); |
| 36 |
g_assert (strcmp (action, "help") == 0); |
| 37 |
|
| 38 |
printf ("You clicked Help\n"); |
| 39 |
|
| 40 |
notify_notification_close (n, NULL); |
| 41 |
|
| 42 |
g_main_loop_quit (loop); |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
ignore_callback (NotifyNotification *n, |
| 47 |
const char *action) |
| 48 |
{ |
| 49 |
g_assert (action != NULL); |
| 50 |
g_assert (strcmp (action, "ignore") == 0); |
| 51 |
|
| 52 |
printf ("You clicked Ignore\n"); |
| 53 |
|
| 54 |
notify_notification_close (n, NULL); |
| 55 |
|
| 56 |
g_main_loop_quit (loop); |
| 57 |
} |
| 58 |
|
| 59 |
static void |
| 60 |
empty_callback (NotifyNotification *n, |
| 61 |
const char *action) |
| 62 |
{ |
| 63 |
g_assert (action != NULL); |
| 64 |
g_assert (strcmp (action, "empty") == 0); |
| 65 |
|
| 66 |
printf ("You clicked Empty Trash\n"); |
| 67 |
|
| 68 |
notify_notification_close (n, NULL); |
| 69 |
|
| 70 |
g_main_loop_quit (loop); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
int |
| 75 |
main (int argc, char **argv) |
| 76 |
{ |
| 77 |
NotifyNotification *n; |
| 78 |
|
| 79 |
if (!notify_init ("Multi Action Test")) |
| 80 |
exit (1); |
| 81 |
|
| 82 |
loop = g_main_loop_new (NULL, FALSE); |
| 83 |
|
| 84 |
n = notify_notification_new ("Low disk space", |
| 85 |
"You can free up some disk space by " |
| 86 |
"emptying the trash can.", |
| 87 |
"drive-harddisk-symbolic"); |
| 88 |
notify_notification_set_hint (n, "transient", g_variant_new_boolean (TRUE)); |
| 89 |
notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL); |
| 90 |
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT); |
| 91 |
notify_notification_add_action (n, |
| 92 |
"help", |
| 93 |
"Help", |
| 94 |
(NotifyActionCallback) help_callback, |
| 95 |
NULL, |
| 96 |
NULL); |
| 97 |
notify_notification_add_action (n, |
| 98 |
"ignore", |
| 99 |
"Ignore", |
| 100 |
(NotifyActionCallback) |
| 101 |
ignore_callback, |
| 102 |
NULL, |
| 103 |
NULL); |
| 104 |
notify_notification_add_action (n, |
| 105 |
"empty", |
| 106 |
"Empty Trash", |
| 107 |
(NotifyActionCallback) empty_callback, |
| 108 |
NULL, |
| 109 |
NULL); |
| 110 |
notify_notification_set_category (n, "device"); |
| 111 |
|
| 112 |
if (!notify_notification_show (n, NULL)) { |
| 113 |
fprintf (stderr, "failed to send notification\n"); |
| 114 |
return 1; |
| 115 |
} |
| 116 |
|
| 117 |
g_main_loop_run (loop); |
| 118 |
|
| 119 |
return 0; |
| 120 |
} |