[gthumb] added the "convert format" tool



commit 7c72f1fb95238dd3938acbc0ea396b25980a684d
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Feb 10 11:36:51 2010 +0100

    added the "convert format" tool

 configure.ac                                       |    3 +
 extensions/Makefile.am                             |    1 +
 extensions/convert_format/Makefile.am              |   35 +++
 extensions/convert_format/actions.c                |   43 ++++
 extensions/convert_format/actions.h                |   32 +++
 extensions/convert_format/callbacks.c              |  107 ++++++++++
 extensions/convert_format/callbacks.h              |   31 +++
 .../convert_format/convert_format.extension.in.in  |   10 +
 extensions/convert_format/data/Makefile.am         |   18 ++
 .../data/gthumb_convert_format.schemas.in          |   17 ++
 extensions/convert_format/data/ui/Makefile.am      |    5 +
 .../convert_format/data/ui/convert-format.ui       |  203 ++++++++++++++++++
 extensions/convert_format/dlg-convert-format.c     |  217 ++++++++++++++++++++
 extensions/convert_format/dlg-convert-format.h     |   31 +++
 extensions/convert_format/main.c                   |   54 +++++
 extensions/convert_format/preferences.h            |   34 +++
 extensions/resize_images/data/ui/resize-images.ui  |   56 +----
 extensions/resize_images/dlg-resize-images.c       |    5 +-
 gthumb/gth-pixbuf-list-task.c                      |   67 ++++++-
 gthumb/gth-pixbuf-list-task.h                      |   19 +-
 gthumb/gth-pixbuf-task.c                           |    6 +-
 21 files changed, 927 insertions(+), 67 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0370df9..84597f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -395,6 +395,9 @@ extensions/change_date/data/ui/Makefile
 extensions/comments/Makefile
 extensions/comments/data/Makefile
 extensions/comments/data/ui/Makefile
+extensions/convert_format/Makefile
+extensions/convert_format/data/Makefile
+extensions/convert_format/data/ui/Makefile
 extensions/desktop_background/Makefile
 extensions/edit_metadata/Makefile
 extensions/edit_metadata/data/Makefile
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 42c5073..bfff982 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -3,6 +3,7 @@ SUBDIRS = 			\
 	catalogs		\
 	change_date		\
 	comments		\
+	convert_format		\
 	desktop_background	\
 	edit_metadata		\
 	exiv2_tools		\
