summaryrefslogtreecommitdiff
path: root/image-converter/caja-image-resizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'image-converter/caja-image-resizer.c')
-rw-r--r--image-converter/caja-image-resizer.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/image-converter/caja-image-resizer.c b/image-converter/caja-image-resizer.c
index 3409d91..ae33b23 100644
--- a/image-converter/caja-image-resizer.c
+++ b/image-converter/caja-image-resizer.c
@@ -1,6 +1,6 @@
/*
* caja-image-resizer.c
- *
+ *
* Copyright (C) 2004-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
@@ -18,7 +18,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author: Jürg Billeter <[email protected]>
- *
+ *
*/
#ifdef HAVE_CONFIG_H
@@ -34,18 +34,18 @@
#include <gtk/gtk.h>
#include <libcaja-extension/caja-file-info.h>
-
+
typedef struct _CajaImageResizerPrivate CajaImageResizerPrivate;
struct _CajaImageResizerPrivate {
GList *files;
-
+
gchar *suffix;
-
+
int images_resized;
int images_total;
gboolean cancelled;
-
+
gchar *size;
GtkDialog *resize_dialog;
@@ -84,9 +84,9 @@ caja_image_resizer_finalize(GObject *object)
{
CajaImageResizer *dialog = CAJA_IMAGE_RESIZER (object);
CajaImageResizerPrivate *priv = CAJA_IMAGE_RESIZER_GET_PRIVATE (dialog);
-
+
g_free (priv->suffix);
-
+
G_OBJECT_CLASS(caja_image_resizer_parent_class)->finalize(object);
}
@@ -162,17 +162,17 @@ caja_image_resizer_transform_filename (CajaImageResizer *resizer, GFile *orig_fi
GFile *parent_file, *new_file;
char *basename, *extension, *new_basename;
-
+
g_return_val_if_fail (G_IS_FILE (orig_file), NULL);
parent_file = g_file_get_parent (orig_file);
basename = g_strdup (g_file_get_basename (orig_file));
-
+
extension = g_strdup (strrchr (basename, '.'));
if (extension != NULL)
basename[strlen (basename) - strlen (extension)] = '\0';
-
+
new_basename = g_strdup_printf ("%s%s%s", basename,
priv->suffix == NULL ? ".tmp" : priv->suffix,
extension == NULL ? "" : extension);
@@ -192,11 +192,11 @@ op_finished (GPid pid, gint status, gpointer data)
{
CajaImageResizer *resizer = CAJA_IMAGE_RESIZER (data);
CajaImageResizerPrivate *priv = CAJA_IMAGE_RESIZER_GET_PRIVATE (resizer);
-
+
gboolean retry = TRUE;
-
+
CajaFileInfo *file = CAJA_FILE_INFO (priv->files->data);
-
+
if (status != 0) {
/* resizing failed */
char *name = caja_file_info_get_name (file);
@@ -207,12 +207,12 @@ op_finished (GPid pid, gint status, gpointer data)
"'%s' cannot be resized. Check whether you have permission to write to this folder.",
name);
g_free (name);
-
+
gtk_dialog_add_button (GTK_DIALOG (msg_dialog), _("_Skip"), 1);
gtk_dialog_add_button (GTK_DIALOG (msg_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (msg_dialog), _("_Retry"), 0);
gtk_dialog_set_default_response (GTK_DIALOG (msg_dialog), 0);
-
+
int response_id = gtk_dialog_run (GTK_DIALOG (msg_dialog));
gtk_widget_destroy (msg_dialog);
if (response_id == 0) {
@@ -222,7 +222,7 @@ op_finished (GPid pid, gint status, gpointer data)
} else if (response_id == 1) {
retry = FALSE;
}
-
+
} else if (priv->suffix == NULL) {
/* resize image in place */
GFile *orig_location = caja_file_info_get_location (file);
@@ -237,7 +237,7 @@ op_finished (GPid pid, gint status, gpointer data)
priv->images_resized++;
priv->files = priv->files->next;
}
-
+
if (!priv->cancelled && priv->files != NULL) {
/* process next image */
run_op (resizer);
@@ -251,9 +251,9 @@ static void
run_op (CajaImageResizer *resizer)
{
CajaImageResizerPrivate *priv = CAJA_IMAGE_RESIZER_GET_PRIVATE (resizer);
-
+
g_return_if_fail (priv->files != NULL);
-
+
CajaFileInfo *file = CAJA_FILE_INFO (priv->files->data);
GFile *orig_location = caja_file_info_get_location (file);
@@ -264,7 +264,7 @@ run_op (CajaImageResizer *resizer)
g_object_unref (new_location);
/* FIXME: check whether new_uri already exists and provide "Replace _All", "_Skip", and "_Replace" options */
-
+
gchar *argv[6];
argv[0] = "/usr/bin/convert";
argv[1] = filename;
@@ -272,32 +272,32 @@ run_op (CajaImageResizer *resizer)
argv[3] = priv->size;
argv[4] = new_filename;
argv[5] = NULL;
-
+
pid_t pid;
if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL)) {
// FIXME: error handling
return;
}
-
+
g_free (filename);
g_free (new_filename);
-
+
g_child_watch_add (pid, op_finished, resizer);
-
+
char *tmp;
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar), (double) (priv->images_resized + 1) / priv->images_total);
tmp = g_strdup_printf (_("Resizing image: %d of %d"), priv->images_resized + 1, priv->images_total);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress_bar), tmp);
g_free (tmp);
-
+
char *name = caja_file_info_get_name (file);
tmp = g_strdup_printf (_("<i>Resizing \"%s\"</i>"), name);
g_free (name);
gtk_label_set_markup (GTK_LABEL (priv->progress_label), tmp);
g_free (tmp);
-
+
}
static void
@@ -325,7 +325,7 @@ caja_image_resizer_response_cb (GtkDialog *dialog, gint response_id, gpointer us
} else {
priv->size = g_strdup_printf ("%dx%d", (int) gtk_spin_button_get_value (priv->width_spinbutton), (int) gtk_spin_button_get_value (priv->height_spinbutton));
}
-
+
run_op (resizer);
}