From 30572a2b73eb102c041d4e239e51e599c1b6dc27 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Fri, 28 Nov 2008 23:56:30 +0100 Subject: [PATCH] Add API to extensions for deactivating and configuration --- midori/midori-extension.c | 88 +++++++++++++++++++++++++++++++++++++++ midori/midori-extension.h | 10 ++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/midori/midori-extension.c b/midori/midori-extension.c index 553292bd..3aadeebb 100644 --- a/midori/midori-extension.c +++ b/midori/midori-extension.c @@ -11,6 +11,10 @@ #include "midori-extension.h" +#if HAVE_CONFIG_H + #include +#endif + #include "midori-app.h" #include @@ -23,6 +27,8 @@ struct _MidoriExtensionPrivate gchar* description; gchar* version; gchar* authors; + + gchar* config_dir; }; enum @@ -37,6 +43,7 @@ enum enum { ACTIVATE, + DEACTIVATE, LAST_SIGNAL }; @@ -75,6 +82,17 @@ midori_extension_class_init (MidoriExtensionClass* class) G_TYPE_NONE, 1, MIDORI_TYPE_APP); + signals[DEACTIVATE] = g_signal_new ( + "deactivate", + G_TYPE_FROM_CLASS (class), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + 0, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0, + G_TYPE_NONE); + gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = midori_extension_finalize; gobject_class->set_property = midori_extension_set_property; @@ -126,6 +144,8 @@ midori_extension_init (MidoriExtension* extension) { extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension, MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate); + + extension->priv->config_dir = NULL; } static void @@ -137,6 +157,8 @@ midori_extension_finalize (GObject* object) katze_assign (extension->priv->description, NULL); katze_assign (extension->priv->version, NULL); katze_assign (extension->priv->authors, NULL); + + katze_assign (extension->priv->config_dir, NULL); } static void @@ -194,3 +216,69 @@ midori_extension_get_property (GObject* object, break; } } + +/** + * midori_extension_is_prepared: + * @extension: a #MidoriExtension + * + * Determines if @extension is prepared for use, for instance + * by ensuring that all required values are set and that it + * is actually activatable. + * + * Return value: %TRUE if @extension is ready for use + **/ +gboolean +midori_extension_is_prepared (MidoriExtension* extension) +{ + g_return_val_if_fail (MIDORI_IS_EXTENSION (extension), FALSE); + + if (extension->priv->name && extension->priv->description + && extension->priv->version && extension->priv->authors + && g_signal_has_handler_pending (extension, signals[ACTIVATE], 0, FALSE)) + return TRUE; + return FALSE; +} + +/** + * midori_extension_deactivate: + * @extension: a #MidoriExtension + * + * Attempts to deactivate @extension in a way that the instance + * is actually finished irreversibly. + **/ +void +midori_extension_deactivate (MidoriExtension* extension) +{ + g_return_if_fail (MIDORI_IS_EXTENSION (extension)); + + g_signal_emit (extension, signals[DEACTIVATE], 0); + g_signal_handlers_destroy (extension); + g_object_run_dispose (G_OBJECT (extension)); +} + +/** + * midori_extension_get_config_dir: + * @extension: a #MidoriExtension + * + * Retrieves the path to a directory reserved for configuration + * files specific to the extension. For that purpose the 'name' + * of the extension is actually part of the path. + * + * The path is actually created if it doesn't already exist. + * + * Return value: a path, such as ~/.config/midori/extensions/name + **/ +const gchar* +midori_extension_get_config_dir (MidoriExtension* extension) +{ + g_return_val_if_fail (MIDORI_IS_EXTENSION (extension), NULL); + g_return_val_if_fail (midori_extension_is_prepared (extension), NULL); + + if (!extension->priv->config_dir) + extension->priv->config_dir = g_build_filename ( + g_get_user_config_dir (), PACKAGE_NAME, "extensions", + extension->priv->name, NULL); + + g_mkdir_with_parents (extension->priv->config_dir, 0700); + return extension->priv->config_dir; +} diff --git a/midori/midori-extension.h b/midori/midori-extension.h index 7bf9e2f6..7f13d5de 100644 --- a/midori/midori-extension.h +++ b/midori/midori-extension.h @@ -48,8 +48,14 @@ struct _MidoriExtensionClass GType midori_extension_get_type (void); -/* There is no API for MidoriExtension. Please use the - available properties and signals. */ +gboolean +midori_extension_is_prepared (MidoriExtension* extension); + +void +midori_extension_deactivate (MidoriExtension* extension); + +const gchar* +midori_extension_get_config_dir (MidoriExtension* extension); G_END_DECLS -- 2.39.5