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="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method>
<method name="ScreenshotWindow">
<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="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method>
<method name="Screenshot">
<arg type="b" direction="in" name="include_cursor"/>
<arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="filename_used"/>
</method>
<method name="SelectArea">
<arg type="i" direction="out" name="x"/>
@ -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);
},

View File

@ -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;

View File

@ -27,7 +27,8 @@ ShellScreenshot *shell_screenshot_new (void);
typedef void (*ShellScreenshotCallback) (ShellScreenshot *screenshot,
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,
int x,