[Xfce4-commits] <xfce4-screenshooter:master> Simplify (screenshooter_take_and_output_screenshot).
Jérôme Guelfucci
jeromeg at xfce.org
Fri Aug 14 00:26:05 CEST 2009
Updating branch refs/heads/master
to 61df0c326ae507884203086c6662399087c1b7f9 (commit)
from a6135b92b0ec2cd20817286b793bfad96b09fc89 (commit)
commit 61df0c326ae507884203086c6662399087c1b7f9
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sun Aug 2 08:53:58 2009 +0200
Simplify (screenshooter_take_and_output_screenshot).
Now, the main dialog of the application is created once in main.c
and hidden/shown when necessary. The idle func is now only responsible
for taking the screenshot and hidding/showing the dialog when needed.
Add a dialog member to the ScreenshotData struct, set it correctly in
the panel plugin and in the application. Fix some indentation in the
panel plugin code.
ChangeLog | 12 +++++++
lib/screenshooter-actions.c | 61 +++++-----------------------------
lib/screenshooter-global.h | 2 +
panel-plugin/screenshooter-plugin.c | 7 ++--
src/main.c | 45 ++++++++++++++++++++++++-
5 files changed, 70 insertions(+), 57 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a53aa14..3a4a7ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,18 @@ Updated Italian and Galician documentation translation.
2009-08-02 jeromeg
+Simplify (screenshooter_take_and_output_screenshot).
+
+Now, the main dialog of the application is created once in main.c
+and hidden/shown when necessary. The idle func is now only responsible
+for taking the screenshot and hidding/showing the dialog when needed.
+
+Add a dialog member to the ScreenshotData struct, set it correctly in
+the panel plugin and in the application. Fix some indentation in the
+panel plugin code.
+
+2009-08-02 jeromeg
+
Add the doc rules to the toplevel Makefile.am.
Also remove all the Makefile.am in the documentation directory.
diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 8c56ca5..359eae0 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -21,36 +21,6 @@
-static void cb_help_response (GtkWidget *dlg,
- gint response,
- gpointer unused);
-
-
-
-/* Internals */
-
-
-
-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 */
@@ -59,25 +29,6 @@ gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd)
{
GdkPixbuf *screenshot;
- if (sd->cli == FALSE)
- {
- GtkWidget *dialog;
- gint response;
-
- /* Set the dialog up */
- dialog = screenshooter_dialog_new (sd, FALSE);
- g_signal_connect (dialog, "response", (GCallback) cb_help_response, NULL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- if (response != GTK_RESPONSE_OK)
- {
- gtk_main_quit ();
- return FALSE;
- }
- }
-
screenshot =
screenshooter_take_screenshot (sd->region, sd->delay, sd->show_mouse);
@@ -122,11 +73,17 @@ gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd)
if (sd->close == 1)
{
- TRACE ("Exit the main loop");
+ if (sd->dialog)
+ gtk_widget_destroy (sd->dialog);
+
gtk_main_quit ();
- return FALSE;
}
else
- return TRUE;
+ {
+ if (sd->dialog)
+ gtk_widget_show (sd->dialog);
+ }
+
+ return FALSE;
}
diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h
index d15f85a..a6e5aef 100644
--- a/lib/screenshooter-global.h
+++ b/lib/screenshooter-global.h
@@ -25,6 +25,7 @@
#endif
#include <glib.h>
+#include <gtk/gtk.h>
/* Possible actions */
enum {
@@ -50,6 +51,7 @@ typedef struct
gchar *app;
gchar *last_user;
gboolean cli;
+ GtkWidget *dialog;
}
ScreenshotData;
diff --git a/panel-plugin/screenshooter-plugin.c b/panel-plugin/screenshooter-plugin.c
index e6e0aa6..b2c0956 100644
--- a/panel-plugin/screenshooter-plugin.c
+++ b/panel-plugin/screenshooter-plugin.c
@@ -142,7 +142,7 @@ static void
cb_free_data (XfcePanelPlugin *plugin, PluginData *pd)
{
if (pd->style_id)
- g_signal_handler_disconnect (plugin, pd->style_id);
+ g_signal_handler_disconnect (plugin, pd->style_id);
pd->style_id = 0;
g_free (pd->sd->screenshot_dir);
@@ -162,14 +162,14 @@ cb_button_clicked (GtkWidget *button, PluginData *pd)
{
/* Make the button unclickable so that the user does not press it while
another screenshot is in progress */
- gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
TRACE ("Start taking the screenshot");
screenshooter_take_and_output_screenshot (pd->sd);
/* Make the panel button clickable */
- gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
}
@@ -332,6 +332,7 @@ screenshooter_plugin_construct (XfcePanelPlugin *plugin)
loop after taking a screenshot */
pd->sd->cli = TRUE;
pd->sd->close = 0;
+ pd->sd->dialog = NULL;
/* Create the panel button */
TRACE ("Create the panel button");
diff --git a/src/main.c b/src/main.c
index 7196b14..8e8a49b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -105,6 +105,37 @@ static GOptionEntry entries[] =
+static void
+cb_dialog_response (GtkWidget *dialog, gint response, ScreenshotData *sd)
+{
+ 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);
+ }
+ }
+ else if (response == GTK_RESPONSE_OK)
+ {
+ gtk_widget_hide (dialog);
+ g_idle_add ((GSourceFunc) screenshooter_take_and_output_screenshot, sd);
+ }
+ else
+ {
+ gtk_widget_destroy (dialog);
+ gtk_main_quit ();
+ }
+}
+
+
+
+
/* Main */
@@ -116,6 +147,7 @@ int main (int argc, char **argv)
const gchar *rc_file;
ScreenshotData *sd = g_new0 (ScreenshotData, 1);
+ sd->dialog = NULL;
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@@ -228,14 +260,23 @@ int main (int argc, char **argv)
g_object_unref (default_save_dir);
g_free (screenshot_dir);
}
+
+ g_idle_add ((GSourceFunc) screenshooter_take_and_output_screenshot,
+ sd);
}
/* Else we show a dialog which allows to set the screenshot options */
else
{
+ GtkWidget *dialog;
+
sd->cli = FALSE;
- }
- g_idle_add ((GSourceFunc) screenshooter_take_and_output_screenshot, sd);
+ /* Set the dialog up */
+ dialog = screenshooter_dialog_new (sd, FALSE);
+ g_signal_connect (dialog, "response", (GCallback) cb_dialog_response, sd);
+ sd->dialog = dialog;
+ gtk_widget_show (dialog);
+ }
gtk_main ();
More information about the Xfce4-commits
mailing list