Updated to match the spec.
This commit is contained in:
parent
8ee064f00a
commit
f4bce0d062
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
Wed Sep 29 21:53:15 PDT 2004 Christian Hammond <chipx86@gnupdate.org>
|
||||||
|
|
||||||
|
* libnotify/notify.c:
|
||||||
|
* libnotify/notify.h:
|
||||||
|
* tests/test-animation.c:
|
||||||
|
* tests/test-basic.c:
|
||||||
|
* tests/test-default-action.c:
|
||||||
|
* tests/test-error.c:
|
||||||
|
* tests/test-image.c:
|
||||||
|
* tests/test-markup.c:
|
||||||
|
* tests/test-multi-actions.c:
|
||||||
|
* tests/test-replace.c:
|
||||||
|
* tools/notify-send.c:
|
||||||
|
- Updated to match the spec.
|
||||||
|
|
||||||
Sat Sep 25 12:59:26 PDT 2004 Christian Hammond <chipx86@gnupdate.org>
|
Sat Sep 25 12:59:26 PDT 2004 Christian Hammond <chipx86@gnupdate.org>
|
||||||
|
|
||||||
* libnotify/notify.c:
|
* libnotify/notify.c:
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* FIXME: do we want so many arguments in the API? */
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -169,34 +167,6 @@ _notify_dbus_message_iter_append_string_or_nil(DBusMessageIter *iter,
|
||||||
dbus_message_iter_append_string(iter, str);
|
dbus_message_iter_append_string(iter, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static char *
|
|
||||||
_notify_dbus_message_iter_get_string_or_nil(DBusMessageIter *iter)
|
|
||||||
{
|
|
||||||
int arg_type;
|
|
||||||
|
|
||||||
g_return_val_if_fail(iter != NULL, NULL);
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(iter);
|
|
||||||
|
|
||||||
if (arg_type == DBUS_TYPE_STRING)
|
|
||||||
return dbus_message_iter_get_string(iter);
|
|
||||||
|
|
||||||
g_return_val_if_fail(arg_type == DBUS_TYPE_NIL, NULL);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_notify_dbus_message_iter_append_app_info(DBusMessageIter *iter)
|
|
||||||
{
|
|
||||||
g_return_if_fail(iter != NULL);
|
|
||||||
|
|
||||||
dbus_message_iter_append_string(iter, _app_name);
|
|
||||||
dbus_message_iter_append_nil(iter); /* App Icon */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static DBusHandlerResult
|
static DBusHandlerResult
|
||||||
_filter_func(DBusConnection *dbus_conn, DBusMessage *message, void *user_data)
|
_filter_func(DBusConnection *dbus_conn, DBusMessage *message, void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -584,9 +554,10 @@ notify_icon_destroy(NotifyIcon *icon)
|
||||||
* Notifications API
|
* Notifications API
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
NotifyHandle *
|
NotifyHandle *
|
||||||
notify_send_notification(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary,
|
notify_send_notification(NotifyHandle *replaces, const char *type,
|
||||||
const char *detailed, const NotifyIcon *icon,
|
NotifyUrgency urgency, const char *summary,
|
||||||
gboolean expires, time_t expire_time,
|
const char *body, const NotifyIcon *icon,
|
||||||
|
gboolean expires, time_t timeout,
|
||||||
gpointer user_data, size_t action_count, ...)
|
gpointer user_data, size_t action_count, ...)
|
||||||
{
|
{
|
||||||
va_list actions;
|
va_list actions;
|
||||||
|
@ -595,8 +566,9 @@ notify_send_notification(NotifyHandle *replaces, NotifyUrgency urgency, const ch
|
||||||
g_return_val_if_fail(summary != NULL, 0);
|
g_return_val_if_fail(summary != NULL, 0);
|
||||||
|
|
||||||
va_start(actions, action_count);
|
va_start(actions, action_count);
|
||||||
handle = notify_send_notification_varg(replaces, urgency, summary, detailed, icon,
|
handle = notify_send_notification_varg(replaces, type, urgency, summary,
|
||||||
expires, expire_time, user_data,
|
body, icon, expires,
|
||||||
|
timeout, user_data,
|
||||||
action_count, actions);
|
action_count, actions);
|
||||||
va_end(actions);
|
va_end(actions);
|
||||||
|
|
||||||
|
@ -604,9 +576,10 @@ notify_send_notification(NotifyHandle *replaces, NotifyUrgency urgency, const ch
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHandle *
|
NotifyHandle *
|
||||||
notify_send_notification_varg(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary,
|
notify_send_notification_varg(NotifyHandle *replaces, const char *type,
|
||||||
const char *detailed, const NotifyIcon *icon,
|
NotifyUrgency urgency, const char *summary,
|
||||||
gboolean expires, time_t expire_time,
|
const char *body, const NotifyIcon *icon,
|
||||||
|
gboolean expires, time_t timeout,
|
||||||
gpointer user_data, size_t action_count,
|
gpointer user_data, size_t action_count,
|
||||||
va_list actions)
|
va_list actions)
|
||||||
{
|
{
|
||||||
|
@ -622,14 +595,14 @@ notify_send_notification_varg(NotifyHandle *replaces, NotifyUrgency urgency, con
|
||||||
|
|
||||||
g_return_val_if_fail(message != NULL, 0);
|
g_return_val_if_fail(message != NULL, 0);
|
||||||
|
|
||||||
#if 0
|
_notify_dbus_message_iter_append_string_or_nil(&iter, _app_name);
|
||||||
_notify_dbus_message_iter_append_app_info(&iter);
|
dbus_message_iter_append_nil(&iter);
|
||||||
#endif
|
dbus_message_iter_append_uint32(&iter,
|
||||||
|
(replaces != NULL ? replaces->id : 0));
|
||||||
dbus_message_iter_append_uint32(&iter, replaces ? replaces->id : 0);
|
_notify_dbus_message_iter_append_string_or_nil(&iter, type);
|
||||||
dbus_message_iter_append_byte(&iter, urgency);
|
dbus_message_iter_append_byte(&iter, urgency);
|
||||||
dbus_message_iter_append_string(&iter, summary);
|
dbus_message_iter_append_string(&iter, summary);
|
||||||
_notify_dbus_message_iter_append_string_or_nil(&iter, detailed);
|
_notify_dbus_message_iter_append_string_or_nil(&iter, body);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: D-BUS 0.22cvs is the first to allow empty arrays, *I think*.
|
* NOTE: D-BUS 0.22cvs is the first to allow empty arrays, *I think*.
|
||||||
|
@ -671,10 +644,14 @@ notify_send_notification_varg(NotifyHandle *replaces, NotifyUrgency urgency, con
|
||||||
g_hash_table_insert(table, &action->id, action);
|
g_hash_table_insert(table, &action->id, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expires)
|
/* Hints */
|
||||||
dbus_message_iter_append_uint32(&iter, expire_time);
|
dbus_message_iter_append_nil(&iter);
|
||||||
else
|
|
||||||
dbus_message_iter_append_nil(&iter);
|
/* Expires */
|
||||||
|
dbus_message_iter_append_boolean(&iter, expires);
|
||||||
|
|
||||||
|
/* Expire Timeout */
|
||||||
|
dbus_message_iter_append_uint32(&iter, (expires ? timeout : 0));
|
||||||
|
|
||||||
dbus_error_init(&error);
|
dbus_error_init(&error);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ typedef enum
|
||||||
{
|
{
|
||||||
NOTIFY_URGENCY_LOW, /**< Low urgency. */
|
NOTIFY_URGENCY_LOW, /**< Low urgency. */
|
||||||
NOTIFY_URGENCY_NORMAL, /**< Normal urgency. */
|
NOTIFY_URGENCY_NORMAL, /**< Normal urgency. */
|
||||||
NOTIFY_URGENCY_HIGH, /**< High urgency. */
|
|
||||||
NOTIFY_URGENCY_CRITICAL, /**< Critical urgency. */
|
NOTIFY_URGENCY_CRITICAL, /**< Critical urgency. */
|
||||||
|
|
||||||
} NotifyUrgency;
|
} NotifyUrgency;
|
||||||
|
@ -152,13 +151,14 @@ void notify_icon_destroy(NotifyIcon *icon);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @param replaces The ID of the notification to atomically replace
|
* @param replaces The ID of the notification to atomically replace
|
||||||
|
* @param type The optional notification type.
|
||||||
* @param urgency The urgency level.
|
* @param urgency The urgency level.
|
||||||
* @param summary The summary of the notification.
|
* @param summary The summary of the notification.
|
||||||
* @param detailed The optional detailed information.
|
* @param body The optional body.
|
||||||
* @param icon The optional icon.
|
* @param icon The optional icon.
|
||||||
* @param expires TRUE if the notification should automatically expire,,
|
* @param expires TRUE if the notification should automatically expire,,
|
||||||
* or FALSE to keep it open until manually closed.
|
* or FALSE to keep it open until manually closed.
|
||||||
* @param expire_time The optional time to automatically close the
|
* @param timeout The optional timeout to automatically close the
|
||||||
* notification, or 0 for the daemon's default.
|
* notification, or 0 for the daemon's default.
|
||||||
* @param user_data User-specified data to send to a callback.
|
* @param user_data User-specified data to send to a callback.
|
||||||
* @param action_count The number of actions.
|
* @param action_count The number of actions.
|
||||||
|
@ -167,11 +167,12 @@ void notify_icon_destroy(NotifyIcon *icon);
|
||||||
* @return A unique ID for the notification.
|
* @return A unique ID for the notification.
|
||||||
*/
|
*/
|
||||||
NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
||||||
|
const char *type,
|
||||||
NotifyUrgency urgency,
|
NotifyUrgency urgency,
|
||||||
const char *summary,
|
const char *summary,
|
||||||
const char *detailed,
|
const char *detailed,
|
||||||
const NotifyIcon *icon,
|
const NotifyIcon *icon,
|
||||||
gboolean expires, time_t expire_time,
|
gboolean expires, time_t timeout,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
size_t action_count, ...);
|
size_t action_count, ...);
|
||||||
|
|
||||||
|
@ -185,13 +186,14 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @param replaces The handle of the notification to atomically replace
|
* @param replaces The handle of the notification to atomically replace
|
||||||
|
* @param type The optional notification type.
|
||||||
* @param urgency The urgency level.
|
* @param urgency The urgency level.
|
||||||
* @param summary The summary of the notification.
|
* @param summary The summary of the notification.
|
||||||
* @param detailed The optional detailed information.
|
* @param detailed The optional body.
|
||||||
* @param icon The optional icon.
|
* @param icon The optional icon.
|
||||||
* @param expires TRUE if the notification should automatically expire,
|
* @param expires TRUE if the notification should automatically expire,
|
||||||
* or FALSE to keep it open until manually closed.
|
* or FALSE to keep it open until manually closed.
|
||||||
* @param expire_time The optional time to automatically close the
|
* @param timeout The optional timeout to automatically close the
|
||||||
* notification, or 0 for the daemon's default.
|
* notification, or 0 for the daemon's default.
|
||||||
* @param user_data User-specified data to send to a callback.
|
* @param user_data User-specified data to send to a callback.
|
||||||
* @param action_count The number of actions.
|
* @param action_count The number of actions.
|
||||||
|
@ -200,12 +202,13 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
||||||
* @return A unique ID for the notification.
|
* @return A unique ID for the notification.
|
||||||
*/
|
*/
|
||||||
NotifyHandle *notify_send_notification_varg(NotifyHandle *replaces,
|
NotifyHandle *notify_send_notification_varg(NotifyHandle *replaces,
|
||||||
|
const char *type,
|
||||||
NotifyUrgency urgency,
|
NotifyUrgency urgency,
|
||||||
const char *summary,
|
const char *summary,
|
||||||
const char *detailed,
|
const char *detailed,
|
||||||
const NotifyIcon *icon,
|
const NotifyIcon *icon,
|
||||||
gboolean expires,
|
gboolean expires,
|
||||||
time_t expire_time,
|
time_t timeout,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
size_t action_count,
|
size_t action_count,
|
||||||
va_list actions);
|
va_list actions);
|
||||||
|
|
|
@ -34,26 +34,26 @@ int frames = 10;
|
||||||
// returns array of pixbufs for a pulsing animation
|
// returns array of pixbufs for a pulsing animation
|
||||||
GdkPixbuf **generate_animation()
|
GdkPixbuf **generate_animation()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
GdkPixbuf *file = gdk_pixbuf_new_from_file("applet-critical.png", NULL);
|
GdkPixbuf *file = gdk_pixbuf_new_from_file("applet-critical.png", NULL);
|
||||||
double alpha = 1.0;
|
double alpha = 1.0;
|
||||||
|
|
||||||
GdkPixbuf **array = g_malloc(sizeof(GdkPixbuf *) * frames);
|
GdkPixbuf **array = g_malloc(sizeof(GdkPixbuf *) * frames);
|
||||||
|
|
||||||
for (i = 0; i < frames; i++)
|
for (i = 0; i < frames; i++)
|
||||||
{
|
{
|
||||||
GdkPixbuf *buf = gdk_pixbuf_copy(file);
|
GdkPixbuf *buf = gdk_pixbuf_copy(file);
|
||||||
|
|
||||||
alpha = sin(M_PI + ((M_PI / frames) * i)) + 1.0;
|
alpha = sin(M_PI + ((M_PI / frames) * i)) + 1.0;
|
||||||
|
|
||||||
gdk_pixbuf_composite(file, buf, 0, 0,
|
gdk_pixbuf_composite(file, buf, 0, 0,
|
||||||
gdk_pixbuf_get_width(buf),
|
gdk_pixbuf_get_width(buf),
|
||||||
gdk_pixbuf_get_height(buf),
|
gdk_pixbuf_get_height(buf),
|
||||||
0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
|
0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
|
||||||
alpha);
|
alpha);
|
||||||
|
|
||||||
array[i] = buf;
|
array[i] = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -62,25 +62,26 @@ GdkPixbuf **generate_animation()
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
notify_init("Animations");
|
notify_init("Animations");
|
||||||
|
|
||||||
for (i = 0; i < frames; i++)
|
for (i = 0; i < frames; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL,
|
||||||
"Summary", "Content",
|
NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, // no icon
|
"Summary", "Content",
|
||||||
TRUE, time(NULL) + 5,
|
NULL, // no icon
|
||||||
NULL, // no user data
|
TRUE, time(NULL) + 5,
|
||||||
0); // no actions
|
NULL, // no user data
|
||||||
|
0); // no actions
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,21 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
notify_init("Basics");
|
notify_init("Basics");
|
||||||
|
|
||||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL,
|
||||||
"Summary", "Content",
|
NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, // no icon
|
"Summary", "Content",
|
||||||
TRUE, time(NULL) + 5,
|
NULL, // no icon
|
||||||
NULL, // no user data
|
TRUE, time(NULL) + 5,
|
||||||
0); // no actions
|
NULL, // no user data
|
||||||
|
0); // no actions
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,36 +37,39 @@ static NotifyHandle *n;
|
||||||
|
|
||||||
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
||||||
{
|
{
|
||||||
assert( uid == 0 );
|
assert( uid == 0 );
|
||||||
|
|
||||||
notify_close(n);
|
notify_close(n);
|
||||||
|
|
||||||
g_main_loop_quit(loop);
|
g_main_loop_quit(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
if (!notify_init("Default Action Test")) exit(1);
|
main()
|
||||||
|
{
|
||||||
|
if (!notify_init("Default Action Test")) exit(1);
|
||||||
|
|
||||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
dbus_connection_setup_with_g_main(conn, NULL);
|
dbus_connection_setup_with_g_main(conn, NULL);
|
||||||
|
|
||||||
n = notify_send_notification(NULL, // replaces nothing
|
n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
"presence.online",
|
||||||
"Matt is online", NULL,
|
NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, // no icon
|
"Matt is online", NULL,
|
||||||
FALSE, 0, // does not expire
|
NULL, // no icon
|
||||||
NULL, // no user data
|
FALSE, 0, // does not expire
|
||||||
1,
|
NULL, // no user data
|
||||||
0, "default", callback); // 1 action
|
1,
|
||||||
|
0, "default", callback); // 1 action
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_main_loop_run(loop);
|
g_main_loop_run(loop);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,24 +24,25 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
notify_init("Error Handling");
|
notify_init("Error Handling");
|
||||||
|
|
||||||
NotifyIcon *icon = notify_icon_new("/no-such");
|
NotifyIcon *icon = notify_icon_new("/no-such");
|
||||||
|
|
||||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL,
|
||||||
"Summary", "Content",
|
NOTIFY_URGENCY_NORMAL,
|
||||||
icon, // no icon
|
"Summary", "Content",
|
||||||
TRUE, time(NULL) + 5,
|
icon, // no icon
|
||||||
NULL, // no user data
|
TRUE, time(NULL) + 5,
|
||||||
0);
|
NULL, // no user data
|
||||||
|
0);
|
||||||
|
|
||||||
notify_icon_destroy(icon);
|
notify_icon_destroy(icon);
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
fprintf(stderr, "failed to get an error ??\n");
|
fprintf(stderr, "failed to get an error ??\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,81 +36,83 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
NotifyHandle *n;
|
NotifyHandle *n;
|
||||||
|
|
||||||
static void send(char *i, size_t rawlen, char *s, char *b)
|
static void send(char *i, size_t rawlen, char *s, char *b)
|
||||||
{
|
{
|
||||||
NotifyIcon *icon;
|
NotifyIcon *icon;
|
||||||
|
|
||||||
if (rawlen > 0)
|
if (rawlen > 0)
|
||||||
icon = notify_icon_new_with_data(rawlen, i);
|
icon = notify_icon_new_with_data(rawlen, i);
|
||||||
else
|
else
|
||||||
icon = notify_icon_new(i);
|
icon = notify_icon_new(i);
|
||||||
|
|
||||||
n = notify_send_notification(NULL, // replaces nothing
|
n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL,
|
||||||
s, b,
|
NOTIFY_URGENCY_NORMAL,
|
||||||
icon,
|
s, b,
|
||||||
TRUE, time(NULL) + 5,
|
icon,
|
||||||
NULL, // no user data
|
TRUE, time(NULL) + 5,
|
||||||
0);
|
NULL, // no user data
|
||||||
|
0);
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_icon_destroy(icon);
|
notify_icon_destroy(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (!notify_init("Images Test")) exit(1);
|
if (!notify_init("Images Test")) exit(1);
|
||||||
|
|
||||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
dbus_connection_setup_with_g_main(conn, NULL);
|
dbus_connection_setup_with_g_main(conn, NULL);
|
||||||
|
|
||||||
// these images exist on fedora core 2 workstation profile. might not on yours
|
// these images exist on fedora core 2 workstation profile. might not on yours
|
||||||
|
|
||||||
send("gnome-starthere",
|
send("gnome-starthere",
|
||||||
0,
|
0,
|
||||||
"Welcome to Linux!",
|
"Welcome to Linux!",
|
||||||
"This is your first login. To begin exploring the system, click on 'Start Here', 'Computer' or 'Applications'");
|
"This is your first login. To begin exploring the system, click on 'Start Here', 'Computer' or 'Applications'");
|
||||||
|
|
||||||
char file[1024];
|
char file[1024];
|
||||||
readlink("/proc/self/exe", file, sizeof(file));
|
readlink("/proc/self/exe", file, sizeof(file));
|
||||||
*strrchr(file, '/') = '\0';
|
*strrchr(file, '/') = '\0';
|
||||||
strcat(file, "/../applet-critical.png");
|
strcat(file, "/../applet-critical.png");
|
||||||
|
|
||||||
printf("sending %s\n", file);
|
printf("sending %s\n", file);
|
||||||
|
|
||||||
send(file,
|
send(file,
|
||||||
0,
|
0,
|
||||||
"Alert!",
|
"Alert!",
|
||||||
"Warning!");
|
"Warning!");
|
||||||
|
|
||||||
|
|
||||||
// FIXME: test raw image transfer
|
// FIXME: test raw image transfer
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(file, &buf) == -1)
|
if (stat(file, &buf) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "could not stat %s: %s", file, strerror(errno));
|
fprintf(stderr, "could not stat %s: %s", file, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(file, O_RDONLY);
|
int fd = open(file, O_RDONLY);
|
||||||
|
|
||||||
void *pngbase = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
void *pngbase = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
send(pngbase,
|
send(pngbase,
|
||||||
buf.st_size,
|
buf.st_size,
|
||||||
"Raw image test",
|
"Raw image test",
|
||||||
"This is an image marshalling test");
|
"This is an image marshalling test");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,24 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
notify_init("Markup");
|
notify_init("Markup");
|
||||||
|
|
||||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
NotifyHandle *n = notify_send_notification(
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL, // replaces nothing
|
||||||
"Summary",
|
NULL,
|
||||||
|
NOTIFY_URGENCY_NORMAL,
|
||||||
|
"Summary",
|
||||||
|
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
|
||||||
|
"<a href='google.com'>linked</a> text",
|
||||||
|
NULL, // no icon
|
||||||
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no user data
|
||||||
|
0); // no actions
|
||||||
|
|
||||||
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, <a href='google.com'>linked</a> text",
|
if (!n) {
|
||||||
|
fprintf(stderr, "failed to send notification\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
NULL, // no icon
|
return 0;
|
||||||
TRUE, time(NULL) + 5,
|
|
||||||
NULL, // no user data
|
|
||||||
0); // no actions
|
|
||||||
|
|
||||||
if (!n) {
|
|
||||||
fprintf(stderr, "failed to send notification\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,56 +30,59 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
NotifyHandle *n;
|
NotifyHandle *n;
|
||||||
|
|
||||||
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
||||||
{
|
{
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
|
|
||||||
assert( uid >= 0 && uid <= 2 );
|
assert( uid >= 0 && uid <= 2 );
|
||||||
|
|
||||||
switch (uid)
|
switch (uid)
|
||||||
{
|
{
|
||||||
case 0: s = "the notification"; break;
|
case 0: s = "the notification"; break;
|
||||||
case 1: s = "Empty Trash"; break;
|
case 1: s = "Empty Trash"; break;
|
||||||
case 2: s = "Help Me"; break;
|
case 2: s = "Help Me"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("You clicked %s\n", s);
|
printf("You clicked %s\n", s);
|
||||||
|
|
||||||
notify_close(n);
|
notify_close(n);
|
||||||
|
|
||||||
g_main_loop_quit(loop);
|
g_main_loop_quit(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (!notify_init("Multi Action Test")) exit(1);
|
if (!notify_init("Multi Action Test")) exit(1);
|
||||||
|
|
||||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
dbus_connection_setup_with_g_main(conn, NULL);
|
dbus_connection_setup_with_g_main(conn, NULL);
|
||||||
|
|
||||||
n = notify_send_notification(NULL, // replaces nothing
|
n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
"device",
|
||||||
"Low disk space", "You can free up some disk space by emptying the trash can.",
|
NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, // no icon
|
"Low disk space",
|
||||||
FALSE, 0, // does not expire
|
"You can free up some disk space by "
|
||||||
NULL, // no user data
|
"emptying the trash can.",
|
||||||
|
NULL, // no icon
|
||||||
|
FALSE, 0, // does not expire
|
||||||
|
NULL, // no user data
|
||||||
|
3, // 3 actions
|
||||||
|
0, "default", callback,
|
||||||
|
1, "Empty Trash", callback,
|
||||||
|
2, "Help Me", callback );
|
||||||
|
|
||||||
3, // 3 actions
|
if (!n) {
|
||||||
0, "default", callback,
|
fprintf(stderr, "failed to send notification\n");
|
||||||
1, "Empty Trash", callback,
|
return 1;
|
||||||
2, "Help Me", callback );
|
}
|
||||||
|
|
||||||
if (!n) {
|
g_main_loop_run(loop);
|
||||||
fprintf(stderr, "failed to send notification\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_main_loop_run(loop);
|
return 0;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,26 +24,28 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
notify_init("Replace Test");
|
notify_init("Replace Test");
|
||||||
|
|
||||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NULL,
|
||||||
"Summary", "Content",
|
NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, // no icon
|
"Summary", "Content",
|
||||||
FALSE, 0, // does not expire
|
NULL, // no icon
|
||||||
NULL, // no user data
|
FALSE, 0, // does not expire
|
||||||
0); // no actions
|
NULL, // no user data
|
||||||
|
0); // no actions
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
notify_send_notification(n, NOTIFY_URGENCY_NORMAL, "Second Summary", "Second Content",
|
notify_send_notification(n, NULL, NOTIFY_URGENCY_NORMAL,
|
||||||
NULL, TRUE, time(NULL) + 5, NULL, 0);
|
"Second Summary", "Second Content",
|
||||||
|
NULL, TRUE, 5, NULL, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,36 +31,39 @@ int
|
||||||
main(int argc, const char **argv)
|
main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const gchar *summary = NULL;
|
const gchar *summary = NULL;
|
||||||
const gchar *description = NULL;
|
const gchar *body = NULL;
|
||||||
|
const gchar *type = NULL;
|
||||||
char *urgency_str = NULL;
|
char *urgency_str = NULL;
|
||||||
gchar *sound = NULL;
|
|
||||||
gchar *icons = NULL;
|
gchar *icons = NULL;
|
||||||
gchar *icon_str = NULL;
|
gchar *icon_str = NULL;
|
||||||
NotifyIcon *icon = NULL;
|
NotifyIcon *icon = NULL;
|
||||||
NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
time_t expire_time = 0;
|
time_t expire_timeout = 0;
|
||||||
char ch;
|
char ch;
|
||||||
poptContext opt_ctx;
|
poptContext opt_ctx;
|
||||||
const char **args;
|
const char **args;
|
||||||
struct poptOption options[] =
|
struct poptOption options[] =
|
||||||
{
|
{
|
||||||
{ "urgency", 'u', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &urgency_str,
|
{ "urgency", 'u', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &urgency_str,
|
||||||
0, N_("Specifies the urgency level (low, normal, high, critical)"),
|
0, N_("Specifies the urgency level (low, normal, critical)."),
|
||||||
NULL },
|
NULL },
|
||||||
{ "expire-time", 't', POPT_ARG_INT | POPT_ARGFLAG_STRIP, &expire_time,
|
{ "expire-time", 't', POPT_ARG_INT | POPT_ARGFLAG_STRIP,
|
||||||
0, N_("Specifies the timestamp at which to expire the notification, or if < current time, specifies timeout in seconds from current time"),
|
&expire_timeout, 0,
|
||||||
|
N_("Specifies the timeout in seconds at which to expire the "
|
||||||
|
"notification."),
|
||||||
NULL },
|
NULL },
|
||||||
{ "sound", 's', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &sound, 0,
|
|
||||||
N_("Specifies a sound file to play on notification."), NULL },
|
|
||||||
{ "icon", 'i', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &icons, 0,
|
{ "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_("ICON1,ICON2,...") },
|
N_("ICON1,ICON2,...") },
|
||||||
|
{ "type", 't', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &type, 0,
|
||||||
|
N_("Specifies the notification type."),
|
||||||
|
N_("ICON1,ICON2,...") },
|
||||||
POPT_AUTOHELP
|
POPT_AUTOHELP
|
||||||
POPT_TABLEEND
|
POPT_TABLEEND
|
||||||
};
|
};
|
||||||
|
|
||||||
opt_ctx = poptGetContext("notify-send", argc, argv, options, 0);
|
opt_ctx = poptGetContext("notify-send", argc, argv, options, 0);
|
||||||
poptSetOtherOptionHelp(opt_ctx, "[OPTIONS]* <summary> [description]");
|
poptSetOtherOptionHelp(opt_ctx, "[OPTIONS]* <summary> [body]");
|
||||||
|
|
||||||
while ((ch = poptGetNextOpt(opt_ctx)) >= 0)
|
while ((ch = poptGetNextOpt(opt_ctx)) >= 0)
|
||||||
;
|
;
|
||||||
|
@ -82,7 +85,7 @@ main(int argc, const char **argv)
|
||||||
|
|
||||||
if (args[1] != NULL)
|
if (args[1] != NULL)
|
||||||
{
|
{
|
||||||
description = args[1];
|
body = args[1];
|
||||||
|
|
||||||
if (args[2] != NULL)
|
if (args[2] != NULL)
|
||||||
{
|
{
|
||||||
|
@ -110,8 +113,6 @@ main(int argc, const char **argv)
|
||||||
urgency = NOTIFY_URGENCY_LOW;
|
urgency = NOTIFY_URGENCY_LOW;
|
||||||
else if (!strcasecmp(urgency_str, "normal"))
|
else if (!strcasecmp(urgency_str, "normal"))
|
||||||
urgency = NOTIFY_URGENCY_NORMAL;
|
urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
else if (!strcasecmp(urgency_str, "high"))
|
|
||||||
urgency = NOTIFY_URGENCY_HIGH;
|
|
||||||
else if (!strcasecmp(urgency_str, "critical"))
|
else if (!strcasecmp(urgency_str, "critical"))
|
||||||
urgency = NOTIFY_URGENCY_CRITICAL;
|
urgency = NOTIFY_URGENCY_CRITICAL;
|
||||||
else
|
else
|
||||||
|
@ -123,11 +124,8 @@ main(int argc, const char **argv)
|
||||||
|
|
||||||
if (!notify_init("notify-send")) exit(1);
|
if (!notify_init("notify-send")) exit(1);
|
||||||
|
|
||||||
/* if the given time is < current time, treat it as a timeout in seconds (ie 5 seconds) */
|
notify_send_notification(NULL, type, urgency, summary, body, icon,
|
||||||
if (expire_time && expire_time < time(NULL)) expire_time += time(NULL);
|
TRUE, expire_timeout, NULL, 0);
|
||||||
|
|
||||||
notify_send_notification(NULL, urgency, summary, description, icon,
|
|
||||||
TRUE, expire_time, NULL, 0);
|
|
||||||
|
|
||||||
if (icon != NULL)
|
if (icon != NULL)
|
||||||
notify_icon_destroy(icon);
|
notify_icon_destroy(icon);
|
||||||
|
|
Loading…
Reference in New Issue