[gnome-desktop/wip/thumbnail-resources: 5/7] thumbnail: Refactor script running part out into a separate function
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop/wip/thumbnail-resources: 5/7] thumbnail: Refactor script running part out into a separate function
- Date: Mon, 1 Oct 2012 21:16:02 +0000 (UTC)
commit 157c91836ff68a9b17fc1da348794ebf75be4d29
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Oct 1 17:52:30 2012 -0300
thumbnail: Refactor script running part out into a separate function
libgnome-desktop/gnome-desktop-thumbnail.c | 63 +++++++++++++++++-----------
1 files changed, 38 insertions(+), 25 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index f375537..2c8da6b 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -1139,6 +1139,42 @@ expand_thumbnailing_script (const char *script,
return NULL;
}
+static GdkPixbuf *
+run_script (char *script, const char *uri, int size)
+{
+ int fd;
+ int exit_status;
+ char *expanded_script;
+ char *tmpname;
+ GdkPixbuf *pixbuf = NULL;
+
+ fd = g_file_open_tmp (".gnome_desktop_thumbnail.XXXXXX", &tmpname, NULL);
+
+ if (fd == -1)
+ return NULL;
+
+ close (fd);
+ expanded_script = expand_thumbnailing_script (script, size, uri, tmpname);
+
+ if (expanded_script == NULL)
+ goto out;
+
+ if (!g_spawn_command_line_sync (expanded_script, NULL, NULL, &exit_status, NULL))
+ goto out;
+
+ if (exit_status != 0)
+ goto out;
+
+ pixbuf = gdk_pixbuf_new_from_file (tmpname, NULL);
+
+ out:
+ g_free (expanded_script);
+ g_unlink (tmpname);
+ g_free (tmpname);
+
+ return pixbuf;
+}
+
/**
* gnome_desktop_thumbnail_factory_generate_thumbnail:
* @factory: a #GnomeDesktopThumbnailFactory
@@ -1160,14 +1196,12 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
const char *mime_type)
{
GdkPixbuf *pixbuf, *scaled, *tmp_pixbuf;
- char *script, *expanded_script;
+ char *script;
int width, height, size;
int original_width = 0;
int original_height = 0;
char dimension[12];
double scale;
- int exit_status;
- char *tmpname;
g_return_val_if_fail (uri != NULL, NULL);
g_return_val_if_fail (mime_type != NULL, NULL);
@@ -1194,28 +1228,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
if (script)
{
- int fd;
-
- fd = g_file_open_tmp (".gnome_desktop_thumbnail.XXXXXX", &tmpname, NULL);
-
- if (fd != -1)
- {
- close (fd);
-
- expanded_script = expand_thumbnailing_script (script, size, uri, tmpname);
- if (expanded_script != NULL &&
- g_spawn_command_line_sync (expanded_script,
- NULL, NULL, &exit_status, NULL) &&
- exit_status == 0)
- {
- pixbuf = gdk_pixbuf_new_from_file (tmpname, NULL);
- }
-
- g_free (expanded_script);
- g_unlink (tmpname);
- g_free (tmpname);
- }
-
+ pixbuf = run_script (script, uri, size);
g_free (script);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]