app: add "running" property to extension.
And connect to this property in the extension manager to allow dynamic reload when starting/stopping an extension. It doesn't work yet for extensions with plug-ins but works with other kinds of data.
This commit is contained in:
@ -35,7 +35,8 @@ enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PATH,
|
||||
PROP_WRITABLE
|
||||
PROP_WRITABLE,
|
||||
PROP_RUNNING
|
||||
};
|
||||
|
||||
struct _GimpExtensionPrivate
|
||||
@ -44,6 +45,7 @@ struct _GimpExtensionPrivate
|
||||
|
||||
AsApp *app;
|
||||
gboolean writable;
|
||||
gboolean running;
|
||||
|
||||
/* Extension metadata: directories. */
|
||||
GList *brush_paths;
|
||||
@ -69,6 +71,7 @@ static void gimp_extension_get_property (GObject *object,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gimp_extension_clean (GimpExtension *extension);
|
||||
static GList * gimp_extension_validate_paths (GimpExtension *extension,
|
||||
const gchar *paths,
|
||||
gboolean as_directories,
|
||||
@ -98,6 +101,10 @@ gimp_extension_class_init (GimpExtensionClass *klass)
|
||||
NULL, NULL, FALSE,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class, PROP_RUNNING,
|
||||
g_param_spec_boolean ("running",
|
||||
NULL, NULL, FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpExtensionPrivate));
|
||||
}
|
||||
@ -115,7 +122,7 @@ gimp_extension_finalize (GObject *object)
|
||||
{
|
||||
GimpExtension *extension = GIMP_EXTENSION (object);
|
||||
|
||||
gimp_extension_stop (extension);
|
||||
gimp_extension_clean (extension);
|
||||
|
||||
g_free (extension->p->path);
|
||||
if (extension->p->app)
|
||||
@ -141,6 +148,9 @@ gimp_extension_set_property (GObject *object,
|
||||
case PROP_WRITABLE:
|
||||
extension->p->writable = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_RUNNING:
|
||||
extension->p->running = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
@ -164,6 +174,9 @@ gimp_extension_get_property (GObject *object,
|
||||
case PROP_WRITABLE:
|
||||
g_value_set_boolean (value, extension->p->writable);
|
||||
break;
|
||||
case PROP_RUNNING:
|
||||
g_value_set_boolean (value, extension->p->running);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
@ -366,7 +379,7 @@ gimp_extension_run (GimpExtension *extension,
|
||||
g_return_val_if_fail (extension->p->app != NULL, FALSE);
|
||||
g_return_val_if_fail (error && *error == NULL, FALSE);
|
||||
|
||||
gimp_extension_stop (extension);
|
||||
gimp_extension_clean (extension);
|
||||
metadata = as_app_get_metadata (extension->p->app);
|
||||
|
||||
value = g_hash_table_lookup (metadata, "GIMP::brush-path");
|
||||
@ -425,7 +438,11 @@ gimp_extension_run (GimpExtension *extension,
|
||||
}
|
||||
|
||||
if (*error)
|
||||
gimp_extension_stop (extension);
|
||||
gimp_extension_clean (extension);
|
||||
|
||||
g_object_set (extension,
|
||||
"running", TRUE,
|
||||
NULL);
|
||||
|
||||
return (*error == NULL);
|
||||
}
|
||||
@ -433,22 +450,10 @@ gimp_extension_run (GimpExtension *extension,
|
||||
void
|
||||
gimp_extension_stop (GimpExtension *extension)
|
||||
{
|
||||
g_list_free_full (extension->p->brush_paths, g_object_unref);
|
||||
extension->p->brush_paths = NULL;
|
||||
g_list_free_full (extension->p->dynamics_paths, g_object_unref);
|
||||
extension->p->dynamics_paths = NULL;
|
||||
g_list_free_full (extension->p->mypaint_brush_paths, g_object_unref);
|
||||
extension->p->brush_paths = NULL;
|
||||
g_list_free_full (extension->p->pattern_paths, g_object_unref);
|
||||
extension->p->pattern_paths = NULL;
|
||||
g_list_free_full (extension->p->gradient_paths, g_object_unref);
|
||||
extension->p->gradient_paths = NULL;
|
||||
g_list_free_full (extension->p->palette_paths, g_object_unref);
|
||||
extension->p->palette_paths = NULL;
|
||||
g_list_free_full (extension->p->tool_preset_paths, g_object_unref);
|
||||
extension->p->tool_preset_paths = NULL;
|
||||
g_list_free_full (extension->p->plug_in_paths, g_object_unref);
|
||||
extension->p->plug_in_paths = NULL;
|
||||
gimp_extension_clean (extension);
|
||||
g_object_set (extension,
|
||||
"running", FALSE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
GList *
|
||||
@ -534,6 +539,27 @@ gimp_extension_id_cmp (GimpExtension *extension,
|
||||
return g_strcmp0 (gimp_object_get_name (extension), id);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_extension_clean (GimpExtension *extension)
|
||||
{
|
||||
g_list_free_full (extension->p->brush_paths, g_object_unref);
|
||||
extension->p->brush_paths = NULL;
|
||||
g_list_free_full (extension->p->dynamics_paths, g_object_unref);
|
||||
extension->p->dynamics_paths = NULL;
|
||||
g_list_free_full (extension->p->mypaint_brush_paths, g_object_unref);
|
||||
extension->p->brush_paths = NULL;
|
||||
g_list_free_full (extension->p->pattern_paths, g_object_unref);
|
||||
extension->p->pattern_paths = NULL;
|
||||
g_list_free_full (extension->p->gradient_paths, g_object_unref);
|
||||
extension->p->gradient_paths = NULL;
|
||||
g_list_free_full (extension->p->palette_paths, g_object_unref);
|
||||
extension->p->palette_paths = NULL;
|
||||
g_list_free_full (extension->p->tool_preset_paths, g_object_unref);
|
||||
extension->p->tool_preset_paths = NULL;
|
||||
g_list_free_full (extension->p->plug_in_paths, g_object_unref);
|
||||
extension->p->plug_in_paths = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_extension_validate_paths:
|
||||
* @extension: the #GimpExtension
|
||||
|
||||
@ -107,6 +107,10 @@ static void gimp_extension_manager_search_directory (GimpExtensionManager
|
||||
GFile *directory,
|
||||
gboolean system_dir);
|
||||
|
||||
static void gimp_extension_manager_extension_running (GimpExtension *extension,
|
||||
GParamSpec *pspec,
|
||||
GimpExtensionManager *manager);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GimpExtensionManager, gimp_extension_manager, GIMP_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
||||
gimp_extension_manager_config_iface_init))
|
||||
@ -523,6 +527,9 @@ gimp_extension_manager_initialize (GimpExtensionManager *manager)
|
||||
(GCompareFunc) g_strcmp0))
|
||||
processed_ids = g_list_prepend (processed_ids,
|
||||
g_strdup (gimp_object_get_name (list->data)));
|
||||
g_signal_connect (list->data, "notify::running",
|
||||
G_CALLBACK (gimp_extension_manager_extension_running),
|
||||
manager);
|
||||
}
|
||||
for (list = manager->p->sys_extensions; list; list = g_list_next (list))
|
||||
{
|
||||
@ -551,6 +558,9 @@ gimp_extension_manager_initialize (GimpExtensionManager *manager)
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
g_signal_connect (list->data, "notify::running",
|
||||
G_CALLBACK (gimp_extension_manager_extension_running),
|
||||
manager);
|
||||
}
|
||||
|
||||
gimp_extension_manager_refresh (manager);
|
||||
@ -807,3 +817,24 @@ gimp_extension_manager_search_directory (GimpExtensionManager *manager,
|
||||
g_object_unref (enumerator);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_extension_manager_extension_running (GimpExtension *extension,
|
||||
GParamSpec *pspec,
|
||||
GimpExtensionManager *manager)
|
||||
{
|
||||
gboolean running;
|
||||
|
||||
g_object_get (extension,
|
||||
"running", &running,
|
||||
NULL);
|
||||
if (running)
|
||||
g_hash_table_insert (manager->p->running_extensions,
|
||||
(gpointer) gimp_object_get_name (extension),
|
||||
extension);
|
||||
else
|
||||
g_hash_table_remove (manager->p->running_extensions,
|
||||
(gpointer) gimp_object_get_name (extension));
|
||||
|
||||
gimp_extension_manager_refresh (manager);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user