1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* (C) 2007 OpenedHand Ltd.
*
* Author: Ross Burton <ross@openedhand.com>
*
* Licensed under the GPL v2 or greater.
*/
#include <gtk/gtk.h>
#include "screenshot-utils.h"
static void
save (GtkWindow *parent, GdkPixbuf *pixbuf, const char *filename)
{
GError *error = NULL;
g_assert (pixbuf);
g_assert (filename);
if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) {
screenshot_show_gerror_dialog (parent, "Could not save screenshot", error);
}
g_object_unref (pixbuf);
}
void
screenshot (const char *filename)
{
GtkWidget *filechooser;
GdkPixbuf *pixbuf;
int response;
/* Get the screenshot */
pixbuf = screenshot_get_pixbuf (GDK_ROOT_WINDOW());
if (!pixbuf) {
screenshot_show_error_dialog (NULL, "Could not capture a screenshot.", NULL);
return;
}
/* If we were passed a filename, save it now */
if (filename) {
save (NULL, pixbuf, filename);
return;
}
/* Otherwise, open a file chooser to get a filename */
filechooser = gtk_file_chooser_dialog_new ("Save Screenshot", NULL,
GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel", GTK_RESPONSE_REJECT,
"Save", GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (filechooser), GTK_RESPONSE_ACCEPT);
#if GTK_CHECK_VERSION(2,7,3)
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (filechooser),
TRUE);
#endif
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filechooser), "Screenshot.png");
gtk_widget_show (filechooser);
/* TODO: add extra widget showing thumbnail */
/* TODO: add combo for available file types -- see gdk_pixbuf_save docs */
/* TODO: add magic options to upload to scap/flickr/etc? */
response = gtk_dialog_run (GTK_DIALOG (filechooser));
if (response == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
save (GTK_WINDOW (filechooser), pixbuf, filename);
}
gtk_widget_destroy (filechooser);
return;
}
|