[gthumb] file properties view: allow to customize the attribute list
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] file properties view: allow to customize the attribute list
- Date: Sat, 7 Mar 2020 18:04:24 +0000 (UTC)
commit a4e09f27bce9008b1c3d9cbed2e1986c986cc1f3
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Mar 7 18:32:28 2020 +0100
file properties view: allow to customize the attribute list
data/gschemas/org.gnome.gthumb.gschema.xml | 3 +
data/ui/favorite-properties.ui | 30 +++++
data/ui/meson.build | 1 +
gthumb/dlg-favorite-properties.c | 176 +++++++++++++++++++++++++++++
gthumb/dlg-favorite-properties.h | 29 +++++
gthumb/gth-file-properties.c | 111 +++++++++++++++---
gthumb/gth-preferences.h | 1 +
gthumb/meson.build | 1 +
8 files changed, 334 insertions(+), 18 deletions(-)
---
diff --git a/data/gschemas/org.gnome.gthumb.gschema.xml b/data/gschemas/org.gnome.gthumb.gschema.xml
index 22aeb391..83aae7ad 100644
--- a/data/gschemas/org.gnome.gthumb.gschema.xml
+++ b/data/gschemas/org.gnome.gthumb.gschema.xml
@@ -141,6 +141,9 @@
<key name="scroll-action" enum="org.gnome.gthumb.GthScrollAction">
<default>'change-file'</default>
</key>
+ <key name="favorite-properties" type="s">
+ <default>'default'</default>
+ </key>
</schema>
<schema id="org.gnome.gthumb.dialogs" path="/org/gnome/gthumb/dialogs/">
diff --git a/data/ui/favorite-properties.ui b/data/ui/favorite-properties.ui
new file mode 100644
index 00000000..2ffe1852
--- /dev/null
+++ b/data/ui/favorite-properties.ui
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.2 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <object class="GtkBox" id="dialog_content">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkScrolledWindow" id="chooser_scrolled_window">
+ <property name="width_request">450</property>
+ <property name="height_request">450</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/data/ui/meson.build b/data/ui/meson.build
index 3429be2b..cfd593eb 100644
--- a/data/ui/meson.build
+++ b/data/ui/meson.build
@@ -1,6 +1,7 @@
ui_files = files(
'browser-preferences.ui',
'extensions-preferences.ui',
+ 'favorite-properties.ui',
'filter-editor.ui',
'histogram-info.ui',
'location.ui',
diff --git a/gthumb/dlg-favorite-properties.c b/gthumb/dlg-favorite-properties.c
new file mode 100644
index 00000000..6ab9a134
--- /dev/null
+++ b/gthumb/dlg-favorite-properties.c
@@ -0,0 +1,176 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2001-2020 The Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include "dlg-favorite-properties.h"
+#include "gth-main.h"
+#include "gth-metadata-chooser.h"
+#include "gth-preferences.h"
+#include "str-utils.h"
+
+
+#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
+
+
+typedef struct {
+ GthBrowser *browser;
+ GtkBuilder *builder;
+ GSettings *settings;
+ GtkWidget *dialog;
+ GtkWidget *metadata_chooser;
+} DialogData;
+
+
+static void
+dialog_data_free (DialogData *data)
+{
+ g_object_unref (data->builder);
+ g_object_unref (data->settings);
+ g_free (data);
+}
+
+
+static void
+destroy_cb (GtkWidget *widget,
+ DialogData *data)
+{
+ gth_browser_set_dialog (data->browser, "favorite_properties", NULL);
+ dialog_data_free (data);
+}
+
+
+static void
+cancel_button_clicked_cb (GtkWidget *widget,
+ DialogData *data)
+{
+ gtk_widget_destroy (data->dialog);
+}
+
+
+static void
+ok_button_clicked_cb (GtkWidget *widget,
+ DialogData *data)
+{
+ char *favourite_properties;
+
+ favourite_properties = gth_metadata_chooser_get_selection (GTH_METADATA_CHOOSER
(data->metadata_chooser));
+ g_settings_set_string (data->settings, PREF_BROWSER_FAVORITE_PROPERTIES, favourite_properties);
+ g_free (favourite_properties);
+
+ gtk_widget_destroy (data->dialog);
+}
+
+
+void
+dlg_favorite_properties (GthBrowser *browser)
+{
+ DialogData *data;
+ char *favourite_properties;
+
+ if (gth_browser_get_dialog (browser, "favorite_properties") != NULL) {
+ gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "favorite_properties")));
+ return;
+ }
+
+ data = g_new0 (DialogData, 1);
+ data->browser = browser;
+ data->builder = _gtk_builder_new_from_file ("favorite-properties.ui", NULL);
+ data->settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
+ data->dialog = g_object_new (GTK_TYPE_DIALOG,
+ "title", _("Preferences"),
+ "transient-for", GTK_WINDOW (browser),
+ "modal", FALSE,
+ "destroy-with-parent", FALSE,
+ "use-header-bar", _gtk_settings_get_dialogs_use_header (),
+ NULL);
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
+ _gtk_builder_get_widget (data->builder, "dialog_content"));
+ gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
+ _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
+ _GTK_LABEL_OK, GTK_RESPONSE_OK,
+ NULL);
+ _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK,
GTK_STYLE_CLASS_SUGGESTED_ACTION);
+ gtk_widget_grab_default (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog),
GTK_RESPONSE_OK));
+ gth_browser_set_dialog (browser, "favorite_properties", data->dialog);
+
+ /* TODO: set the widget data */
+
+ data->metadata_chooser = gth_metadata_chooser_new (GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW, FALSE);
+ gtk_widget_show (data->metadata_chooser);
+ gtk_container_add (GTK_CONTAINER (_gtk_builder_get_widget (data->builder,
"chooser_scrolled_window")), data->metadata_chooser);
+
+ favourite_properties = g_settings_get_string (data->settings, PREF_BROWSER_FAVORITE_PROPERTIES);
+ if (_g_str_equal (favourite_properties, "default")) {
+ GString *attributes;
+ GList *metadata_info;
+ GList *scan;
+
+ attributes = g_string_new ("");
+ metadata_info = gth_main_get_all_metadata_info ();
+ for (scan = metadata_info; scan; scan = scan->next) {
+ GthMetadataInfo *info = scan->data;
+
+ if ((info->flags & GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW) !=
GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW)
+ continue;
+
+ if (info->id == NULL)
+ continue;
+
+ if (g_str_has_prefix (info->id, "Exif"))
+ continue;
+ else if (g_str_has_prefix (info->id, "Iptc"))
+ continue;
+ else if (g_str_has_prefix (info->id, "Xmp"))
+ continue;
+
+ g_string_append (attributes, info->id);
+ g_string_append_c (attributes, ',');
+ }
+
+ gth_metadata_chooser_set_selection (GTH_METADATA_CHOOSER (data->metadata_chooser),
attributes->str);
+
+ g_string_free (attributes, TRUE);
+ }
+ else
+ gth_metadata_chooser_set_selection (GTH_METADATA_CHOOSER (data->metadata_chooser),
favourite_properties);
+
+ g_free (favourite_properties);
+
+ /* set the signals handlers. */
+
+ g_signal_connect (G_OBJECT (data->dialog),
+ "destroy",
+ G_CALLBACK (destroy_cb),
+ data);
+ g_signal_connect (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_CANCEL),
+ "clicked",
+ G_CALLBACK (cancel_button_clicked_cb),
+ data);
+ g_signal_connect (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK),
+ "clicked",
+ G_CALLBACK (ok_button_clicked_cb),
+ data);
+
+ /* run dialog. */
+
+ gtk_widget_show (data->dialog);
+}
diff --git a/gthumb/dlg-favorite-properties.h b/gthumb/dlg-favorite-properties.h
new file mode 100644
index 00000000..554b7f6e
--- /dev/null
+++ b/gthumb/dlg-favorite-properties.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2001-2020 The Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DLG_FAVORITE_PROPERTIES_H
+#define DLG_FAVORITE_PROPERTIES_H
+
+#include "gth-browser.h"
+
+void dlg_favorite_properties (GthBrowser *browser);
+
+#endif /* DLG_FAVORITE_PROPERTIES_H */
diff --git a/gthumb/gth-file-properties.c b/gthumb/gth-file-properties.c
index cfea4a2e..23277743 100644
--- a/gthumb/gth-file-properties.c
+++ b/gthumb/gth-file-properties.c
@@ -21,9 +21,11 @@
#include <config.h>
#include <glib/gi18n.h>
+#include "dlg-favorite-properties.h"
#include "glib-utils.h"
#include "gth-file-properties.h"
#include "gth-main.h"
+#include "gth-preferences.h"
#include "gth-property-view.h"
#include "gth-string-list.h"
#include "gth-time.h"
@@ -57,12 +59,16 @@ enum {
struct _GthFilePropertiesPrivate {
+ GSettings *settings;
GtkWidget *main_container;
GtkWidget *tree_view;
GtkListStore *tree_model;
GtkWidget *popup_menu;
+ GtkWidget *edit_favorites_menu_item;
gboolean show_details;
GthFileData *last_file_data;
+ GHashTable *favorites;
+ gboolean default_favorites;
};
@@ -162,29 +168,34 @@ gth_file_properties_real_set_file (GthPropertyView *base,
if ((info->flags & GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW) !=
GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW)
continue;
+ if (info->id == NULL)
+ continue;
+
value = gth_file_data_get_attribute_as_string (file_data, info->id);
if ((value == NULL) || (*value == '\0')) {
g_free (value);
continue;
}
- if (info->id != NULL) {
- if (g_str_has_prefix (info->id, "Exif")) {
- if (! self->priv->show_details)
- continue;
- }
- else if (g_str_has_prefix (info->id, "Iptc")) {
- if (! self->priv->show_details)
- continue;
- }
- else if (g_str_has_prefix (info->id, "Xmp")) {
- if (! self->priv->show_details)
- continue;
- }
- else
- if (self->priv->show_details)
- continue;
+ if (! self->priv->show_details && ! self->priv->default_favorites) {
+ if (! g_hash_table_contains (self->priv->favorites, info->id))
+ continue;
+ }
+ else if (g_str_has_prefix (info->id, "Exif")) {
+ if (! self->priv->show_details)
+ continue;
+ }
+ else if (g_str_has_prefix (info->id, "Iptc")) {
+ if (! self->priv->show_details)
+ continue;
}
+ else if (g_str_has_prefix (info->id, "Xmp")) {
+ if (! self->priv->show_details)
+ continue;
+ }
+ else
+ if (self->priv->show_details)
+ continue;
if (value != NULL) {
char *utf8_value;
@@ -263,11 +274,33 @@ gth_file_properties_finalize (GObject *base)
if (self->priv->popup_menu != NULL)
gtk_widget_destroy (self->priv->popup_menu);
_g_object_unref (self->priv->last_file_data);
+ _g_object_unref (self->priv->settings);
+ if (self->priv->favorites != NULL)
+ g_hash_table_unref (self->priv->favorites);
G_OBJECT_CLASS (gth_file_properties_parent_class)->finalize (base);
}
+static void
+update_favorites (GthFileProperties *self)
+{
+ char *favorites;
+
+ if (self->priv->show_details)
+ return;
+
+ favorites = g_settings_get_string (self->priv->settings, PREF_BROWSER_FAVORITE_PROPERTIES);
+
+ if (self->priv->favorites != NULL)
+ g_hash_table_unref (self->priv->favorites);
+ self->priv->favorites = _g_str_split_as_hash_table (favorites);
+ self->priv->default_favorites = _g_str_equal (favorites, "default");
+
+ g_free (favorites);
+}
+
+
static void
gth_file_properties_set_property (GObject *object,
guint property_id,
@@ -281,6 +314,9 @@ gth_file_properties_set_property (GObject *object,
switch (property_id) {
case PROP_SHOW_DETAILS:
self->priv->show_details = g_value_get_boolean (value);
+ update_favorites (self);
+ if (self->priv->edit_favorites_menu_item != NULL)
+ gtk_widget_set_visible (self->priv->edit_favorites_menu_item, !
self->priv->show_details);
break;
default:
break;
@@ -353,6 +389,15 @@ copy_menu_item_activate_cb (GtkMenuItem *menuitem,
}
+static void
+edit_favorites_menu_item_activate_cb (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GthFileProperties *self = user_data;
+ dlg_favorite_properties (GTH_BROWSER (_gtk_widget_get_toplevel_if_window (GTK_WIDGET (self))));
+}
+
+
static gboolean
tree_view_button_press_event_cb (GtkWidget *widget,
GdkEventButton *event,
@@ -394,6 +439,18 @@ tree_view_popup_menu_cb (GtkWidget *widget,
}
+static void
+pref_favorite_properties_changed (GSettings *settings,
+ const char *key,
+ gpointer user_data)
+{
+ GthFileProperties *self = user_data;
+
+ update_favorites (self);
+ gth_property_view_set_file (GTH_PROPERTY_VIEW (self), self->priv->last_file_data);
+}
+
+
static void
gth_file_properties_init (GthFileProperties *self)
{
@@ -405,6 +462,15 @@ gth_file_properties_init (GthFileProperties *self)
self->priv = gth_file_properties_get_instance_private (self);
self->priv->show_details = FALSE;
self->priv->last_file_data = NULL;
+ self->priv->settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
+ self->priv->favorites = NULL;
+
+ update_favorites (self);
+
+ g_signal_connect (self->priv->settings,
+ "changed::" PREF_BROWSER_FAVORITE_PROPERTIES,
+ G_CALLBACK (pref_favorite_properties_changed),
+ self);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
gtk_box_set_spacing (GTK_BOX (self), 6);
@@ -438,14 +504,23 @@ gth_file_properties_init (GthFileProperties *self)
/* popup menu */
self->priv->popup_menu = gtk_menu_new ();
+
menu_item = gtk_menu_item_new_with_label (_GTK_LABEL_COPY);
gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (self->priv->popup_menu),
- menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (self->priv->popup_menu), menu_item);
g_signal_connect (menu_item,
"activate",
G_CALLBACK (copy_menu_item_activate_cb),
self);
+
+ self->priv->edit_favorites_menu_item = menu_item = gtk_menu_item_new_with_label (_("Preferences"));
+ gtk_widget_set_visible (menu_item, ! self->priv->show_details);
+ gtk_menu_shell_append (GTK_MENU_SHELL (self->priv->popup_menu), menu_item);
+ g_signal_connect (menu_item,
+ "activate",
+ G_CALLBACK (edit_favorites_menu_item_activate_cb),
+ self);
+
g_signal_connect (self->priv->tree_view,
"button-press-event",
G_CALLBACK (tree_view_button_press_event_cb),
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index 9c3d4f09..7c7f3a13 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -81,6 +81,7 @@ G_BEGIN_DECLS
#define PREF_FULLSCREEN_THUMBNAILS_VISIBLE "fullscreen-thumbnails-visible"
#define PREF_FULLSCREEN_SIDEBAR "fullscreen-sidebar"
#define PREF_VIEWER_SCROLL_ACTION "scroll-action"
+#define PREF_BROWSER_FAVORITE_PROPERTIES "favorite-properties"
/* keys: add to catalog */
diff --git a/gthumb/meson.build b/gthumb/meson.build
index ee44adc5..64c93578 100644
--- a/gthumb/meson.build
+++ b/gthumb/meson.build
@@ -158,6 +158,7 @@ source_files = files(
'cairo-scale.c',
'cairo-utils.c',
'color-utils.c',
+ 'dlg-favorite-properties.c',
'dlg-location.c',
'dlg-personalize-filters.c',
'dlg-preferences.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]