[gthumb] added a GthImportDestinationButton widget



commit eea97793153158a699724cbadfecdc9df297d745
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Aug 4 23:39:39 2010 +0200

    added a GthImportDestinationButton widget
    
    Widget to be used in all the import dialogs to display and specify
    the import destination folder.

 extensions/importer/Makefile.am                    |    2 +
 .../importer/gth-import-destination-button.c       |  199 ++++++++++++++++++++
 .../importer/gth-import-destination-button.h       |   57 ++++++
 extensions/importer/importer.h                     |    1 +
 .../photo_importer/data/ui/photo-importer.ui       |   54 +-----
 extensions/photo_importer/dlg-photo-importer.c     |   54 +-----
 6 files changed, 268 insertions(+), 99 deletions(-)
---
diff --git a/extensions/importer/Makefile.am b/extensions/importer/Makefile.am
index 87b2d06..29e7f2c 100644
--- a/extensions/importer/Makefile.am
+++ b/extensions/importer/Makefile.am
@@ -8,6 +8,7 @@ ENUM_TYPES =					\
 	gth-import-enum-types.c
 
 HEADER_FILES = 					\
+	gth-import-destination-button.h		\
 	gth-import-preferences-dialog.h		\
 	gth-import-task.h			\
 	preferences.h				\
@@ -37,6 +38,7 @@ gth-import-enum-types.c: $(HEADER_FILES) gth-import-enum-types.h
 libimporter_la_SOURCES = 			\
 	$(ENUM_TYPES)				\
 	$(HEADER_FILES)				\
+	gth-import-destination-button.c		\
 	gth-import-preferences-dialog.c		\
 	gth-import-task.c			\
 	importer.h				\