diff --git a/extensions/convert_format/Makefile.am b/extensions/convert_format/Makefile.am
new file mode 100644
index 0000000..43a85f6
--- /dev/null
+++ b/extensions/convert_format/Makefile.am
@@ -0,0 +1,35 @@
+SUBDIRS = data
+
+extensiondir = $(pkglibdir)/extensions
+extension_LTLIBRARIES = libconvert_format.la
+
+libconvert_format_la_SOURCES = 		\
+	actions.c			\
+	actions.h			\
+	callbacks.c			\
+	callbacks.h			\
+	dlg-convert-format.c		\
+	dlg-convert-format.h		\
+	main.c				\
+	preferences.h
+
+libconvert_format_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
+libconvert_format_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
+libconvert_format_la_LIBADD = $(GTHUMB_LIBS)
+libconvert_format_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
+
+extensioninidir = $(extensiondir)
+extensionini_in_files = convert_format.extension.in.in
+extensionini_DATA = $(extensionini_in_files:.extension.in.in=.extension)
+
+%.extension.in: %.extension.in.in $(extension_LTLIBRARIES)
+	$(AM_V_GEN)( sed -e "s|%LIBRARY%|`. ./$(extension_LTLIBRARIES) && echo $$dlname`|" \
+	$< > $@ )
+
+%.extension: %.extension.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@
+
+EXTRA_DIST = $(extensionini_in_files) 
+
+DISTCLEANFILES = $(extensionini_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/extensions/convert_format/actions.c b/extensions/convert_format/actions.c
new file mode 100644
index 0000000..199942d
--- /dev/null
+++ b/extensions/convert_format/actions.c
@@ -0,0 +1,43 @@
+/* -*- 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 <gthumb.h>
+#include "dlg-convert-format.h"
+
+
+void
+gth_browser_activate_action_tool_convert_format (GtkAction  *action,
+					         GthBrowser *browser)
+{
+	GList *items;
+	GList *file_list;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+	dlg_convert_format (browser, file_list);
+
+	_g_object_list_unref (file_list);
+	_gtk_tree_path_list_free (items);
+}
diff --git a/extensions/convert_format/actions.h b/extensions/convert_format/actions.h
new file mode 100644
index 0000000..312abeb
--- /dev/null
+++ b/extensions/convert_format/actions.h
@@ -0,0 +1,32 @@
+/* -*- 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 ACTIONS_H
+#define ACTIONS_H
+
+#include <gtk/gtk.h>
+
+#define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
+
+DEFINE_ACTION(gth_browser_activate_action_tool_convert_format)
+
+#endif /* ACTIONS_H */
diff --git a/extensions/convert_format/callbacks.c b/extensions/convert_format/callbacks.c
new file mode 100644
index 0000000..1522490
--- /dev/null
+++ b/extensions/convert_format/callbacks.c
@@ -0,0 +1,107 @@
+/* -*- 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 <glib-object.h>
+#include <gthumb.h>
+#include "actions.h"
+
+
+#define BROWSER_DATA_KEY "convert-format-browser-data"
+
+
+static const char *fixed_ui_info =
+"<ui>"
+"  <popup name='ListToolsPopup'>"
+"    <placeholder name='Tools'>"
+"      <menuitem name='ConvertFormat' action='Tool_ConvertFormat'/>"
+"    </placeholder>"
+"  </popup>"
+"</ui>";
+
+
+static GtkActionEntry action_entries[] = {
+	{ "Tool_ConvertFormat", GTK_STOCK_CONVERT,
+	  N_("Convert Format..."), NULL,
+	  N_("Convert image format"),
+	  G_CALLBACK (gth_browser_activate_action_tool_convert_format) },
+};
+
+
+typedef struct {
+	GtkActionGroup *action_group;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+	g_free (data);
+}
+
+
+void
+cf__gth_browser_construct_cb (GthBrowser *browser)
+{
+	BrowserData *data;
+	GError      *error = NULL;
+
+	g_return_if_fail (GTH_IS_BROWSER (browser));
+
+	data = g_new0 (BrowserData, 1);
+
+	data->action_group = gtk_action_group_new ("Convert Format Actions");
+	gtk_action_group_set_translation_domain (data->action_group, NULL);
+	gtk_action_group_add_actions (data->action_group,
+				      action_entries,
+				      G_N_ELEMENTS (action_entries),
+				      browser);
+	gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
+
+	if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
+		g_message ("building menus failed: %s", error->message);
+		g_clear_error (&error);
+	}
+
+	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
+}
+
+
+void
+cf__gth_browser_update_sensitivity_cb (GthBrowser *browser)
+{
+	BrowserData *data;
+	GtkAction   *action;
+	int          n_selected;
+	gboolean     sensitive;
+
+	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+	g_return_if_fail (data != NULL);
+
+	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	sensitive = n_selected > 0;
+
+	action = gtk_action_group_get_action (data->action_group, "Tool_ConvertFormat");
+	g_object_set (action, "sensitive", sensitive, NULL);
+}
diff --git a/extensions/convert_format/callbacks.h b/extensions/convert_format/callbacks.h
new file mode 100644
index 0000000..611f3a8
--- /dev/null
+++ b/extensions/convert_format/callbacks.h
@@ -0,0 +1,31 @@
+/* -*- 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 CALLBACKS_H
+#define CALLBACKS_H
+
+#include <gthumb.h>
+
+void  cf__gth_browser_construct_cb            (GthBrowser *browser);
+void  cf__gth_browser_update_sensitivity_cb   (GthBrowser *browser);
+
+#endif /* CALLBACKS_H */
diff --git a/extensions/convert_format/convert_format.extension.in.in b/extensions/convert_format/convert_format.extension.in.in
new file mode 100644
index 0000000..5874db5
--- /dev/null
+++ b/extensions/convert_format/convert_format.extension.in.in
@@ -0,0 +1,10 @@
+[Extension]
+_Name=Convert format
+_Description=Save images in a different format
+_Authors=gthumb development team
+Copyright=Copyright © 2010 The Free Software Foundation, Inc.
+Version=1.0
+
+[Loader]
+Type=module
+File=%LIBRARY%
diff --git a/extensions/convert_format/data/Makefile.am b/extensions/convert_format/data/Makefile.am
new file mode 100644
index 0000000..a837977
--- /dev/null
+++ b/extensions/convert_format/data/Makefile.am
@@ -0,0 +1,18 @@
+SUBDIRS = ui
+
+schemadir = @GCONF_SCHEMA_FILE_DIR@
+schema_in_files = gthumb_convert_format.schemas.in
+schema_DATA = $(schema_in_files:.schemas.in=.schemas)
+
+ INTLTOOL_SCHEMAS_RULE@
+
+if GCONF_SCHEMAS_INSTALL
+install-data-local:
+	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/extensions/convert_format/data/$(schema_DATA)
+endif
+
+EXTRA_DIST = $(schema_in_files)
+
+CLEANFILES = $(schema_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/extensions/convert_format/data/gthumb_convert_format.schemas.in b/extensions/convert_format/data/gthumb_convert_format.schemas.in
new file mode 100644
index 0000000..e17ae93
--- /dev/null
+++ b/extensions/convert_format/data/gthumb_convert_format.schemas.in
@@ -0,0 +1,17 @@
+<gconfschemafile>
+    <schemalist>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/convert_format/mime_type</key>
+	<applyto>/apps/gthumb/ext/convert_format/mime_type</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default>image/jpeg</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
+    </schemalist>
+</gconfschemafile>
diff --git a/extensions/convert_format/data/ui/Makefile.am b/extensions/convert_format/data/ui/Makefile.am
new file mode 100644
index 0000000..149a19b
--- /dev/null
+++ b/extensions/convert_format/data/ui/Makefile.am
@@ -0,0 +1,5 @@
+uidir = $(pkgdatadir)/ui
+ui_DATA = convert-format.ui
+EXTRA_DIST = $(ui_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/extensions/convert_format/data/ui/convert-format.ui b/extensions/convert_format/data/ui/convert-format.ui
new file mode 100644
index 0000000..c939682
--- /dev/null
+++ b/extensions/convert_format/data/ui/convert-format.ui
@@ -0,0 +1,203 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkDialog" id="convert_format_dialog">
+    <property name="border_width">6</property>
+    <property name="title" translatable="yes">Convert Format</property>
+    <property name="resizable">False</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox8">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkVBox" id="vbox61">
+            <property name="visible">True</property>
+            <property name="border_width">6</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkVBox" id="vbox63">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label106">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">New format</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkComboBox" id="mime_type_combobox">
+                        <property name="visible">True</property>
+                        <property name="model">mime_type_liststore</property>
+                        <child>
+                          <object class="GtkCellRendererPixbuf" id="cellrenderertext1"/>
+                          <attributes>
+                            <attribute name="pixbuf">0</attribute>
+                          </attributes>
+                        </child>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                          <attributes>
+                            <attribute name="text">2</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="saving_box">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Destination</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkFileChooserButton" id="destination_filechooserbutton">
+                        <property name="visible">True</property>
+                        <property name="create_folders">False</property>
+                        <property name="action">select-folder</property>
+                        <property name="title" translatable="yes">Choose destination folder</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area8">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="help_button">
+                <property name="label">gtk-help</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+                <property name="secondary">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok_button">
+                <property name="label">gtk-execute</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-11">help_button</action-widget>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="0">ok_button</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkImage" id="ok_image">
+    <property name="visible">True</property>
+    <property name="stock">gtk-ok</property>
+  </object>
+  <object class="GtkListStore" id="mime_type_liststore">
+    <columns>
+      <!-- column-name icon -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name mime_type -->
+      <column type="gchararray"/>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+</interface>
diff --git a/extensions/convert_format/dlg-convert-format.c b/extensions/convert_format/dlg-convert-format.c
new file mode 100644
index 0000000..81f11da
--- /dev/null
+++ b/extensions/convert_format/dlg-convert-format.c
@@ -0,0 +1,217 @@
+/* -*- 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 <gtk/gtk.h>
+#include <gthumb.h>
+#include "dlg-convert-format.h"
+#include "preferences.h"
+
+
+#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
+#define DEFAULT_MIME_TYPE "image/jpeg"
+
+
+enum {
+	MIME_TYPE_COLUMN_ICON = 0,
+	MIME_TYPE_COLUMN_TYPE,
+	MIME_TYPE_COLUMN_DESCRIPTION
+};
+
+
+typedef struct {
+	GthBrowser *browser;
+	GList      *file_list;
+	GtkBuilder *builder;
+	GtkWidget  *dialog;
+	gboolean    use_destination;
+} DialogData;
+
+
+static void
+dialog_destroy_cb (GtkWidget  *widget,
+		   DialogData *data)
+{
+	gth_browser_set_dialog (data->browser, "convert_format", NULL);
+
+	g_object_unref (data->builder);
+	_g_object_list_unref (data->file_list);
+	g_free (data);
+}
+
+
+static void
+help_button_clicked_cb (GtkWidget  *widget,
+			DialogData *data)
+{
+	show_help_dialog (GTK_WINDOW (data->dialog), "convert-format");
+}
+
+
+static void
+convert_step (GthPixbufTask *pixbuf_task)
+{
+	pixbuf_task->dest = gdk_pixbuf_copy (pixbuf_task->src);
+}
+
+
+static void
+ok_button_clicked_cb (GtkWidget  *widget,
+		      DialogData *data)
+{
+	GtkTreeIter  iter;
+	char        *mime_type;
+	GthTask     *convert_task;
+	GthTask     *list_task;
+
+	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter);
+	gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("mime_type_liststore")), &iter,
+			    MIME_TYPE_COLUMN_TYPE, &mime_type,
+			    -1);
+	eel_gconf_set_string (PREF_CONVERT_FORMAT_MIME_TYPE, mime_type);
+
+	convert_task = gth_pixbuf_task_new (_("Converting images"),
+					    TRUE,
+					    NULL,
+					    convert_step,
+					    NULL,
+					    NULL,
+					    NULL);
+	list_task = gth_pixbuf_list_task_new (data->browser,
+					      data->file_list,
+					      GTH_PIXBUF_TASK (convert_task));
+	gth_pixbuf_list_task_set_overwrite_mode (GTH_PIXBUF_LIST_TASK (list_task), GTH_OVERWRITE_ASK);
+	gth_pixbuf_list_task_set_output_mime_type (GTH_PIXBUF_LIST_TASK (list_task), mime_type);
+	if (data->use_destination) {
+		GFile *destination;
+
+		destination = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")));
+		gth_pixbuf_list_task_set_destination (GTH_PIXBUF_LIST_TASK (list_task), destination);
+
+		g_object_unref (destination);
+	}
+	gth_browser_exec_task (data->browser, list_task, FALSE);
+
+	g_object_unref (list_task);
+	g_object_unref (convert_task);
+	g_free (mime_type);
+	gtk_widget_destroy (data->dialog);
+}
+
+
+void
+dlg_convert_format (GthBrowser *browser,
+		    GList      *file_list)
+{
+	DialogData *data;
+	GArray     *savers;
+
+	if (gth_browser_get_dialog (browser, "convert_format") != NULL) {
+		gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "convert_format")));
+		return;
+	}
+
+	data = g_new0 (DialogData, 1);
+	data->browser = browser;
+	data->builder = _gtk_builder_new_from_file ("convert-format.ui", "convert_format");
+	data->file_list = gth_file_data_list_dup (file_list);
+	data->use_destination = GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser));
+
+	/* Get the widgets. */
+
+	data->dialog = _gtk_builder_get_widget (data->builder, "convert_format_dialog");
+	gth_browser_set_dialog (browser, "convert_format", data->dialog);
+	g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data);
+
+	/* Set widgets data. */
+
+	savers = gth_main_get_type_set ("pixbuf-saver");
+	if (savers != NULL) {
+		char         *default_mime_type;
+		GthIconCache *icon_cache;
+		GtkListStore *list_store;
+		int           i;
+
+		default_mime_type = eel_gconf_get_string (PREF_CONVERT_FORMAT_MIME_TYPE, DEFAULT_MIME_TYPE);
+		icon_cache = gth_icon_cache_new_for_widget (data->dialog, GTK_ICON_SIZE_MENU);
+		list_store = (GtkListStore *) GET_WIDGET ("mime_type_liststore");
+		for (i = 0; i < savers->len; i++) {
+			GType           saver_type;
+			GthPixbufSaver *saver;
+			const char     *mime_type;
+			GdkPixbuf      *pixbuf;
+			GtkTreeIter     iter;
+
+			saver_type = g_array_index (savers, GType, i);
+			saver = g_object_new (saver_type, NULL);
+			mime_type = gth_pixbuf_saver_get_mime_type (saver);
+			pixbuf = gth_icon_cache_get_pixbuf (icon_cache, g_content_type_get_icon (mime_type));
+			gtk_list_store_append (list_store, &iter);
+			gtk_list_store_set (list_store, &iter,
+					    MIME_TYPE_COLUMN_ICON, pixbuf,
+					    MIME_TYPE_COLUMN_TYPE, mime_type,
+					    MIME_TYPE_COLUMN_DESCRIPTION, g_content_type_get_description (mime_type),
+					    -1);
+
+			if (strcmp (default_mime_type, mime_type) == 0)
+				gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter);
+
+			g_object_unref (pixbuf);
+			g_object_unref (saver);
+		}
+
+		gth_icon_cache_free (icon_cache);
+		g_free (default_mime_type);
+	}
+
+	if (data->use_destination) {
+		gtk_file_chooser_set_file (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")), gth_browser_get_location (browser), NULL);
+		gtk_widget_show (GET_WIDGET ("saving_box"));
+	}
+	else
+		gtk_widget_hide (GET_WIDGET ("saving_box"));
+
+	/* Set the signals handlers. */
+
+	g_signal_connect (G_OBJECT (data->dialog),
+			  "destroy",
+			  G_CALLBACK (dialog_destroy_cb),
+			  data);
+	g_signal_connect (GET_WIDGET ("ok_button"),
+			  "clicked",
+			  G_CALLBACK (ok_button_clicked_cb),
+			  data);
+        g_signal_connect (GET_WIDGET ("help_button"),
+                          "clicked",
+                          G_CALLBACK (help_button_clicked_cb),
+                          data);
+	g_signal_connect_swapped (GET_WIDGET ("cancel_button"),
+				  "clicked",
+				  G_CALLBACK (gtk_widget_destroy),
+				  G_OBJECT (data->dialog));
+
+	/* Run dialog. */
+
+	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser));
+	gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE);
+	gtk_widget_show (data->dialog);
+}
diff --git a/extensions/convert_format/dlg-convert-format.h b/extensions/convert_format/dlg-convert-format.h
new file mode 100644
index 0000000..6b198b8
--- /dev/null
+++ b/extensions/convert_format/dlg-convert-format.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2010 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DLG_CONVERT_FORMAT_H
+#define DLG_CONVERT_FORMAT_H
+
+#include <gthumb.h>
+
+void   dlg_convert_format (GthBrowser *browser,
+			   GList      *file_list  /* GthFileData */);
+
+#endif /* DLG_CONVERT_FORMAT_H */
diff --git a/extensions/convert_format/main.c b/extensions/convert_format/main.c
new file mode 100644
index 0000000..5e5f646
--- /dev/null
+++ b/extensions/convert_format/main.c
@@ -0,0 +1,54 @@
+/* -*- 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 <gtk/gtk.h>
+#include <gthumb.h>
+#include "callbacks.h"
+
+
+G_MODULE_EXPORT void
+gthumb_extension_activate (void)
+{
+	gth_hook_add_callback ("gth-browser-construct", 35, G_CALLBACK (cf__gth_browser_construct_cb), NULL);
+	gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (cf__gth_browser_update_sensitivity_cb), NULL);
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_deactivate (void)
+{
+}
+
+
+G_MODULE_EXPORT gboolean
+gthumb_extension_is_configurable (void)
+{
+	return FALSE;
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_configure (GtkWindow *parent)
+{
+}
diff --git a/extensions/convert_format/preferences.h b/extensions/convert_format/preferences.h
new file mode 100644
index 0000000..ae31db5
--- /dev/null
+++ b/extensions/convert_format/preferences.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 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 PREFERENCES_H
+#define PREFERENCES_H
+
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define  PREF_CONVERT_FORMAT_MIME_TYPE  "/apps/gthumb/ext/convert_format/mime_type"
+
+G_END_DECLS
+
+#endif /* PREFERENCES_H */
diff --git a/extensions/resize_images/data/ui/resize-images.ui b/extensions/resize_images/data/ui/resize-images.ui
index 4207007..6ab6c87 100644
--- a/extensions/resize_images/data/ui/resize-images.ui
+++ b/extensions/resize_images/data/ui/resize-images.ui
@@ -158,9 +158,6 @@
                               </packing>
                             </child>
                             <child>
