[gthumb] moved the photo importer preferences to the extension section



commit 1525f2db1a22d309313a980d1d5627d613b43682
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Dec 26 11:48:07 2015 +0100

    moved the photo importer preferences to the extension section
    
    to make the preferences dialog less messy

 extensions/photo_importer/Makefile.am              |   24 ++--
 extensions/photo_importer/callbacks.c              |   66 -----------
 extensions/photo_importer/callbacks.h              |    3 -
 .../data/ui/photo-importer-options.ui              |   53 +++++++--
 .../dlg-photo-importer-preferences.c               |  121 ++++++++++++++++++++
 .../dlg-photo-importer-preferences.h               |   29 +++++
 extensions/photo_importer/main.c                   |    5 +-
 7 files changed, 208 insertions(+), 93 deletions(-)
---
diff --git a/extensions/photo_importer/Makefile.am b/extensions/photo_importer/Makefile.am
index c6cfb54..0c690d3 100644
--- a/extensions/photo_importer/Makefile.am
+++ b/extensions/photo_importer/Makefile.am
@@ -3,17 +3,19 @@ SUBDIRS = data
 extensiondir = $(pkglibdir)/extensions
 extension_LTLIBRARIES = libphoto_importer.la
 
-libphoto_importer_la_SOURCES =                 \
-       actions.c                       \
-       actions.h                       \
-       callbacks.c                     \
-       callbacks.h                     \
-       dlg-photo-importer.c            \
-       dlg-photo-importer.h            \
-       main.c                          \
-       photo-importer.h                \
-       preferences.h                   \
-       resources.c                     \
+libphoto_importer_la_SOURCES =                         \
+       actions.c                               \
+       actions.h                               \
+       callbacks.c                             \
+       callbacks.h                             \
+       dlg-photo-importer.c                    \
+       dlg-photo-importer.h                    \
+       dlg-photo-importer-preferences.c        \
+       dlg-photo-importer-preferences.h        \
+       main.c                                  \
+       photo-importer.h                        \
+       preferences.h                           \
+       resources.c                             \
        resources.h
        
 libphoto_importer_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
diff --git a/extensions/photo_importer/callbacks.c b/extensions/photo_importer/callbacks.c
index 9d4e0a0..7470728 100644
--- a/extensions/photo_importer/callbacks.c
+++ b/extensions/photo_importer/callbacks.c
@@ -119,69 +119,3 @@ pi__import_photos_cb (GthBrowser *browser,
                         data,
                         import_data_unref);
 }
-
-
-/* -- pi__dlg_preferences_construct_cb -- */
-
-
-#define PREFERENCES_DATA_KEY "photo-import-preference-data"
-
-
-typedef struct {
-       GtkBuilder *builder;
-       GSettings  *settings;
-} PreferencesData;
-
-
-static void
-preferences_data_free (PreferencesData *data)
-{
-       g_object_unref (data->settings);
-       g_object_unref (data->builder);
-       g_free (data);
-}
-
-
-static void
-adjust_orientation_checkbutton_toggled_cb (GtkToggleButton *button,
-                                          PreferencesData *data)
-{
-       g_settings_set_boolean (data->settings, PREF_PHOTO_IMPORTER_ADJUST_ORIENTATION, 
gtk_toggle_button_get_active (button));
-}
-
-
-void
-pi__dlg_preferences_construct_cb (GtkWidget  *dialog,
-                                 GthBrowser *browser,
-                                 GtkBuilder *dialog_builder)
-{
-       PreferencesData *data;
-       GtkWidget       *general_vbox;
-       GtkWidget       *importer_options;
-       GtkWidget       *widget;
-
-       data = g_new0 (PreferencesData, 1);
-       data->builder = gtk_builder_new_from_resource 
("/org/gnome/gThumb/photo_importer/data/ui/photo-importer-options.ui");
-       data->settings = g_settings_new (GTHUMB_PHOTO_IMPORTER_SCHEMA);
-
-       general_vbox = _gtk_builder_get_widget (dialog_builder, "general_page");
-       importer_options = _gtk_builder_get_widget (data->builder, "importer_options");
-       gtk_box_pack_start (GTK_BOX (general_vbox),
-                           importer_options,
-                           FALSE,
-                           FALSE,
-                           0);
-       /* move the options before the 'other' options */
-       gtk_box_reorder_child (GTK_BOX (general_vbox),
-                              importer_options,
-                              _gtk_container_get_n_children (GTK_CONTAINER (general_vbox)) - 2);
-
-       widget = _gtk_builder_get_widget (data->builder, "adjust_orientation_checkbutton");
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), g_settings_get_boolean (data->settings, 
PREF_PHOTO_IMPORTER_ADJUST_ORIENTATION));
-       g_signal_connect (widget,
-                         "toggled",
-                         G_CALLBACK (adjust_orientation_checkbutton_toggled_cb),
-                         data);
-
-       g_object_set_data_full (G_OBJECT (dialog), PREFERENCES_DATA_KEY, data, (GDestroyNotify) 
preferences_data_free);
-}
diff --git a/extensions/photo_importer/callbacks.h b/extensions/photo_importer/callbacks.h
index 06d13ef..6c9cdd8 100644
--- a/extensions/photo_importer/callbacks.h
+++ b/extensions/photo_importer/callbacks.h
@@ -27,8 +27,5 @@
 void pi__gth_browser_construct_cb      (GthBrowser *browser);
 void pi__import_photos_cb              (GthBrowser *browser,
                                        GFile      *source);
