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.
This commit is contained in:
Christian Dywan 2009-03-25 02:07:27 +01:00
parent d0a947528c
commit 164bd5b265
2 changed files with 36 additions and 8 deletions

View file

@ -15,8 +15,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include "midori-app.h"
#include <katze/katze.h> #include <katze/katze.h>
#include "sokoke.h" #include "sokoke.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -30,6 +28,7 @@ struct _MidoriExtensionPrivate
gchar* version; gchar* version;
gchar* authors; gchar* authors;
MidoriApp* app;
gboolean active; gboolean active;
gchar* config_dir; gchar* config_dir;
GList* lsettings; GList* lsettings;
@ -217,7 +216,11 @@ static void
midori_extension_activate_cb (MidoriExtension* extension, midori_extension_activate_cb (MidoriExtension* extension,
MidoriApp* app) 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 /* If a configuration directory was requested before activation we
assume we should load and save settings. This is a detail that 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); lsettings = g_list_next (lsettings);
} }
extension->priv->app = g_object_ref (app);
extension->priv->active = TRUE; extension->priv->active = TRUE;
/* FIXME: Disconnect all signal handlers */ /* FIXME: Disconnect all signal handlers */
} }
@ -289,6 +293,7 @@ midori_extension_init (MidoriExtension* extension)
extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension, extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension,
MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate); MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate);
extension->priv->app = NULL;
extension->priv->active = FALSE; extension->priv->active = FALSE;
extension->priv->config_dir = NULL; extension->priv->config_dir = NULL;
extension->priv->lsettings = NULL; extension->priv->lsettings = NULL;
@ -305,6 +310,7 @@ midori_extension_finalize (GObject* object)
{ {
MidoriExtension* extension = MIDORI_EXTENSION (object); MidoriExtension* extension = MIDORI_EXTENSION (object);
katze_object_assign (extension->priv->app, NULL);
katze_assign (extension->priv->name, NULL); katze_assign (extension->priv->name, NULL);
katze_assign (extension->priv->description, NULL); katze_assign (extension->priv->description, NULL);
katze_assign (extension->priv->version, NULL); katze_assign (extension->priv->version, NULL);
@ -417,16 +423,35 @@ midori_extension_is_active (MidoriExtension* extension)
* midori_extension_deactivate: * midori_extension_deactivate:
* @extension: a #MidoriExtension * @extension: a #MidoriExtension
* *
* Attempts to deactivate @extension in a way that the instance * Attempts to deactivate @extension.
* is actually finished irreversibly.
**/ **/
void void
midori_extension_deactivate (MidoriExtension* extension) 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); 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;
} }
/** /**

View file

@ -12,7 +12,7 @@
#ifndef __MIDORI_EXTENSION_H__ #ifndef __MIDORI_EXTENSION_H__
#define __MIDORI_EXTENSION_H__ #define __MIDORI_EXTENSION_H__
#include <glib-object.h> #include "midori-app.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -57,6 +57,9 @@ midori_extension_is_active (MidoriExtension* extension);
void void
midori_extension_deactivate (MidoriExtension* extension); midori_extension_deactivate (MidoriExtension* extension);
MidoriApp*
midori_extension_get_app (MidoriExtension* extension);
const gchar* const gchar*
midori_extension_get_config_dir (MidoriExtension* extension); midori_extension_get_config_dir (MidoriExtension* extension);