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
This commit is contained in:
Cosimo Cecchi 2012-12-10 09:03:49 -05:00
parent acba0e47d8
commit dcad22bfa8
3 changed files with 25 additions and 12 deletions

View File

@ -27,6 +27,7 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
<arg type="b" direction="in" name="flash"/> <arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/> <arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/> <arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method> </method>
<method name="ScreenshotWindow"> <method name="ScreenshotWindow">
<arg type="b" direction="in" name="include_frame"/> <arg type="b" direction="in" name="include_frame"/>
@ -34,12 +35,14 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
<arg type="b" direction="in" name="flash"/> <arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/> <arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/> <arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method> </method>
<method name="Screenshot"> <method name="Screenshot">
<arg type="b" direction="in" name="include_cursor"/> <arg type="b" direction="in" name="include_cursor"/>
<arg type="b" direction="in" name="flash"/> <arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/> <arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/> <arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method> </method>
<method name="SelectArea"> <method name="SelectArea">
<arg type="i" direction="out" name="x"/> <arg type="i" direction="out" name="x"/>
@ -118,13 +121,13 @@ const GnomeShell = new Lang.Class({
return [success, returnValue]; return [success, returnValue];
}, },
_onScreenshotComplete: function(obj, result, area, flash, invocation) { _onScreenshotComplete: function(obj, result, area, filenameUsed, flash, invocation) {
if (flash && result) { if (flash && result) {
let flashspot = new Flashspot.Flashspot(area); let flashspot = new Flashspot.Flashspot(area);
flashspot.fire(); flashspot.fire();
} }
let retval = GLib.Variant.new('(b)', [result]); let retval = GLib.Variant.new('(bs)', [result, filenameUsed]);
invocation.return_value(retval); invocation.return_value(retval);
}, },

View File

@ -32,6 +32,7 @@ typedef struct _screenshot_data {
ShellScreenshot *screenshot; ShellScreenshot *screenshot;
char *filename; char *filename;
char *filename_used;
cairo_surface_t *image; cairo_surface_t *image;
cairo_rectangle_int_t screenshot_area; cairo_rectangle_int_t screenshot_area;
@ -64,18 +65,21 @@ on_screenshot_written (GObject *source,
if (screenshot_data->callback) if (screenshot_data->callback)
screenshot_data->callback (screenshot_data->screenshot, screenshot_data->callback (screenshot_data->screenshot,
g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)), 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); cairo_surface_destroy (screenshot_data->image);
g_object_unref (screenshot_data->screenshot); g_object_unref (screenshot_data->screenshot);
g_free (screenshot_data->filename); g_free (screenshot_data->filename);
g_free (screenshot_data->filename_used);
g_free (screenshot_data); g_free (screenshot_data);
} }
/* called in an I/O thread */ /* called in an I/O thread */
static GOutputStream * static GOutputStream *
get_stream_for_path (const gchar *path, get_stream_for_path (const gchar *path,
const gchar *filename) const gchar *filename,
gchar **filename_used)
{ {
GOutputStream *stream; GOutputStream *stream;
GFile *file; GFile *file;
@ -95,15 +99,17 @@ get_stream_for_path (const gchar *path,
file = g_file_new_for_path (real_path); file = g_file_new_for_path (real_path);
stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL)); stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
g_free (real_path);
g_object_unref (file); g_object_unref (file);
*filename_used = real_path;
return stream; return stream;
} }
/* called in an I/O thread */ /* called in an I/O thread */
static GOutputStream * static GOutputStream *
get_stream_for_filename (const gchar *filename) get_stream_for_filename (const gchar *filename,
gchar **filename_used)
{ {
const gchar *path; const gchar *path;
@ -115,11 +121,12 @@ get_stream_for_filename (const gchar *filename)
return NULL; return NULL;
} }
return get_stream_for_path (path, filename); return get_stream_for_path (path, filename, filename_used);
} }
static GOutputStream * static GOutputStream *
prepare_write_stream (const gchar *filename) prepare_write_stream (const gchar *filename,
gchar **filename_used)
{ {
GOutputStream *stream; GOutputStream *stream;
GFile *file; GFile *file;
@ -127,12 +134,13 @@ prepare_write_stream (const gchar *filename)
if (g_path_is_absolute (filename)) if (g_path_is_absolute (filename))
{ {
file = g_file_new_for_path (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)); stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
g_object_unref (file); g_object_unref (file);
} }
else else
{ {
stream = get_stream_for_filename (filename); stream = get_stream_for_filename (filename, filename_used);
} }
return stream; return stream;
@ -162,7 +170,8 @@ write_screenshot_thread (GSimpleAsyncResult *result,
g_assert (screenshot_data != NULL); 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) if (stream == NULL)
status = CAIRO_STATUS_FILE_NOT_FOUND; status = CAIRO_STATUS_FILE_NOT_FOUND;

View File

@ -26,8 +26,9 @@ GType shell_screenshot_get_type (void) G_GNUC_CONST;
ShellScreenshot *shell_screenshot_new (void); ShellScreenshot *shell_screenshot_new (void);
typedef void (*ShellScreenshotCallback) (ShellScreenshot *screenshot, typedef void (*ShellScreenshotCallback) (ShellScreenshot *screenshot,
gboolean success, gboolean success,
cairo_rectangle_int_t *screenshot_area); cairo_rectangle_int_t *screenshot_area,
const gchar *filename_used);
void shell_screenshot_screenshot_area (ShellScreenshot *screenshot, void shell_screenshot_screenshot_area (ShellScreenshot *screenshot,
int x, int x,