diff --git a/extensions/importer/gth-import-destination-button.c b/extensions/importer/gth-import-destination-button.c
new file mode 100644
index 0000000..cfae299
--- /dev/null
+++ b/extensions/importer/gth-import-destination-button.c
@@ -0,0 +1,199 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2010 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include "gth-import-destination-button.h"
+
+
+static gpointer parent_class = NULL;
+
+
+struct _GthImportDestinationButtonPrivate {
+	GtkWidget *destination_icon;
+	GtkWidget *destination_label;
+	GtkWidget *subfolder_label;
+};
+
+
+static void
+gth_import_destination_button_finalize (GObject *object)
+{
+	GthImportDestinationButton *self;
+
+	self = GTH_IMPORT_DESTINATION_BUTTON (object);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gth_import_destination_button_class_init (GthImportDestinationButtonClass *klass)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (GthImportDestinationButtonPrivate));
+
+	object_class = (GObjectClass*) klass;
+	object_class->finalize = gth_import_destination_button_finalize;
+}
+
+
+static void
+gth_import_destination_button_init (GthImportDestinationButton *self)
+{
+	GtkWidget      *box;
+	GtkWidget      *label_box;
+	PangoAttrList  *attr_list;
+	PangoAttribute *attr;
+
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_IMPORT_DESTINATION_BUTTON, GthImportDestinationButtonPrivate);
+
+	gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Click to change the destination or the automatic subfolder"));
+
+	box = gtk_hbox_new (FALSE, 6);
+	gtk_widget_show (box);
+	gtk_container_add (GTK_CONTAINER (self), box);
+
+	self->priv->destination_icon = gtk_image_new ();
+	gtk_widget_show (self->priv->destination_icon);
+	gtk_box_pack_start (GTK_BOX (box), self->priv->destination_icon, FALSE, FALSE, 0);
+
+	label_box = gtk_hbox_new (FALSE, 0);
+	gtk_widget_show (label_box);
+	gtk_box_pack_start (GTK_BOX (box), label_box, TRUE, TRUE, 0);
+
+	self->priv->destination_label = gtk_label_new ("");
+	gtk_widget_show (self->priv->destination_label);
+	gtk_box_pack_start (GTK_BOX (label_box), self->priv->destination_label, FALSE, FALSE, 0);
+
+	self->priv->subfolder_label = gtk_label_new ("");
+	gtk_label_set_ellipsize (GTK_LABEL (self->priv->subfolder_label), PANGO_ELLIPSIZE_END);
+	gtk_misc_set_alignment (GTK_MISC (self->priv->subfolder_label), 0.0, 0.5);
+
+	attr_list = pango_attr_list_new ();
+	attr = pango_attr_foreground_new (45489, 13107, 1799);
+	pango_attr_list_insert (attr_list, attr);
+	g_object_set (self->priv->subfolder_label, "attributes", attr_list, NULL);
+	pango_attr_list_unref (attr_list);
+
+	gtk_widget_show (self->priv->subfolder_label);
+	gtk_box_pack_start (GTK_BOX (label_box), self->priv->subfolder_label, TRUE, TRUE, 0);
+}
+
+
+GType
+gth_import_destination_button_get_type (void)
+{
+	static GType type = 0;
+
+	if (type == 0) {
+		static const GTypeInfo g_define_type_info = {
+			sizeof (GthImportDestinationButtonClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) gth_import_destination_button_class_init,
+			(GClassFinalizeFunc) NULL,
+			NULL,
+			sizeof (GthImportDestinationButton),
+			0,
+			(GInstanceInitFunc) gth_import_destination_button_init,
+			NULL
+		};
+		type = g_type_register_static (GTK_TYPE_BUTTON,
+					       "GthImportDestinationButton",
+					       &g_define_type_info,
+					       0);
+	}
+
+	return type;
+}
+
+
+static void
+preferences_dialog_destination_changed_cb (GthImportPreferencesDialog *dialog,
+					   GthImportDestinationButton *self)
+{
+	GFile *destination;
+	GFile *destination_example;
+
+	destination = gth_import_preferences_dialog_get_destination (dialog);
+	destination_example = gth_import_preferences_dialog_get_destination_example (dialog);
+	if ((destination != NULL) && (destination_example != NULL)) {
+		char *name;
+
+		name = g_file_get_parse_name (destination);
+		gtk_image_set_from_icon_name(GTK_IMAGE (self->priv->destination_icon), "folder", GTK_ICON_SIZE_MENU);
+		gtk_label_set_text (GTK_LABEL (self->priv->destination_label), name);
+		g_free (name);
+
+		name = g_file_get_relative_path (destination, destination_example);
+		if ((name != NULL) && (strcmp (name, "") != 0)) {
+			char *example_path;
+
+			example_path = g_strconcat (G_DIR_SEPARATOR_S, name, NULL);
+			gtk_label_set_text (GTK_LABEL (self->priv->subfolder_label), example_path);
+
+			g_free (example_path);
+		}
+		else
+			gtk_label_set_text (GTK_LABEL (self->priv->subfolder_label), "");
+
+		g_free (name);
+	}
+	else {
+		gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->destination_icon), "dialog-error", GTK_ICON_SIZE_MENU);
+		gtk_label_set_text (GTK_LABEL (self->priv->destination_label), _("Invalid Destination"));
+		gtk_label_set_text (GTK_LABEL (self->priv->subfolder_label), "");
+	}
+
+	_g_object_unref (destination_example);
+	_g_object_unref (destination);
+}
+
+
+static void
+gth_import_destination_button_construct (GthImportDestinationButton *button,
+					 GthImportPreferencesDialog *dialog)
+{
+	g_signal_connect (dialog,
+			  "destination_changed",
+			  G_CALLBACK (preferences_dialog_destination_changed_cb),
+			  button);
+	g_signal_connect_swapped (button,
+			  	  "clicked",
+			  	  G_CALLBACK (gtk_window_present),
+			  	  dialog);
+}
+
+
+GtkWidget *
+gth_import_destination_button_new (GthImportPreferencesDialog *dialog)
+{
+	GtkWidget *button;
+
+	button = (GtkWidget *) g_object_new (GTH_TYPE_IMPORT_DESTINATION_BUTTON, NULL);
+	gth_import_destination_button_construct (GTH_IMPORT_DESTINATION_BUTTON (button), dialog);
+
+	return button;
+}
diff --git a/extensions/importer/gth-import-destination-button.h b/extensions/importer/gth-import-destination-button.h
new file mode 100644
index 0000000..f989ccd
--- /dev/null
+++ b/extensions/importer/gth-import-destination-button.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2010 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+ 
+#ifndef GTH_IMPORT_DESTINATION_BUTTON_H
+#define GTH_IMPORT_DESTINATION_BUTTON_H
+
+#include <gtk/gtk.h>
+#include <gthumb.h>
+#include "gth-import-preferences-dialog.h"
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_IMPORT_DESTINATION_BUTTON            (gth_import_destination_button_get_type ())
+#define GTH_IMPORT_DESTINATION_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_IMPORT_DESTINATION_BUTTON, GthImportDestinationButton))
+#define GTH_IMPORT_DESTINATION_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_IMPORT_DESTINATION_BUTTON, GthImportDestinationButtonClass))
+#define GTH_IS_IMPORT_DESTINATION_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_IMPORT_DESTINATION_BUTTON))
+#define GTH_IS_IMPORT_DESTINATION_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_IMPORT_DESTINATION_BUTTON))
+#define GTH_IMPORT_DESTINATION_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_IMPORT_DESTINATION_BUTTON, GthImportDestinationButtonClass))
+
+typedef struct _GthImportDestinationButton GthImportDestinationButton;
+typedef struct _GthImportDestinationButtonClass GthImportDestinationButtonClass;
+typedef struct _GthImportDestinationButtonPrivate GthImportDestinationButtonPrivate;
+
+struct _GthImportDestinationButton {
+	GtkButton parent_instance;
+	GthImportDestinationButtonPrivate *priv;
+};
+
+struct _GthImportDestinationButtonClass {
+	GtkButtonClass parent_class;
+};
+
+GType        gth_import_destination_button_get_type  (void);
+GtkWidget *  gth_import_destination_button_new       (GthImportPreferencesDialog *dialog);
+
+G_END_DECLS
+
+#endif /* GTH_IMPORT_DESTINATION_BUTTON_H */
diff --git a/extensions/importer/importer.h b/extensions/importer/importer.h
index 8a18ee1..5781894 100644
--- a/extensions/importer/importer.h
+++ b/extensions/importer/importer.h
@@ -25,6 +25,7 @@
 #define IMPORTER_H
 
 #include "extensions/importer/gth-import-enum-types.h"
