From 73e8920c461a5403f8f0ad1e9754910c3089ef2f Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 15 Jan 2006 22:42:46 +0000 Subject: Add NetworkManager magic for connection status autodetection. Defaults to 2006-01-15 Christian Persch * configure.ac: * embed/mozilla/Makefile.am: * embed/mozilla/mozilla-embed-single.cpp: * src/Makefile.am: Add NetworkManager magic for connection status autodetection. Defaults to disabled because I'm not very happy with the libnm-glib implementation. Oh, and it may crash on startup, too. --- embed/mozilla/mozilla-embed-single.cpp | 104 ++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 7 deletions(-) (limited to 'embed/mozilla/mozilla-embed-single.cpp') diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 05cdfbf18..d542dc20c 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -1,7 +1,7 @@ /* vim:set ts=8 noet sw=8: * Copyright (C) 2000-2004 Marco Pesenti Gritti * Copyright (C) 2003 Robert Marcano - * Copyright (C) 2003, 2004 Christian Persch + * Copyright (C) 2003, 2004, 2005, 2006 Christian Persch * Copyright (C) 2005 Crispin Flowerday * * This program is free software; you can redistribute it and/or modify @@ -102,8 +102,17 @@ #include #endif /* ALLOW_PRIVATE_API */ +#ifdef HAVE_GECKO_1_8 +#include +#include "EphyUtils.h" +#endif + #include +#ifdef ENABLE_NETWORK_MANAGER +#include +#endif + #define MOZILLA_PROFILE_DIR "/mozilla" #define MOZILLA_PROFILE_NAME "epiphany" #define MOZILLA_PROFILE_FILE "prefs.js" @@ -120,6 +129,11 @@ struct MozillaEmbedSinglePrivate EphySingle *mSingleObserver; +#ifdef ENABLE_NETWORK_MANAGER + libnm_glib_ctx *nm_context; + guint nm_callback_id; +#endif + guint online : 1; }; @@ -522,6 +536,62 @@ mozilla_init_observer (MozillaEmbedSingle *single) } } +#ifdef ENABLE_NETWORK_MANAGER + +static void +network_state_cb (libnm_glib_ctx *context, + gpointer data) +{ + EphyEmbedSingle *single = EPHY_EMBED_SINGLE (data); + libnm_glib_state state; + + state = libnm_glib_get_network_state (context); + + LOG ("Network state: %d\n", state); + + switch (state) + { + case LIBNM_NO_DBUS: + case LIBNM_NO_NETWORKMANAGER: + case LIBNM_INVALID_CONTEXT: + /* do nothing */ + break; + case LIBNM_NO_NETWORK_CONNECTION: + ephy_embed_single_set_network_status (single, FALSE); + break; + case LIBNM_ACTIVE_NETWORK_CONNECTION: + ephy_embed_single_set_network_status (single, TRUE); + break; + } +} + +static void +mozilla_init_network_manager (MozillaEmbedSingle *single) +{ + MozillaEmbedSinglePrivate *priv = single->priv; + + priv->nm_context = libnm_glib_init (); + if (priv->nm_context == NULL) + { + g_warning ("Could not initialise NetworkManager, connection status will not be managed!\n"); + return; + } + + priv->nm_callback_id = libnm_glib_register_callback (priv->nm_context, + network_state_cb, + single, NULL); + if (priv->nm_callback_id == 0) + { + libnm_glib_shutdown (priv->nm_context); + priv->nm_context = NULL; + + g_warning ("Could not connect to NetworkManager, connection status will not be managed!\n"); + return; + } +} + +#endif /* ENABLE_NETWORK_MANAGER */ + static gboolean init_services (MozillaEmbedSingle *single) { @@ -544,6 +614,8 @@ init_services (MozillaEmbedSingle *single) /* Fire up the beast */ gtk_moz_embed_push_startup (); + mozilla_register_components (); + /* Until gtkmozembed does this itself */ mozilla_init_chrome (); @@ -563,10 +635,12 @@ init_services (MozillaEmbedSingle *single) mozilla_notifiers_init (); STOP_PROFILER ("Mozilla prefs notifiers") - mozilla_register_components (); - mozilla_init_observer (single); +#ifdef ENABLE_NETWORK_MANAGER + mozilla_init_network_manager (single); +#endif + return TRUE; } @@ -621,13 +695,29 @@ static void mozilla_embed_single_dispose (GObject *object) { MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (object); + MozillaEmbedSinglePrivate *priv = single->priv; + + if (priv->mSingleObserver) + { + priv->mSingleObserver->Detach (); + NS_RELEASE (priv->mSingleObserver); + priv->mSingleObserver = nsnull; + } - if (single->priv->mSingleObserver) +#ifdef ENABLE_NETWORK_MANAGER + if (priv->nm_context != NULL) { - single->priv->mSingleObserver->Detach (); - NS_RELEASE (single->priv->mSingleObserver); - single->priv->mSingleObserver = nsnull; + if (priv->nm_callback_id != 0) + { + libnm_glib_unregister_callback (priv->nm_context, + priv->nm_callback_id); + priv->nm_callback_id = 0; + } + + libnm_glib_shutdown (priv->nm_context); + priv->nm_context = NULL; } +#endif parent_class->dispose (object); } -- cgit v1.2.3