-void pi__dlg_preferences_construct_cb  (GtkWidget  *dialog,
-                                       GthBrowser *browser,
-                                       GtkBuilder *dialog_builder);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/photo_importer/data/ui/photo-importer-options.ui 
b/extensions/photo_importer/data/ui/photo-importer-options.ui
index f23e6c5..9cd2a33 100644
--- a/extensions/photo_importer/data/ui/photo-importer-options.ui
+++ b/extensions/photo_importer/data/ui/photo-importer-options.ui
@@ -1,19 +1,20 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.19.0 -->
 <interface>
   <requires lib="gtk+" version="3.0"/>
-  <object class="GtkBox" id="importer_options">
+  <object class="GtkBox" id="dialog_content">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
+    <property name="border_width">15</property>
     <property name="orientation">vertical</property>
     <property name="spacing">6</property>
     <child>
       <object class="GtkLabel" id="label3">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">0</property>
         <property name="label" translatable="yes">After importing from a device:</property>
         <property name="use_markup">True</property>
+        <property name="xalign">0</property>
         <attributes>
           <attribute name="weight" value="bold"/>
         </attributes>
@@ -28,17 +29,47 @@
       <object class="GtkAlignment" id="alignment3">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="top_padding">6</property>
         <property name="left_padding">12</property>
         <child>
-          <object class="GtkCheckButton" id="adjust_orientation_checkbutton">
-            <property name="label" translatable="yes">_Rotate the images physically</property>
-            <property name="use_action_appearance">False</property>
+          <object class="GtkBox" id="box1">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="use_underline">True</property>
-            <property name="xalign">0</property>
-            <property name="draw_indicator">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkCheckButton" id="adjust_orientation_checkbutton">
+                <property name="label" translatable="yes">_Rotate the images physically</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="delete_files_checkbutton">
+                <property name="label" translatable="yes">_Delete the imported files from the 
source</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
           </object>
         </child>
       </object>
