[gthumb] add to catalog: select the last used catalog by default



commit 30f7713671f42a40809724b2d3ff10d99f0127da
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Nov 18 11:42:29 2019 +0100

    add to catalog: select the last used catalog by default

 data/gschemas/meson.build                          |  1 +
 .../gschemas/org.gnome.gthumb.catalogs.gschema.xml | 27 ++++++++++++++++++
 extensions/catalogs/dlg-add-to-catalog.c           | 15 +++++++++-
 extensions/catalogs/preferences.h                  | 33 ++++++++++++++++++++++
 4 files changed, 75 insertions(+), 1 deletion(-)
---
diff --git a/data/gschemas/meson.build b/data/gschemas/meson.build
index 0cf9e5cf..7afc8c85 100644
--- a/data/gschemas/meson.build
+++ b/data/gschemas/meson.build
@@ -2,6 +2,7 @@ schemas_dir = join_paths(datadir, 'glib-2.0', 'schemas')
 
 gschema_files = files(
   'org.gnome.gthumb.gschema.xml',
+  'org.gnome.gthumb.catalogs.gschema.xml',
   'org.gnome.gthumb.change-date.gschema.xml',
   'org.gnome.gthumb.comments.gschema.xml',
   'org.gnome.gthumb.contact-sheet.gschema.xml',
diff --git a/data/gschemas/org.gnome.gthumb.catalogs.gschema.xml 
b/data/gschemas/org.gnome.gthumb.catalogs.gschema.xml
new file mode 100644
index 00000000..f9f0229b
--- /dev/null
+++ b/data/gschemas/org.gnome.gthumb.catalogs.gschema.xml
@@ -0,0 +1,27 @@
+<!--
+  gThumb
+
+  Copyright © 2019 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/>.
+-->
+<schemalist>
+
+  <schema id="org.gnome.gthumb.catalogs" path="/org/gnome/gthumb/catalogs/" gettext-domain="gthumb">
+    <key name="last-catalog" type="s">
+      <default>''</default>
+    </key>
+  </schema>
+
+</schemalist>
diff --git a/extensions/catalogs/dlg-add-to-catalog.c b/extensions/catalogs/dlg-add-to-catalog.c
index fdb6348f..742a221a 100644
--- a/extensions/catalogs/dlg-add-to-catalog.c
+++ b/extensions/catalogs/dlg-add-to-catalog.c
@@ -24,6 +24,7 @@
 #include "dlg-add-to-catalog.h"
 #include "gth-catalog.h"
 #include "gth-file-source-catalogs.h"
+#include "preferences.h"
 
 
 #define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
@@ -91,6 +92,7 @@ typedef struct {
        GthFileData   *new_library;
        gulong         file_selection_changed_event;
        guint          update_selection_event;
+       GSettings     *settings;
 } DialogData;
 
 
@@ -112,6 +114,7 @@ destroy_cb (GtkWidget  *widget,
        _g_object_unref (data->catalog_source);
        _g_object_unref (data->new_catalog);
        _g_object_unref (data->new_library);
+       _g_object_unref (data->settings);
        g_object_unref (data->builder);
        g_free (data);
 }
@@ -223,6 +226,7 @@ static void
 add_selection_to_catalog (DialogData *data,
                          gboolean    close_after_adding)
 {
+       char  *last_catalog;
        GList *items;
        GList *file_list;
 
@@ -231,6 +235,10 @@ add_selection_to_catalog (DialogData *data,
        if (data->add_data->catalog_file == NULL)
                return;
 
+       last_catalog = g_file_get_uri (data->add_data->catalog_file);
+       g_settings_set_string (data->settings, PREF_CATALOGS_LAST_CATALOG, last_catalog);
+       g_free (last_catalog);
+
        _g_object_list_unref (data->add_data->files);
        data->add_data->files = NULL;
 
@@ -654,6 +662,7 @@ dlg_add_to_catalog (GthBrowser *browser)
 {
        DialogData       *data;
        GtkTreeSelection *selection;
+       char             *last_catalog;
 
        if (gth_browser_get_dialog (browser, ADD_TO_CATALOG_DIALOG_NAME)) {
                gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, 
ADD_TO_CATALOG_DIALOG_NAME)));
@@ -664,6 +673,7 @@ dlg_add_to_catalog (GthBrowser *browser)
        data->browser = browser;
        data->builder = _gtk_builder_new_from_file ("add-to-catalog.ui", "catalogs");
        data->dialog = _gtk_builder_get_widget (data->builder, "add_to_catalog_dialog");
+       data->settings = g_settings_new (GTHUMB_CATALOGS_SCHEMA);
 
        gth_browser_set_dialog (browser, ADD_TO_CATALOG_DIALOG_NAME, data->dialog);
 
@@ -672,13 +682,16 @@ dlg_add_to_catalog (GthBrowser *browser)
        data->add_data->parent_window = data->add_data->dialog = data->dialog;
        add_data_ref (data->add_data);
 
-       data->source_tree = gth_vfs_tree_new ("catalog:///");
+       last_catalog = g_settings_get_string (data->settings, PREF_CATALOGS_LAST_CATALOG);
+       data->source_tree = gth_vfs_tree_new ("catalog:///", last_catalog);
        gtk_widget_show (data->source_tree);
        gtk_container_add (GTK_CONTAINER (GET_WIDGET ("catalog_list_scrolled_window")), data->source_tree);
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("catalogs_label")), data->source_tree);
        update_sensitivity (data);
 
+       g_free (last_catalog);
+
        /* Set the signals handlers. */
 
        g_signal_connect (G_OBJECT (data->dialog),
diff --git a/extensions/catalogs/preferences.h b/extensions/catalogs/preferences.h
new file mode 100644
index 00000000..755cf0b8
--- /dev/null
+++ b/extensions/catalogs/preferences.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 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 CATALOGS_PREFERENCES_H
+#define CATALOGS_PREFERENCES_H
+
+/* schema */
+
+#define GTHUMB_CATALOGS_SCHEMA     GTHUMB_SCHEMA ".catalogs"
+
+/* keys */
+
+#define PREF_CATALOGS_LAST_CATALOG "last-catalog"
+
+#endif /* CATALOGS_PREFERENCES_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]