From dcad22bfa826cca0a32484d74d57f4e4a273bc7a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 10 Dec 2012 09:03:49 -0500 Subject: [PATCH] screenshot: change API to return the filename used for saving Since we also support passing a basename now, clients might be interested in knowing the path used to save the file. Add an out argument to the interface for that. https://bugzilla.gnome.org/show_bug.cgi?id=688004 --- js/ui/shellDBus.js | 7 +++++-- src/shell-screenshot.c | 25 +++++++++++++++++-------- src/shell-screenshot.h | 5 +++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js index 436497406..f2d91a9ab 100644 --- a/js/ui/shellDBus.js +++ b/js/ui/shellDBus.js @@ -27,6 +27,7 @@ const GnomeShellIface = + @@ -34,12 +35,14 @@ const GnomeShellIface = + + @@ -118,13 +121,13 @@ const GnomeShell = new Lang.Class({ return [success, returnValue]; }, - _onScreenshotComplete: function(obj, result, area, flash, invocation) { + _onScreenshotComplete: function(obj, result, area, filenameUsed, flash, invocation) { if (flash && result) { let flashspot = new Flashspot.Flashspot(area); flashspot.fire(); } - let retval = GLib.Variant.new('(b)', [result]); + let retval = GLib.Variant.new('(bs)', [result, filenameUsed]); invocation.return_value(retval); }, diff --git a/src/shell-screenshot.c b/src/shell-screenshot.c index 5c0109331..b05550ecb 100644 --- a/src/shell-screenshot.c +++ b/src/shell-screenshot.c @@ -32,6 +32,7 @@ typedef struct _screenshot_data { ShellScreenshot *screenshot; char *filename; + char *filename_used; cairo_surface_t *image; cairo_rectangle_int_t screenshot_area; @@ -64,18 +65,21 @@ on_screenshot_written (GObject *source, if (screenshot_data->callback) screenshot_data->callback (screenshot_data->screenshot, g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)), - &screenshot_data->screenshot_area); + &screenshot_data->screenshot_area, + screenshot_data->filename_used); cairo_surface_destroy (screenshot_data->image); g_object_unref (screenshot_data->screenshot); g_free (screenshot_data->filename); + g_free (screenshot_data->filename_used); g_free (screenshot_data); } /* called in an I/O thread */ static GOutputStream * get_stream_for_path (const gchar *path, - const gchar *filename) + const gchar *filename, + gchar **filename_used) { GOutputStream *stream; GFile *file; @@ -95,15 +99,17 @@ get_stream_for_path (const gchar *path, file = g_file_new_for_path (real_path); stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL)); - g_free (real_path); g_object_unref (file); + *filename_used = real_path; + return stream; } /* called in an I/O thread */ static GOutputStream * -get_stream_for_filename (const gchar *filename) +get_stream_for_filename (const gchar *filename, + gchar **filename_used) { const gchar *path; @@ -115,11 +121,12 @@ get_stream_for_filename (const gchar *filename) return NULL; } - return get_stream_for_path (path, filename); + return get_stream_for_path (path, filename, filename_used); } static GOutputStream * -prepare_write_stream (const gchar *filename) +prepare_write_stream (const gchar *filename, + gchar **filename_used) { GOutputStream *stream; GFile *file; @@ -127,12 +134,13 @@ prepare_write_stream (const gchar *filename) if (g_path_is_absolute (filename)) { file = g_file_new_for_path (filename); + *filename_used = g_strdup (filename); stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL)); g_object_unref (file); } else { - stream = get_stream_for_filename (filename); + stream = get_stream_for_filename (filename, filename_used); } return stream; @@ -162,7 +170,8 @@ write_screenshot_thread (GSimpleAsyncResult *result, g_assert (screenshot_data != NULL); - stream = prepare_write_stream (screenshot_data->filename); + stream = prepare_write_stream (screenshot_data->filename, + &screenshot_data->filename_used); if (stream == NULL) status = CAIRO_STATUS_FILE_NOT_FOUND; diff --git a/src/shell-screenshot.h b/src/shell-screenshot.h index 26b3667ee..76925f31c 100644 --- a/src/shell-screenshot.h +++ b/src/shell-screenshot.h @@ -26,8 +26,9 @@ GType shell_screenshot_get_type (void) G_GNUC_CONST; ShellScreenshot *shell_screenshot_new (void); typedef void (*ShellScreenshotCallback) (ShellScreenshot *screenshot, - gboolean success, - cairo_rectangle_int_t *screenshot_area); + gboolean success, + cairo_rectangle_int_t *screenshot_area, + const gchar *filename_used); void shell_screenshot_screenshot_area (ShellScreenshot *screenshot, int x,