[Xfce4-commits] <xfce4-screenshooter:master> Rainy day. Major interface rethinking.
Jérôme Guelfucci
jeromeg at xfce.org
Fri Aug 14 00:26:11 CEST 2009
Updating branch refs/heads/master
to e1d446387ba42bae3d8f52056f90809177bd6724 (commit)
from 98c6971ced389996a99335e1b926b56c1c1e5911 (commit)
commit e1d446387ba42bae3d8f52056f90809177bd6724
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Mon Aug 3 15:49:19 2009 +0200
Rainy day. Major interface rethinking.
This new interface is based on a suggestion by Yves-Alexis Pérez. The
former main dialog is split into two dialogs: one for selecting the
region to be captured and the delay, while the second one displays a
preview of the screenshot and lists the available actions.
The main application shows the first dialog, then the second one. If
one of the region cli options is given, the screenshot is taken
accordingly and the second dialog is displayed.
The panel plugin uses the first dialog as a configuration dialog. When
you click the plugin, the screenshot is taken and the second dialog is
shown.
ChangeLog | 17 ++
lib/screenshooter-actions.c | 76 +++++--
lib/screenshooter-actions.h | 3 +-
lib/screenshooter-dialogs.c | 389 ++++++++++++-----------------------
lib/screenshooter-dialogs.h | 11 +-
lib/screenshooter-global.h | 1 +
panel-plugin/screenshooter-plugin.c | 23 +--
src/main.c | 7 +-
8 files changed, 216 insertions(+), 311 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1311bab..439e579 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,23 @@ Updated Italian and Galician documentation translation.
2009-08-03 jeromeg
+Rainy day. Major interface rethinking.
+
+This new interface is based on a suggestion by Yves-Alexis Pérez. The
+former main dialog is split into two dialogs: one for selecting the
+region to be captured and the delay, while the second one displays a
+preview of the screenshot and lists the available actions.
+
+The main application shows the first dialog, then the second one. If
+one of the region cli options is given, the screenshot is taken
+accordingly and the second dialog is displayed.
+
+The panel plugin uses the first dialog as a configuration dialog. When
+you click the plugin, the screenshot is taken and the second dialog is
+shown.
+
+2009-08-03 jeromeg
+
Reenable the old active window workaround.
In some cases, the WM/X server does not update the active window
diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index d744e22..3faa9a8 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -21,61 +21,97 @@
+static void
+cb_help_response (GtkWidget *dialog, gint response, gpointer unused)
+{
+ if (response == GTK_RESPONSE_HELP)
+ {
+ GError *error_help = NULL;
+
+ g_signal_stop_emission_by_name (dialog, "response");
+
+ /* Launch the help page and show an error dialog if there was an error. */
+ if (!g_spawn_command_line_async ("xfhelp4 xfce4-screenshooter.html", &error_help))
+ {
+ screenshooter_error ("%s", error_help->message);
+ g_error_free (error_help);
+ }
+ }
+}
+
+
+
/* Public */
-gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd)
+gboolean screenshooter_take_screenshot_idle (ScreenshotData *sd)
+{
+ sd->screenshot = screenshooter_take_screenshot (sd->region,
+ sd->delay,
+ sd->show_mouse,
+ sd->plugin);
+
+ if (sd->screenshot != NULL)
+ g_idle_add ((GSourceFunc) screenshooter_action_idle, sd);
+ else
+ gtk_main_quit ();
+
+ return FALSE;
+}
+
+gboolean screenshooter_action_idle (ScreenshotData *sd)
{
- GdkPixbuf *screenshot;
+ GtkWidget *dialog = screenshooter_actions_dialog_new (sd);
+ gint response;
+
+ g_signal_connect (dialog, "response",
+ (GCallback) cb_help_response, NULL);
- screenshot = screenshooter_take_screenshot (sd->region,
- sd->delay,
- sd->show_mouse,
- sd->plugin);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
- g_return_val_if_fail (screenshot != NULL, FALSE);
+ if (response == GTK_RESPONSE_CANCEL)
+ {
+ gtk_widget_destroy (dialog);
+ gtk_main_quit ();
+ return FALSE;
+ }
if (sd->action == SAVE)
{
if (sd->screenshot_dir == NULL)
sd->screenshot_dir = screenshooter_get_home_uri ();
- screenshooter_save_screenshot (screenshot,
- TRUE,
- sd->screenshot_dir);
+ screenshooter_save_screenshot (sd->screenshot, sd->screenshot_dir);
}
else if (sd->action == CLIPBOARD)
{
- screenshooter_copy_to_clipboard (screenshot);
+ screenshooter_copy_to_clipboard (sd->screenshot);
}
else
{
GFile *temp_dir = g_file_new_for_path (g_get_tmp_dir ());
const gchar *temp_dir_uri = g_file_get_uri (temp_dir);
const gchar *screenshot_path =
- screenshooter_save_screenshot (screenshot, FALSE, temp_dir_uri);
+ screenshooter_save_screenshot (sd->screenshot, temp_dir_uri);
if (screenshot_path != NULL)
{
if (sd->action == OPEN)
- {
- screenshooter_open_screenshot (screenshot_path, sd->app);
- }
+ screenshooter_open_screenshot (screenshot_path, sd->app);
else
- {
- screenshooter_upload_to_zimagez (screenshot_path, sd->last_user);
- }
+ screenshooter_upload_to_zimagez (screenshot_path, sd->last_user);
}
g_object_unref (temp_dir);
}
- g_object_unref (screenshot);
-
if (!sd->plugin)
gtk_main_quit ();
+ gtk_widget_destroy (dialog);
+ g_object_unref (sd->screenshot);
+
return FALSE;
}
diff --git a/lib/screenshooter-actions.h b/lib/screenshooter-actions.h
index 33d7835..b2bfc21 100644
--- a/lib/screenshooter-actions.h
+++ b/lib/screenshooter-actions.h
@@ -26,6 +26,7 @@
#include "screenshooter-dialogs.h"
#include "screenshooter-zimagez.h"
-gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd);
+gboolean screenshooter_take_screenshot_idle (ScreenshotData *sd);
+gboolean screenshooter_action_idle (ScreenshotData *sd);
#endif
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index 2f109e4..b47a717 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -20,6 +20,7 @@
#include "screenshooter-dialogs.h"
#define ICON_SIZE 16
+#define THUMB_SIZE 200
/* Prototypes */
@@ -106,9 +107,7 @@ static gchar
static void cb_fullscreen_screen_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->region = FULLSCREEN;
- }
+ sd->region = FULLSCREEN;
}
@@ -117,9 +116,7 @@ static void cb_fullscreen_screen_toggled (GtkToggleButton *tb, ScreenshotData *s
static void cb_active_window_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->region = ACTIVE_WINDOW;
- }
+ sd->region = ACTIVE_WINDOW;
}
@@ -128,9 +125,7 @@ static void cb_active_window_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_rectangle_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->region = SELECT;
- }
+ sd->region = SELECT;
}
@@ -139,13 +134,9 @@ static void cb_rectangle_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_show_mouse_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->show_mouse = 1;
- }
+ sd->show_mouse = 1;
else
- {
- sd->show_mouse = 0;
- }
+ sd->show_mouse = 0;
}
@@ -154,9 +145,7 @@ static void cb_show_mouse_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_save_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->action = SAVE;
- }
+ sd->action = SAVE;
}
@@ -182,9 +171,7 @@ cb_toggle_set_insensi (GtkToggleButton *tb, GtkWidget *widget)
static void cb_open_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->action = OPEN;
- }
+ sd->action = OPEN;
}
@@ -192,9 +179,7 @@ static void cb_open_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_clipboard_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->action = CLIPBOARD;
- }
+ sd->action = CLIPBOARD;
}
@@ -202,9 +187,7 @@ static void cb_clipboard_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_zimagez_toggled (GtkToggleButton *tb, ScreenshotData *sd)
{
if (gtk_toggle_button_get_active (tb))
- {
- sd->action = UPLOAD;
- }
+ sd->action = UPLOAD;
}
@@ -213,7 +196,6 @@ static void cb_zimagez_toggled (GtkToggleButton *tb, ScreenshotData *sd)
static void cb_default_folder (GtkWidget *chooser, ScreenshotData *sd)
{
g_free (sd->screenshot_dir);
-
sd->screenshot_dir = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
}
@@ -268,7 +250,6 @@ static gchar *generate_filename_for_uri (const gchar *uri)
for (i = 1; exists; ++i)
{
base_name = g_strdup_printf (_("Screenshot-%d.png"), i);
-
file = g_file_get_child (directory, base_name);
if (!g_file_query_exists (file, NULL))
@@ -295,7 +276,6 @@ static void cb_combo_active_item_changed (GtkWidget *box, ScreenshotData *sd)
gchar *active_command = NULL;
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (box), &iter);
-
gtk_tree_model_get (model, &iter, 2, &active_command, -1);
g_free (sd->app);
@@ -338,13 +318,11 @@ static void add_item (GAppInfo *app_info, GtkWidget *liststore)
if (G_LIKELY (names != NULL))
{
if (names[0] != NULL)
- {
- pixbuf = gtk_icon_theme_load_icon (icon_theme,
- names[0],
- ICON_SIZE,
- GTK_ICON_LOOKUP_GENERIC_FALLBACK,
- NULL);
- }
+ pixbuf = gtk_icon_theme_load_icon (icon_theme,
+ names[0],
+ ICON_SIZE,
+ GTK_ICON_LOOKUP_GENERIC_FALLBACK,
+ NULL);
g_strfreev (names);
}
@@ -379,7 +357,7 @@ static void add_item (GAppInfo *app_info, GtkWidget *liststore)
static void populate_liststore (GtkListStore *liststore)
{
const gchar *content_type;
- GList *list_app;
+ GList *list_app;
content_type = "image/png";
@@ -390,7 +368,6 @@ static void populate_liststore (GtkListStore *liststore)
if (G_LIKELY (list_app != NULL))
{
g_list_foreach (list_app, (GFunc) add_item, liststore);
-
g_list_free (list_app);
}
}
@@ -461,9 +438,9 @@ static GdkPixbuf
height = gdk_pixbuf_get_height (screenshot);
if (width > height)
- i = width / 150;
+ i = width / THUMB_SIZE;
else
- i = height / 150;
+ i = height / THUMB_SIZE;
if (i == 0)
return gdk_pixbuf_copy (screenshot);
@@ -587,24 +564,19 @@ save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file)
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
-
gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
gtk_window_set_icon_name (GTK_WINDOW (dialog), "document-save");
-
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG(dialog)->vbox), 12);
gtk_label_set_markup (GTK_LABEL (label1),
_("<span weight=\"bold\" stretch=\"semiexpanded\">The screenshot "
"is being transferred to:</span>"));
-
gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
-
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox),
label1,
FALSE,
FALSE,
0);
-
gtk_widget_show (label1);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox),
@@ -612,7 +584,6 @@ save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file)
FALSE,
FALSE,
0);
-
gtk_widget_show (label2);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox),
@@ -620,9 +591,7 @@ save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file)
FALSE,
FALSE,
0);
-
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 0);
-
gtk_widget_show (progress_bar);
g_signal_connect (dialog, "response", G_CALLBACK (cb_transfer_dialog_response),
@@ -656,13 +625,9 @@ static gchar
/* If the URI is a local one, we save directly */
if (!screenshooter_is_remote_uri (save_uri))
- {
- result = save_screenshot_to_local_path (screenshot, save_file);
- }
+ result = save_screenshot_to_local_path (screenshot, save_file);
else
- {
- save_screenshot_to_remote_location (screenshot, save_file);
- }
+ save_screenshot_to_remote_location (screenshot, save_file);
g_object_unref (save_file);
@@ -675,15 +640,12 @@ static gchar
-/* Build the preferences dialog.
- at sd: a ScreenshotData to set the options.
-*/
-GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
+GtkWidget *screenshooter_region_dialog_new (ScreenshotData *sd, gboolean plugin)
{
GtkWidget *dlg, *main_alignment;
GtkWidget *vbox;
- GtkWidget *capture_table, *actions_table;
+ GtkWidget *capture_table;
GtkWidget *area_main_box, *area_box, *area_label, *area_alignment;
GtkWidget *active_window_button,
@@ -695,15 +657,6 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
GtkWidget *delay_main_box, *delay_box, *delay_label, *delay_alignment;
GtkWidget *delay_spinner_box, *delay_spinner, *seconds_label;
- GtkWidget *actions_main_box, *actions_label, *actions_alignment;
- GtkWidget *save_radio_button, *dir_chooser;
- GtkWidget *clipboard_radio_button, *open_with_radio_button;
- GtkWidget *zimagez_radio_button;
-
- GtkListStore *liststore;
- GtkWidget *combobox;
- GtkCellRenderer *renderer, *renderer_pixbuf;
-
/* Create the dialog */
if (!plugin)
{
@@ -740,31 +693,24 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
-
gtk_container_set_border_width (GTK_CONTAINER (dlg), 0);
gtk_window_set_icon_name (GTK_WINDOW (dlg), "applets-screenshooter");
/* Create the main alignment for the dialog */
main_alignment = gtk_alignment_new (0, 0, 1, 1);
-
gtk_alignment_set_padding (GTK_ALIGNMENT (main_alignment), 6, 0, 12, 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_alignment, TRUE, TRUE, 0);
-
gtk_widget_show (main_alignment);
/* Create the main box for the dialog */
vbox = gtk_vbox_new (FALSE, 10);
-
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
gtk_container_add (GTK_CONTAINER (main_alignment), vbox);
gtk_widget_show (vbox);
/* Create the table to align the differents parts of the top of the UI */
capture_table = gtk_table_new (2, 2, FALSE);
-
gtk_table_set_col_spacings (GTK_TABLE (capture_table), 20);
-
gtk_box_pack_start (GTK_BOX (vbox), capture_table, TRUE, TRUE, 0);
gtk_widget_show (capture_table);
@@ -775,22 +721,17 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
/* Create area label */
area_label = gtk_label_new ("");
-
gtk_label_set_markup (GTK_LABEL (area_label),
_("<span weight=\"bold\" stretch=\"semiexpanded\">"
"Region to capture</span>"));
-
gtk_misc_set_alignment (GTK_MISC (area_label), 0, 0);
gtk_widget_show (area_label);
gtk_container_add (GTK_CONTAINER (area_main_box), area_label);
/* Create area alignment */
area_alignment = gtk_alignment_new (0, 0, 1, 1);
-
gtk_container_add (GTK_CONTAINER (area_main_box), area_alignment);
-
gtk_alignment_set_padding (GTK_ALIGNMENT (area_alignment), 0, 6, 12, 0);
-
gtk_widget_show (area_alignment);
/* Create area box */
@@ -805,56 +746,41 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
fullscreen_button =
gtk_radio_button_new_with_mnemonic (NULL,
_("Entire screen"));
-
gtk_box_pack_start (GTK_BOX (area_box),
fullscreen_button, FALSE,
FALSE, 0);
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fullscreen_button),
(sd->region == FULLSCREEN));
-
gtk_widget_set_tooltip_text (fullscreen_button,
_("Take a screenshot of the entire screen"));
-
g_signal_connect (G_OBJECT (fullscreen_button), "toggled",
G_CALLBACK (cb_fullscreen_screen_toggled),
sd);
-
gtk_widget_show (fullscreen_button);
/* Active window */
active_window_button =
gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (fullscreen_button),
_("Active window"));
-
gtk_box_pack_start (GTK_BOX (area_box),
active_window_button, FALSE,
FALSE, 0);
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_window_button),
(sd->region == ACTIVE_WINDOW));
-
gtk_widget_set_tooltip_text (active_window_button,
_("Take a screenshot of the active window"));
-
g_signal_connect (G_OBJECT (active_window_button), "toggled",
G_CALLBACK (cb_active_window_toggled),
sd);
-
gtk_widget_show (active_window_button);
/* Rectangle */
rectangle_button =
gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (fullscreen_button),
_("Select a region"));
-
- gtk_box_pack_start (GTK_BOX (area_box),
- rectangle_button, FALSE,
- FALSE, 0);
-
+ gtk_box_pack_start (GTK_BOX (area_box), rectangle_button, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rectangle_button),
(sd->region == SELECT));
-
gtk_widget_set_tooltip_text (rectangle_button,
_("Select a region to be captured by clicking a point of "
"the screen without releasing the mouse button, "
@@ -863,60 +789,43 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
g_signal_connect (G_OBJECT (rectangle_button), "toggled",
G_CALLBACK (cb_rectangle_toggled), sd);
-
gtk_widget_show (rectangle_button);
/* Create show mouse checkbox */
show_mouse_checkbox =
gtk_check_button_new_with_label (_("Capture the mouse pointer"));
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_mouse_checkbox),
(sd->show_mouse == 1));
-
gtk_widget_set_sensitive (show_mouse_checkbox, (sd->region != SELECT));
-
gtk_widget_set_tooltip_text (show_mouse_checkbox,
_("Display the mouse pointer on the screenshot"));
-
gtk_box_pack_start (GTK_BOX (area_box),
show_mouse_checkbox, FALSE,
FALSE, 5);
-
gtk_widget_show (show_mouse_checkbox);
-
g_signal_connect (G_OBJECT (show_mouse_checkbox), "toggled",
G_CALLBACK (cb_show_mouse_toggled), sd);
-
g_signal_connect (G_OBJECT (rectangle_button), "toggled",
G_CALLBACK (cb_toggle_set_insensi), show_mouse_checkbox);
/* Create the main box for the delay stuff */
delay_main_box = gtk_vbox_new (FALSE, 6);
-
gtk_widget_show (delay_main_box);
-
gtk_table_attach_defaults (GTK_TABLE (capture_table), delay_main_box, 1, 2, 0, 1);
/* Create delay label */
delay_label = gtk_label_new ("");
-
gtk_label_set_markup (GTK_LABEL(delay_label),
_("<span weight=\"bold\" stretch=\"semiexpanded\">"
"Delay before capturing</span>"));
-
gtk_misc_set_alignment(GTK_MISC (delay_label), 0, 0);
-
gtk_box_pack_start (GTK_BOX (delay_main_box), delay_label, FALSE, FALSE, 0);
-
gtk_widget_show (delay_label);
/* Create delay alignment */
delay_alignment = gtk_alignment_new (0, 0, 0, 0);
-
gtk_box_pack_start (GTK_BOX (delay_main_box), delay_alignment, FALSE, FALSE, 0);
-
gtk_alignment_set_padding (GTK_ALIGNMENT (delay_alignment), 0, 6, 12, 0);
-
gtk_widget_show (delay_alignment);
/* Create delay box */
@@ -927,28 +836,21 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
/* Create delay spinner */
delay_spinner_box = gtk_hbox_new (FALSE, 4);
- gtk_widget_show (delay_spinner_box);
-
gtk_box_pack_start (GTK_BOX (delay_box), delay_spinner_box, FALSE, FALSE, 0);
+ gtk_widget_show (delay_spinner_box);
delay_spinner = gtk_spin_button_new_with_range(0.0, 60.0, 1.0);
-
gtk_spin_button_set_value (GTK_SPIN_BUTTON (delay_spinner), sd->delay);
-
gtk_widget_set_tooltip_text (delay_spinner,
_("Delay in seconds before the screenshot is taken"));
-
- gtk_widget_show (delay_spinner);
-
gtk_box_pack_start (GTK_BOX (delay_spinner_box), delay_spinner, FALSE, FALSE, 0);
+ gtk_widget_show (delay_spinner);
seconds_label = gtk_label_new (_("seconds"));
- gtk_widget_show (seconds_label);
-
gtk_box_pack_start (GTK_BOX (delay_spinner_box), seconds_label, FALSE, FALSE, 0);
-
g_signal_connect (G_OBJECT (delay_spinner), "value-changed",
G_CALLBACK (cb_delay_spinner_changed), sd);
+ gtk_widget_show (seconds_label);
/* Set the delay box as inactive when we capture rectangles */
g_signal_connect (G_OBJECT (rectangle_button), "toggled",
@@ -957,149 +859,169 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
/* Set the default state */
cb_toggle_set_insensi (GTK_TOGGLE_BUTTON (rectangle_button), delay_box);
+ return dlg;
+}
+
+
+
+/* Build the preferences dialog.
+ at sd: a ScreenshotData to set the options.
+*/
+GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
+{
+ GtkWidget *dlg, *main_alignment;
+ GtkWidget *vbox;
+
+ GtkWidget *main_table, *actions_table;
+
+ GtkWidget *actions_main_box, *actions_label, *actions_alignment;
+ GtkWidget *save_radio_button, *dir_chooser;
+ GtkWidget *clipboard_radio_button, *open_with_radio_button;
+ GtkWidget *zimagez_radio_button;
+
+ GtkListStore *liststore;
+ GtkWidget *combobox;
+ GtkCellRenderer *renderer, *renderer_pixbuf;
+
+ GtkWidget *preview, *preview_frame, *preview_alignment, *preview_label;
+ GdkPixbuf *thumbnail;
+
+ dlg = xfce_titled_dialog_new_with_buttons (_("Screenshot"),
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT|
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_HELP,
+ GTK_RESPONSE_HELP,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_OK,
+ NULL);
+
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dlg), _("Action"));
+ gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
+ gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (dlg), 0);
+ gtk_window_set_icon_name (GTK_WINDOW (dlg), "applets-screenshooter");
+
+ /* Create the main alignment for the dialog */
+ main_alignment = gtk_alignment_new (0, 0, 1, 1);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (main_alignment), 6, 0, 12, 12);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_alignment, TRUE, TRUE, 0);
+ gtk_widget_show (main_alignment);
+
+ /* Create the main box for the dialog */
+ vbox = gtk_vbox_new (FALSE, 10);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+ gtk_container_add (GTK_CONTAINER (main_alignment), vbox);
+ gtk_widget_show (vbox);
+
+ /* Create the table to align the differents parts of the top of the UI */
+ main_table = gtk_table_new (1, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (main_table), 30);
+ gtk_box_pack_start (GTK_BOX (vbox), main_table, TRUE, TRUE, 0);
+ gtk_widget_show (main_table);
+
/* Create the actions main box */
actions_main_box = gtk_vbox_new (FALSE, 6);
-
- gtk_box_pack_start (GTK_BOX (vbox), actions_main_box, TRUE, TRUE, 0);
+ gtk_table_attach_defaults (GTK_TABLE (main_table), actions_main_box, 0, 1, 0, 1);
gtk_widget_show (actions_main_box);
/* Create actions label */
-
actions_label = gtk_label_new ("");
-
gtk_label_set_markup (GTK_LABEL (actions_label),
_("<span weight=\"bold\" stretch=\"semiexpanded\">Action"
- "</span>"));
-
+ "</span>"));
gtk_misc_set_alignment (GTK_MISC (actions_label), 0, 0);
gtk_widget_show (actions_label);
gtk_box_pack_start (GTK_BOX (actions_main_box), actions_label, FALSE, FALSE, 0);
/* Create actions alignment */
actions_alignment = gtk_alignment_new (0, 0, 1, 1);
-
gtk_alignment_set_padding (GTK_ALIGNMENT (actions_alignment), 0, 6, 12, 0);
-
gtk_box_pack_start (GTK_BOX (actions_main_box), actions_alignment, TRUE, TRUE, 0);
gtk_widget_show (actions_alignment);
/* Create the actions table */
actions_table = gtk_table_new (4, 2, FALSE);
-
gtk_table_set_row_spacings (GTK_TABLE (actions_table), 3);
gtk_table_set_col_spacings (GTK_TABLE (actions_table), 15);
-
gtk_container_add (GTK_CONTAINER (actions_alignment), actions_table);
gtk_widget_show (actions_table);
/* Save option radio button */
save_radio_button = gtk_radio_button_new_with_mnemonic (NULL, _("Save in:"));
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (save_radio_button),
(sd->action == SAVE));
-
g_signal_connect (G_OBJECT (save_radio_button), "toggled",
G_CALLBACK (cb_save_toggled), sd);
-
gtk_widget_set_tooltip_text (save_radio_button, _("Save the screenshot to a PNG file"));
-
- gtk_widget_show (save_radio_button);
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), save_radio_button, 0, 1, 0, 1);
+ gtk_widget_show (save_radio_button);
/* Directory chooser */
dir_chooser =
gtk_file_chooser_button_new (_("Default save location"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
-
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dir_chooser),
sd->screenshot_dir);
-
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dir_chooser), FALSE);
-
- gtk_widget_show (dir_chooser);
-
gtk_widget_set_tooltip_text (dir_chooser, _("Set the default save location"));
-
g_signal_connect (G_OBJECT (dir_chooser), "selection-changed",
G_CALLBACK (cb_default_folder), sd);
-
g_signal_connect (G_OBJECT (save_radio_button), "toggled",
G_CALLBACK (cb_toggle_set_sensi), dir_chooser);
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), dir_chooser, 1, 2, 0, 1);
+ gtk_widget_show (dir_chooser);
/* Copy to clipboard radio button */
clipboard_radio_button =
gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (save_radio_button),
- _("Copy to the clipboard"));
-
- gtk_widget_show (clipboard_radio_button);
-
+ _("Copy to the clipboard"));
gtk_widget_set_tooltip_text (clipboard_radio_button,
_("Copy the screenshot to the clipboard so that it can be "
"pasted later"));
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (clipboard_radio_button),
(sd->action == CLIPBOARD));
-
g_signal_connect (G_OBJECT (clipboard_radio_button), "toggled",
G_CALLBACK (cb_clipboard_toggled), sd);
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), clipboard_radio_button,
0, 1, 1, 2);
+ gtk_widget_show (clipboard_radio_button);
/* Open with radio button */
open_with_radio_button =
gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (save_radio_button),
- _("Open with:"));
-
- gtk_widget_show (open_with_radio_button);
-
+ _("Open with:"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (open_with_radio_button),
(sd->action == OPEN));
-
g_signal_connect (G_OBJECT (open_with_radio_button), "toggled",
G_CALLBACK (cb_open_toggled), sd);
-
gtk_widget_set_tooltip_text (open_with_radio_button,
_("Open the screenshot with the chosen application"));
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), open_with_radio_button,
0, 1, 2, 3);
+ gtk_widget_show (open_with_radio_button);
/* Open with combobox */
liststore = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
-
combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (liststore));
-
renderer = gtk_cell_renderer_text_new ();
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
-
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer_pixbuf, FALSE);
-
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
-
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL);
-
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer_pixbuf,
"pixbuf", 0, NULL);
-
populate_liststore (liststore);
-
set_default_item (combobox, sd);
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), combobox, 1, 2, 2, 3);
-
g_signal_connect (G_OBJECT (combobox), "changed",
G_CALLBACK (cb_combo_active_item_changed), sd);
-
- gtk_widget_show_all (combobox);
-
gtk_widget_set_tooltip_text (combobox, _("Application to open the screenshot"));
-
g_signal_connect (G_OBJECT (open_with_radio_button), "toggled",
G_CALLBACK (cb_toggle_set_sensi), combobox);
+ gtk_widget_show_all (combobox);
/* Run the callback functions to grey/ungrey the correct widgets */
cb_toggle_set_sensi (GTK_TOGGLE_BUTTON (open_with_radio_button), combobox);
@@ -1108,115 +1030,58 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin)
zimagez_radio_button =
gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (save_radio_button),
_("Host on ZimageZ"));
-
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (zimagez_radio_button),
(sd->action == UPLOAD));
-
gtk_widget_set_tooltip_text (zimagez_radio_button,
_("Host the screenshot on ZimageZ, a free online "
"image hosting service"));
-
g_signal_connect (G_OBJECT (zimagez_radio_button), "toggled",
G_CALLBACK (cb_zimagez_toggled), sd);
-
gtk_table_attach_defaults (GTK_TABLE (actions_table), zimagez_radio_button,
0, 1, 3, 4);
-
gtk_widget_show (zimagez_radio_button);
+ /* Preview of the screenshot */
+ preview_frame = gtk_frame_new ("");
+ preview_label = gtk_label_new ("");
+ gtk_label_set_markup (GTK_LABEL (preview_label),
+ _("<span weight=\"bold\" stretch=\"semiexpanded\"> Preview "
+ "</span>"));
+ gtk_frame_set_label_widget (GTK_FRAME (preview_frame), preview_label);
+ gtk_table_attach_defaults (GTK_TABLE (main_table), preview_frame, 1, 2, 0, 1);
+ gtk_widget_show (preview_label);
+ gtk_widget_show (preview_frame);
+
+ preview_alignment = gtk_alignment_new (0, 0, 1, 1);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (preview_alignment), 8, 8, 8, 8);
+ gtk_container_add (GTK_CONTAINER (preview_frame), preview_alignment);
+ gtk_widget_show (preview_alignment);
+
+ thumbnail = screenshot_get_thumbnail (sd->screenshot);
+ preview = gtk_image_new_from_pixbuf (thumbnail);
+ gtk_container_add (GTK_CONTAINER (preview_alignment), preview);
+ g_object_unref (thumbnail);
+ gtk_widget_show (preview);
+
return dlg;
}
-/* Saves the screenshot according to the options in sd.
+/* Saves the screenshot in the given directory.
* @screenshot: a GdkPixbuf containing our screenshot
- * show_save_dialog: whether the save dialog should be shown.
- * @default_dir: the default save location.
+ * @directory: the default save location.
*/
gchar
-*screenshooter_save_screenshot (GdkPixbuf *screenshot,
- gboolean show_save_dialog,
- const gchar *default_dir)
+*screenshooter_save_screenshot (GdkPixbuf *screenshot, const gchar *directory)
{
- gchar *filename = generate_filename_for_uri (default_dir);
+ gchar *filename = generate_filename_for_uri (directory);
gchar *savename = NULL;
+ gchar *save_uri = g_build_filename (directory, filename, NULL);
- if (show_save_dialog)
- {
- GdkPixbuf *thumbnail;
-
- GtkWidget *preview;
- GtkWidget *chooser;
- gchar *save_uri = NULL;
- gint dialog_response;
-
- /* If the user wants a save dialog, we run it, and grab the
- * filename the user has chosen. */
-
- /* Create the dialog and set its default properties */
- chooser =
- gtk_file_chooser_dialog_new (_("Save screenshot as..."),
- NULL,
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_SAVE,
- GTK_RESPONSE_ACCEPT,
- NULL);
-
- gtk_window_set_icon_name (GTK_WINDOW (chooser), "applets-screenshooter");
-
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (chooser), TRUE);
-
- gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
-
- gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
-
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_dir);
-
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), filename);
-
- /* Create the preview and the thumbnail */
-
- preview = gtk_image_new ();
-
- gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview);
-
- thumbnail = screenshot_get_thumbnail (screenshot);
-
- gtk_image_set_from_pixbuf (GTK_IMAGE (preview), thumbnail);
-
- g_object_unref (thumbnail);
-
- dialog_response = gtk_dialog_run (GTK_DIALOG (chooser));
-
- /* The user pressed the save button */
- if (G_LIKELY (dialog_response == GTK_RESPONSE_ACCEPT))
- {
- save_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
- }
-
- gtk_widget_destroy (chooser);
-
- if (G_LIKELY (save_uri != NULL))
- {
- savename = save_screenshot_to (screenshot, save_uri);
-
- g_free (save_uri);
- }
- }
- else
- {
- /* Else, we just save the file in the default folder */
- gchar *save_uri = g_build_filename (default_dir, filename, NULL);
-
- savename = save_screenshot_to (screenshot, save_uri);
-
- g_free (save_uri);
- }
+ savename = save_screenshot_to (screenshot, save_uri);
- TRACE ("Free the gchars and unref the GFiles");
+ g_free (save_uri);
g_free (filename);
return savename;
diff --git a/lib/screenshooter-dialogs.h b/lib/screenshooter-dialogs.h
index 893f2c1..64a3257 100644
--- a/lib/screenshooter-dialogs.h
+++ b/lib/screenshooter-dialogs.h
@@ -36,10 +36,11 @@
#include <libxfcegui4/libxfcegui4.h>
+GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd);
+GtkWidget *screenshooter_region_dialog_new (ScreenshotData *sd,
+ gboolean plugin);
+gchar *screenshooter_save_screenshot (GdkPixbuf *screenshot,
+ const gchar *directory);
+
-GtkWidget *screenshooter_dialog_new (ScreenshotData *sd,
- gboolean plugin);
-gchar *screenshooter_save_screenshot (GdkPixbuf *screenshot,
- gboolean show_save_dialog,
- const gchar *default_dir);
#endif
diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h
index cf19918..db96ee5 100644
--- a/lib/screenshooter-global.h
+++ b/lib/screenshooter-global.h
@@ -50,6 +50,7 @@ typedef struct
gchar *screenshot_dir;
gchar *app;
gchar *last_user;
+ GdkPixbuf *screenshot;
}
ScreenshotData;
diff --git a/panel-plugin/screenshooter-plugin.c b/panel-plugin/screenshooter-plugin.c
index b3d5c2c..0f0756f 100644
--- a/panel-plugin/screenshooter-plugin.c
+++ b/panel-plugin/screenshooter-plugin.c
@@ -111,22 +111,17 @@ static gboolean
cb_set_size (XfcePanelPlugin *plugin, int size, PluginData *pd)
{
GdkPixbuf *pb;
-
int width = size - 2 - 2 * MAX (pd->button->style->xthickness,
pd->button->style->ythickness);
TRACE ("Get the icon from the theme");
-
pb = xfce_themed_icon_load (SCREENSHOT_ICON_NAME, width);
TRACE ("Set the new icon");
-
gtk_image_set_from_pixbuf (GTK_IMAGE (pd->image), pb);
-
g_object_unref (pb);
TRACE ("Request size for the plugin");
-
gtk_widget_set_size_request (GTK_WIDGET (plugin), size, size);
return TRUE;
@@ -166,7 +161,7 @@ cb_button_clicked (GtkWidget *button, PluginData *pd)
TRACE ("Start taking the screenshot");
- screenshooter_take_and_output_screenshot (pd->sd);
+ screenshooter_take_screenshot_idle (pd->sd);
/* Make the panel button clickable */
gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
@@ -196,7 +191,6 @@ screenshooter_plugin_read_rc_file (XfcePanelPlugin *plugin, PluginData *pd)
gchar *rc_file = xfce_panel_plugin_lookup_rc_file (plugin);
screenshooter_read_rc_file (rc_file, pd->sd);
-
g_free (rc_file);
}
@@ -209,10 +203,9 @@ pd: the associated PluginData.
static void
screenshooter_plugin_write_rc_file (XfcePanelPlugin *plugin, PluginData *pd)
{
- gchar * rc_file = xfce_panel_plugin_save_location (plugin, TRUE);
+ gchar *rc_file = xfce_panel_plugin_save_location (plugin, TRUE);
screenshooter_write_rc_file (rc_file, pd->sd);
-
g_free (rc_file);
}
@@ -228,7 +221,6 @@ cb_dialog_response (GtkWidget *dlg, int response, PluginData *pd)
if (response == GTK_RESPONSE_OK)
{
g_object_set_data (G_OBJECT (pd->plugin), "dialog", NULL);
-
gtk_widget_destroy (dlg);
/* Update tooltips according to the chosen option */
@@ -238,8 +230,7 @@ cb_dialog_response (GtkWidget *dlg, int response, PluginData *pd)
xfce_panel_plugin_unblock_menu (pd->plugin);
screenshooter_plugin_write_rc_file (pd->plugin, pd);
}
-
- if (response == GTK_RESPONSE_HELP)
+ else if (response == GTK_RESPONSE_HELP)
{
GError *error_help = NULL;
@@ -262,22 +253,16 @@ cb_properties_dialog (XfcePanelPlugin *plugin, PluginData *pd)
GtkWidget *dlg;
TRACE ("Create the dialog");
-
- dlg = screenshooter_dialog_new (pd->sd, TRUE);
+ dlg = screenshooter_region_dialog_new (pd->sd, TRUE);
/* Block the menu to prevent the user from launching several dialogs at
the same time */
-
TRACE ("Block the menu");
-
xfce_panel_plugin_block_menu (plugin);
TRACE ("Run the dialog");
-
g_object_set_data (G_OBJECT (plugin), "dialog", dlg);
-
g_signal_connect (dlg, "response", G_CALLBACK (cb_dialog_response), pd);
-
gtk_widget_show (dlg);
}
diff --git a/src/main.c b/src/main.c
index a05c397..e24599e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -118,7 +118,7 @@ cb_dialog_response (GtkWidget *dialog, gint response, ScreenshotData *sd)
else if (response == GTK_RESPONSE_OK)
{
gtk_widget_destroy (dialog);
- g_idle_add ((GSourceFunc) screenshooter_take_and_output_screenshot, sd);
+ g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
}
else
{
@@ -248,8 +248,7 @@ int main (int argc, char **argv)
g_free (screenshot_dir);
}
- g_idle_add ((GSourceFunc) screenshooter_take_and_output_screenshot,
- sd);
+ g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
}
/* Else we show a dialog which allows to set the screenshot options */
else
@@ -257,7 +256,7 @@ int main (int argc, char **argv)
GtkWidget *dialog;
/* Set the dialog up */
- dialog = screenshooter_dialog_new (sd, FALSE);
+ dialog = screenshooter_region_dialog_new (sd, FALSE);
g_signal_connect (dialog, "response", (GCallback) cb_dialog_response, sd);
gtk_widget_show (dialog);
}
More information about the Xfce4-commits
mailing list