Commit b1cbb5e6 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[image_print] load the selected metadata

parent 3f4c082c
......@@ -214,7 +214,7 @@ gth_metadata_provider_constructor (GType type,
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "comment::*", NULL);
g_object_set (self, "readable-attributes", "comment::*,Embedded::Image::*", NULL);
g_object_set (self, "writable-attributes", "comment::*,Embedded::Image::*", NULL);
return obj;
......
......@@ -188,7 +188,7 @@ gth_metadata_provider_constructor (GType type,
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "Exif::*,Xmp::*,Iptc::*", NULL);
g_object_set (self, "readable-attributes", "Exif::*,Xmp::*,Iptc::*,Embedded::Image::*", NULL);
g_object_set (self, "writable-attributes", "Exif::*,Xmp::*,Iptc::*,Embedded::Image::*", NULL);
return obj;
......
......@@ -14,6 +14,7 @@ libimage_print_la_SOURCES = \
gth-image-print-job.h \
gth-load-image-info-task.c \
gth-load-image-info-task.h \
preferences.h \
main.c
libimage_print_la_CPPFLAGS = $(GTHUMB_CFLAGS) $(DISABLE_DEPRECATED) $(WARNINGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
......
SUBDIRS = ui
schemadir = @GCONF_SCHEMA_FILE_DIR@
schema_in_files = gthumb_image_print.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/image_print/data/$(schema_DATA)
endif
EXTRA_DIST = $(schema_in_files)
CLEANFILES = $(schema_DATA)
-include $(top_srcdir)/git.mk
<gconfschemafile>
<schemalist>
<schema>
<key>/schemas/apps/gthumb/ext/image_print/caption</key>
<applyto>/apps/gthumb/ext/image_print/caption</applyto>
<owner>gthumb</owner>
<type>string</type>
<default></default>
<locale name="C">
<short></short>
<long>
</long>
</locale>
</schema>
</schemalist>
</gconfschemafile>
......@@ -28,10 +28,11 @@
#include "gth-image-info.h"
#include "gth-image-print-job.h"
#include "gth-load-image-info-task.h"
#include "preferences.h"
#define GET_WIDGET(name) _gtk_builder_get_widget (self->priv->builder, (name))
#define DEFAULT_PADDING 20.0
#define PREVIEW_SCALE_FACTOR 3.0 /* FIXME: why 3.0 ? */
enum {
......@@ -54,6 +55,7 @@ struct _GthImagePrintJobPrivate {
GtkPrintOperation *print_operation;
GtkBuilder *builder;
GtkWidget *caption_chooser;
GthImageInfo *selected;
/* settings */
......@@ -121,7 +123,8 @@ gth_image_print_job_init (GthImagePrintJob *self)
self->priv->task = NULL;
self->priv->page_setup = NULL;
self->priv->current_page = 0;
self->priv->caption_attributes = g_strdup (""); /* FIXME: load from a gconf key */
self->priv->caption_attributes = eel_gconf_get_string (PREF_IMAGE_PRINT_CAPTION, "");
self->priv->selected = NULL;
}
......@@ -317,7 +320,11 @@ gth_image_print_job_update_page_layout (GthImagePrintJob *self,
if (image_info->page != page)
continue;
if (self->priv->selected == NULL)
self->priv->selected = image_info;
gth_image_info_rotate (image_info, (360 - image_info->rotation) % 360);
/*
if (((self->priv->max_image_width > self->priv->max_image_height)
&& (image_info->pixbuf_width < image_info->pixbuf_height))
|| ((self->priv->max_image_width < self->priv->max_image_height)
......@@ -325,6 +332,7 @@ gth_image_print_job_update_page_layout (GthImagePrintJob *self,
{
gth_image_info_rotate (image_info, 270);
}
*/
image_info->zoom = 1.0;
image_info->boundary.x = (image_info->col - 1) * (self->priv->max_image_width + self->priv->x_padding);
......@@ -403,9 +411,6 @@ gth_image_print_job_update_page_layout (GthImagePrintJob *self,
}
#define PREVIEW_SCALE_FACTOR 3.0 /* FIXME: why 3.0 ? */
static void
gth_image_print_job_update_layout (GthImagePrintJob *self,
gdouble page_width,
......@@ -446,7 +451,10 @@ gth_image_print_job_paint (GthImagePrintJob *self,
cairo_save (cr);
cairo_set_line_width (cr, 0.5);
cairo_set_source_rgb (cr, .5, .5, .5);
if (image_info == self->priv->selected)
cairo_set_source_rgb (cr, 1.0, .0, .0);
else
cairo_set_source_rgb (cr, .5, .5, .5);
cairo_rectangle (cr,
x_offset + image_info->boundary.x,
y_offset + image_info->boundary.y,
......@@ -640,6 +648,19 @@ gth_image_print_job_update_status (GthImagePrintJob *self)
}
static void
gth_image_print_job_update_image_controls (GthImagePrintJob *self)
{
int idx;
if (self->priv->selected == NULL)
return;
idx = self->priv->selected->rotation / 90;
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("rotation_combobox")), idx);
}
static void
gth_image_print_job_update_preview (GthImagePrintJob *self)
{
......@@ -652,9 +673,10 @@ gth_image_print_job_update_preview (GthImagePrintJob *self)
gtk_page_setup_get_orientation (self->priv->page_setup));
gtk_widget_queue_draw (GET_WIDGET ("preview_drawingarea"));
gth_image_print_job_update_image_controls (self);
text = g_strdup_printf (_("Page %d of %d"), self->priv->current_page + 1, self->priv->n_pages);
gtk_label_set_text (GTK_LABEL (GET_WIDGET ("page_label")), text);
gtk_widget_set_sensitive (GET_WIDGET ("next_page_button"), self->priv->current_page < self->priv->n_pages - 1);
gtk_widget_set_sensitive (GET_WIDGET ("prev_page_button"), self->priv->current_page > 0);
......@@ -714,6 +736,7 @@ next_page_button_clicked_cb (GtkWidget *widget,
GthImagePrintJob *self = user_data;
self->priv->current_page = MIN (self->priv->current_page + 1, self->priv->n_pages - 1);
self->priv->selected = NULL;
gth_image_print_job_update_preview (self);
}
......@@ -725,6 +748,7 @@ prev_page_button_clicked_cb (GtkWidget *widget,
GthImagePrintJob *self = user_data;
self->priv->current_page = MAX (0, self->priv->current_page - 1);
self->priv->selected = NULL;
gth_image_print_job_update_preview (self);
}
......@@ -773,6 +797,7 @@ caption_chooser_changed_cb (GthMetadataChooser *chooser,
reload_required = attribute_list_reaload_required (self->priv->caption_attributes, new_caption_attributes);
g_free (self->priv->caption_attributes);
self->priv->caption_attributes = new_caption_attributes;
eel_gconf_set_string (PREF_IMAGE_PRINT_CAPTION, self->priv->caption_attributes);
if (reload_required)
gth_image_print_job_load_metadata (self);
......@@ -792,6 +817,8 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
gtk_widget_show (self->priv->caption_chooser);
gtk_container_add (GTK_CONTAINER (GET_WIDGET ("caption_scrolledwindow")), self->priv->caption_chooser);
gth_metadata_chooser_set_selection (GTH_METADATA_CHOOSER (self->priv->caption_chooser), self->priv->caption_attributes);
g_signal_connect (GET_WIDGET ("preview_drawingarea"),
"expose_event",
G_CALLBACK (preview_expose_event_cb),
......@@ -844,6 +871,7 @@ operation_update_custom_widget_cb (GtkPrintOperation *operation,
gtk_widget_set_size_request (GET_WIDGET ("preview_drawingarea"),
gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM),
gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM));
gth_image_print_job_update_preview (self);
}
......@@ -1005,7 +1033,9 @@ gth_image_print_job_run (GthImagePrintJob *self,
self->priv->action = action;
self->priv->browser = browser;
self->priv->task = gth_load_image_info_task_new (self->priv->images, self->priv->n_images);
self->priv->task = gth_load_image_info_task_new (self->priv->images,
self->priv->n_images,
self->priv->caption_attributes);
g_signal_connect (self->priv->task,
"completed",
G_CALLBACK (load_image_info_task_completed_cb),
......
......@@ -30,6 +30,7 @@ struct _GthLoadImageInfoTaskPrivate {
GthImageInfo **images;
int n_images;
int current;
char *attributes;
GthImageLoader *loader;
};
......@@ -48,6 +49,7 @@ gth_load_image_info_task_finalize (GObject *object)
for (i = 0; i < self->priv->n_images; i++)
gth_image_info_unref (self->priv->images[i]);
g_free (self->priv->images);
g_free (self->priv->attributes);
g_object_unref (self->priv->loader);
G_OBJECT_CLASS (parent_class)->finalize (object);
......@@ -57,27 +59,53 @@ gth_load_image_info_task_finalize (GObject *object)
static void load_current_image (GthLoadImageInfoTask *self);
static void
load_next_image (GthLoadImageInfoTask *self)
{
self->priv->current++;
load_current_image (self);
}
static void
metadata_ready_cb (GList *files,
GError *error,
gpointer user_data)
{
GthLoadImageInfoTask *self = user_data;
if (error != NULL) {
gth_task_completed (GTH_TASK (self), error);
return;
}
load_next_image (self);
}
static void
image_loader_ready_cb (GthImageLoader *loader,
GError *error,
gpointer user_data)
{
GthLoadImageInfoTask *self = user_data;
GthImageInfo *image_info;
GdkPixbuf *pixbuf;
if (error == NULL)
g_cancellable_set_error_if_cancelled (gth_task_get_cancellable (GTH_TASK (self)), &error);
if (error != NULL) {
gth_task_completed (GTH_TASK (self), error);
return;
}
image_info = self->priv->images[self->priv->current];
pixbuf = gth_image_loader_get_pixbuf (loader);
if (pixbuf != NULL) {
GthImageInfo *image_info;
int thumb_w, thumb_h;
int thumb_w, thumb_h;
image_info = self->priv->images[self->priv->current];
image_info->pixbuf = g_object_ref (pixbuf);
thumb_w = image_info->pixbuf_width = gdk_pixbuf_get_width (pixbuf);
thumb_h = image_info->pixbuf_height = gdk_pixbuf_get_height (pixbuf);
if (scale_keeping_ratio (&thumb_w, &thumb_h, THUMBNAIL_SIZE, THUMBNAIL_SIZE, FALSE))
......@@ -94,8 +122,20 @@ image_loader_ready_cb (GthImageLoader *loader,
}
}
self->priv->current++;
load_current_image (self);
if (strcmp (self->priv->attributes, "") != 0) {
GList *files;
files = g_list_prepend (NULL, image_info->file_data);
_g_query_metadata_async (files,
self->priv->attributes,
gth_task_get_cancellable (GTH_TASK (self)),
metadata_ready_cb,
self);
g_list_free (files);
}
else
load_next_image (self);
}
......@@ -106,7 +146,6 @@ load_current_image (GthLoadImageInfoTask *self)
char *details;
if (self->priv->current >= self->priv->n_images) {
/* FIXME: read the required metadata as well */
gth_task_completed (GTH_TASK (self), NULL);
return;
}
......@@ -208,7 +247,8 @@ gth_load_image_info_task_get_type (void)
GthTask *
gth_load_image_info_task_new (GthImageInfo **images,
int n_images)
int n_images,
const char *attributes)
{
GthLoadImageInfoTask *self;
int n;
......@@ -219,6 +259,7 @@ gth_load_image_info_task_new (GthImageInfo **images,
self->priv->images[n] = gth_image_info_ref (images[n]);
self->priv->images[n] = NULL;
self->priv->n_images = n;
self->priv->attributes = g_strdup (attributes);
self->priv->current = 0;
return (GthTask *) self;
......
......@@ -51,7 +51,8 @@ struct _GthLoadImageInfoTaskClass {
GType gth_load_image_info_task_get_type (void);
GthTask * gth_load_image_info_task_new (GthImageInfo **images,
int n_images);
int n_images,
const char *attributes);
G_END_DECLS
......
/* -*- 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_IMAGE_PRINT_CAPTION "/apps/gthumb/ext/image_print/caption"
G_END_DECLS
#endif /* PREFERENCES_H */
......@@ -2107,6 +2107,20 @@ _g_file_append_path (GFile *file,
}
static gboolean
attribute_matches_mask (const char *attribute,
const char *mask)
{
char *pattern_end;
pattern_end = g_strstr_len (mask, -1, "*");
if (pattern_end == NULL)
return strcmp (attribute, mask) == 0;
else
return strncmp (attribute, mask, pattern_end - mask) == 0;
}
static gboolean
_g_file_attributes_matches_mask (const char *attributes,
const char *mask)
......@@ -2119,14 +2133,14 @@ _g_file_attributes_matches_mask (const char *attributes,
attributes_v = g_strsplit (attributes, ",", -1);
mask_v = g_strsplit (mask, ",", -1);
for (i = 0; ! matches && (mask_v[i] != NULL); i++) {
GFileAttributeMatcher *matcher;
int j;
matcher = g_file_attribute_matcher_new (mask_v[i]);
for (j = 0; ! matches && (attributes_v[j] != NULL); j++)
matches = g_file_attribute_matcher_matches (matcher, attributes_v[j]);
int j;
g_file_attribute_matcher_unref (matcher);
for (j = 0; ! matches && (attributes_v[j] != NULL); j++) {
matches = attribute_matches_mask (attributes_v[j], mask_v[i]);
#if 0
g_print ("attr: %s <=> mask: %s : %d\n", attributes_v[j], mask_v[i], matches);
#endif
}
}
g_strfreev (mask_v);
......
......@@ -48,9 +48,9 @@ GthMetadataInfo file_metadata_info[] = {
{ "general::format", N_("Format"), "general", 12, GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
{ "Embedded::Image::DateTime", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
{ "Embedded::Image::Comment", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
{ "Embedded::Image::Comment", N_("Comment"), "general", 14, GTH_METADATA_ALLOW_IN_PRINT },
{ "Embedded::Image::Location", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
{ "Embedded::Image::Keywords", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
{ "Embedded::Image::Keywords", N_("Tags"), "general", 16, GTH_METADATA_ALLOW_IN_PRINT },
{ "Embedded::Image::Orientation", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
{ "Embedded::Photo::DateTimeOriginal", "", "", 0, GTH_METADATA_ALLOW_NOWHERE },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment