[Xfce4-commits] <midori:master> Turn libnotify into a build-time dependency, mind notify-send

Christian Dywan noreply at xfce.org
Tue Dec 15 00:06:02 CET 2009


Updating branch refs/heads/master
         to a94cf71700a9f931844c3f86eae559296f09da64 (commit)
       from f905420967af81f55f3e7f95b4df22fc856831aa (commit)

commit a94cf71700a9f931844c3f86eae559296f09da64
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Dec 14 23:51:05 2009 +0100

    Turn libnotify into a build-time dependency, mind notify-send
    
    libnotify support is decided at build-time now, to avoid so name
    issues. notify-send is still optional at runtime as a fallback.

 midori/midori-app.c         |   89 +++++++++++--------------------------------
 midori/midori-preferences.c |   15 +++++--
 midori/wscript_build        |    2 +-
 wscript                     |   11 +++++
 4 files changed, 46 insertions(+), 71 deletions(-)

diff --git a/midori/midori-app.c b/midori/midori-app.c
index c354c91..0574259 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -40,20 +40,8 @@
     #include "socket.h"
 #endif
 
-#if !HAVE_HILDON
-typedef struct _NotifyNotification NotifyNotification;
-
-typedef struct
-{
-    gboolean            (*init)               (const gchar* app_name);
-    void                (*uninit)             (void);
-    NotifyNotification* (*notification_new)   (const gchar* summary,
-                                               const gchar* body,
-                                               const gchar* icon,
-                                               GtkWidget*   attach);
-    gboolean            (*notification_show)  (NotifyNotification* notification,
-                                               GError**            error);
-} LibNotifyFuncs;
+#if HAVE_LIBNOTIFY
+    #include <libnotify/notify.h>
 #endif
 
 struct _MidoriApp
@@ -75,10 +63,7 @@ struct _MidoriApp
     MidoriAppInstance instance;
 
     #if !HAVE_HILDON
-    /* libnotify handling */
-    gchar*         program_notify_send;
-    GModule*       libnotify_module;
-    LibNotifyFuncs libnotify_funcs;
+    gchar* program_notify_send;
     #endif
 };
 
@@ -129,9 +114,6 @@ static void
 midori_app_finalize (GObject* object);
 
 static void
-midori_app_init_libnotify (MidoriApp* app);
-
-static void
 midori_app_set_property (GObject*      object,
                          guint         prop_id,
                          const GValue* value,
@@ -722,7 +704,11 @@ midori_app_init (MidoriApp* app)
 
     app->instance = MidoriAppInstanceNull;
 
-    midori_app_init_libnotify (app);
+    #if HAVE_LIBNOTIFY
+    notify_init ("midori");
+    #endif
+
+    app->program_notify_send = g_find_program_in_path ("notify-send");
 }
 
 static void
@@ -750,14 +736,11 @@ midori_app_finalize (GObject* object)
     sock_cleanup ();
     #endif
 
-    #if !HAVE_HILDON
-    if (app->libnotify_module)
-    {
-        app->libnotify_funcs.uninit ();
-        g_module_close (app->libnotify_module);
-    }
-    katze_assign (app->program_notify_send, NULL);
+    #if HAVE_LIBNOTIFY
+    if (notify_is_initted ())
+        notify_uninit ();
     #endif
+    katze_assign (app->program_notify_send, NULL);
 
     G_OBJECT_CLASS (midori_app_parent_class)->finalize (object);
 }
@@ -1146,35 +1129,6 @@ midori_app_quit (MidoriApp* app)
     g_signal_emit (app, signals[QUIT], 0);
 }
 
