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.
This commit is contained in:
Christian Dywan 2009-12-14 23:51:05 +01:00
parent f905420967
commit a94cf71700
4 changed files with 46 additions and 71 deletions

View file

@ -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
};
@ -128,9 +113,6 @@ static guint signals[LAST_SIGNAL];
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,
@ -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)
{

View file

@ -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" */

View file

@ -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'

11
wscript
View file

@ -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 ())