Add API to extensions for deactivating and configuration
This commit is contained in:
parent
2bc42bfd8d
commit
30572a2b73
2 changed files with 96 additions and 2 deletions
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
#include "midori-extension.h"
|
#include "midori-extension.h"
|
||||||
|
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "midori-app.h"
|
#include "midori-app.h"
|
||||||
|
|
||||||
#include <katze/katze.h>
|
#include <katze/katze.h>
|
||||||
|
@ -23,6 +27,8 @@ struct _MidoriExtensionPrivate
|
||||||
gchar* description;
|
gchar* description;
|
||||||
gchar* version;
|
gchar* version;
|
||||||
gchar* authors;
|
gchar* authors;
|
||||||
|
|
||||||
|
gchar* config_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -37,6 +43,7 @@ enum
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ACTIVATE,
|
ACTIVATE,
|
||||||
|
DEACTIVATE,
|
||||||
|
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
@ -75,6 +82,17 @@ midori_extension_class_init (MidoriExtensionClass* class)
|
||||||
G_TYPE_NONE, 1,
|
G_TYPE_NONE, 1,
|
||||||
MIDORI_TYPE_APP);
|
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 = G_OBJECT_CLASS (class);
|
||||||
gobject_class->finalize = midori_extension_finalize;
|
gobject_class->finalize = midori_extension_finalize;
|
||||||
gobject_class->set_property = midori_extension_set_property;
|
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,
|
extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension,
|
||||||
MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate);
|
MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate);
|
||||||
|
|
||||||
|
extension->priv->config_dir = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -137,6 +157,8 @@ midori_extension_finalize (GObject* object)
|
||||||
katze_assign (extension->priv->description, NULL);
|
katze_assign (extension->priv->description, NULL);
|
||||||
katze_assign (extension->priv->version, NULL);
|
katze_assign (extension->priv->version, NULL);
|
||||||
katze_assign (extension->priv->authors, NULL);
|
katze_assign (extension->priv->authors, NULL);
|
||||||
|
|
||||||
|
katze_assign (extension->priv->config_dir, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -194,3 +216,69 @@ midori_extension_get_property (GObject* object,
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -48,8 +48,14 @@ struct _MidoriExtensionClass
|
||||||
GType
|
GType
|
||||||
midori_extension_get_type (void);
|
midori_extension_get_type (void);
|
||||||
|
|
||||||
/* There is no API for MidoriExtension. Please use the
|
gboolean
|
||||||
available properties and signals. */
|
midori_extension_is_prepared (MidoriExtension* extension);
|
||||||
|
|
||||||
|
void
|
||||||
|
midori_extension_deactivate (MidoriExtension* extension);
|
||||||
|
|
||||||
|
const gchar*
|
||||||
|
midori_extension_get_config_dir (MidoriExtension* extension);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue