[gnome-screenshot] screenshot: Add command option --file
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-screenshot] screenshot: Add command option --file
- Date: Wed, 23 May 2012 18:32:03 +0000 (UTC)
commit 78bbf6ef75aa43973799d258e0a426119885cc07
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Wed May 23 20:15:28 2012 +0200
screenshot: Add command option --file
https://bugzilla.gnome.org/show_bug.cgi?id=129768
src/screenshot-application.c | 27 ++++++++++++++++++++++++---
src/screenshot-config.c | 8 +++++++-
src/screenshot-config.h | 4 +++-
3 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 710b1e9..7beeb35 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -175,8 +175,11 @@ save_pixbuf_handle_error (ScreenshotApplication *self,
}
else
{
+ g_critical ("Unable to save the screenshot: %s", error->message);
screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot"));
g_application_release (G_APPLICATION (self));
+ if (screenshot_config->file != NULL)
+ exit (EXIT_FAILURE);
}
}
@@ -334,7 +337,11 @@ build_filename_ready_cb (GObject *source,
_("Unable to capture a screenshot"),
_("Error creating file"));
else
- screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot"));
+ {
+ screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot"));
+ if (screenshot_config->file != NULL)
+ exit (EXIT_FAILURE);
+ }
return;
}
@@ -378,6 +385,8 @@ finish_prepare_screenshot (ScreenshotApplication *self,
screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot"));
g_application_release (G_APPLICATION (self));
+ if (screenshot_config->file != NULL)
+ exit (EXIT_FAILURE);
return;
}
@@ -417,7 +426,14 @@ finish_prepare_screenshot (ScreenshotApplication *self,
*
* screenshot_ensure_icc_profile (window);
*/
- screenshot_build_filename_async (build_filename_ready_cb, self);
+ if (screenshot_config->file != NULL)
+ {
+ self->priv->save_uri = g_file_get_uri (screenshot_config->file);
+ self->priv->should_overwrite = TRUE;
+ screenshot_save_to_file (self);
+ }
+ else
+ screenshot_build_filename_async (build_filename_ready_cb, self);
}
static void
@@ -487,6 +503,7 @@ screenshot_application_local_command_line (GApplication *app,
gboolean interactive_arg = FALSE;
gchar *border_effect_arg = NULL;
guint delay_arg = 0;
+ gchar *file_arg = NULL;
const GOptionEntry entries[] = {
{ "clipboard", 'c', 0, G_OPTION_ARG_NONE, &clipboard_arg, N_("Send the grab directly to the clipboard"), NULL },
{ "window", 'w', 0, G_OPTION_ARG_NONE, &window_arg, N_("Grab a window instead of the entire screen"), NULL },
@@ -496,6 +513,7 @@ screenshot_application_local_command_line (GApplication *app,
{ "delay", 'd', 0, G_OPTION_ARG_INT, &delay_arg, N_("Take screenshot after specified delay [in seconds]"), N_("seconds") },
{ "border-effect", 'e', 0, G_OPTION_ARG_STRING, &border_effect_arg, N_("Effect to add to the border (shadow, border or none)"), N_("effect") },
{ "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive_arg, N_("Interactively set options"), NULL },
+ { "file", 'f', 0, G_OPTION_ARG_FILENAME, &file_arg, N_("Save screenshot directly to this file"), N_("filename") },
{ NULL },
};
@@ -529,7 +547,8 @@ screenshot_application_local_command_line (GApplication *app,
disable_border_arg,
border_effect_arg,
delay_arg,
- interactive_arg);
+ interactive_arg,
+ file_arg);
if (!res)
{
@@ -547,6 +566,8 @@ screenshot_application_local_command_line (GApplication *app,
out:
g_option_context_free (context);
+ g_free (border_effect_arg);
+ g_free (file_arg);
return TRUE;
}
diff --git a/src/screenshot-config.c b/src/screenshot-config.c
index f99a553..d920d45 100644
--- a/src/screenshot-config.c
+++ b/src/screenshot-config.c
@@ -41,7 +41,8 @@ screenshot_load_config (gboolean clipboard_arg,
gboolean disable_border_arg,
const gchar *border_effect_arg,
guint delay_arg,
- gboolean interactive_arg)
+ gboolean interactive_arg,
+ const gchar *file_arg)
{
static gboolean initialized = FALSE;
ScreenshotConfig *config;
@@ -71,6 +72,9 @@ screenshot_load_config (gboolean clipboard_arg,
config->settings = g_settings_new ("org.gnome.gnome-screenshot");
if (config->interactive)
{
+ if (file_arg)
+ g_warning ("Option --file is ignored in interactive mode.");
+
config->save_dir =
g_settings_get_string (config->settings,
LAST_SAVE_DIRECTORY_KEY);
@@ -106,6 +110,8 @@ screenshot_load_config (gboolean clipboard_arg,
config->border_effect = g_strdup (border_effect_arg);
config->copy_to_clipboard = clipboard_arg;
+ if (file_arg != NULL)
+ config->file = g_file_new_for_commandline_arg (file_arg);
}
config->include_icc_profile =
diff --git a/src/screenshot-config.h b/src/screenshot-config.h
index c5b1aa5..4cf55c7 100644
--- a/src/screenshot-config.h
+++ b/src/screenshot-config.h
@@ -29,6 +29,7 @@ typedef struct {
GSettings *settings;
gchar *save_dir;
+ GFile *file;
gboolean copy_to_clipboard;
@@ -55,7 +56,8 @@ gboolean screenshot_load_config (gboolean clipboard_arg,
gboolean disable_border_arg,
const gchar *border_effect_arg,
guint delay_arg,
- gboolean interactive_arg);
+ gboolean interactive_arg,
+ const gchar *file_arg);
void screenshot_save_config (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]