tazpkg view tazpkg-notification.c @ rev 963

modules/install: prefex "exact" packages over than "provided" packages.
In other words when requested "linux-agp": prefer "linux-agp" (if it exists) over the "linux-libre-agp".
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Feb 26 00:54:19 2018 +0200 (2018-02-26)
parents
children
line source
1 /*
2 * tazpkg-notification: part of TazPkg - SliTaz package manager.
3 * Show Freedesktop notification (with action buttons).
4 *
5 * Based on the sources provided in the libnotify / tests.
6 * Copyright(C) 2004 Mike Hearn <mike@navi.cx> - LGPL 2.1
7 *
8 * I have no skills in C. This program may have bugs.
9 * Aleksej Bobylev <al.bobylev@gmail.com>, 2016
10 *
11 * Commandline arguments:
12 * 1 : Notification body text
13 * [2]: Urgency flag:
14 * 0 or absent: normal urgency
15 * 1: critical urgency
16 * [3]: Button label for first action
17 * [4]: Button label for second action
18 *
19 * Output:
20 * 1: If first button was pressed
21 * 2: If second button was pressed
22 */
24 #include <libnotify/notify.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <string.h>
30 static GMainLoop *loop;
32 static void
33 _handle_closed (GObject * obj)
34 {
35 printf ("\n");
36 g_object_unref (obj);
37 g_main_loop_quit (loop);
38 }
40 static void
41 action1_callback (NotifyNotification *n, const char *action)
42 {
43 g_assert (action != NULL);
44 g_assert (strcmp (action, "act1") == 0);
46 printf ("1");
48 notify_notification_close (n, NULL);
50 g_main_loop_quit (loop);
51 }
52 static void
53 action2_callback (NotifyNotification *n, const char *action)
54 {
55 g_assert (action != NULL);
56 g_assert (strcmp (action, "act2") == 0);
58 printf ("2");
60 notify_notification_close (n, NULL);
62 g_main_loop_quit (loop);
63 }
66 int
67 main (int argc, char **argv)
68 {
69 NotifyNotification *n;
71 if (!notify_init ("TazPkg Notification"))
72 exit (1);
74 loop = g_main_loop_new (NULL, FALSE);
76 if (argc < 3 || strcmp (argv[2], "0") == 0) {
77 n = notify_notification_new ("TazPkg", argv[1], "dialog-information");
78 } else {
79 n = notify_notification_new ("TazPkg", argv[1], "dialog-warning");
80 notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL);
81 notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER);
82 }
84 notify_notification_set_hint (n, "transient", g_variant_new_boolean (TRUE));
86 if (argc >= 4)
87 notify_notification_add_action (n, "act1", argv[3], (NotifyActionCallback) action1_callback, NULL, NULL);
88 if (argc >= 5)
89 notify_notification_add_action (n, "act2", argv[4], (NotifyActionCallback) action2_callback, NULL, NULL);
91 g_signal_connect (G_OBJECT (n), "closed", G_CALLBACK (_handle_closed), NULL);
93 if (!notify_notification_show (n, NULL))
94 return 1;
96 g_main_loop_run (loop);
98 return 0;
99 }