[gthumb] metadata chooser: added property to allow reordering
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] metadata chooser: added property to allow reordering
- Date: Sat, 7 Mar 2020 18:04:19 +0000 (UTC)
commit d0cd557ac3d139f7da1032c8b89e31c21c2d9cdf
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Mar 7 18:31:34 2020 +0100
metadata chooser: added property to allow reordering
extensions/contact_sheet/dlg-contact-sheet.c | 2 +-
extensions/image_print/gth-image-print-job.c | 2 +-
extensions/webalbums/dlg-web-exporter.c | 4 +-
gthumb/dlg-preferences-browser.c | 2 +-
gthumb/gth-metadata-chooser.c | 159 ++++++++++++++++++++-------
gthumb/gth-metadata-chooser.h | 4 +-
6 files changed, 130 insertions(+), 43 deletions(-)
---
diff --git a/extensions/contact_sheet/dlg-contact-sheet.c b/extensions/contact_sheet/dlg-contact-sheet.c
index 3752214a..877d14c0 100644
--- a/extensions/contact_sheet/dlg-contact-sheet.c
+++ b/extensions/contact_sheet/dlg-contact-sheet.c
@@ -724,7 +724,7 @@ dlg_contact_sheet (GthBrowser *browser,
gth_browser_set_dialog (browser, "contact_sheet", data->dialog);
g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data);
- data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PRINT);
+ data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PRINT, TRUE);
gtk_widget_show (data->thumbnail_caption_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("thumbnail_caption_scrolledwindow")),
data->thumbnail_caption_chooser);
diff --git a/extensions/image_print/gth-image-print-job.c b/extensions/image_print/gth-image-print-job.c
index 11b99684..71f25028 100644
--- a/extensions/image_print/gth-image-print-job.c
+++ b/extensions/image_print/gth-image-print-job.c
@@ -1420,7 +1420,7 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
GthImagePrintJob *self = user_data;
self->priv->builder = _gtk_builder_new_from_file ("print-layout.ui", "image_print");
- self->priv->caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PRINT);
+ self->priv->caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PRINT, TRUE);
gtk_widget_show (self->priv->caption_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("caption_scrolledwindow")),
self->priv->caption_chooser);
diff --git a/extensions/webalbums/dlg-web-exporter.c b/extensions/webalbums/dlg-web-exporter.c
index 17f92f6d..6cee34f7 100644
--- a/extensions/webalbums/dlg-web-exporter.c
+++ b/extensions/webalbums/dlg-web-exporter.c
@@ -393,11 +393,11 @@ dlg_web_exporter (GthBrowser *browser,
gth_browser_set_dialog (browser, "web_exporter", data->dialog);
g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data);
- data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_FILE_LIST);
+ data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_FILE_LIST, TRUE);
gtk_widget_show (data->thumbnail_caption_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("thumbnail_caption_scrolledwindow")),
data->thumbnail_caption_chooser);
- data->image_attributes_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW);
+ data->image_attributes_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW,
TRUE);
gtk_widget_show (data->image_attributes_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("image_caption_scrolledwindow")),
data->image_attributes_chooser);
diff --git a/gthumb/dlg-preferences-browser.c b/gthumb/dlg-preferences-browser.c
index bd0228f5..55e9cca4 100644
--- a/gthumb/dlg-preferences-browser.c
+++ b/gthumb/dlg-preferences-browser.c
@@ -131,7 +131,7 @@ browser__dlg_preferences_construct_cb (GtkWidget *dialog,
/* caption list */
- data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_FILE_LIST);
+ data->thumbnail_caption_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_FILE_LIST, TRUE);
gtk_widget_show (data->thumbnail_caption_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("caption_scrolledwindow")),
data->thumbnail_caption_chooser);
diff --git a/gthumb/gth-metadata-chooser.c b/gthumb/gth-metadata-chooser.c
index c03a500c..4b9a9a5e 100644
--- a/gthumb/gth-metadata-chooser.c
+++ b/gthumb/gth-metadata-chooser.c
@@ -42,6 +42,12 @@ enum {
};
+/* Properties */
+enum {
+ PROP_0,
+ PROP_REORDERABLE
+};
+
/* Signals */
enum {
CHANGED,
@@ -51,6 +57,7 @@ enum {
struct _GthMetadataChooserPrivate {
GthMetadataFlags allowed_flags;
+ gboolean reorderable;
gulong row_inserted_event;
gulong row_deleted_event;
guint changed_id;
@@ -66,9 +73,67 @@ G_DEFINE_TYPE_WITH_CODE (GthMetadataChooser,
G_ADD_PRIVATE (GthMetadataChooser))
+
+static void
+ggth_metadata_chooser_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GthMetadataChooser *self;
+
+ self = GTH_METADATA_CHOOSER (object);
+
+ switch (property_id) {
+ case PROP_REORDERABLE:
+ self->priv->reorderable = g_value_get_boolean (value);
+ break;
+ default:
+ break;
+ }
+}
+
+
+static void
+gth_metadata_chooser_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GthMetadataChooser *self;
+
+ self = GTH_METADATA_CHOOSER (object);
+
+ switch (property_id) {
+ case PROP_REORDERABLE:
+ g_value_set_boolean (value, self->priv->reorderable);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
static void
gth_metadata_chooser_class_init (GthMetadataChooserClass *klass)
{
+ GObjectClass *object_class;
+
+ object_class = (GObjectClass*) klass;
+ object_class->set_property = ggth_metadata_chooser_set_property;
+ object_class->get_property = gth_metadata_chooser_get_property;
+
+ /* properties */
+
+ g_object_class_install_property (object_class,
+ PROP_REORDERABLE,
+ g_param_spec_boolean ("reorderable",
+ "Reorderable",
+ "Whether the user can reorder the list",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
/* signals */
gth_metadata_chooser_signals[CHANGED] =
@@ -107,10 +172,23 @@ item_data_free (ItemData *item_data)
static int
item_data_compare_func (gconstpointer a,
- gconstpointer b)
+ gconstpointer b,
+ gpointer user_data)
{
- ItemData *item_a = (ItemData *) a;
- ItemData *item_b = (ItemData *) b;
+ GthMetadataChooser *self = user_data;
+ ItemData *item_a = (ItemData *) a;
+ ItemData *item_b = (ItemData *) b;
+
+ if (! self->priv->reorderable) {
+ if (item_a->sort_order < item_b->sort_order)
+ return -1;
+ else if (item_a->sort_order > item_b->sort_order)
+ return 1;
+ else
+ return g_strcmp0 (item_a->id, item_b->id);
+ }
+
+ /* self->priv->reorderable == TRUE */
if (item_a->separator) {
if (item_b->used)
@@ -186,7 +264,7 @@ gth_metadata_chooser_reorder_list (GthMetadataChooser *self)
}
while (gtk_tree_model_iter_next (model, &iter));
- list = g_list_sort (list, item_data_compare_func);
+ list = g_list_sort_with_data (list, item_data_compare_func, self);
new_order = g_new (int, g_list_length (list));
for (pos = 0, scan = list; scan; pos++, scan = scan->next) {
ItemData *item_data = scan->data;
@@ -315,7 +393,7 @@ gth_metadata_chooser_init (GthMetadataChooser *self)
G_TYPE_BOOLEAN);
gtk_tree_view_set_model (GTK_TREE_VIEW (self), GTK_TREE_MODEL (store));
g_object_unref (store);
- gtk_tree_view_set_reorderable (GTK_TREE_VIEW (self), TRUE);
+ gtk_tree_view_set_reorderable (GTK_TREE_VIEW (self), self->priv->reorderable);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (self), FALSE);
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (self),
row_separator_func,
@@ -361,11 +439,12 @@ gth_metadata_chooser_init (GthMetadataChooser *self)
GtkWidget *
-gth_metadata_chooser_new (GthMetadataFlags allowed_flags)
+gth_metadata_chooser_new (GthMetadataFlags allowed_flags,
+ gboolean reorderable)
{
GthMetadataChooser *self;
- self = g_object_new (GTH_TYPE_METADATA_CHOOSER, NULL);
+ self = g_object_new (GTH_TYPE_METADATA_CHOOSER, "reorderable", reorderable, NULL);
self->priv->allowed_flags = allowed_flags;
gth_metadata_chooser_set_selection (self, "");
@@ -393,51 +472,57 @@ gth_metadata_chooser_set_selection (GthMetadataChooser *self,
attributes_v = gth_main_get_metadata_attributes ("*");
ids_v = g_strsplit (ids, ",", -1);
- for (i = 0; ids_v[i] != NULL; i++) {
- int idx;
- GthMetadataInfo *info;
- const char *name;
- GthMetadataCategory *category;
- idx = _g_strv_find (attributes_v, ids_v[i]);
- if (idx < 0)
- continue;
+ if (self->priv->reorderable) {
+ for (i = 0; ids_v[i] != NULL; i++) {
+ int idx;
+ GthMetadataInfo *info;
+ const char *name;
+ GthMetadataCategory *category;
- info = gth_main_get_metadata_info (attributes_v[idx]);
- if ((info == NULL) || ((info->flags & self->priv->allowed_flags) == 0))
- continue;
+ idx = _g_strv_find (attributes_v, ids_v[i]);
+ if (idx < 0)
+ continue;
- name = info->display_name;
- if (name == NULL)
- name = info->id;
+ info = gth_main_get_metadata_info (attributes_v[idx]);
+ if ((info == NULL) || ((info->flags & self->priv->allowed_flags) == 0))
+ continue;
- category = gth_main_get_metadata_category (info->category);
+ if (info->display_name != NULL)
+ name = _(info->display_name);
+ else
+ name = info->id;
+
+ category = gth_main_get_metadata_category (info->category);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ WEIGHT_COLUMN, PANGO_WEIGHT_NORMAL,
+ NAME_COLUMN, name,
+ ID_COLUMN, info->id,
+ SORT_ORDER_COLUMN, (category->sort_order * CATEGORY_SIZE) +
info->sort_order,
+ USED_COLUMN, TRUE,
+ SEPARATOR_COLUMN, FALSE,
+ IS_METADATA_COLUMN, TRUE,
+ -1);
+ }
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
- WEIGHT_COLUMN, PANGO_WEIGHT_NORMAL,
- NAME_COLUMN, _(name),
- ID_COLUMN, info->id,
- SORT_ORDER_COLUMN, (category->sort_order * CATEGORY_SIZE) +
info->sort_order,
- USED_COLUMN, TRUE,
- SEPARATOR_COLUMN, FALSE,
- IS_METADATA_COLUMN, TRUE,
- -1);
+ SEPARATOR_COLUMN, TRUE,
+ -1);
}
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- SEPARATOR_COLUMN, TRUE,
- -1);
-
category_root = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
for (i = 0; attributes_v[i] != NULL; i++) {
+ gboolean used;
GtkTreeIter iter;
GthMetadataInfo *info;
const char *name;
GthMetadataCategory *category;
- if (_g_strv_find (ids_v, attributes_v[i]) >= 0)
+ used = _g_strv_find (ids_v, attributes_v[i]) >= 0;
+ if (self->priv->reorderable && used)
continue;
info = gth_main_get_metadata_info (attributes_v[i]);
@@ -471,7 +556,7 @@ gth_metadata_chooser_set_selection (GthMetadataChooser *self,
NAME_COLUMN, _(name),
ID_COLUMN, info->id,
SORT_ORDER_COLUMN, (category->sort_order * CATEGORY_SIZE) +
info->sort_order,
- USED_COLUMN, FALSE,
+ USED_COLUMN, used,
SEPARATOR_COLUMN, FALSE,
IS_METADATA_COLUMN, TRUE,
-1);
diff --git a/gthumb/gth-metadata-chooser.h b/gthumb/gth-metadata-chooser.h
index d09f4f98..4279c09f 100644
--- a/gthumb/gth-metadata-chooser.h
+++ b/gthumb/gth-metadata-chooser.h
@@ -23,6 +23,7 @@
#define GTH_METADATA_CHOOSER_H
#include <gtk/gtk.h>
+#include "gth-metadata.h"
G_BEGIN_DECLS
@@ -51,7 +52,8 @@ struct _GthMetadataChooserClass {
};
GType gth_metadata_chooser_get_type (void);
-GtkWidget * gth_metadata_chooser_new (GthMetadataFlags allowed_flags);
+GtkWidget * gth_metadata_chooser_new (GthMetadataFlags allowed_flags,
+ gboolean reorderable);
void gth_metadata_chooser_set_selection (GthMetadataChooser *self,
char *ids);
char * gth_metadata_chooser_get_selection (GthMetadataChooser *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]