-                              <placeholder/>
-                            </child>
-                            <child>
                               <object class="GtkHBox" id="hbox2">
                                 <property name="visible">True</property>
                                 <child>
@@ -186,6 +183,9 @@
                                 <property name="right_attach">3</property>
                               </packing>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -235,7 +235,7 @@
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">Saving</property>
+                    <property name="label" translatable="yes">Destination</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -247,55 +247,19 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHBox" id="hbox1">
+                  <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
+                    <property name="left_padding">12</property>
                     <child>
-                      <object class="GtkLabel" id="label2">
+                      <object class="GtkFileChooserButton" id="destination_filechooserbutton">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">    </property>
+                        <property name="action">select-folder</property>
+                        <property name="create_folders">False</property>
+                        <property name="title" translatable="yes">Choose destination folder</property>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkTable" id="table1">
-                        <property name="visible">True</property>
-                        <property name="n_columns">2</property>
-                        <property name="column_spacing">6</property>
-                        <property name="row_spacing">6</property>
-                        <child>
-                          <object class="GtkLabel" id="label3">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">_Destination:</property>
-                            <property name="use_underline">True</property>
-                          </object>
-                          <packing>
-                            <property name="x_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkFileChooserButton" id="destination_filechooserbutton">
-                            <property name="visible">True</property>
-                            <property name="action">select-folder</property>
-                            <property name="title" translatable="yes">Choose destination folder</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
                     </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
                     <property name="position">1</property>
                   </packing>
                 </child>