+#include "extensions/importer/gth-import-destination-button.h"
 #include "extensions/importer/gth-import-preferences-dialog.h"
 #include "extensions/importer/gth-import-task.h"
 #include "extensions/importer/preferences.h"
diff --git a/extensions/photo_importer/data/ui/photo-importer.ui b/extensions/photo_importer/data/ui/photo-importer.ui
index 6c50903..a6dbe34 100644
--- a/extensions/photo_importer/data/ui/photo-importer.ui
+++ b/extensions/photo_importer/data/ui/photo-importer.ui
@@ -204,66 +204,16 @@
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">_Destination:</property>
                     <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">destination_button</property>
                   </object>
                   <packing>
                     <property name="x_options">GTK_FILL</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="destination_button">
+                  <object class="GtkHBox" id="destination_button_box">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes">Click to change the destination or set an automatic subfolder</property>
                     <child>
-                      <object class="GtkHBox" id="hbox2">
-                        <property name="visible">True</property>
-                        <property name="spacing">6</property>
-                        <child>
-                          <object class="GtkImage" id="destination_icon">
-                            <property name="visible">True</property>
-                            <property name="icon_name">folder</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkHBox" id="hbox3">
-                            <property name="visible">True</property>
-                            <child>
-                              <object class="GtkLabel" id="destination_label">
-                                <property name="visible">True</property>
-                                <property name="xalign">0</property>
-                                <property name="label">/home/user/Images</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="destination_example_label">
-                                <property name="visible">True</property>
-                                <property name="xalign">0</property>
-                                <property name="label">/garden/2010-06-23</property>
-                                <property name="ellipsize">end</property>
-                                <attributes>
-                                  <attribute name="foreground" value="#b1eb33440710"/>
-                                </attributes>
-                              </object>
-                              <packing>
-                                <property name="position">1</property>
-                              </packing>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                      </object>
+                      <placeholder/>
                     </child>
                   </object>
                   <packing>
