From b53194649eb8bb201ee5543e49b2dc4c7957be91 Mon Sep 17 00:00:00 2001
From: Colin Clark
Date: Thu, 1 Nov 2018 13:59:03 +0000
Subject: [PATCH] Eliminate FIXME: enable or disable individual plugins from
configure
Additional checkbox in Edit/Configure Plugins to prevent plugins being
displayed in the menus
---
doc/docbook/GuidePluginsConfig.xml | 8 +++
plugins/Makefile.am | 1 -
src/desktop_file.c | 96 ++++++++++++++++++++++++++++++
src/editors.c | 25 +++++++-
src/editors.h | 2 +
src/options.c | 2 +
src/options.h | 2 +
src/rcfile.c | 78 ++++++++++++++++++++++++
web/help/GuidePluginsConfig.html | 6 ++
9 files changed, 218 insertions(+), 2 deletions(-)
diff --git a/doc/docbook/GuidePluginsConfig.xml b/doc/docbook/GuidePluginsConfig.xml
index 6977b434..5b03723e 100644
--- a/doc/docbook/GuidePluginsConfig.xml
+++ b/doc/docbook/GuidePluginsConfig.xml
@@ -27,6 +27,14 @@
The list has the following columns:
+
+
+ Disabled
+
+
+ If the checkbox is ticked, the plugin will not be displayed in Geeqie menus.
+
+
Name
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 929d7dd9..b0b5d65e 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,4 +1,3 @@
-#FIXME enable or disable individual plugins from configure
SUBDIRS = rotate symlink ufraw import geocode-parameters export-jpeg tethered-photography camera-import image-crop
qq_desktoptemplatedir = $(appdir)
diff --git a/src/desktop_file.c b/src/desktop_file.c
index b3b7e21a..471ab5e8 100644
--- a/src/desktop_file.c
+++ b/src/desktop_file.c
@@ -414,6 +414,7 @@ static gint editor_list_window_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkT
{
gint n = GPOINTER_TO_INT(data);
gint ret = 0;
+ gboolean bool1, bool2;
switch (n)
{
@@ -441,6 +442,25 @@ static gint editor_list_window_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkT
g_free(s2);
}
break;
+ case DESKTOP_FILE_COLUMN_DISABLED:
+ {
+ gtk_tree_model_get(model, a, n, &bool1, -1);
+ gtk_tree_model_get(model, b, n, &bool2, -1);
+
+ if (bool1 == bool2)
+ {
+ ret = 0;
+ }
+ else if (bool1 > bool2)
+ {
+ ret = -1;
+ }
+ else
+ {
+ ret = 1;
+ }
+ break;
+ }
default:
g_return_val_if_reached(0);
@@ -449,6 +469,67 @@ static gint editor_list_window_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkT
return ret;
}
+static void plugin_disable_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data)
+{
+ EditorListWindow *ewl = data;
+ GtkTreePath *tpath;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gboolean disabled;
+ gchar *path;
+ GList *list;
+ gchar *haystack;
+
+ tpath = gtk_tree_path_new_from_string(path_str);
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view));
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
+ gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, DESKTOP_FILE_COLUMN_DISABLED, &disabled, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, DESKTOP_FILE_COLUMN_PATH, &path, -1);
+
+ gtk_list_store_set(GTK_LIST_STORE(desktop_file_list), &iter, DESKTOP_FILE_COLUMN_DISABLED, !disabled, -1);
+
+ if (!disabled)
+ {
+ options->disabled_plugins = g_list_append((options->disabled_plugins), g_strdup(path));
+ }
+ else
+ {
+ list = options->disabled_plugins;
+ while (list)
+ {
+ haystack = list->data;
+
+ if (haystack && strcmp(haystack, path) == 0)
+ {
+ g_free(haystack);
+ options->disabled_plugins = g_list_remove(options->disabled_plugins, haystack);
+ }
+
+ list = list->next;
+ }
+ }
+
+ layout_editors_reload_start();
+ layout_editors_reload_finish();
+}
+
+static void plugin_disable_set_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
+ GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
+{
+ gboolean disabled;
+
+ gtk_tree_model_get(tree_model, iter, DESKTOP_FILE_COLUMN_DISABLED, &disabled, -1);
+
+ if (disabled)
+ {
+ g_object_set(GTK_CELL_RENDERER(cell), "active", TRUE, NULL);
+ }
+ else
+ {
+ g_object_set(GTK_CELL_RENDERER(cell), "active", FALSE, NULL);
+ }
+}
+
static void editor_list_window_create(void)
{
GtkWidget *win_vbox;
@@ -531,6 +612,19 @@ static void editor_list_window_create(void)
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ewl->view), FALSE);
+ column = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(column, _("Disabled"));
+ gtk_tree_view_column_set_resizable(column, TRUE);
+
+ renderer = gtk_cell_renderer_toggle_new();
+ g_signal_connect(G_OBJECT(renderer), "toggled",
+ G_CALLBACK(plugin_disable_cb), ewl);
+ gtk_tree_view_column_pack_start(column, renderer, FALSE);
+ gtk_tree_view_column_set_cell_data_func(column, renderer, plugin_disable_set_func,
+ NULL, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->view), column);
+ gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_DISABLED);
+
column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(column, _("Name"));
gtk_tree_view_column_set_resizable(column, TRUE);
@@ -579,6 +673,8 @@ static void editor_list_window_create(void)
GINT_TO_POINTER(DESKTOP_FILE_COLUMN_NAME), NULL);
gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_PATH, editor_list_window_sort_cb,
GINT_TO_POINTER(DESKTOP_FILE_COLUMN_PATH), NULL);
+ gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_DISABLED, editor_list_window_sort_cb,
+ GINT_TO_POINTER(DESKTOP_FILE_COLUMN_DISABLED), NULL);
/* set initial sort order */
gtk_tree_sortable_set_sort_column_id(sortable, DESKTOP_FILE_COLUMN_NAME, GTK_SORT_ASCENDING);
diff --git a/src/editors.c b/src/editors.c
index 2ddc34bd..aa970acf 100644
--- a/src/editors.c
+++ b/src/editors.c
@@ -184,6 +184,8 @@ gboolean editor_read_desktop_file(const gchar *path)
gchar *try_exec;
GtkTreeIter iter;
gboolean category_geeqie = FALSE;
+ GList *work;
+ gboolean disabled;
if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */
@@ -352,9 +354,25 @@ gboolean editor_read_desktop_file(const gchar *path)
if (editor->ignored) return TRUE;
+ work = options->disabled_plugins;
+
+ disabled = FALSE;
+ while (work)
+ {
+ if (g_strcmp0(path, work->data) == 0)
+ {
+ disabled = TRUE;
+ break;
+ }
+ work = work->next;
+ }
+
+ editor->disabled = disabled;
+
gtk_list_store_append(desktop_file_list, &iter);
gtk_list_store_set(desktop_file_list, &iter,
DESKTOP_FILE_COLUMN_KEY, key,
+ DESKTOP_FILE_COLUMN_DISABLED, editor->disabled,
DESKTOP_FILE_COLUMN_NAME, editor->name,
DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden ? _("yes") : _("no"),
DESKTOP_FILE_COLUMN_WRITABLE, access_file(path, W_OK),
@@ -383,7 +401,7 @@ void editor_table_clear(void)
}
else
{
- desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
+ desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
}
if (editors)
{
@@ -470,6 +488,11 @@ static void editor_list_add_cb(gpointer key, gpointer value, gpointer data)
strcmp(editor->key, CMD_DELETE) == 0 ||
strcmp(editor->key, CMD_FOLDER) == 0) return;
+ if (editor->disabled)
+ {
+ return;
+ }
+
*listp = g_list_prepend(*listp, editor);
}
diff --git a/src/editors.h b/src/editors.h
index 508ab300..5c2811e2 100644
--- a/src/editors.h
+++ b/src/editors.h
@@ -58,6 +58,7 @@ struct _EditorDescription {
EditorFlags flags;
gboolean hidden; /* explicitly hidden, shown in configuration dialog */
gboolean ignored; /* not interesting, do not show at all */
+ gboolean disabled; /* display disabled by user */
};
#define EDITOR_ERRORS(flags) ((flags) & EDITOR_ERROR_MASK)
@@ -74,6 +75,7 @@ enum {
enum {
DESKTOP_FILE_COLUMN_KEY,
+ DESKTOP_FILE_COLUMN_DISABLED,
DESKTOP_FILE_COLUMN_NAME,
DESKTOP_FILE_COLUMN_HIDDEN,
DESKTOP_FILE_COLUMN_WRITABLE,
diff --git a/src/options.c b/src/options.c
index f8721f6e..cf9764b1 100644
--- a/src/options.c
+++ b/src/options.c
@@ -202,6 +202,8 @@ ConfOptions *init_options(ConfOptions *options)
options->printer.image_text_position = 1;
options->printer.page_text_position = 3;
+ options->disabled_plugins = NULL;
+
return options;
}
diff --git a/src/options.h b/src/options.h
index a5f52cf7..46748c23 100644
--- a/src/options.h
+++ b/src/options.h
@@ -314,6 +314,8 @@ struct _ConfOptions
} printer;
gboolean read_metadata_in_idle;
+
+ GList *disabled_plugins;
};
ConfOptions *options;
diff --git a/src/rcfile.c b/src/rcfile.c
index 41a1977d..12c5a785 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -551,6 +551,38 @@ static void write_marks_tooltips(GString *outstr, gint indent)
WRITE_NL(); WRITE_STRING("");
}
+static void write_disabled_plugins(GString *outstr, gint indent)
+{
+ GtkTreeIter iter;
+ gboolean valid;
+ gboolean disabled;
+ gchar *desktop_path;
+
+ WRITE_NL(); WRITE_STRING("");
+ indent++;
+
+ if (desktop_file_list)
+ {
+ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(desktop_file_list), &iter);
+ while (valid)
+ {
+ gtk_tree_model_get(GTK_TREE_MODEL(desktop_file_list), &iter, DESKTOP_FILE_COLUMN_DISABLED, &disabled, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(desktop_file_list), &iter, DESKTOP_FILE_COLUMN_PATH, &desktop_path, -1);
+
+ if (disabled)
+ {
+ WRITE_NL();
+ write_char_option(outstr, indent, "");
+ }
+ g_free(desktop_path);
+ valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(desktop_file_list), &iter);
+ }
+ }
+
+ indent--;
+ WRITE_NL(); WRITE_STRING("");
+}
/*
*-----------------------------------------------------------------------------
@@ -607,6 +639,9 @@ gboolean save_config_to_file(const gchar *utf8_path, ConfOptions *options)
WRITE_SEPARATOR();
write_marks_tooltips(outstr, indent);
+ WRITE_SEPARATOR();
+ write_disabled_plugins(outstr, indent);
+
WRITE_SEPARATOR();
keyword_tree_write_config(outstr, indent);
indent--;
@@ -914,6 +949,30 @@ static void options_load_marks_tooltips(GQParserData *parser_data, GMarkupParseC
}
+static void options_load_disabled_plugins(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
+{
+ gint i = GPOINTER_TO_INT(data);
+ struct {
+ gchar *path;
+ } tmp;
+
+ while (*attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+ tmp.path = NULL;
+ if (READ_CHAR_FULL("path", tmp.path))
+ {
+ options->disabled_plugins = g_list_append(options->disabled_plugins, g_strdup(tmp.path));
+ continue;
+ }
+
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+ i++;
+ options_parse_func_set_data(parser_data, GINT_TO_POINTER(i));
+}
+
/*
*-----------------------------------------------------------------------------
* xml file structure (private)
@@ -973,6 +1032,20 @@ static void options_parse_marks_tooltips(GQParserData *parser_data, GMarkupParse
}
}
+static void options_parse_disabled_plugins(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
+{
+ if (g_ascii_strcasecmp(element_name, "plugin") == 0)
+ {
+ options_load_disabled_plugins(parser_data, context, element_name, attribute_names, attribute_values, data, error);
+ options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+ }
+ else
+ {
+ log_printf("unexpected in : <%s>\n", element_name);
+ options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+ }
+}
+
static void options_parse_filter(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
{
if (g_ascii_strcasecmp(element_name, "file_type") == 0)
@@ -1053,6 +1126,11 @@ static void options_parse_global(GQParserData *parser_data, GMarkupParseContext
if (!keyword_tree) keyword_tree_new();
options_parse_func_push(parser_data, options_parse_keyword_tree, NULL, NULL);
}
+ else if (g_ascii_strcasecmp(element_name, "disabled_plugins") == 0)
+ {
+ options_load_disabled_plugins(parser_data, context, element_name, attribute_names, attribute_values, data, error);
+ options_parse_func_push(parser_data, options_parse_disabled_plugins, NULL, NULL);
+ }
else
{
log_printf("unexpected in : <%s>\n", element_name);
diff --git a/web/help/GuidePluginsConfig.html b/web/help/GuidePluginsConfig.html
index 704de5ea..f612b728 100644
--- a/web/help/GuidePluginsConfig.html
+++ b/web/help/GuidePluginsConfig.html
@@ -492,6 +492,12 @@ dd.answer div.label { float: left; }
-
+ Disabled
+
+-
+
If the checkbox is ticked, the plugin will not be displayed in Geeqie menus.
+
+-
Name
-
--
2.20.1