[Goodies-commits] r7361 - in xfce4-screenshooter/trunk: . lib panel-plugin src

Jerome Guelfucci jeromeg at xfce.org
Mon May 18 14:03:14 CEST 2009


Author: jeromeg
Date: 2009-05-18 12:03:14 +0000 (Mon, 18 May 2009)
New Revision: 7361

Modified:
   xfce4-screenshooter/trunk/ChangeLog
   xfce4-screenshooter/trunk/lib/screenshooter-actions.c
   xfce4-screenshooter/trunk/lib/screenshooter-actions.h
   xfce4-screenshooter/trunk/lib/screenshooter-global.h
   xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
   xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c
   xfce4-screenshooter/trunk/src/main.c
Log:
	* lib/screenshooter-global.h: add a cli gboolean to the ScreenshotData
	  structure. Combined with the close member of the structure, this
	  allows to close the application or not depending on how the
	  executable is called.
	* src/main.c, lib/screenshooter-actions.{c,h}: move the dialog
	  stuff to (screenshooter_take_and_output_screenshot) which is
	  from now on a GSourceFunc. It returns TRUE if we want to take
	  another screenshot, else it quits the main loop and returns
	  FALSE. It is called via g_idle_add in (main), which allows us
	  to always have a main loop. The workaround consisting in
	  sleep (1) before taking a screenshot seems useless now.
	* lib/screenshooter-zimagez.c: don't start and exit a main
	  loop here, run the dialog instead of showing it.
	* panel-plugin/screenshooter-plugin.c: set the cli member of the
	  structure to false when initializing the plugin.


Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/ChangeLog	2009-05-18 12:03:14 UTC (rev 7361)
@@ -1,5 +1,23 @@
-2009-05-17 jeromeg
+2009-05-18 jeromeg
 
+	* lib/screenshooter-global.h: add a cli gboolean to the ScreenshotData
+	  structure. Combined with the close member of the structure, this
+	  allows to close the application or not depending on how the
+	  executable is called.
+	* src/main.c, lib/screenshooter-actions.{c,h}: move the dialog
+	  stuff to (screenshooter_take_and_output_screenshot) which is
+	  from now on a GSourceFunc. It returns TRUE if we want to take
+	  another screenshot, else it quits the main loop and returns
+	  FALSE. It is called via g_idle_add in (main), which allows us
+	  to always have a main loop. The workaround consisting in
+	  sleep (1) before taking a screenshot seems useless now.
+	* lib/screenshooter-zimagez.c: don't start and exit a main
+	  loop here, run the dialog instead of showing it.
+	* panel-plugin/screenshooter-plugin.c: set the cli member of the
+	  structure to false when initializing the plugin.
+
+2009-05-18 jeromeg
+
 	* lib/screenshooter-utils.c (screenshooter_error),
 	  lib/screenshooter-job.c (screenshooter_job_ask_info):
 	  do not initialize va_list to NULL, that's wrong and useless.

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-05-18 12:03:14 UTC (rev 7361)
@@ -19,13 +19,74 @@
 
 #include "screenshooter-actions.h"
 
-void screenshooter_take_and_output_screenshot (ScreenshotData *sd)
+
+
+static void     cb_help_response (GtkWidget *dlg,
+                                  gint       response,
+                                  gpointer   unused);
+
+
+
+/* Internals */
+
+
+
+static void
+cb_help_response (GtkWidget *dialog, gint response, gpointer unused)
 {
-  GdkPixbuf *screenshot =
-    screenshooter_take_screenshot (sd->region, sd->delay, sd->show_mouse);
+  if (response == GTK_RESPONSE_HELP)
+    {
+      GError *error_help = NULL;
 
-  g_return_if_fail (screenshot != 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)
+{
+  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));
+
+      if (response == GTK_RESPONSE_OK)
+        {
+          gtk_widget_hide (dialog);
+        }
+      else
+        {
+          gtk_widget_destroy (dialog);
+          gtk_main_quit ();
+
+          return FALSE;
+        }
+    }
+
+  screenshot = screenshooter_take_screenshot (sd->region, sd->delay, sd->show_mouse);
+
+  g_return_val_if_fail (screenshot != NULL, FALSE);
+
   if (sd->action == SAVE)
     {
       if (sd->screenshot_dir == NULL)
@@ -64,5 +125,13 @@
     }
 
   g_object_unref (screenshot);
