From 451eef9b275ce006b270a3569d96e531e24dd15a Mon Sep 17 00:00:00 2001 From: Alexander van der Meij Date: Fri, 29 Aug 2014 20:52:13 +0200 Subject: implementation of extension interface and status management (gsoc2014) --- libcaja-private/Makefile.am | 2 + libcaja-private/caja-column-utilities.c | 3 +- libcaja-private/caja-extensions.c | 205 +++++++++++++++++++++++++++ libcaja-private/caja-extensions.h | 48 +++++++ libcaja-private/caja-file.c | 4 +- libcaja-private/caja-global-preferences.c | 1 + libcaja-private/caja-global-preferences.h | 5 +- libcaja-private/caja-module.c | 11 +- libcaja-private/caja-module.h | 2 +- libcaja-private/org.mate.caja.gschema.xml.in | 9 ++ 10 files changed, 280 insertions(+), 10 deletions(-) create mode 100644 libcaja-private/caja-extensions.c create mode 100644 libcaja-private/caja-extensions.h (limited to 'libcaja-private') diff --git a/libcaja-private/Makefile.am b/libcaja-private/Makefile.am index b3bffb2f..4e7b10f9 100644 --- a/libcaja-private/Makefile.am +++ b/libcaja-private/Makefile.am @@ -85,6 +85,8 @@ libcaja_private_la_SOURCES = \ caja-dnd.h \ caja-emblem-utils.c \ caja-emblem-utils.h \ + caja-extensions.c \ + caja-extensions.h \ caja-entry.c \ caja-entry.h \ caja-file-attributes.h \ diff --git a/libcaja-private/caja-column-utilities.c b/libcaja-private/caja-column-utilities.c index 1ba570df..49b022c8 100644 --- a/libcaja-private/caja-column-utilities.c +++ b/libcaja-private/caja-column-utilities.c @@ -29,6 +29,7 @@ #include #include #include +#include #include static GList * @@ -140,7 +141,7 @@ get_extension_columns (void) GList *providers; GList *l; - providers = caja_module_get_extensions_for_type (CAJA_TYPE_COLUMN_PROVIDER); + providers = caja_extensions_get_for_type (CAJA_TYPE_COLUMN_PROVIDER); columns = NULL; diff --git a/libcaja-private/caja-extensions.c b/libcaja-private/caja-extensions.c new file mode 100644 index 00000000..b15923fd --- /dev/null +++ b/libcaja-private/caja-extensions.c @@ -0,0 +1,205 @@ +/* + * caja-extension.c - extension management functions + * + * Copyright (C) 2014 MATE Desktop. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Author: Alexander van der Meij + */ + +#include "caja-extensions.h" + +#include "caja-global-preferences.h" +#include "caja-module.h" + +#include + + +static GList *caja_extensions = NULL; + + +Extension * +extension_new (gchar *filename, gboolean state, GObject *module) +{ + Extension *ext; + + ext = g_new0 (Extension, 1); + ext->filename = filename; + ext->state = state; + ext->module = module; + return ext; +} + +/* functions related to persistent configuration through gsettings: */ + +static gboolean +gsettings_key_has_value (const gchar *value) +{ + gchar **list; + gint i; + + list = g_settings_get_strv (caja_extension_preferences, + CAJA_PREFERENCES_DISABLED_EXTENSIONS); + + if (list != NULL) + { + for (i = 0; list[i]; i++) + { + if (g_ascii_strcasecmp (value, list[i]) == 0) + { + g_strfreev (list); + return TRUE; + } + } + } + g_strfreev (list); + return FALSE; +} + +static gboolean +gsettings_append_to_list (const char *value) +{ + gchar **current; + gchar **new; + gint size; + gboolean retval; + + current = g_settings_get_strv (caja_extension_preferences, + CAJA_PREFERENCES_DISABLED_EXTENSIONS); + + for (size = 0; current[size] != NULL; size++); + + size += 1; + size += 1; + + new = g_realloc_n (current, size, sizeof (gchar *)); + + new[size - 2] = g_strdup (value); + new[size - 1] = NULL; + + retval = g_settings_set_strv (caja_extension_preferences, + CAJA_PREFERENCES_DISABLED_EXTENSIONS, + (const gchar **) new); + + g_strfreev (new); + return retval; +} + +static gboolean +gsettings_remove_from_list (const char *value) +{ + gchar **current; + GArray *array; + gint i; + gboolean retval; + + current = g_settings_get_strv (caja_extension_preferences, + CAJA_PREFERENCES_DISABLED_EXTENSIONS); + + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); + + for (i = 0; current[i] != NULL; i++) + { + if (g_strcmp0 (current[i], value) != 0) + array = g_array_append_val (array, current[i]); + } + + retval = g_settings_set_strv (caja_extension_preferences, + CAJA_PREFERENCES_DISABLED_EXTENSIONS, + (const gchar **) array->data); + + g_strfreev (current); + g_array_free (array, TRUE); + return retval; +} + +/* functions related to the extension management */ + +static gboolean +caja_extension_is_disabled (const gchar *extname) +{ + if (gsettings_key_has_value (extname)) + { + return TRUE; + } + return FALSE; +} + +GList * +caja_extensions_get_for_type (GType type) +{ + GList *l; + GList *ret = NULL; + + for (l = caja_extensions; l != NULL; l = l->next) + { + Extension *ext = l->data; + if (ext->state) // only load enabled extensions + { + if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (ext->module), type)) + { + g_object_ref (ext->module); + ret = g_list_prepend (ret, ext->module); + } + } + } + g_list_free (l); + return ret; +} + +GList * +caja_extensions_get_list (void) +{ + return caja_extensions; +} + +void +caja_extension_register (gchar *filename, GObject *module) +{ + gboolean state = TRUE; // new extensions are enabled by default. + gchar *extname; + + extname = g_strndup (filename, strlen(filename) - 3); + + if (caja_extension_is_disabled (extname)) + state = FALSE; + + Extension *ext = extension_new (extname, state, module); + caja_extensions = g_list_append (caja_extensions, ext); +} + +gboolean +caja_extension_set_state (Extension *ext, gboolean new_state) +{ + if (ext) + { + g_return_val_if_fail (ext->state != new_state, FALSE); + ext->state = new_state; + } + + gboolean retval; + if (new_state) { + retval = gsettings_remove_from_list (ext->filename); + } + else { + retval = gsettings_append_to_list (ext->filename); + } + + g_return_val_if_fail (retval == TRUE, FALSE); + return TRUE; +} + diff --git a/libcaja-private/caja-extensions.h b/libcaja-private/caja-extensions.h new file mode 100644 index 00000000..35d0a50e --- /dev/null +++ b/libcaja-private/caja-extensions.h @@ -0,0 +1,48 @@ +/* + * caja-extension.c - extension management functions + * + * Copyright (C) 2014 MATE Desktop. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Author: Alexander van der Meij + */ + +#ifndef CAJA_EXTENSIONS_H +#define CAJA_EXTENSIONS_H + +#include +#include + +typedef struct _Extension { + gchar *filename; + gboolean state; + GObject *module; +}Extension; + +#define EXTENSION(x) ((Extension*)x) + +void caja_extension_register (gchar *filename, GObject *module); + +void caja_extensions_setup (void); +GList *caja_extensions_get_list (void); +GList *caja_extensions_get_for_type (GType type); + + + + +#endif // CAJA_EXTENSIONS_H + diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c index 3e642391..d80629e2 100644 --- a/libcaja-private/caja-file.c +++ b/libcaja-private/caja-file.c @@ -62,6 +62,8 @@ #include #include +#include + #include #include #include @@ -7586,7 +7588,7 @@ caja_file_invalidate_extension_info_internal (CajaFile *file) g_list_free_full (file->details->pending_info_providers, g_object_unref); file->details->pending_info_providers = - caja_module_get_extensions_for_type (CAJA_TYPE_INFO_PROVIDER); + caja_extensions_get_for_type (CAJA_TYPE_INFO_PROVIDER); } void diff --git a/libcaja-private/caja-global-preferences.c b/libcaja-private/caja-global-preferences.c index f66dc95f..98f44e80 100644 --- a/libcaja-private/caja-global-preferences.c +++ b/libcaja-private/caja-global-preferences.c @@ -83,6 +83,7 @@ caja_global_preferences_init (void) caja_desktop_preferences = g_settings_new("org.mate.caja.desktop"); caja_tree_sidebar_preferences = g_settings_new("org.mate.caja.sidebar-panels.tree"); caja_list_view_preferences = g_settings_new("org.mate.caja.list-view"); + caja_extension_preferences = g_settings_new("org.mate.caja.extensions"); mate_background_preferences = g_settings_new("org.mate.background"); mate_lockdown_preferences = g_settings_new("org.mate.lockdown"); diff --git a/libcaja-private/caja-global-preferences.h b/libcaja-private/caja-global-preferences.h index ee76abb8..d97c7225 100644 --- a/libcaja-private/caja-global-preferences.h +++ b/libcaja-private/caja-global-preferences.h @@ -202,10 +202,8 @@ typedef enum #define CAJA_PREFERENCES_DESKTOP_VOLUMES_VISIBLE "volumes-visible" #define CAJA_PREFERENCES_DESKTOP_NETWORK_VISIBLE "network-icon-visible" #define CAJA_PREFERENCES_DESKTOP_NETWORK_NAME "network-icon-name" - - /* Lockdown */ #define CAJA_PREFERENCES_LOCKDOWN_COMMAND_LINE "disable-command-line" - +#define CAJA_PREFERENCES_DISABLED_EXTENSIONS "disabled-extensions" void caja_global_preferences_init (void); char *caja_global_preferences_get_default_folder_viewer_preference_as_iid (void); @@ -218,6 +216,7 @@ GSettings *caja_desktop_preferences; GSettings *caja_tree_sidebar_preferences; GSettings *caja_compact_view_preferences; GSettings *caja_list_view_preferences; +GSettings *caja_extension_preferences; GSettings *mate_background_preferences; GSettings *mate_lockdown_preferences; diff --git a/libcaja-private/caja-module.c b/libcaja-private/caja-module.c index b24dc053..07951498 100644 --- a/libcaja-private/caja-module.c +++ b/libcaja-private/caja-module.c @@ -152,6 +152,7 @@ module_object_weak_notify (gpointer user_data, GObject *object) static void add_module_objects (CajaModule *module) { + GObject *object; const GType *types; int num_types; int i; @@ -164,8 +165,10 @@ add_module_objects (CajaModule *module) { break; } - caja_module_add_type (types[i]); + object = caja_module_add_type (types[i]); } + gchar *filename = g_path_get_basename (module->path); + caja_extension_register (filename, object); } static CajaModule * @@ -210,10 +213,8 @@ load_module_dir (const char *dirname) name, NULL); caja_module_load_file (filename); - g_free (filename); } } - g_dir_close (dir); } } @@ -236,6 +237,7 @@ void caja_module_setup (void) { static gboolean initialized = FALSE; + GList *res; if (!initialized) { @@ -279,7 +281,7 @@ caja_module_extension_list_free (GList *extensions) g_list_free (extensions); } -void +GObject * caja_module_add_type (GType type) { GObject *object; @@ -290,4 +292,5 @@ caja_module_add_type (GType type) NULL); module_objects = g_list_prepend (module_objects, object); + return object; } diff --git a/libcaja-private/caja-module.h b/libcaja-private/caja-module.h index b89cbf34..c02ad17a 100644 --- a/libcaja-private/caja-module.h +++ b/libcaja-private/caja-module.h @@ -37,7 +37,7 @@ extern "C" { /* Add a type to the module interface - allows caja to add its own modules * without putting them in separate shared libraries */ - void caja_module_add_type (GType type); + GObject *caja_module_add_type (GType type); #ifdef __cplusplus } diff --git a/libcaja-private/org.mate.caja.gschema.xml.in b/libcaja-private/org.mate.caja.gschema.xml.in index 1cf7fa0e..8aef7ade 100644 --- a/libcaja-private/org.mate.caja.gschema.xml.in +++ b/libcaja-private/org.mate.caja.gschema.xml.in @@ -457,4 +457,13 @@ <_description>The side pane view to show in newly opened windows. + + + + [ ] + List of extensions in disabled state. + This list contains the extensions that are currently de-activated. + + + -- cgit v1.2.1