summaryrefslogtreecommitdiff
path: root/libcaja-private
diff options
context:
space:
mode:
authorAlexander van der Meij <[email protected]>2014-08-29 20:52:13 +0200
committerStefano Karapetsas <[email protected]>2014-10-27 11:23:51 +0100
commit451eef9b275ce006b270a3569d96e531e24dd15a (patch)
treec69beecbd84db9fc21479f4b0b5c2246c466d819 /libcaja-private
parent2ce11c50a5f7cca914af7646cae5fb6d5362b5cf (diff)
downloadcaja-451eef9b275ce006b270a3569d96e531e24dd15a.tar.bz2
caja-451eef9b275ce006b270a3569d96e531e24dd15a.tar.xz
implementation of extension interface and status management (gsoc2014)
Diffstat (limited to 'libcaja-private')
-rw-r--r--libcaja-private/Makefile.am2
-rw-r--r--libcaja-private/caja-column-utilities.c3
-rw-r--r--libcaja-private/caja-extensions.c205
-rw-r--r--libcaja-private/caja-extensions.h48
-rw-r--r--libcaja-private/caja-file.c4
-rw-r--r--libcaja-private/caja-global-preferences.c1
-rw-r--r--libcaja-private/caja-global-preferences.h5
-rw-r--r--libcaja-private/caja-module.c11
-rw-r--r--libcaja-private/caja-module.h2
-rw-r--r--libcaja-private/org.mate.caja.gschema.xml.in9
10 files changed, 280 insertions, 10 deletions
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 <eel/eel-glib-extensions.h>
#include <glib/gi18n.h>
#include <libcaja-extension/caja-column-provider.h>
+#include <libcaja-private/caja-extensions.h>
#include <libcaja-private/caja-module.h>
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 <[email protected]>
+ */
+
+#include "caja-extensions.h"
+
+#include "caja-global-preferences.h"
+#include "caja-module.h"
+
+#include <string.h>
+
+
+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 <[email protected]>
+ */
+
+#ifndef CAJA_EXTENSIONS_H
+#define CAJA_EXTENSIONS_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+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 <libcaja-extension/caja-file-info.h>
#include <libcaja-extension/caja-extension-private.h>
+#include <libcaja-private/caja-extensions.h>
+
#include <libxml/parser.h>
#include <pwd.h>
#include <stdlib.h>
@@ -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.</_description>
</key>
</schema>
+
+ <schema path="/org/mate/caja/extensions/" id="org.mate.caja.extensions" gettext-domain="caja">
+ <key type="as" name="disabled-extensions">
+ <default>[ ]</default>
+ <summary>List of extensions in disabled state.</summary>
+ <description>This list contains the extensions that are currently de-activated.</description>
+ </key>
+ </schema>
+
</schemalist>