[gthumb: 10/23] contact_sheet: allow to use any pixbuf saver
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 10/23] contact_sheet: allow to use any pixbuf saver
- Date: Sun, 26 Dec 2010 19:20:34 +0000 (UTC)
commit 8c8209f961e716c4392378bf4ecc35d191fb083e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Dec 24 13:19:26 2010 +0100
contact_sheet: allow to use any pixbuf saver
.../data/gthumb_contact_sheet.schemas.in | 6 +-
.../contact_sheet/data/ui/contact-sheet-creator.ui | 33 ++----
extensions/contact_sheet/dlg-contact-sheet.c | 118 +++++++++++++-------
.../contact_sheet/gth-contact-sheet-creator.c | 43 +++++---
.../contact_sheet/gth-contact-sheet-creator.h | 5 +-
extensions/contact_sheet/preferences.h | 2 +-
6 files changed, 121 insertions(+), 86 deletions(-)
---
diff --git a/extensions/contact_sheet/data/gthumb_contact_sheet.schemas.in b/extensions/contact_sheet/data/gthumb_contact_sheet.schemas.in
index 751df67..646f5ff 100644
--- a/extensions/contact_sheet/data/gthumb_contact_sheet.schemas.in
+++ b/extensions/contact_sheet/data/gthumb_contact_sheet.schemas.in
@@ -54,11 +54,11 @@
</schema>
<schema>
- <key>/schemas/apps/gthumb/ext/contact_sheet/extension</key>
- <applyto>/apps/gthumb/ext/contact_sheet/extension</applyto>
+ <key>/schemas/apps/gthumb/ext/contact_sheet/mime_type</key>
+ <applyto>/apps/gthumb/ext/contact_sheet/mime_type</applyto>
<owner>gthumb</owner>
<type>string</type>
- <default>jpeg</default>
+ <default>image/jpeg</default>
<locale name="C">
<short></short>
<long>
diff --git a/extensions/contact_sheet/data/ui/contact-sheet-creator.ui b/extensions/contact_sheet/data/ui/contact-sheet-creator.ui
index 9cf8ee7..5299471 100644
--- a/extensions/contact_sheet/data/ui/contact-sheet-creator.ui
+++ b/extensions/contact_sheet/data/ui/contact-sheet-creator.ui
@@ -630,7 +630,7 @@
<child>
<object class="GtkTable" id="table3">
<property name="visible">True</property>
- <property name="n_rows">4</property>
+ <property name="n_rows">3</property>
<property name="n_columns">3</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
@@ -741,15 +741,6 @@
<child>
<placeholder/>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
</child>
</object>
@@ -1044,20 +1035,6 @@
<action-widget response="-5">ok_button</action-widget>
</action-widgets>
</object>
- <object class="GtkListStore" id="filetype_liststore">
- <columns>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">jpeg</col>
- </row>
- <row>
- <col id="0" translatable="yes">png</col>
- </row>
- </data>
- </object>
<object class="GtkAdjustment" id="rows_adjustment">
<property name="upper">100</property>
<property name="step_increment">1</property>
@@ -1096,4 +1073,12 @@
<column type="GdkPixbuf"/>
</columns>
</object>
+ <object class="GtkListStore" id="filetype_liststore">
+ <columns>
+ <!-- column-name default_extension -->
+ <column type="gchararray"/>
+ <!-- column-name mime_type -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
</interface>
diff --git a/extensions/contact_sheet/dlg-contact-sheet.c b/extensions/contact_sheet/dlg-contact-sheet.c
index 358c2b3..56c3083 100644
--- a/extensions/contact_sheet/dlg-contact-sheet.c
+++ b/extensions/contact_sheet/dlg-contact-sheet.c
@@ -33,10 +33,6 @@
#define PREVIEW_SIZE 112
enum {
- FILETYPE_COLUMN_NAME
-};
-
-enum {
THEME_COLUMN_IDX,
THEME_COLUMN_NAME,
THEME_COLUMN_DISPLAY_NAME,
@@ -53,6 +49,11 @@ enum {
THUMBNAIL_SIZE_TYPE_COLUMN_NAME
};
+enum {
+ FILE_TYPE_COLUMN_DEFAULT_EXTENSION,
+ FILE_TYPE_COLUMN_MIME_TYPE
+};
+
typedef struct {
GthBrowser *browser;
GList *file_list;
@@ -110,7 +111,8 @@ ok_clicked_cb (GtkWidget *widget,
char *s_value;
GFile *destination;
const char *template;
- char *extension;
+ char *mime_type;
+ char *file_extension;
gboolean create_image_map;
char *theme_name;
int theme_idx;
@@ -142,13 +144,14 @@ ok_clicked_cb (GtkWidget *widget,
template = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry")));
eel_gconf_set_string (PREF_CONTACT_SHEET_TEMPLATE, template);
- extension = NULL;
+ mime_type = NULL;
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("filetype_combobox")), &iter)) {
gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("filetype_liststore")),
&iter,
- FILETYPE_COLUMN_NAME, &extension,
+ FILE_TYPE_COLUMN_MIME_TYPE, &mime_type,
+ FILE_TYPE_COLUMN_DEFAULT_EXTENSION, &file_extension,
-1);
- eel_gconf_set_string (PREF_CONTACT_SHEET_EXTENSION, extension);
+ eel_gconf_set_string (PREF_CONTACT_SHEET_MIME_TYPE, mime_type);
}
create_image_map = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("image_map_checkbutton")));
@@ -218,7 +221,7 @@ ok_clicked_cb (GtkWidget *widget,
gth_contact_sheet_creator_set_footer (GTH_CONTACT_SHEET_CREATOR (task), footer);
gth_contact_sheet_creator_set_destination (GTH_CONTACT_SHEET_CREATOR (task), destination);
gth_contact_sheet_creator_set_filename_template (GTH_CONTACT_SHEET_CREATOR (task), template);
- gth_contact_sheet_creator_set_filetype (GTH_CONTACT_SHEET_CREATOR (task), extension);
+ gth_contact_sheet_creator_set_mime_type (GTH_CONTACT_SHEET_CREATOR (task), mime_type, file_extension);
gth_contact_sheet_creator_set_write_image_map (GTH_CONTACT_SHEET_CREATOR (task), create_image_map);
if (theme_idx >= 0)
gth_contact_sheet_creator_set_theme (GTH_CONTACT_SHEET_CREATOR (task), g_list_nth_data (data->themes, theme_idx));
@@ -235,7 +238,8 @@ ok_clicked_cb (GtkWidget *widget,
g_free (thumbnail_caption);
g_free (theme_name);
- g_free (extension);
+ g_free (file_extension);
+ g_free (mime_type);
g_object_unref (destination);
}
@@ -427,6 +431,9 @@ dlg_contact_sheet (GthBrowser *browser,
GList *scan;
char *caption;
char *s_value;
+ GFile *file;
+ char *default_mime_type;
+ GArray *savers;
if (gth_browser_get_dialog (browser, "contact_sheet") != NULL) {
gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "contact_sheet")));
@@ -451,9 +458,65 @@ dlg_contact_sheet (GthBrowser *browser,
/* Set widgets data. */
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("header_entry")),
+ g_file_info_get_edit_name (gth_browser_get_location_data (browser)->info));
+
+ s_value = eel_gconf_get_string (PREF_CONTACT_SHEET_FOOTER, "");
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("footer_entry")), s_value);
+ g_free (s_value);
+
+ s_value = eel_gconf_get_path (PREF_CONTACT_SHEET_DESTINATION, NULL);
+ if (s_value == NULL) {
+ GFile *location = gth_browser_get_location (data->browser);
+ if (location != NULL)
+ s_value = g_file_get_uri (location);
+ else
+ s_value = g_strdup (get_home_uri ());
+ }
+ file = g_file_new_for_uri (s_value);
+ gtk_file_chooser_set_file (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")), file, NULL);
+ g_object_unref (file);
+ g_free (s_value);
+
+ s_value = eel_gconf_get_path (PREF_CONTACT_SHEET_TEMPLATE, NULL);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), s_value);
+ g_free (s_value);
+
+ default_mime_type = eel_gconf_get_string (PREF_CONTACT_SHEET_MIME_TYPE, "image/jpeg");
+ active_index = 0;
+ savers = gth_main_get_type_set ("pixbuf-saver");
+ for (i = 0; (savers != NULL) && (i < savers->len); i++) {
+ GthPixbufSaver *saver;
+ GtkTreeIter iter;
+
+ saver = g_object_new (g_array_index (savers, GType, i), NULL);
+
+ if (g_str_equal (default_mime_type, gth_pixbuf_saver_get_mime_type (saver)))
+ active_index = i;
+
+ gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("filetype_liststore")), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("filetype_liststore")), &iter,
+ FILE_TYPE_COLUMN_MIME_TYPE, gth_pixbuf_saver_get_mime_type (saver),
+ FILE_TYPE_COLUMN_DEFAULT_EXTENSION, gth_pixbuf_saver_get_default_ext (saver),
+ -1);
+
+ g_object_unref (saver);
+ }
+ g_free (default_mime_type);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("filetype_combobox")), active_index);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GET_WIDGET("image_map_checkbutton")), eel_gconf_get_boolean (PREF_CONTACT_SHEET_HTML_IMAGE_MAP, FALSE));
+
+ load_themes (data);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("theme_liststore")),
+ THEME_COLUMN_NAME,
+ GTK_SORT_ASCENDING);
+
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("images_per_index_spinbutton")), eel_gconf_get_integer (PREF_CONTACT_SHEET_IMAGES_PER_PAGE, 25));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("single_index_checkbutton")), eel_gconf_get_boolean (PREF_CONTACT_SHEET_SINGLE_PAGE, FALSE));
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("cols_spinbutton")), eel_gconf_get_integer (PREF_CONTACT_SHEET_COLUMNS, 5));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("same_size_checkbutton")), eel_gconf_get_boolean (PREF_CONTACT_SHEET_SAME_SIZE, FALSE));
default_sort_type = eel_gconf_get_string (PREF_CONTACT_SHEET_SORT_TYPE, "general::unsorted");
active_index = 0;
@@ -472,27 +535,11 @@ dlg_contact_sheet (GthBrowser *browser,
-1);
}
g_list_free (sort_types);
+ g_free (default_sort_type);
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("sort_combobox")), active_index);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reverse_order_checkbutton")), eel_gconf_get_boolean (PREF_CONTACT_SHEET_SORT_INVERSE, FALSE));
- g_free (default_sort_type);
-
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("header_entry")),
- g_file_info_get_edit_name (gth_browser_get_location_data (browser)->info));
-
- s_value = eel_gconf_get_string (PREF_CONTACT_SHEET_FOOTER, "");
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("footer_entry")), s_value);
- g_free (s_value);
-
- caption = eel_gconf_get_string (PREF_CONTACT_SHEET_THUMBNAIL_CAPTION, DEFAULT_CONTACT_SHEET_THUMBNAIL_CAPTION);
- gth_metadata_chooser_set_selection (GTH_METADATA_CHOOSER (data->thumbnail_caption_chooser), caption);
- g_free (caption);
-
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("theme_liststore")),
- THEME_COLUMN_NAME,
- GTK_SORT_ASCENDING);
-
for (i = 0; i < thumb_sizes; i++) {
char *name;
GtkTreeIter iter;
@@ -508,20 +555,13 @@ dlg_contact_sheet (GthBrowser *browser,
g_free (name);
}
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("thumbnail_size_combobox")), get_idx_from_size (eel_gconf_get_integer (PREF_CONTACT_SHEET_THUMBNAIL_SIZE, 128)));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("squared_thumbnail_checkbutton")), eel_gconf_get_boolean (PREF_CONTACT_SHEET_SQUARED_THUMBNAIL, FALSE));
- load_themes (data);
- update_sensitivity (data);
-
- {
- char *destination;
-
- destination = eel_gconf_get_path (PREF_CONTACT_SHEET_DESTINATION, NULL);
- if (destination == NULL)
- destination = g_strdup (get_home_uri ());
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")), destination);
+ caption = eel_gconf_get_string (PREF_CONTACT_SHEET_THUMBNAIL_CAPTION, DEFAULT_CONTACT_SHEET_THUMBNAIL_CAPTION);
+ gth_metadata_chooser_set_selection (GTH_METADATA_CHOOSER (data->thumbnail_caption_chooser), caption);
+ g_free (caption);
- g_free (destination);
- }
+ update_sensitivity (data);
/* Set the signals handlers. */
diff --git a/extensions/contact_sheet/gth-contact-sheet-creator.c b/extensions/contact_sheet/gth-contact-sheet-creator.c
index 489b277..26dc19c 100644
--- a/extensions/contact_sheet/gth-contact-sheet-creator.c
+++ b/extensions/contact_sheet/gth-contact-sheet-creator.c
@@ -75,7 +75,8 @@ struct _GthContactSheetCreatorPrivate {
char *footer;
GFile *destination;
char *template;
- char *filetype;
+ char *mime_type;
+ char *file_extension;
gboolean write_image_map;
GthContactSheetTheme *theme;
int images_per_index;
@@ -97,6 +98,7 @@ struct _GthContactSheetCreatorPrivate {
PangoLayout *pango_layout;
GthImageLoader *image_loader;
+ GthPixbufSaver *pixbuf_saver;
GList *files; /* ItemData list */
GList *current_file; /* Next file to be loaded. */
gint n_files; /* Used for the progress signal. */
@@ -236,7 +238,7 @@ begin_page (GthContactSheetCreator *self,
cairo_surface_t *surface;
name = _g_get_name_from_template (self->priv->template_v, page_n - 1);
- display_name = g_strdup_printf ("%s.%s", name, self->priv->filetype);
+ display_name = g_strdup_printf ("%s.%s", name, self->priv->file_extension);
gth_task_progress (GTH_TASK (self),
_("Creating images"),
display_name,
@@ -327,20 +329,19 @@ end_page (GthContactSheetCreator *self,
GFile *file;
pixbuf = _gdk_pixbuf_new_from_cairo_surface (self->priv->cr);
- if (! gdk_pixbuf_save_to_buffer (pixbuf,
- &buffer,
- &size,
- self->priv->filetype,
- &error,
- (g_str_equal(self->priv->filetype, "jpeg") ? "quality" : NULL),
- "90",
- NULL))
+ if (! gth_pixbuf_saver_save_pixbuf (self->priv->pixbuf_saver,
+ pixbuf,
+ &buffer,
+ &size,
+ self->priv->mime_type,
+ &error))
{
- /* TODO */
+ gth_task_completed (GTH_TASK (self), error);
+ return;
}
name = _g_get_name_from_template (self->priv->template_v, page_n - 1);
- display_name = g_strdup_printf ("%s.%s", name, self->priv->filetype);
+ display_name = g_strdup_printf ("%s.%s", name, self->priv->file_extension);
file = g_file_get_child_for_display_name (self->priv->destination, display_name, NULL);
if (! g_write_file (file,
@@ -650,6 +651,9 @@ export (GthContactSheetCreator *self)
GList *scan;
ItemData *item_data;
+ if (self->priv->pixbuf_saver == NULL)
+ self->priv->pixbuf_saver = gth_main_get_pixbuf_saver (self->priv->mime_type);
+
columns = ((self->priv->page_width - self->priv->theme->col_spacing) / (self->priv->thumb_width + (self->priv->theme->frame_hpadding * 2) + self->priv->theme->col_spacing));
first_row = TRUE;
begin_page (self, ++page_n);
@@ -1075,6 +1079,7 @@ gth_contact_sheet_creator_finalize (GObject *object)
_g_object_list_unref (self->priv->created_files);
g_list_foreach (self->priv->files, (GFunc) item_data_free, NULL);
g_list_free (self->priv->files);
+ _g_object_unref (self->priv->pixbuf_saver);
_g_object_unref (self->priv->image_loader);
_g_object_unref (self->priv->pango_layout);
_g_object_unref (self->priv->pango_context);
@@ -1082,7 +1087,8 @@ gth_contact_sheet_creator_finalize (GObject *object)
cairo_destroy (self->priv->cr);
g_free (self->priv->thumbnail_caption);
gth_contact_sheet_theme_ref (self->priv->theme);
- g_free (self->priv->filetype);
+ g_free (self->priv->mime_type);
+ g_free (self->priv->file_extension);
g_free (self->priv->template);
_g_object_unref (self->priv->destination);
g_free (self->priv->footer);
@@ -1119,7 +1125,8 @@ gth_contact_sheet_creator_init (GthContactSheetCreator *self)
self->priv->footer = NULL;
self->priv->destination = NULL;
self->priv->template = NULL;
- self->priv->filetype = NULL;
+ self->priv->mime_type = NULL;
+ self->priv->file_extension = NULL;
self->priv->write_image_map = FALSE;
self->priv->images_per_index = 0;
self->priv->single_index = FALSE;
@@ -1216,10 +1223,12 @@ gth_contact_sheet_creator_set_filename_template (GthContactSheetCreator *self,
void
-gth_contact_sheet_creator_set_filetype (GthContactSheetCreator *self,
- const char *filetype)
+gth_contact_sheet_creator_set_mime_type (GthContactSheetCreator *self,
+ const char *mime_type,
+ const char *file_extension)
{
- _g_strset (&self->priv->filetype, filetype);
+ _g_strset (&self->priv->mime_type, mime_type);
+ _g_strset (&self->priv->file_extension, file_extension);
}
diff --git a/extensions/contact_sheet/gth-contact-sheet-creator.h b/extensions/contact_sheet/gth-contact-sheet-creator.h
index 6d37e9f..2b01181 100644
--- a/extensions/contact_sheet/gth-contact-sheet-creator.h
+++ b/extensions/contact_sheet/gth-contact-sheet-creator.h
@@ -60,8 +60,9 @@ void gth_contact_sheet_creator_set_destination (GthContactSheetCreat
GFile *destination);
void gth_contact_sheet_creator_set_filename_template (GthContactSheetCreator *self,
const char *filename_template);
-void gth_contact_sheet_creator_set_filetype (GthContactSheetCreator *self,
- const char *filetype);
+void gth_contact_sheet_creator_set_mime_type (GthContactSheetCreator *self,
+ const char *mime_type,
+ const char *file_extension);
void gth_contact_sheet_creator_set_write_image_map (GthContactSheetCreator *self,
gboolean value);
void gth_contact_sheet_creator_set_theme (GthContactSheetCreator *self,
diff --git a/extensions/contact_sheet/preferences.h b/extensions/contact_sheet/preferences.h
index f8cc006..3daf69f 100644
--- a/extensions/contact_sheet/preferences.h
+++ b/extensions/contact_sheet/preferences.h
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
#define PREF_CONTACT_SHEET_FOOTER "/apps/gthumb/ext/contact_sheet/footer"
#define PREF_CONTACT_SHEET_DESTINATION "/apps/gthumb/ext/contact_sheet/destination"
#define PREF_CONTACT_SHEET_TEMPLATE "/apps/gthumb/ext/contact_sheet/template"
-#define PREF_CONTACT_SHEET_EXTENSION "/apps/gthumb/ext/contact_sheet/extension"
+#define PREF_CONTACT_SHEET_MIME_TYPE "/apps/gthumb/ext/contact_sheet/mime_type"
#define PREF_CONTACT_SHEET_HTML_IMAGE_MAP "/apps/gthumb/ext/contact_sheet/html_image_map"
#define PREF_CONTACT_SHEET_THEME "/apps/gthumb/ext/contact_sheet/theme"
#define PREF_CONTACT_SHEET_IMAGES_PER_PAGE "/apps/gthumb/ext/contact_sheet/images_per_page"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]