diff --git a/extensions/resize_images/dlg-resize-images.c b/extensions/resize_images/dlg-resize-images.c
index ebcab1f..53cfa0f 100644
--- a/extensions/resize_images/dlg-resize-images.c
+++ b/extensions/resize_images/dlg-resize-images.c
@@ -28,10 +28,10 @@
 
 
 #define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
-#define DEFAULT_FILE_TYPE "jpeg"
 #define DEFAULT_WIDTH 640
 #define DEFAULT_HEIGHT 480
 
+
 GthUnit units[] = { GTH_UNIT_PIXELS, GTH_UNIT_PERCENTAGE };
 
 
@@ -197,7 +197,7 @@ dlg_resize_images (GthBrowser *browser,
 	data->browser = browser;
 	data->builder = _gtk_builder_new_from_file ("resize-images.ui", "resize_images");
 	data->file_list = gth_file_data_list_dup (file_list);
-	data->use_destination = GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source(browser));
+	data->use_destination = GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser));
 
 	/* Get the widgets. */
 
@@ -225,7 +225,6 @@ dlg_resize_images (GthBrowser *browser,
 	g_signal_connect (G_OBJECT (data->dialog),
 			  "destroy",
 			  G_CALLBACK (destroy_cb),
-
 			  data);
 	g_signal_connect (GET_WIDGET ("ok_button"),
 			  "clicked",
diff --git a/gthumb/gth-pixbuf-list-task.c b/gthumb/gth-pixbuf-list-task.c
index 06384a0..1149fa6 100644
--- a/gthumb/gth-pixbuf-list-task.c
+++ b/gthumb/gth-pixbuf-list-task.c
@@ -40,9 +40,10 @@ struct _GthPixbufListTaskPrivate {
 	int                   n_files;
 	GdkPixbuf            *original_pixbuf;
 	GdkPixbuf            *new_pixbuf;
-	GFile                *destination;
+	GFile                *destination_folder;
 	GthOverwriteMode      overwrite_mode;
 	GthOverwriteResponse  overwrite_response;
+	char                 *mime_type;
 };
 
 
@@ -56,7 +57,8 @@ gth_pixbuf_list_task_finalize (GObject *object)
 
 	self = GTH_PIXBUF_LIST_TASK (object);
 
-	_g_object_unref (self->priv->destination);
+	g_free (self->priv->mime_type);
+	_g_object_unref (self->priv->destination_folder);
 	_g_object_unref (self->priv->original_pixbuf);
 	_g_object_unref (self->priv->new_pixbuf);
 	g_signal_handler_disconnect (self->priv->task, self->priv->task_completed);
@@ -122,8 +124,8 @@ overwrite_dialog_response_cb (GtkDialog *dialog,
 			GFile *parent;
 			GFile *new_destination;
 
-			if (self->priv->destination != NULL) {
-				parent = g_object_ref (self->priv->destination);
+			if (self->priv->destination_folder != NULL) {
+				parent = g_object_ref (self->priv->destination_folder);
 			}
 			else {
 				GthFileData *file_data;
@@ -263,6 +265,44 @@ pixbuf_task_save_current_pixbuf (GthPixbufListTask *self,
 
 
 static void
+set_current_destination_file (GthPixbufListTask *self)
+{
+	GthFileData *file_data;
+	char        *display_name;
+	GFile       *parent;
+	GFile       *destination;
+
+	file_data = self->priv->current->data;
+	if (self->priv->mime_type != NULL) {
+		char           *no_ext;
+		GthPixbufSaver *saver;
+
+		no_ext = _g_uri_remove_extension (g_file_info_get_display_name (file_data->info));
+		saver = gth_main_get_pixbuf_saver (self->priv->mime_type);
+		g_return_if_fail (saver != NULL);
+		display_name = g_strconcat (no_ext, ".", gth_pixbuf_saver_get_default_ext (saver), NULL);
+		gth_file_data_set_mime_type (file_data, self->priv->mime_type);
+
+		g_object_unref (saver);
+		g_free (no_ext);
+	}
+	else
+		display_name = g_strdup (g_file_info_get_display_name (file_data->info));
+
+	if (self->priv->destination_folder != NULL)
+		parent = g_object_ref (self->priv->destination_folder);
+	else
+		parent = g_file_get_parent (file_data->file);
+	destination = g_file_get_child_for_display_name (parent, display_name, NULL);
+	gth_file_data_set_file (file_data, destination);
+
+	g_object_unref (destination);
+	g_object_unref (parent);
+	g_free (display_name);
+}
+
+
+static void
 pixbuf_task_completed_cb (GthTask  *task,
 			  GError   *error,
 			  gpointer  user_data)
@@ -279,6 +319,7 @@ pixbuf_task_completed_cb (GthTask  *task,
 		return;
 	}
 
+	set_current_destination_file (self);
 	pixbuf_task_save_current_pixbuf (self,
 					 NULL,
 					 (self->priv->overwrite_mode == GTH_OVERWRITE_OVERWRITE));
@@ -381,8 +422,9 @@ gth_pixbuf_list_task_init (GthPixbufListTask *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_PIXBUF_LIST_TASK, GthPixbufListTaskPrivate);
 	self->priv->original_pixbuf = NULL;
-	self->priv->destination = NULL;
+	self->priv->destination_folder = NULL;
 	self->priv->overwrite_response = GTH_OVERWRITE_RESPONSE_UNSPECIFIED;
+	self->priv->mime_type = NULL;
 }
 
 
@@ -449,8 +491,8 @@ void
 gth_pixbuf_list_task_set_destination (GthPixbufListTask *self,
 				      GFile             *folder)
 {
-	_g_object_unref (self->priv->destination);
-	self->priv->destination = _g_object_ref (folder);
+	_g_object_unref (self->priv->destination_folder);
+	self->priv->destination_folder = _g_object_ref (folder);
 }
 
 
@@ -460,3 +502,14 @@ gth_pixbuf_list_task_set_overwrite_mode (GthPixbufListTask    *self,
 {
 	self->priv->overwrite_mode = overwrite_mode;
 }
+
+
+void
+gth_pixbuf_list_task_set_output_mime_type (GthPixbufListTask *self,
+					   const char        *mime_type)
+{
+	g_free (self->priv->mime_type);
+	self->priv->mime_type = NULL;
+	if (mime_type != NULL)
+		self->priv->mime_type = g_strdup (mime_type);
+}
diff --git a/gthumb/gth-pixbuf-list-task.h b/gthumb/gth-pixbuf-list-task.h
index 0f97af0..6465921 100644
--- a/gthumb/gth-pixbuf-list-task.h
+++ b/gthumb/gth-pixbuf-list-task.h
@@ -50,15 +50,16 @@ struct _GthPixbufListTaskClass {
 	GthTaskClass __parent;
 };
 
-GType      gth_pixbuf_list_task_get_type            (void);
-GthTask *  gth_pixbuf_list_task_new                 (GthBrowser           *browser,
-						     GList                *file_list, /* GthFileData list */
-						     GthPixbufTask        *task);
-void       gth_pixbuf_list_task_set_destination     (GthPixbufListTask    *self,
-						     GFile                *folder);
-void       gth_pixbuf_list_task_set_overwrite_mode  (GthPixbufListTask    *self,
-						     GthOverwriteMode      overwrite_mode);
-
+GType      gth_pixbuf_list_task_get_type             (void);
+GthTask *  gth_pixbuf_list_task_new                  (GthBrowser           *browser,
+						      GList                *file_list, /* GthFileData list */
+						      GthPixbufTask        *task);
+void       gth_pixbuf_list_task_set_destination      (GthPixbufListTask    *self,
+						      GFile                *folder);
+void       gth_pixbuf_list_task_set_overwrite_mode   (GthPixbufListTask    *self,
+						      GthOverwriteMode      overwrite_mode);
+void       gth_pixbuf_list_task_set_output_mime_type (GthPixbufListTask    *self,
+						      const char           *mime_type);
 G_END_DECLS
 
 #endif /* GTH_PIXBUF_LIST_TASK_H */
diff --git a/gthumb/gth-pixbuf-task.c b/gthumb/gth-pixbuf-task.c
index db16e93..0530cb6 100644
--- a/gthumb/gth-pixbuf-task.c
+++ b/gthumb/gth-pixbuf-task.c
@@ -119,7 +119,8 @@ execute_step (GthPixbufTask *self)
 
 	self->line_step = 0;
 	while (self->line_step < self->width) {
-		(*self->priv->step_func) (self);
+		if (self->priv->step_func != NULL)
+			(*self->priv->step_func) (self);
 		self->src_pixel += dir * self->bytes_per_pixel;
 		self->dest_pixel += dir * self->bytes_per_pixel;
 		self->column += dir;
@@ -147,7 +148,8 @@ execute_pixbuf_task (gpointer user_data)
 	if (self->priv->single_step) {
 		gboolean terminated;
 
-		(*self->priv->step_func) (self);
+		if (self->priv->step_func != NULL)
+			(*self->priv->step_func) (self);
 		terminated = TRUE;
 		gth_async_task_set_data (GTH_ASYNC_TASK (self), &terminated, NULL, NULL);
 	}



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