diff --git a/extensions/photo_importer/dlg-photo-importer.c b/extensions/photo_importer/dlg-photo-importer.c
index b01f762..45cea28 100644
--- a/extensions/photo_importer/dlg-photo-importer.c
+++ b/extensions/photo_importer/dlg-photo-importer.c
@@ -270,45 +270,6 @@ file_view_selection_changed_cb (GtkIconView *iconview,
 
 
 static void
-preferences_dialog_destination_changed_cb (GthImportPreferencesDialog *dialog,
-					   DialogData                 *data)
-{
-	GFile *destination;
-	GFile *destination_example;
-
-	destination = gth_import_preferences_dialog_get_destination (dialog);
-	destination_example = gth_import_preferences_dialog_get_destination_example (dialog);
-	if ((destination != NULL) && (destination_example != NULL)) {
-		char *name;
-
-		name = g_file_get_parse_name (destination);
-		gtk_image_set_from_icon_name(GTK_IMAGE (GET_WIDGET("destination_icon")), "folder", GTK_ICON_SIZE_MENU);
-		gtk_label_set_text (GTK_LABEL (GET_WIDGET ("destination_label")), name);
-		g_free (name);
-
-		name = g_file_get_relative_path (destination, destination_example);
-		if ((name != NULL) && (strcmp (name, "") != 0)) {
-			char *example_path;
-
-			example_path = g_strconcat (G_DIR_SEPARATOR_S, name, NULL);
-			gtk_label_set_text (GTK_LABEL (GET_WIDGET ("destination_example_label")), example_path);
-
-			g_free (example_path);
-		}
-
-		g_free (name);
-	}
-	else {
-		gtk_image_set_from_icon_name(GTK_IMAGE (GET_WIDGET("destination_icon")), "dialog-error", GTK_ICON_SIZE_MENU);
-		gtk_label_set_text (GTK_LABEL (GET_WIDGET ("destination_label")), _("Invalid Destination"));
-	}
-
-	_g_object_unref (destination_example);
-	_g_object_unref (destination);
-}
-
-
-static void
 list_ready_cb (GList    *files,
 	       GError   *error,
 	       gpointer  user_data)
@@ -633,6 +594,13 @@ dlg_photo_importer (GthBrowser *browser,
 	data->preferences_dialog = gth_import_preferences_dialog_new ();
 	gtk_window_set_transient_for (GTK_WINDOW (data->preferences_dialog), GTK_WINDOW (data->dialog));
 
+	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("destination_button_box")),
+			    gth_import_destination_button_new (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog)),
+			    TRUE,
+			    TRUE,
+			    0);
+	gtk_widget_show_all (GET_WIDGET ("destination_button_box"));
+
 	/* Set the signals handlers. */
 
 	g_signal_connect (G_OBJECT (data->dialog),
@@ -663,10 +631,6 @@ dlg_photo_importer (GthBrowser *browser,
 			  "selection_changed",
 			  G_CALLBACK (file_view_selection_changed_cb),
 			  data);
-	g_signal_connect (data->preferences_dialog,
-			  "destination_changed",
-			  G_CALLBACK (preferences_dialog_destination_changed_cb),
-			  data);
 	g_signal_connect (GET_WIDGET ("preferences_button"),
 			  "clicked",
 			  G_CALLBACK (preferences_button_clicked_cb),
@@ -679,10 +643,6 @@ dlg_photo_importer (GthBrowser *browser,
 				"changed",
 				G_CALLBACK (event_entry_changed_cb),
 				data);
-	g_signal_connect (GET_WIDGET ("destination_button"),
-			  "clicked",
-			  G_CALLBACK (preferences_button_clicked_cb),
-			  data);
 
 	/* Run dialog. */
 



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