diff --git a/extensions/photo_importer/dlg-photo-importer-preferences.c 
b/extensions/photo_importer/dlg-photo-importer-preferences.c
new file mode 100644
index 0000000..a230729
--- /dev/null
+++ b/extensions/photo_importer/dlg-photo-importer-preferences.c
@@ -0,0 +1,121 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2015 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 <gthumb.h>
+#include "dlg-photo-importer-preferences.h"
+#include "preferences.h"
+
+
+typedef struct {
+       GtkBuilder *builder;
+       GSettings  *settings;
+       GtkWidget  *dialog;
+} DialogData;
+
+
+static void
+destroy_cb (GtkWidget  *widget,
+           DialogData *data)
+{
+       g_object_unref (data->builder);
+       g_object_unref (data->settings);
+       g_free (data);
+}
+
+
+static void
+adjust_orientation_checkbutton_toggled_cb (GtkToggleButton *button,
+                                          DialogData      *data)
+{
+       g_settings_set_boolean (data->settings,
+                               PREF_PHOTO_IMPORTER_ADJUST_ORIENTATION,
+                               gtk_toggle_button_get_active (button));
+}
+
+
+static void
+delete_files_checkbutton_toggled_cb (GtkToggleButton *button,
+                                          DialogData      *data)
+{
+       g_settings_set_boolean (data->settings,
+                               PREF_PHOTO_IMPORTER_DELETE_FROM_DEVICE,
+                               gtk_toggle_button_get_active (button));
+}
+
+
+void
+dlg_photo_importer_preferences (GtkWindow *parent)
+{
+       DialogData *data;
+
+       data = g_new0 (DialogData, 1);
+       data->builder = gtk_builder_new_from_resource 
("/org/gnome/gThumb/photo_importer/data/ui/photo-importer-options.ui");
+       data->settings = g_settings_new (GTHUMB_PHOTO_IMPORTER_SCHEMA);
+
+       /* Get the widgets. */
+
+       data->dialog = g_object_new (GTK_TYPE_DIALOG,
+                                    "title", _("Preferences"),
+                                    "transient-for", GTK_WINDOW (parent),
+                                    "modal", TRUE,
+                                    "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_OK, GTK_RESPONSE_CLOSE,
+                               NULL);
+       gtk_style_context_add_class (gtk_widget_get_style_context (gtk_dialog_get_widget_for_response 
(GTK_DIALOG (data->dialog), GTK_RESPONSE_CLOSE)),
+                                    GTK_STYLE_CLASS_SUGGESTED_ACTION);
+
+       /* Set widgets data. */
+
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (data->builder, 
"adjust_orientation_checkbutton")),
+                                     g_settings_get_boolean (data->settings, 
PREF_PHOTO_IMPORTER_ADJUST_ORIENTATION));
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (data->builder, 
"delete_files_checkbutton")),
+                                     g_settings_get_boolean (data->settings, 
PREF_PHOTO_IMPORTER_DELETE_FROM_DEVICE));
+
+       /* Set the signals handlers. */
+
+       g_signal_connect (G_OBJECT (data->dialog),
+                         "destroy",
+                         G_CALLBACK (destroy_cb),
+                         data);
+       g_signal_connect_swapped (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), 
GTK_RESPONSE_CLOSE),
+                                 "clicked",
+                                 G_CALLBACK (gtk_widget_destroy),
+                                 G_OBJECT (data->dialog));
+       g_signal_connect (gtk_builder_get_object (data->builder, "adjust_orientation_checkbutton"),
+                         "clicked",
+                         G_CALLBACK (adjust_orientation_checkbutton_toggled_cb),
+                         data);
+       g_signal_connect (gtk_builder_get_object (data->builder, "delete_files_checkbutton"),
+                         "clicked",
+                         G_CALLBACK (delete_files_checkbutton_toggled_cb),
+                         data);
+
+       /* run dialog. */
+
+       gtk_widget_show (data->dialog);
+}
diff --git a/extensions/photo_importer/dlg-photo-importer-preferences.h 
b/extensions/photo_importer/dlg-photo-importer-preferences.h
new file mode 100644
index 0000000..6626aa2
--- /dev/null
+++ b/extensions/photo_importer/dlg-photo-importer-preferences.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2015 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_PHOTO_IMPORTER_PREFERENCES_H
+#define DLG_PHOTO_IMPORTER_PREFERENCES_H
+
+#include <gthumb.h>
+
+void dlg_photo_importer_preferences (GtkWindow *parent);
+
+#endif /* DLG_PHOTO_IMPORTER_PREFERENCES_H */
diff --git a/extensions/photo_importer/main.c b/extensions/photo_importer/main.c
index 6b52ac7..a281c11 100644
--- a/extensions/photo_importer/main.c
+++ b/extensions/photo_importer/main.c
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 #include <gthumb.h>
 #include "callbacks.h"
+#include "dlg-photo-importer-preferences.h"
 
 
 G_MODULE_EXPORT void
@@ -31,7 +32,6 @@ gthumb_extension_activate (void)
 {
        gth_hook_add_callback ("import-photos", 10, G_CALLBACK (pi__import_photos_cb), NULL);
        gth_hook_add_callback ("gth-browser-construct", 9, G_CALLBACK (pi__gth_browser_construct_cb), NULL);
-       gth_hook_add_callback ("dlg-preferences-construct", 10, G_CALLBACK 
(pi__dlg_preferences_construct_cb), NULL);
 }
 
 
@@ -44,11 +44,12 @@ gthumb_extension_deactivate (void)
 G_MODULE_EXPORT gboolean
 gthumb_extension_is_configurable (void)
 {
-       return FALSE;
+       return TRUE;
 }
 
 
 G_MODULE_EXPORT void
 gthumb_extension_configure (GtkWindow *parent)
 {
+       dlg_photo_importer_preferences (parent);
 }


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