* libnotify/notifynotification.c (SIGNAL_TYPE_CLOSED): "closed" glib
signal added (notify_notification_clear_hints): New API for clearing out the hints hash (notify_notification_ref, notify_notification_unref): removed - use g_object_ref/unref * tests/*: Various changes to the test binaries
This commit is contained in:
parent
941757b593
commit
38c83b0ef5
|
@ -25,11 +25,13 @@
|
||||||
static void notify_notification_class_init (NotifyNotificationClass * klass);
|
static void notify_notification_class_init (NotifyNotificationClass * klass);
|
||||||
static void notify_notification_init (NotifyNotification * sp);
|
static void notify_notification_init (NotifyNotification * sp);
|
||||||
static void notify_notification_finalize (GObject * object);
|
static void notify_notification_finalize (GObject * object);
|
||||||
|
static void _close_signal_handler (DBusGProxy *proxy,
|
||||||
|
guint32 id,
|
||||||
|
NotifyNotification *notification);
|
||||||
|
|
||||||
struct NotifyNotificationPrivate
|
struct NotifyNotificationPrivate
|
||||||
{
|
{
|
||||||
guint32 id;
|
guint32 id;
|
||||||
|
|
||||||
gchar *summary;
|
gchar *summary;
|
||||||
gchar *message;
|
gchar *message;
|
||||||
|
|
||||||
|
@ -58,19 +60,18 @@ struct NotifyNotificationPrivate
|
||||||
DBusGProxy *proxy;
|
DBusGProxy *proxy;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
SIGNAL_TYPE_CLOSED,
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
} NotifyNotificationSignalType;
|
} NotifyNotificationSignalType;
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
NotifyNotification *object;
|
NotifyNotification *object;
|
||||||
} NotifyNotificationSignal;
|
} NotifyNotificationSignal;
|
||||||
|
|
||||||
/* static guint notify_notification_signals[LAST_SIGNAL] = { 0 }; */
|
static guint notify_notification_signals[LAST_SIGNAL] = { 0 };
|
||||||
static GObjectClass *parent_class = NULL;
|
static GObjectClass *parent_class = NULL;
|
||||||
|
|
||||||
GType
|
GType
|
||||||
|
@ -107,9 +108,16 @@ notify_notification_class_init (NotifyNotificationClass * klass)
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
parent_class = g_type_class_peek_parent (klass);
|
||||||
object_class->finalize = notify_notification_finalize;
|
object_class->finalize = notify_notification_finalize;
|
||||||
|
|
||||||
/* Create signals here:
|
/* Create signals here: */
|
||||||
notify_notification_signals[SIGNAL_TYPE_EXAMPLE] = g_signal_new(...)
|
notify_notification_signals[SIGNAL_TYPE_CLOSED] =
|
||||||
*/
|
g_signal_new ("closed",
|
||||||
|
G_TYPE_FROM_CLASS (object_class),
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
G_STRUCT_OFFSET (NotifyNotificationClass, closed),
|
||||||
|
NULL, NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -177,6 +185,10 @@ notify_notification_finalize (GObject * object)
|
||||||
if (priv->user_data_free_func != NULL)
|
if (priv->user_data_free_func != NULL)
|
||||||
priv->user_data_free_func (priv->user_data);
|
priv->user_data_free_func (priv->user_data);
|
||||||
|
|
||||||
|
dbus_g_proxy_disconnect_signal (priv->proxy, "NotificationClosed",
|
||||||
|
_close_signal_handler,
|
||||||
|
object);
|
||||||
|
|
||||||
g_free (obj->priv);
|
g_free (obj->priv);
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -304,18 +316,6 @@ notify_notification_new (const gchar * summary,
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyNotification *
|
|
||||||
notify_notification_ref (NotifyNotification * notification)
|
|
||||||
{
|
|
||||||
return NOTIFY_NOTIFICATION (g_object_ref (G_OBJECT (notification)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
notify_notification_unref (NotifyNotification * notification)
|
|
||||||
{
|
|
||||||
g_object_unref (G_OBJECT (notification));
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
notify_notification_update (NotifyNotification * notification,
|
notify_notification_update (NotifyNotification * notification,
|
||||||
const gchar * summary,
|
const gchar * summary,
|
||||||
|
@ -385,8 +385,22 @@ filter_func (DBusConnection *connection,
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_close_signal_handler (DBusGProxy *proxy,
|
||||||
|
guint32 id,
|
||||||
|
NotifyNotification *notification)
|
||||||
|
{
|
||||||
|
printf ("Got the NotificationClosed signal (id = %i, notification->id = %i)\n"
|
||||||
|
, id, notification->priv->id);
|
||||||
|
|
||||||
|
if (id == notification->priv->id)
|
||||||
|
g_signal_emit (notification,
|
||||||
|
notify_notification_signals[SIGNAL_TYPE_CLOSED],
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
notify_notification_show (NotifyNotification * notification, GError ** error)
|
notify_notification_show (NotifyNotification *notification, GError **error)
|
||||||
{
|
{
|
||||||
NotifyNotificationPrivate *priv;
|
NotifyNotificationPrivate *priv;
|
||||||
GError *tmp_error;
|
GError *tmp_error;
|
||||||
|
@ -408,15 +422,17 @@ notify_notification_show (NotifyNotification * notification, GError ** error)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the object here because
|
|
||||||
* we need to start listening for signals
|
|
||||||
*/
|
|
||||||
dbus_g_connection_register_g_object (bus, "/org/freedesktop/NotifyNotification", G_OBJECT (notification));
|
|
||||||
|
|
||||||
priv->proxy = dbus_g_proxy_new_for_name (bus,
|
priv->proxy = dbus_g_proxy_new_for_name (bus,
|
||||||
NOTIFY_DBUS_NAME,
|
NOTIFY_DBUS_NAME,
|
||||||
NOTIFY_DBUS_CORE_OBJECT,
|
NOTIFY_DBUS_CORE_OBJECT,
|
||||||
NOTIFY_DBUS_CORE_INTERFACE);
|
NOTIFY_DBUS_CORE_INTERFACE);
|
||||||
|
|
||||||
|
dbus_g_proxy_add_signal (priv->proxy, "NotificationClosed",
|
||||||
|
G_TYPE_UINT, NULL);
|
||||||
|
dbus_g_proxy_connect_signal (priv->proxy, "NotificationClosed",
|
||||||
|
_close_signal_handler,
|
||||||
|
notification, NULL);
|
||||||
|
|
||||||
dbus_g_connection_unref (bus);
|
dbus_g_connection_unref (bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,8 +731,21 @@ notify_notification_set_hint_string (NotifyNotification * notification,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_remove_all (void)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_notification_clear_hints (NotifyNotification *notification)
|
||||||
|
{
|
||||||
|
g_hash_table_foreach_remove (notification->priv->hints,
|
||||||
|
(GHRFunc) _remove_all, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
notify_notification_add_action (NotifyNotification * notification,
|
notify_notification_add_action (NotifyNotification *notification,
|
||||||
const char *action,
|
const char *action,
|
||||||
const char *label,
|
const char *label,
|
||||||
NotifyActionCallback callback)
|
NotifyActionCallback callback)
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
/* Add Signal Functions Here */
|
/* Add Signal Functions Here */
|
||||||
|
void (*closed) (void);
|
||||||
} NotifyNotificationClass;
|
} NotifyNotificationClass;
|
||||||
|
|
||||||
typedef void (*NotifyActionCallback )(NotifyNotification *, gchar *);
|
typedef void (*NotifyActionCallback )(NotifyNotification *, gchar *);
|
||||||
|
@ -105,6 +106,8 @@ gboolean notify_notification_set_hint_byte_array (
|
||||||
const guchar *value,
|
const guchar *value,
|
||||||
gsize len);
|
gsize len);
|
||||||
|
|
||||||
|
void notify_notification_clear_hints (NotifyNotification *notification);
|
||||||
|
|
||||||
gboolean notify_notification_add_action (NotifyNotification *notification,
|
gboolean notify_notification_add_action (NotifyNotification *notification,
|
||||||
const char *action,
|
const char *action,
|
||||||
const char *label,
|
const char *label,
|
||||||
|
|
|
@ -29,7 +29,7 @@ int main() {
|
||||||
notify_init("Basics");
|
notify_init("Basics");
|
||||||
|
|
||||||
n = notify_notification_new ("Summary",
|
n = notify_notification_new ("Summary",
|
||||||
"Content",
|
"Content that is very long 8374983278r32j4 rhjjfh dw8f 43jhf 8ds7 ur2389f jdbjkt h8924yf jkdbjkt 892hjfiHER98HEJIF BDSJHF hjdhF JKLH 890YRHEJHFU 89HRJKSHFJ YE8UI HR3UIH89EFHIUEUF9DHFUIBuiew f89hsajiJ FHJKDSKJFH SDJKFH KJASDFJK HKJADSHFK JSAHF89WE HUIIUG JG kjG JKGJGHJg JHG H J HJGJHDG HJKJG hgd hgjhf df h3eui fusidyaiu rh f98ehkrnm e8rv9y 43heh vijdhjkewdkjsjfjk sdhkjf hdkj fadskj hfkjdsh",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
notify_notification_set_timeout (n, 3000); //3 seconds
|
notify_notification_set_timeout (n, 3000); //3 seconds
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,10 @@ int main(int argc, char *argv[]) {
|
||||||
if (!notify_init("Images Test")) exit(1);
|
if (!notify_init("Images Test")) exit(1);
|
||||||
|
|
||||||
n = notify_notification_new ("Icon Test", "Testing stock icon", "stock_help", NULL);
|
n = notify_notification_new ("Icon Test", "Testing stock icon", "stock_help", NULL);
|
||||||
|
|
||||||
|
notify_notification_set_hint_int32 (n, "x", 300);
|
||||||
|
notify_notification_set_hint_int32 (n, "y", 24);
|
||||||
|
|
||||||
notify_notification_set_timeout (n, NOTIFY_TIMEOUT_NEVER);
|
notify_notification_set_timeout (n, NOTIFY_TIMEOUT_NEVER);
|
||||||
if (!notify_notification_show (n, NULL)) {
|
if (!notify_notification_show (n, NULL)) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
|
|
|
@ -24,6 +24,16 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <dbus/dbus.h>
|
||||||
|
#include <dbus/dbus-glib.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
_handle_closed (GObject *o)
|
||||||
|
{
|
||||||
|
g_message ("closing");
|
||||||
|
g_object_unref (o);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
emit_notification(int x, int y)
|
emit_notification(int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -40,47 +50,51 @@ emit_notification(int x, int y)
|
||||||
notify_notification_set_hint_int32 (n, "x", x);
|
notify_notification_set_hint_int32 (n, "x", x);
|
||||||
notify_notification_set_hint_int32 (n, "y", y);
|
notify_notification_set_hint_int32 (n, "y", y);
|
||||||
|
|
||||||
|
g_signal_connect (n, "closed", _handle_closed, NULL);
|
||||||
|
|
||||||
if (!notify_notification_show (n, NULL)) {
|
if (!notify_notification_show (n, NULL)) {
|
||||||
fprintf(stderr, "failed to send notification\n");
|
fprintf(stderr, "failed to send notification\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static gboolean
|
||||||
main(int argc, char **argv)
|
_popup_random_bubble (void)
|
||||||
{
|
{
|
||||||
GdkDisplay *display;
|
GdkDisplay *display;
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
|
|
||||||
int screen_x2, screen_y2;
|
int screen_x2, screen_y2;
|
||||||
|
int x, y;
|
||||||
gdk_init(&argc, &argv);
|
|
||||||
|
|
||||||
notify_init("XY");
|
|
||||||
|
|
||||||
display = gdk_display_get_default();
|
display = gdk_display_get_default();
|
||||||
screen = gdk_display_get_default_screen(display);
|
screen = gdk_display_get_default_screen(display);
|
||||||
screen_x2 = gdk_screen_get_width(screen) - 1;
|
screen_x2 = gdk_screen_get_width(screen) - 1;
|
||||||
screen_y2 = gdk_screen_get_height(screen) - 1;
|
screen_y2 = gdk_screen_get_height(screen) - 1;
|
||||||
|
|
||||||
emit_notification(0, 0);
|
x = g_random_int_range (0, screen_x2);
|
||||||
g_usleep (1000000);
|
y = g_random_int_range (0, screen_y2);
|
||||||
emit_notification(screen_x2, 0);
|
emit_notification(x, y);
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(5, 150);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(screen_x2 - 5, 150);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(0, screen_y2 / 2);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(screen_x2, screen_y2 / 2);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(5, screen_y2 - 150);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(screen_x2 - 5, screen_y2 - 150);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(0, screen_y2);
|
|
||||||
g_usleep (1000000);
|
|
||||||
emit_notification(screen_x2, screen_y2);
|
|
||||||
|
|
||||||
return 0;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
GMainLoop *loop;
|
||||||
|
DBusConnection *conn;
|
||||||
|
|
||||||
|
gdk_init(&argc, &argv);
|
||||||
|
|
||||||
|
notify_init("XY");
|
||||||
|
|
||||||
|
conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
|
||||||
|
|
||||||
|
dbus_connection_setup_with_g_main (conn, NULL);
|
||||||
|
|
||||||
|
g_timeout_add (1000, _popup_random_bubble, NULL);
|
||||||
|
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
g_main_loop_run (loop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ int main() {
|
||||||
"This notification should point to 150, 10",
|
"This notification should point to 150, 10",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
notify_notification_set_hint_int32 (n, "x", 150);
|
notify_notification_set_hint_int32 (n, "x", 30);
|
||||||
notify_notification_set_hint_int32 (n, "y", 10);
|
notify_notification_set_hint_int32 (n, "y", 10);
|
||||||
|
|
||||||
if (!notify_notification_show (n, NULL)) {
|
if (!notify_notification_show (n, NULL)) {
|
||||||
|
|
Loading…
Reference in New Issue