-static void
-midori_app_init_libnotify (MidoriApp* app)
-{
-    #if !HAVE_HILDON
-    app->libnotify_module = g_module_open ("libnotify.so.1", G_MODULE_BIND_LOCAL);
-
-    if (app->libnotify_module != NULL)
-    {
-        g_module_symbol (app->libnotify_module, "notify_init",
-            (void*) &(app->libnotify_funcs.init));
-        g_module_symbol (app->libnotify_module, "notify_uninit",
-            (void*) &(app->libnotify_funcs.uninit));
-        g_module_symbol (app->libnotify_module, "notify_notification_new",
-            (void*) &(app->libnotify_funcs.notification_new));
-        g_module_symbol (app->libnotify_module, "notify_notification_show",
-            (void*) &(app->libnotify_funcs.notification_show));
-
-        /* init libnotify */
-        if (!app->libnotify_funcs.init || !app->libnotify_funcs.init ("midori"))
-        {
-             g_module_close (app->libnotify_module);
-             app->libnotify_module = NULL;
-        }
-    }
-
-    app->program_notify_send = g_find_program_in_path ("notify-send");
-    #endif
-}
-
 /**
  * midori_app_send_notification:
  * @app: a #MidoriApp
@@ -1193,23 +1147,26 @@ midori_app_send_notification (MidoriApp*   app,
                               const gchar* title,
                               const gchar* message)
 {
+    g_return_if_fail (MIDORI_IS_APP (app));
+    g_return_if_fail (title);
+
     #if HAVE_HILDON
     hildon_banner_show_information_with_markup (GTK_WIDGET (app->browser),
                                                 "midori", message);
     #else
     gboolean sent = FALSE;
 
-    g_return_if_fail (MIDORI_IS_APP (app));
-    g_return_if_fail (title);
-
-    if (app->libnotify_module)
+    #if HAVE_LIBNOTIFY
+    if (notify_is_initted ())
     {
-        NotifyNotification* n;
+        NotifyNotification* note;
 
-        n = app->libnotify_funcs.notification_new (title, message, "midori", NULL);
-        sent = app->libnotify_funcs.notification_show (n, NULL);
-        g_object_unref (n);
+        note = notify_notification_new (title, message, "midori", NULL);
+        sent = notify_notification_show (note, NULL);
+        g_object_unref (note);
     }
+    #endif
+
     /* Fall back to the command line program "notify-send" */
     if (!sent && app->program_notify_send)
     {
diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c
index d48e538..d1645d9 100644
--- a/midori/midori-preferences.c
+++ b/midori/midori-preferences.c
@@ -22,6 +22,10 @@
 #include <glib/gi18n.h>
 #include <libsoup/soup.h>
 
+#if HAVE_LIBNOTIFY
+    #include <libnotify/notify.h>
+#endif
+
 struct _MidoriPreferences
 {
     KatzePreferences parent_instance;
@@ -334,10 +338,13 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
     SPANNED_ADD (button);
     label = katze_property_proxy (settings, "ask-for-destination-folder", NULL);
     INDENTED_ADD (label);
-    button = katze_property_proxy (settings, "notify-transfer-completed", NULL);
-    /* FIXME: Disable the option if notifications presumably cannot be sent
-      gtk_widget_set_sensitive (button, FALSE); */
-    SPANNED_ADD (button);
+    #if HAVE_LIBNOTIFY
+    if (notify_is_initted () || g_find_program_in_path ("notify-send"))
+    {
+        button = katze_property_proxy (settings, "notify-transfer-completed", NULL);
+        SPANNED_ADD (button);
+    }
+    #endif
     #endif
 
     /* Page "Appearance" */
diff --git a/midori/wscript_build b/midori/wscript_build
index c1904ff..8948599 100644
--- a/midori/wscript_build
+++ b/midori/wscript_build
@@ -10,7 +10,7 @@ obj.target = 'midori'
 obj.includes = '. ..'
 obj.find_sources_in_dirs ('.', excludes=['main.c'])
 obj.add_marshal_file ('marshal.list', 'midori_cclosure_marshal')
-obj.uselib = 'UNIQUE LIBSOUP LIBIDN GIO GTK SQLITE WEBKIT LIBXML ' \
+obj.uselib = 'UNIQUE LIBSOUP LIBIDN GIO GTK SQLITE LIBNOTIFY WEBKIT LIBXML ' \
              'WS2_32 OPENSSL ' \
              'HILDON HILDON_FM'
 obj.uselib_local = 'katze'
diff --git a/wscript b/wscript
index a7a81ac..994b0c2 100644
--- a/wscript
+++ b/wscript
@@ -190,6 +190,15 @@ def configure (conf):
         sqlite = 'no '
     conf.define ('HAVE_SQLITE', [0,1][sqlite == 'yes'])
 
+    if option_enabled ('libnotify'):
+        check_pkg ('libnotify', mandatory=False)
+        libnotify = ['N/A','yes'][conf.env['HAVE_LIBNOTIFY'] == 1]
+        if libnotify != 'yes':
+            option_checkfatal ('libnotify', 'notifications')
+    else:
+        libnotify = 'no '
+    conf.define ('HAVE_LIBNOTIFY', [0,1][libnotify == 'yes'])
+
     conf.check (lib='m', mandatory=True)
     check_pkg ('gmodule-2.0', '2.8.0', False)
     check_pkg ('gthread-2.0', '2.8.0', False)
@@ -296,6 +305,7 @@ def configure (conf):
         Localization:        %(nls)s (intltool)
         Icon optimizations:  %(icons)s (rsvg-convert)
         Persistent history:  %(sqlite)s (sqlite3)
+        Notifications:       %(libnotify)s (libnotify)
 
         IDN support:         %(idn)s (libidn or libsoup 2.27.90)
         User documentation:  %(user_docs)s (docutils)
@@ -344,6 +354,7 @@ def set_options (opt):
     add_enable_option ('unique', 'single instance support', group)
     add_enable_option ('libidn', 'international domain name support', group)
     add_enable_option ('sqlite', 'history database support', group)
+    add_enable_option ('libnotify', 'notification support', group)
     add_enable_option ('addons', 'building of extensions', group)
     add_enable_option ('hildon', 'Maemo integration', group, disable=not is_maemo ())
 



More information about the Xfce4-commits mailing list