+
+  if ((sd->cli == TRUE) || (sd->close == 1))
+    {
+      gtk_main_quit ();
+      return FALSE;
+    }
+  else
+    return TRUE;
 }
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.h	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.h	2009-05-18 12:03:14 UTC (rev 7361)
@@ -26,6 +26,6 @@
 #include "screenshooter-dialogs.h"
 #include "screenshooter-zimagez.h"
 
-void screenshooter_take_and_output_screenshot (ScreenshotData *sd);
+gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd);
 
 #endif

Modified: xfce4-screenshooter/trunk/lib/screenshooter-global.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-global.h	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/lib/screenshooter-global.h	2009-05-18 12:03:14 UTC (rev 7361)
@@ -48,6 +48,7 @@
   gint close;
   gchar *screenshot_dir;
   gchar *app;
+  gboolean cli;
 }
 ScreenshotData;
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-05-18 12:03:14 UTC (rev 7361)
@@ -955,8 +955,6 @@
   g_object_unref (G_OBJECT (job));
 
   gtk_widget_destroy (dialog);
-
-  gtk_main_quit ();
 }
 
 
@@ -1019,7 +1017,5 @@
   g_signal_connect (job, "finished", (GCallback) cb_finished, dialog);
   g_signal_connect (job, "info-message", (GCallback) cb_update_info, label);
 
-  gtk_widget_show (dialog);
-
-  gtk_main ();
+  gtk_dialog_run (GTK_DIALOG (dialog));
 }

Modified: xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c
===================================================================
--- xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c	2009-05-18 12:03:14 UTC (rev 7361)
@@ -319,6 +319,8 @@
   g_thread_init (NULL);
 
   pd->sd = sd;
+  /* The panel plugin ignores the close settings, as in command line */
+  pd->sd->cli = TRUE;
 
   TRACE ("Initialize the text domain");
 

Modified: xfce4-screenshooter/trunk/src/main.c
===================================================================
--- xfce4-screenshooter/trunk/src/main.c	2009-05-18 08:12:33 UTC (rev 7360)
+++ xfce4-screenshooter/trunk/src/main.c	2009-05-18 12:03:14 UTC (rev 7361)
@@ -103,63 +103,8 @@
   }
 };
 
-static void
-cb_dialog_response (GtkWidget *dlg, int response, ScreenshotData *sd);
 
 
-
-/* Internals */
-
-
-
-static void
-cb_dialog_response (GtkWidget *dialog, int response, ScreenshotData *sd)
-{
-  if (response == GTK_RESPONSE_HELP)
-    {
-      GError *error_help = NULL;
-
-      /* 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)
-    {
-      GdkDisplay *display = gdk_display_get_default ();
-
-      gtk_widget_hide (dialog);
-
-      gdk_display_sync (display);
-
-      /* Make sure the window manager had time to set the new active
-      * window.*/
-      if (sd->region != SELECT)
-        sleep (1);
-
-      screenshooter_take_and_output_screenshot (sd);
-
-      if (sd->close == 1)
-        {
-          gtk_widget_destroy (dialog);
-          gtk_main_quit ();
-        }
-      else
-        {
-          gtk_widget_show (dialog);
-        }
-    }
-  else
-    {
-      gtk_widget_destroy (dialog);
-      gtk_main_quit ();
-    }
-}
-
-
-
 /* Main */
 
 
@@ -221,6 +166,8 @@
   /* If a region cli option is given, take the screenshot accordingly.*/
   if (fullscreen || window || region)
     {
+      sd->cli = TRUE;
+
       /* Set the region to be captured */
       if (window)
         {
@@ -281,31 +228,27 @@
           g_object_unref (default_save_dir);
           g_free (screenshot_dir);
         }
-
-      screenshooter_take_and_output_screenshot (sd);
     }
-  /* Else we just show up the main application */
+  /* 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);
+
+  gtk_main ();
+
+  /* Save preferences */
+  if (!(fullscreen || window || region))
+    {
       const gchar *preferences_file =
         xfce_resource_save_location (XFCE_RESOURCE_CONFIG,
                                      "xfce4/xfce4-screenshooter",
                                      TRUE);
 
-      /* Set the dialog up */
-
-      dialog = screenshooter_dialog_new (sd, FALSE);
-
-      g_signal_connect (dialog, "response", G_CALLBACK (cb_dialog_response), sd);
-      gtk_widget_show (dialog);
-
-      gtk_main ();
-
-      /* Save preferences */
       if (preferences_file != NULL)
         screenshooter_write_rc_file (preferences_file, sd);
-
     }
 
   g_free (sd->screenshot_dir);




More information about the Goodies-commits mailing list