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