Re: [Rhythmbox-devel] Libnotify
- From: Renato Araujo <renatox gmail com>
- To: Mark Rosenstand <mark borkware net>
- Cc: rhythmbox-devel gnome org
- Subject: Re: [Rhythmbox-devel] Libnotify
- Date: Tue, 4 Oct 2005 00:56:29 -0300
I made this patch for integrate libnotify in RB, this detect when you
have libnotiy and use that if present.
BR
Renato Araujo
On 10/3/05, Mark Rosenstand <mark borkware net> wrote:
> Jaap Haitsma <jaap haitsma org> wrote:
> > Renato Araujo wrote:
> > > Hi guys i made a litle changes to use libnotify to display systray
> > > messages take a look in image.
> > > What you think about?
> >
> > Rhythmbox already contains eggnotificationbubble.[ch] to do
> > notifications. So I guess you'd better use that.
> >
> > Would be nice if the community would come up with one recommended
> > library for doing notifications.
>
> That's pretty much the purpose of libnotify/notification-daemon if I
> know Christian right :-)
> _______________________________________________
> rhythmbox-devel mailing list
> rhythmbox-devel gnome org
> http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
>
Index: configure.ac
===================================================================
RCS file: /cvs/gnome/rhythmbox/configure.ac,v
retrieving revision 1.171
diff -u -3 -p -u -p -r1.171 configure.ac
--- configure.ac 24 Sep 2005 15:39:24 -0000 1.171
+++ configure.ac 4 Oct 2005 03:54:09 -0000
@@ -191,6 +191,11 @@ if test x"$enable_daap" = xyes; then
fi
fi
+PKG_CHECK_MODULES(NOTIFY, \
+ libnotify,
+ have_libnotify=yes,
+ have_libnotify=no)
+
AC_ARG_WITH(mdns,
AC_HELP_STRING([--with-mdns=auto|howl|avahi],
[Select the mDNS/DNS-SD implementation to use (default auto)]),,
@@ -271,6 +276,13 @@ if test x"$enable_daap" = xyes; then
fi
fi
AM_CONDITIONAL(USE_DAAP, test "x$enable_daap" = "xyes")
+
+if test x"$have_libnotify" = xyes; then
+ AC_DEFINE(HAVE_NOTIFY, 1, [Define if libnotify should be enabled])
+ AC_SUBST(NOTIFY_CFLAGS)
+ AC_SUBST(NOTIFY_LIBS)
+fi
+AM_CONDITIONAL(USE_NOTIFY, test "x$have_libnotify" = "xyes")
dnl AC_CHECK_LIB(lirc_client, lirc_init,
dnl [ AC_CHECK_HEADER(lirc/lirc_client.h,
Index: shell/Makefile.am
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/Makefile.am,v
retrieving revision 1.59
diff -u -3 -p -u -p -r1.59 Makefile.am
--- shell/Makefile.am 24 Sep 2005 15:40:43 -0000 1.59
+++ shell/Makefile.am 4 Oct 2005 03:54:09 -0000
@@ -148,6 +148,11 @@ rhythmbox_LDADD += $(SOUP_LIBS) \
$(top_builddir)/daapsharing/libdaapsharing.la
endif
+if USE_NOTIFY
+rhythmbox_LDADD += $(NOTIFY_LIBS)
+endif
+
+
BUILT_SOURCES += $(tab_files)
CLEANFILES += $(BUILT_SOURCES)
Index: shell/rb-tray-icon.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-tray-icon.c,v
retrieving revision 1.20
diff -u -3 -p -u -p -r1.20 rb-tray-icon.c
--- shell/rb-tray-icon.c 2 Sep 2005 01:53:09 -0000 1.20
+++ shell/rb-tray-icon.c 4 Oct 2005 03:54:10 -0000
@@ -70,9 +70,6 @@ static void rb_tray_icon_drop_cb (GtkWid
struct RBTrayIconPrivate
{
GtkTooltips *tooltips;
-
- EggNotificationBubble *bubble;
-
GtkUIManager *ui_manager;
GtkActionGroup *actiongroup;
@@ -505,24 +502,6 @@ rb_tray_icon_set_tooltip (RBTrayIcon *ic
tooltip, NULL);
}
-static void
-rb_tray_icon_hide_notify_cb (EggNotificationBubble *bubble, gpointer data)
-{
- gboolean visible;
- RBTrayIcon *icon;
-
- icon = RB_TRAY_ICON (data);
-
- rb_debug ("hiding notification");
-
- egg_notification_bubble_hide (bubble);
- visible = rb_remote_proxy_get_visibility (icon->priv->proxy);
- if (!visible) {
- rb_debug ("setting visible");
- rb_remote_proxy_set_visibility (icon->priv->proxy, TRUE);
- }
-}
-
void
rb_tray_icon_notify (RBTrayIcon *icon,
guint timeout,
@@ -530,24 +509,13 @@ rb_tray_icon_notify (RBTrayIcon *icon,
GtkWidget *msgicon,
const char *secondary)
{
- if (icon->priv->bubble) {
- g_object_unref (icon->priv->bubble);
- g_signal_handlers_disconnect_by_func (icon->priv->bubble,
- rb_tray_icon_hide_notify_cb,
- icon);
- }
rb_debug ("doing notify: %s", primary);
- icon->priv->bubble = egg_tray_icon_notify (EGG_TRAY_ICON (icon), timeout, primary, msgicon, secondary);
- g_object_ref (icon->priv->bubble);
- g_signal_connect_object (icon->priv->bubble,
- "clicked",
- G_CALLBACK (rb_tray_icon_hide_notify_cb),
- icon, 0);
+ egg_tray_icon_notify (EGG_TRAY_ICON (icon), timeout, primary, msgicon, secondary);
}
void
rb_tray_icon_cancel_notify (RBTrayIcon *icon)
{
- if (icon->priv->bubble)
- egg_notification_bubble_hide (icon->priv->bubble);
+ egg_tray_icon_cancel_message (EGG_TRAY_ICON (icon), 1);
}
+
Index: widgets/eggtrayicon.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/eggtrayicon.c,v
retrieving revision 1.4
diff -u -3 -p -u -p -r1.4 eggtrayicon.c
--- widgets/eggtrayicon.c 2 Sep 2005 01:53:09 -0000 1.4
+++ widgets/eggtrayicon.c 4 Oct 2005 03:54:10 -0000
@@ -23,14 +23,20 @@
#include <libintl.h>
#include "eggtrayicon.h"
+#include "rb-stock-icons.h"
+#include "rb-file-helpers.h"
#include <gdkconfig.h>
+#include <gtk/gtkimage.h>
#if defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#elif defined (GDK_WINDOWING_WIN32)
#include <gdk/gdkwin32.h>
#endif
+#ifdef HAVE_NOTIFY
+#include <libnotify/notify.h>
+#endif
#ifndef EGG_COMPILATION
#ifndef _
@@ -53,6 +59,14 @@ enum {
PROP_0,
PROP_ORIENTATION
};
+
+#ifdef HAVE_NOTIFY
+struct _Notify {
+ NotifyHints *hints;
+ NotifyIcon *icon;
+ NotifyHandle *handle;
+};
+#endif
static GtkPlugClass *parent_class = NULL;
@@ -104,7 +118,12 @@ egg_tray_icon_init (EggTrayIcon *icon)
{
icon->stamp = 1;
icon->orientation = GTK_ORIENTATION_HORIZONTAL;
-
+#ifdef HAVE_NOTIFY
+ icon->notify = g_new0 (Notify, 1);
+ icon->notify->handle = NULL;
+ icon->notify->hints = NULL;
+ icon->notify->icon = NULL;
+#endif
gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
}
@@ -265,6 +284,10 @@ egg_tray_icon_unrealize (GtkWidget *widg
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
#endif
+#ifdef HAVE_NOTIFY
+ notify_close (EGG_TRAY_ICON (widget)->notify->handle);
+ g_free (EGG_TRAY_ICON(widget)->notify);
+#endif
}
#ifdef GDK_WINDOWING_X11
@@ -448,6 +471,9 @@ egg_tray_icon_send_message (EggTrayIcon
g_return_val_if_fail (timeout >= 0, 0);
g_return_val_if_fail (message != NULL, 0);
+#ifdef HAVE_NOTIFY
+ egg_tray_icon_notify (icon, timeout, _("Notification"), NULL, message);
+#else
if (!icon->bubble)
{
icon->bubble = egg_notification_bubble_new ();
@@ -457,6 +483,7 @@ egg_tray_icon_send_message (EggTrayIcon
egg_notification_bubble_set (icon->bubble, _("Notification"),
NULL, message);
egg_notification_bubble_show (icon->bubble, timeout);
+#endif
return 1;
}
@@ -466,10 +493,18 @@ egg_tray_icon_cancel_message (EggTrayIco
guint id)
{
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
+#ifdef HAVE_NOTIFY
+ if (icon->notify->handle)
+ {
+ notify_close (icon->notify->handle);
+ icon->notify->handle = NULL;
+ }
+#else
g_return_if_fail (id > 0);
g_return_if_fail (icon->bubble != NULL);
egg_notification_bubble_hide (icon->bubble);
+#endif
}
GtkOrientation
@@ -480,13 +515,88 @@ egg_tray_icon_get_orientation (EggTrayIc
return icon->orientation;
}
-EggNotificationBubble *
+#ifndef HAVE_NOTIFY
+static void
+egg_tray_icon_hide_notify_cb (EggNotificationBubble *bubble, gpointer data)
+{
+ egg_tray_icon_cancel_message (EGG_TRAY_ICON (data), 1);
+}
+#endif
+
+void
egg_tray_icon_notify (EggTrayIcon *icon,
guint timeout,
const char *primary,
GtkWidget *msgicon,
const char *secondary)
{
+#ifdef HAVE_NOTIFY
+ gint x, y;
+ GtkRequisition size;
+ NotifyIcon *icon_notify = NULL;
+ NotifyHints *hints;
+ char *fn;
+
+
+ if (!notify_is_initted ())
+ if (!notify_init ("rhythmbox"))
+ return;
+
+ gdk_window_get_origin (GTK_WIDGET (icon)->window, &x, &y);
+ gtk_widget_size_request (GTK_WIDGET (icon), &size);
+ x += size.width / 2;
+ y += size.height;
+
+ hints = notify_hints_new ();
+ notify_hints_set_int (hints, "x", x);
+ notify_hints_set_int (hints, "y", y);
+
+ if (msgicon)
+ {
+ GdkPixbuf *pix;
+ pix = gtk_image_get_pixbuf (GTK_IMAGE (msgicon));
+ if (pix)
+ {
+ char *tmp;
+ GError *error = NULL;
+ tmp = g_strdup_printf ("%s/.gnome2/rb-notify-icon.png", g_get_home_dir ());
+ if (gdk_pixbuf_save (pix, tmp, "png", &error, NULL))
+ {
+ icon_notify = notify_icon_new_from_uri (tmp);
+ }
+ else
+ {
+ icon_notify = NULL;
+ }
+ g_free (pix);
+ g_free (tmp);
+ }
+ }
+ else
+ {
+ fn = g_strconcat (RB_STOCK_TRAY_ICON, ".png", NULL);
+ icon_notify = notify_icon_new_from_uri (rb_file (fn));
+ g_free (fn);
+ }
+
+ if (icon->notify->handle)
+ {
+ notify_close (icon->notify->handle);
+ }
+
+ icon->notify->hints = hints;
+ icon->notify->icon = icon_notify;
+ icon->notify->handle = notify_send_notification (NULL, "transfer",
+ NOTIFY_URGENCY_LOW,
+ primary,
+ secondary,
+ icon_notify,
+ TRUE, timeout/1000,
+ hints,
+ NULL,
+ 0);
+ return;
+#else
gint x, y;
gdk_window_get_origin (GTK_WIDGET (icon)->window,
&x, &y);
@@ -494,10 +604,15 @@ egg_tray_icon_notify (EggTrayIcon *icon,
{
icon->bubble = egg_notification_bubble_new ();
egg_notification_bubble_attach (icon->bubble, GTK_WIDGET (icon));
+ g_signal_connect_object (icon->bubble,
+ "clicked",
+ G_CALLBACK (egg_tray_icon_hide_notify_cb),
+ icon, 0);
}
egg_notification_bubble_set (icon->bubble, primary,
msgicon, secondary);
egg_notification_bubble_show (icon->bubble, timeout);
- return icon->bubble;
+ return;
+#endif
}
Index: widgets/eggtrayicon.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/eggtrayicon.h,v
retrieving revision 1.3
diff -u -3 -p -u -p -r1.3 eggtrayicon.h
--- widgets/eggtrayicon.h 2 Sep 2005 01:53:09 -0000 1.3
+++ widgets/eggtrayicon.h 4 Oct 2005 03:54:10 -0000
@@ -21,11 +21,17 @@
#ifndef __EGG_TRAY_ICON_H__
#define __EGG_TRAY_ICON_H__
+#include <config.h>
+
#include <gtk/gtkplug.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
+#ifdef HAVE_NOTIFY
+#include <libnotify/notify.h>
+#else
#include "eggnotificationbubble.h"
+#endif
G_BEGIN_DECLS
@@ -38,6 +44,9 @@ G_BEGIN_DECLS
typedef struct _EggTrayIcon EggTrayIcon;
typedef struct _EggTrayIconClass EggTrayIconClass;
+#ifdef HAVE_NOTIFY
+typedef struct _Notify Notify;
+#endif
struct _EggTrayIcon
{
@@ -53,7 +62,11 @@ struct _EggTrayIcon
Window manager_window;
#endif
GtkOrientation orientation;
+#ifdef HAVE_NOTIFY
+ Notify *notify;
+#else
EggNotificationBubble *bubble;
+#endif
};
struct _EggTrayIconClass
@@ -77,12 +90,12 @@ void egg_tray_icon_cancel_messag
gboolean egg_tray_icon_have_manager (EggTrayIcon *icon);
-EggNotificationBubble *egg_tray_icon_notify (EggTrayIcon *icon,
- guint timeout,
- const char *primary,
- GtkWidget *msgicon,
- const char *secondary);
-
+void egg_tray_icon_notify (EggTrayIcon *icon,
+ guint timeout,
+ const char *primary,
+ GtkWidget *msgicon,
+ const char *secondary);
+
GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]