tazpkg annotate tazpkg-notification.c @ rev 947

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