tazpkg diff tazpkg-notification.c @ rev 899

Add tazpkg-notification.c to get feedback from notification bubble with action button(s), rework tazpkg-notify; make pot & msgmerge
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Mar 09 05:22:42 2016 +0200 (2016-03-09)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tazpkg-notification.c	Wed Mar 09 05:22:42 2016 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +/*
     1.5 + * tazpkg-notification: part of TazPkg - SliTaz package manager.
     1.6 + * Show Freedesktop notification (with action buttons).
     1.7 + *
     1.8 + * Based on the sources provided in the libnotify / tests.
     1.9 + * Copyright(C) 2004 Mike Hearn <mike@navi.cx> - LGPL 2.1
    1.10 + *
    1.11 + * I have no skills in C. This program may have bugs.
    1.12 + * Aleksej Bobylev <al.bobylev@gmail.com>, 2016
    1.13 + *
    1.14 + * Commandline arguments:
    1.15 + *   1 : Notification body text
    1.16 + *  [2]: Urgency flag:
    1.17 + *       0 or absent: normal urgency
    1.18 + *       1: critical urgency
    1.19 + *  [3]: Button label for first action
    1.20 + *  [4]: Button label for second action
    1.21 + *
    1.22 + * Output:
    1.23 + *   1: If first button was pressed
    1.24 + *   2: If second button was pressed
    1.25 + */
    1.26 +
    1.27 +#include <libnotify/notify.h>
    1.28 +#include <stdio.h>
    1.29 +#include <unistd.h>
    1.30 +#include <stdlib.h>
    1.31 +#include <string.h>
    1.32 +
    1.33 +static GMainLoop *loop;
    1.34 +
    1.35 +static void
    1.36 +_handle_closed (GObject * obj)
    1.37 +{
    1.38 +	printf ("\n");
    1.39 +	g_object_unref (obj);
    1.40 +	g_main_loop_quit (loop);
    1.41 +}
    1.42 +
    1.43 +static void
    1.44 +action1_callback (NotifyNotification *n, const char *action)
    1.45 +{
    1.46 +	g_assert (action != NULL);
    1.47 +	g_assert (strcmp (action, "act1") == 0);
    1.48 +
    1.49 +	printf ("1");
    1.50 +
    1.51 +	notify_notification_close (n, NULL);
    1.52 +
    1.53 +	g_main_loop_quit (loop);
    1.54 +}
    1.55 +static void
    1.56 +action2_callback (NotifyNotification *n, const char *action)
    1.57 +{
    1.58 +	g_assert (action != NULL);
    1.59 +	g_assert (strcmp (action, "act2") == 0);
    1.60 +
    1.61 +	printf ("2");
    1.62 +
    1.63 +	notify_notification_close (n, NULL);
    1.64 +
    1.65 +	g_main_loop_quit (loop);
    1.66 +}
    1.67 +
    1.68 +
    1.69 +int
    1.70 +main (int argc, char **argv)
    1.71 +{
    1.72 +	NotifyNotification *n;
    1.73 +
    1.74 +	if (!notify_init ("TazPkg Notification"))
    1.75 +		exit (1);
    1.76 +
    1.77 +	loop = g_main_loop_new (NULL, FALSE);
    1.78 +
    1.79 +	if (argc < 3 || strcmp (argv[2], "0") == 0) {
    1.80 +		n = notify_notification_new ("TazPkg", argv[1], "dialog-information");
    1.81 +	} else {
    1.82 +		n = notify_notification_new ("TazPkg", argv[1], "dialog-warning");
    1.83 +		notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL);
    1.84 +		notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER);
    1.85 +	}
    1.86 +
    1.87 +	notify_notification_set_hint (n, "transient", g_variant_new_boolean (TRUE));
    1.88 +
    1.89 +	if (argc >= 4)
    1.90 +		notify_notification_add_action (n, "act1", argv[3], (NotifyActionCallback) action1_callback, NULL, NULL);
    1.91 +	if (argc >= 5)
    1.92 +		notify_notification_add_action (n, "act2", argv[4], (NotifyActionCallback) action2_callback, NULL, NULL);
    1.93 +
    1.94 +	g_signal_connect (G_OBJECT (n), "closed", G_CALLBACK (_handle_closed), NULL);
    1.95 +
    1.96 +	if (!notify_notification_show (n, NULL))
    1.97 +		return 1;
    1.98 +
    1.99 +	g_main_loop_run (loop);
   1.100 +
   1.101 +	return 0;
   1.102 +}