Patch by M.S. to switch notify-send to use GOption instead of popt, to add -v, --version, -h, and --hint options, and to rename -T, --type to -c, --category. This also fixes assertions when calling notify-send "". This closes ticket #41.
This commit is contained in:
parent
30961cc1a6
commit
d4768ac937
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Fri Apr 21 14:21:47 PDT 2006 Christian Hammond <chipx86@chipx86.com>
|
||||||
|
|
||||||
|
* tools/Makefile.am:
|
||||||
|
* tools/notify-send.c:
|
||||||
|
* NEWS:
|
||||||
|
* configure.ac:
|
||||||
|
- Patch by M.S. to switch notify-send to use GOption instead of popt,
|
||||||
|
to add -v, --version, -h, and --hint options, and to rename
|
||||||
|
-T, --type to -c, --category. This also fixes assertions when calling
|
||||||
|
notify-send "". This closes ticket #41.
|
||||||
|
|
||||||
Mon Mar 20 14:12:15 PST 2006 Christian Hammond <chipx86@chipx86.com>
|
Mon Mar 20 14:12:15 PST 2006 Christian Hammond <chipx86@chipx86.com>
|
||||||
|
|
||||||
* tools/notify-send.c:
|
* tools/notify-send.c:
|
||||||
|
|
6
NEWS
6
NEWS
|
@ -1,3 +1,9 @@
|
||||||
|
version 0.3.3:
|
||||||
|
* Patch by M.S. to switch notify-send to use GOption instead of popt,
|
||||||
|
to add -v, --version, -h, and --hint options, and to rename
|
||||||
|
-T, --type to -c, --category. This also fixes assertions when calling
|
||||||
|
notify-send "". (Bug #41)
|
||||||
|
|
||||||
version 0.3.2 (23-January-2006):
|
version 0.3.2 (23-January-2006):
|
||||||
* Added back notify_get_server_info() and notify_get_server_caps().
|
* Added back notify_get_server_info() and notify_get_server_caps().
|
||||||
* Fixed to work with D-BUS 0.36 and higher. However, it's best to note
|
* Fixed to work with D-BUS 0.36 and higher. However, it's best to note
|
||||||
|
|
|
@ -87,8 +87,6 @@ AC_EXEEXT
|
||||||
|
|
||||||
AM_PROG_LIBTOOL
|
AM_PROG_LIBTOOL
|
||||||
|
|
||||||
AC_CHECK_LIB([popt], [poptGetArg], , AC_MSG_ERROR([Popt is required]))
|
|
||||||
|
|
||||||
REQ_DBUS_VERSION=0.36
|
REQ_DBUS_VERSION=0.36
|
||||||
pkg_modules="gtk+-2.0 >= 2.2.2 glib-2.0 >= 2.2.2, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION"
|
pkg_modules="gtk+-2.0 >= 2.2.2 glib-2.0 >= 2.2.2, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION"
|
||||||
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
|
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
|
||||||
|
|
|
@ -2,8 +2,7 @@ bin_PROGRAMS = notify-send
|
||||||
|
|
||||||
common_ldflags = \
|
common_ldflags = \
|
||||||
$(top_builddir)/libnotify/libnotify.la \
|
$(top_builddir)/libnotify/libnotify.la \
|
||||||
$(PACKAGE_LIBS) \
|
$(PACKAGE_LIBS)
|
||||||
-lpopt
|
|
||||||
|
|
||||||
notify_send_SOURCES = notify-send.c
|
notify_send_SOURCES = notify-send.c
|
||||||
notify_send_LDADD = $(common_ldflags)
|
notify_send_LDADD = $(common_ldflags)
|
||||||
|
|
|
@ -18,82 +18,194 @@
|
||||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||||
* MA 02111-1307 USA
|
* MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
#include <libnotify/notify.h>
|
#include <libnotify/notify.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
#include <popt.h>
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <glib/gprintf.h>
|
||||||
|
|
||||||
#define N_(x) (x)
|
#define N_(x) (x)
|
||||||
|
#define GETTEXT_PACKAGE NULL
|
||||||
|
|
||||||
|
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
g_option_arg_urgency_cb(const gchar *option_name,
|
||||||
|
const gchar *value,
|
||||||
|
gpointer data,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (value != NULL)
|
||||||
|
{
|
||||||
|
if (!strcasecmp(value, "low"))
|
||||||
|
urgency = NOTIFY_URGENCY_LOW;
|
||||||
|
else if (!strcasecmp(value, "normal"))
|
||||||
|
urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
|
else if (!strcasecmp(value, "critical"))
|
||||||
|
urgency = NOTIFY_URGENCY_CRITICAL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||||
|
N_("Unknown urgency %s specified. "
|
||||||
|
"Known urgency levels: low, "
|
||||||
|
"normal, critical."),
|
||||||
|
value);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
notify_notification_set_hint_variant(NotifyNotification *notification,
|
||||||
|
const gchar *type, const gchar *key,
|
||||||
|
const gchar *value, GError **error)
|
||||||
|
{
|
||||||
|
static gboolean conv_error = FALSE;
|
||||||
|
if (!strcasecmp(type, "string"))
|
||||||
|
{
|
||||||
|
notify_notification_set_hint_string(notification, key, value);
|
||||||
|
}
|
||||||
|
else if (!strcasecmp(type, "int"))
|
||||||
|
{
|
||||||
|
if (!g_ascii_isdigit(*value))
|
||||||
|
conv_error = TRUE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gint h_int = (gint)g_ascii_strtoull(value, NULL, 10);
|
||||||
|
notify_notification_set_hint_int32(notification, key, h_int);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcasecmp(type, "double"))
|
||||||
|
{
|
||||||
|
if (!g_ascii_isdigit(*value))
|
||||||
|
conv_error = TRUE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gdouble h_double = g_strtod(value, NULL);
|
||||||
|
notify_notification_set_hint_double(notification, key, h_double);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcasecmp(type, "byte"))
|
||||||
|
{
|
||||||
|
gint h_byte = (gint)g_ascii_strtoull(value, NULL, 10);
|
||||||
|
|
||||||
|
if (h_byte < 0 || h_byte > 0xFF)
|
||||||
|
conv_error = TRUE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notify_notification_set_hint_byte(notification, key,
|
||||||
|
(guchar)h_byte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||||
|
N_("Invalid hint type \"%s\". Valid types "
|
||||||
|
"are int, double, string and byte."),
|
||||||
|
type);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conv_error)
|
||||||
|
{
|
||||||
|
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||||
|
N_("Value \"%s\" of hint \"%s\" could not be "
|
||||||
|
"parsed as type \"%s\"."),
|
||||||
|
value, key, type);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char **argv)
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const gchar *summary = NULL;
|
static const gchar *summary = NULL;
|
||||||
const gchar *body = "";
|
static const gchar *body = "";
|
||||||
const gchar *type = NULL;
|
static const gchar *type = NULL;
|
||||||
char *urgency_str = NULL;
|
static gchar *icon_str = NULL;
|
||||||
gchar *icon_str = NULL;
|
static gchar *icons = NULL;
|
||||||
gchar *icons = NULL;
|
static gchar **n_text = NULL;
|
||||||
NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
static gchar **hints = NULL;
|
||||||
long expire_timeout = NOTIFY_EXPIRES_DEFAULT;
|
static gboolean do_version = FALSE;
|
||||||
int ch;
|
static gboolean hint_error = FALSE;
|
||||||
poptContext opt_ctx;
|
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
|
||||||
const char **args;
|
GOptionContext *opt_ctx;
|
||||||
NotifyNotification *notify;
|
NotifyNotification *notify;
|
||||||
|
GError *error = NULL;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
struct poptOption options[] =
|
static const GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{ "urgency", 'u', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &urgency_str,
|
{ "urgency", 'u', 0, G_OPTION_ARG_CALLBACK, g_option_arg_urgency_cb,
|
||||||
0, N_("Specifies the urgency level (low, normal, critical)."),
|
N_("Specifies the urgency level (low, normal, critical)."),
|
||||||
NULL },
|
N_("LEVEL") },
|
||||||
{ "expire-time", 't', POPT_ARG_INT | POPT_ARGFLAG_STRIP,
|
{ "expire-time", 't', 0,G_OPTION_ARG_INT, &expire_timeout,
|
||||||
&expire_timeout, 0,
|
|
||||||
N_("Specifies the timeout in milliseconds at which to expire the "
|
N_("Specifies the timeout in milliseconds at which to expire the "
|
||||||
"notification."),
|
"notification."), N_("TIME") },
|
||||||
NULL },
|
{ "icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
|
||||||
{ "icon", 'i', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &icons, 0,
|
|
||||||
N_("Specifies an icon filename or stock icon to display."),
|
N_("Specifies an icon filename or stock icon to display."),
|
||||||
N_("ICON") },
|
N_("ICON[,ICON...]") },
|
||||||
{ "type", 'T', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &type, 0,
|
{ "category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
|
||||||
N_("Specifies the notification type."),
|
N_("Specifies the notification category."),
|
||||||
N_("TYPE") },
|
N_("TYPE[,TYPE...]") },
|
||||||
POPT_AUTOHELP
|
{ "hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
|
||||||
POPT_TABLEEND
|
N_("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
|
||||||
|
N_("TYPE:NAME:VALUE") },
|
||||||
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
|
||||||
|
N_("Version of the package."),
|
||||||
|
NULL },
|
||||||
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &n_text, NULL,
|
||||||
|
NULL },
|
||||||
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
g_type_init();
|
g_type_init();
|
||||||
|
|
||||||
opt_ctx = poptGetContext("notify-send", argc, argv, options, 0);
|
g_set_prgname(argv[0]);
|
||||||
poptSetOtherOptionHelp(opt_ctx, "[OPTIONS]* <summary> [body]");
|
|
||||||
|
|
||||||
while ((ch = poptGetNextOpt(opt_ctx)) >= 0)
|
opt_ctx = g_option_context_new(N_("<SUMMARY> [BODY] - "
|
||||||
;
|
"create a notification"));
|
||||||
|
g_option_context_add_main_entries(opt_ctx, entries, GETTEXT_PACKAGE);
|
||||||
|
retval = g_option_context_parse(opt_ctx, &argc, &argv, &error);
|
||||||
|
g_option_context_free(opt_ctx);
|
||||||
|
|
||||||
if (ch < -1 || (args = poptGetArgs(opt_ctx)) == NULL)
|
if (!retval)
|
||||||
{
|
{
|
||||||
poptPrintUsage(opt_ctx, stderr, 0);
|
g_warning("%s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0] != NULL)
|
if (do_version)
|
||||||
summary = args[0];
|
{
|
||||||
|
g_printf("%s %s\n", g_get_prgname(), VERSION);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
|
||||||
|
summary = n_text[0];
|
||||||
|
|
||||||
if (summary == NULL)
|
if (summary == NULL)
|
||||||
{
|
{
|
||||||
poptPrintUsage(opt_ctx, stderr, 0);
|
g_warning("%s", N_("No summary specified."));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1] != NULL)
|
if (n_text[1] != NULL)
|
||||||
{
|
{
|
||||||
body = args[1];
|
body = n_text[1];
|
||||||
|
|
||||||
if (args[2] != NULL)
|
if (n_text[2] != NULL)
|
||||||
{
|
{
|
||||||
poptPrintUsage(opt_ctx, stderr, 0);
|
g_warning("%s", N_("Invalid number of options."));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,41 +215,64 @@ main(int argc, const char **argv)
|
||||||
char *c;
|
char *c;
|
||||||
|
|
||||||
/* XXX */
|
/* XXX */
|
||||||
if ((c = strchr(icons, ',')) != NULL)
|
if((c = strchr(icons, ',')) != NULL)
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
|
|
||||||
icon_str = icons;
|
icon_str = icons;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (urgency_str != NULL)
|
|
||||||
{
|
|
||||||
if (!strcasecmp(urgency_str, "low"))
|
|
||||||
urgency = NOTIFY_URGENCY_LOW;
|
|
||||||
else if (!strcasecmp(urgency_str, "normal"))
|
|
||||||
urgency = NOTIFY_URGENCY_NORMAL;
|
|
||||||
else if (!strcasecmp(urgency_str, "critical"))
|
|
||||||
urgency = NOTIFY_URGENCY_CRITICAL;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
poptPrintHelp(opt_ctx, stderr, 0);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!notify_init("notify-send"))
|
if (!notify_init("notify-send"))
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
notify = notify_notification_new(summary, body, icon_str, NULL);
|
notify = notify_notification_new(summary, body, icon_str, NULL);
|
||||||
notify_notification_set_category(notify, type);
|
notify_notification_set_category(notify, type);
|
||||||
notify_notification_set_urgency(notify, urgency);
|
notify_notification_set_urgency(notify, urgency);
|
||||||
notify_notification_set_timeout(notify, expire_timeout);
|
notify_notification_set_timeout(notify, expire_timeout);
|
||||||
|
|
||||||
notify_notification_show(notify, NULL);
|
// Set hints
|
||||||
|
if (hints != NULL)
|
||||||
|
{
|
||||||
|
gint i = 0;
|
||||||
|
gint l;
|
||||||
|
gchar *hint = NULL;
|
||||||
|
gchar **tokens = NULL;
|
||||||
|
|
||||||
|
while ((hint = hints[i++]))
|
||||||
|
{
|
||||||
|
tokens = g_strsplit(hint, ":", -1);
|
||||||
|
l = g_strv_length(tokens);
|
||||||
|
|
||||||
|
if (l != 3)
|
||||||
|
{
|
||||||
|
g_warning("%s", N_("Invalid hint syntax specified. "
|
||||||
|
"Use TYPE:NAME:VALUE."));
|
||||||
|
hint_error = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = notify_notification_set_hint_variant(
|
||||||
|
notify, tokens[0], tokens[1], tokens[2], &error);
|
||||||
|
|
||||||
|
if (!retval)
|
||||||
|
{
|
||||||
|
g_warning("%s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
hint_error = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev(tokens);
|
||||||
|
if (hint_error)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hint_error)
|
||||||
|
notify_notification_show(notify, NULL);
|
||||||
|
|
||||||
g_object_unref(G_OBJECT(notify));
|
g_object_unref(G_OBJECT(notify));
|
||||||
|
|
||||||
poptFreeContext(opt_ctx);
|
|
||||||
notify_uninit();
|
notify_uninit();
|
||||||
|
|
||||||
return 0;
|
exit(hint_error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue