notify-send: Add support for boolean hints

Boolean hints are used for some common parameters such as "transient".

Original bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636343
This commit is contained in:
Marco Trevisan (Treviño) 2022-04-27 20:33:40 +02:00
parent 6e871a4047
commit d6f4734adf
2 changed files with 13 additions and 2 deletions

View File

@ -101,7 +101,7 @@
<varlistentry> <varlistentry>
<term><option>-h</option>, <option>--hint</option>=<replaceable>TYPE</replaceable>:<replaceable>NAME</replaceable>:<replaceable>VALUE</replaceable> </term> <term><option>-h</option>, <option>--hint</option>=<replaceable>TYPE</replaceable>:<replaceable>NAME</replaceable>:<replaceable>VALUE</replaceable> </term>
<listitem> <listitem>
<para>Specifies basic extra data to pass. Valid types are <literal>INT</literal>, <literal>DOUBLE</literal>, <literal>STRING</literal> and <literal>BYTE</literal>.</para> <para>Specifies basic extra data to pass. Valid types are <literal>BOOLEAN</literal>, <literal>INT</literal>, <literal>DOUBLE</literal>, <literal>STRING</literal> and <literal>BYTE</literal>.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -100,6 +100,17 @@ notify_notification_set_hint_variant (NotifyNotification *notification,
key, key,
(guchar) h_byte); (guchar) h_byte);
} }
} else if (g_ascii_strcasecmp (type, "boolean") == 0) {
gboolean h_boolean = FALSE;
if (g_ascii_strcasecmp (value, "true") == 0) {
h_boolean = TRUE;
} else if (g_ascii_isdigit (*value)) {
h_boolean = !!g_ascii_strtoull (value, NULL, 10);
}
notify_notification_set_hint (notification, key,
g_variant_new_boolean (h_boolean));
} else { } else {
*error = g_error_new (G_OPTION_ERROR, *error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE, G_OPTION_ERROR_BAD_VALUE,
@ -197,7 +208,7 @@ main (int argc, char *argv[])
N_("TYPE[,TYPE...]")}, N_("TYPE[,TYPE...]")},
{"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints, {"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
N_ N_
("Specifies basic extra data to pass. Valid types are int, double, string and byte."), ("Specifies basic extra data to pass. Valid types are boolean, int, double, string and byte."),
N_("TYPE:NAME:VALUE")}, N_("TYPE:NAME:VALUE")},
{"print-id", 'p', 0, G_OPTION_ARG_NONE, &print_id, {"print-id", 'p', 0, G_OPTION_ARG_NONE, &print_id,
N_ ("Print the notification ID."), NULL}, N_ ("Print the notification ID."), NULL},