From 164bd5b265d29262a5ba3c552cbe9da916d876a2 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 25 Mar 2009 02:07:27 +0100 Subject: [PATCH] Add midori_extension_get_app and enforce a valid app We change the deactivation so that an extension is regarded as active until the 'deactivate' signal was processed. And we define that 'activate' must be called with a valid app. --- midori/midori-extension.c | 39 ++++++++++++++++++++++++++++++++------- midori/midori-extension.h | 5 ++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/midori/midori-extension.c b/midori/midori-extension.c index ce02313b..99030c34 100644 --- a/midori/midori-extension.c +++ b/midori/midori-extension.c @@ -15,8 +15,6 @@ #include #endif -#include "midori-app.h" - #include #include "sokoke.h" #include @@ -30,6 +28,7 @@ struct _MidoriExtensionPrivate gchar* version; gchar* authors; + MidoriApp* app; gboolean active; gchar* config_dir; GList* lsettings; @@ -217,7 +216,11 @@ static void midori_extension_activate_cb (MidoriExtension* extension, MidoriApp* app) { - GList* lsettings = g_list_first (extension->priv->lsettings); + GList* lsettings; + + g_return_if_fail (MIDORI_IS_APP (app)); + + lsettings = g_list_first (extension->priv->lsettings); /* If a configuration directory was requested before activation we assume we should load and save settings. This is a detail that @@ -279,6 +282,7 @@ midori_extension_activate_cb (MidoriExtension* extension, lsettings = g_list_next (lsettings); } + extension->priv->app = g_object_ref (app); extension->priv->active = TRUE; /* FIXME: Disconnect all signal handlers */ } @@ -289,6 +293,7 @@ midori_extension_init (MidoriExtension* extension) extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension, MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate); + extension->priv->app = NULL; extension->priv->active = FALSE; extension->priv->config_dir = NULL; extension->priv->lsettings = NULL; @@ -305,6 +310,7 @@ midori_extension_finalize (GObject* object) { MidoriExtension* extension = MIDORI_EXTENSION (object); + katze_object_assign (extension->priv->app, NULL); katze_assign (extension->priv->name, NULL); katze_assign (extension->priv->description, NULL); katze_assign (extension->priv->version, NULL); @@ -417,16 +423,35 @@ midori_extension_is_active (MidoriExtension* extension) * midori_extension_deactivate: * @extension: a #MidoriExtension * - * Attempts to deactivate @extension in a way that the instance - * is actually finished irreversibly. + * Attempts to deactivate @extension. **/ void midori_extension_deactivate (MidoriExtension* extension) { - g_return_if_fail (MIDORI_IS_EXTENSION (extension)); + g_return_if_fail (midori_extension_is_active (extension)); - extension->priv->active = FALSE; g_signal_emit (extension, signals[DEACTIVATE], 0); + extension->priv->active = FALSE; + katze_object_assign (extension->priv->app, NULL); +} + +/** + * midori_extension_get_app: + * @extension: a #MidoriExtension + * + * Retrieves the #MidoriApp the extension belongs to. The + * extension has to be active. + * + * Return value: the #MidoriApp instance + * + * Since 0.1.6 + **/ +MidoriApp* +midori_extension_get_app (MidoriExtension* extension) +{ + g_return_val_if_fail (midori_extension_is_active (extension), NULL); + + return extension->priv->app; } /** diff --git a/midori/midori-extension.h b/midori/midori-extension.h index 3cab6ba6..1125d4cb 100644 --- a/midori/midori-extension.h +++ b/midori/midori-extension.h @@ -12,7 +12,7 @@ #ifndef __MIDORI_EXTENSION_H__ #define __MIDORI_EXTENSION_H__ -#include +#include "midori-app.h" G_BEGIN_DECLS @@ -57,6 +57,9 @@ midori_extension_is_active (MidoriExtension* extension); void midori_extension_deactivate (MidoriExtension* extension); +MidoriApp* +midori_extension_get_app (MidoriExtension* extension); + const gchar* midori_extension_get_config_dir (MidoriExtension* extension);