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

Jerome Guelfucci jeromeg at xfce.org
Sat Mar 14 15:10:58 CET 2009


Author: jeromeg
Date: 2009-03-14 14:10:58 +0000 (Sat, 14 Mar 2009)
New Revision: 6901

Modified:
   xfce4-screenshooter/trunk/ChangeLog
   xfce4-screenshooter/trunk/TODO
   xfce4-screenshooter/trunk/autogen.sh
   xfce4-screenshooter/trunk/configure.ac.in
   xfce4-screenshooter/trunk/lib/screenshooter-actions.c
   xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
   xfce4-screenshooter/trunk/panel-plugin/Makefile.am
   xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c
   xfce4-screenshooter/trunk/src/Makefile.am
   xfce4-screenshooter/trunk/src/main.c
Log:
Fix most of the issues introduced by the previous commit.
Gthread-2.0 >= 2.6.0 is now required.

* configure.ac.in, src/main.c, src/Makefile.am,
  panel-plugin/screenshooter-plugin.c, panel-plugin/Makefile.am:
  add a dependence on gthread and initialize the threads at startup.
* TODO: updated.
* lib/screenshooter-actions.c: use the URI of the temporary directory
  and not its path, fixes the open with mode.
* lib/screenshooter-dialogs.c:
  - (cb_progress_upload) add the remaining number of bytes to the
    progress bar.
  - (cb_finished_upload) add some debugging information.
  - (save_screenshot_to_local_path) return the save location.
  - (save_screenshot_to_remote_location):
     + tweak the layout of the progress dialog.
     + run the dialog AFTER starting the copy so that it does not block
      everything.
     + delete the temp file after the transfer.
  - (save_screenshot_to) return the save location when saving to a
    local destination.
  - (screenshooter_save_screenshot):
     + destroy the dialog as early as possible so that it does not
       block the main loop.
     + fix the open with mode here too.
* autogen.sh: use git svn instead of git svn.


Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/ChangeLog	2009-03-14 14:10:58 UTC (rev 6901)
@@ -1,5 +1,34 @@
 2009-03-12 jeromeg
 
+  Fix most of the issues introduced by the previous commit.
+  Gthread-2.0 >= 2.6.0 is now required.
+
+  * configure.ac.in, src/main.c, src/Makefile.am,
+    panel-plugin/screenshooter-plugin.c, panel-plugin/Makefile.am:
+    add a dependence on gthread and initialize the threads at startup.
+  * TODO: updated.
+  * lib/screenshooter-actions.c: use the URI of the temporary directory
+    and not its path, fixes the open with mode.
+  * lib/screenshooter-dialogs.c:
+    - (cb_progress_upload) add the remaining number of bytes to the
+      progress bar.
+    - (cb_finished_upload) add some debugging information.
+    - (save_screenshot_to_local_path) return the save location.
+    - (save_screenshot_to_remote_location):
+       + tweak the layout of the progress dialog.
+       + run the dialog AFTER starting the copy so that it does not block
+        everything.
+       + delete the temp file after the transfer.
+    - (save_screenshot_to) return the save location when saving to a
+      local destination.
+    - (screenshooter_save_screenshot):
+       + destroy the dialog as early as possible so that it does not
+         block the main loop.
+       + fix the open with mode here too.
+  * autogen.sh: use git svn instead of git svn.
+
+2009-03-12 jeromeg
+
   Port the saving of screenshots to GIO. Some things still need to be
   polished. Some things might be broken, like opening a screenshot with
   an application.

Modified: xfce4-screenshooter/trunk/TODO
===================================================================
--- xfce4-screenshooter/trunk/TODO	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/TODO	2009-03-14 14:10:58 UTC (rev 6901)
@@ -3,12 +3,6 @@
 * Check for leaks using valgrind.
 * Use Xshape to have a transparent background in the generated screenshots.
 
-Rewritte generate_filename_for_uri or remove it. Jannis suggestion:
-You can use GDir for reading the contents of a directory and you can use 
-regular expressions (GPattern or something) for matching strings against 
-patterns, so why not iterate over the contents of a directory and 
-determine the Screenshots-%d.png file with the largest %d?
-
 Low priority:
 * Try to get borders captured with compiz.
 * Consider porting the code to use GObjects instead of structs.

Modified: xfce4-screenshooter/trunk/autogen.sh
===================================================================
--- xfce4-screenshooter/trunk/autogen.sh	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/autogen.sh	2009-03-14 14:10:58 UTC (rev 6901)
@@ -32,7 +32,7 @@
 # substitute revision and linguas
 linguas=$(sed -e '/^#/d' po/LINGUAS)
 if [ -d .git/svn ]; then
-    revision=$(git-svn find-rev trunk)
+    revision=$(git svn find-rev trunk)
 elif [ -d .svn ]; then
     revision=$(LC_ALL=C svn info $0 | awk '/^Revision: / {printf "%05d\n", $2}')
 else

Modified: xfce4-screenshooter/trunk/configure.ac.in
===================================================================
--- xfce4-screenshooter/trunk/configure.ac.in	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/configure.ac.in	2009-03-14 14:10:58 UTC (rev 6901)
@@ -53,6 +53,7 @@
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.4.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
 XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
+XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.6.0])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
 XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-03-14 14:10:58 UTC (rev 6901)
@@ -43,20 +43,24 @@
         }
       else
         {
-          gchar *tempdir = g_strdup (g_get_tmp_dir ());
+          GFile *temp_dir = g_file_new_for_path (g_get_tmp_dir ());
 
+          gchar *temp_dir_uri = g_file_get_uri (temp_dir);
+
           gchar *screenshot_path =
             screenshooter_save_screenshot (screenshot,
                                            FALSE,
-                                           tempdir);
+                                           temp_dir_uri);
+
           if (screenshot_path != NULL)
             {
               screenshooter_open_screenshot (screenshot_path, sd->app);
               g_free (screenshot_path);
             }
 
-          if (tempdir != NULL)
-            g_free (tempdir);
+          g_free (temp_dir_uri);
+
+          g_object_unref (temp_dir);
         }
 
       g_object_unref (screenshot);

Modified: xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c	2009-03-14 14:10:58 UTC (rev 6901)
@@ -455,9 +455,15 @@
 {
   gdouble fraction = (double) current_num_bytes / (double) total_num_bytes;
 
-  TRACE ("Progress callback!");
+  gint remaining = (int) total_num_bytes - (int) current_num_bytes;
 
+  gchar *bar_text = g_strdup_printf (_("%i bytes remaining"), remaining);
+
   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (user_data), fraction);
+
+  gtk_progress_bar_set_text (GTK_PROGRESS_BAR (user_data), bar_text);
+
+  g_free (bar_text);
 }
 
 
@@ -472,8 +478,12 @@
 
   success = g_file_copy_finish (G_FILE (source_object), res, &error);
 
+  TRACE ("The transfer is finished");
+
   if (!success)
     {
+      TRACE ("An error occurred");
+
       xfce_err (error->message);
 
       g_error_free (error);
@@ -489,6 +499,8 @@
 {
   if (G_LIKELY (response == GTK_RESPONSE_CANCEL))
     {
+      TRACE ("Cancel the screenshot");
+
       g_cancellable_cancel (cancellable);
 
       gtk_widget_destroy (dialog);
@@ -497,8 +509,8 @@
  
 
 
-static void
-save_screenshot_to_local_path (GdkPixbuf *screenshot, GFile *save_file)
+static gchar
+*save_screenshot_to_local_path (GdkPixbuf *screenshot, GFile *save_file)
 {
   GError *error = NULL;
   gchar *save_path = g_file_get_path (save_file);
@@ -508,9 +520,15 @@
       xfce_err ("%s", error->message);
       
       g_error_free (error);
+
+      g_free (save_path);
+      
+      return NULL;
     }
-
-  g_free (save_path);
+  else
+    {
+      return save_path;
+    }
 }
 
 static void
@@ -522,7 +540,7 @@
 
   GCancellable *cancellable = g_cancellable_new ();
   
-  GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Transfering the screenshot..."),
+  GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Transfer"),
                                                    NULL,
                                                    GTK_DIALOG_NO_SEPARATOR,
                                                    GTK_STOCK_CANCEL,
@@ -541,7 +559,7 @@
   gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
   gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
   
-  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), 20);
+  gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
   gtk_window_set_icon_name (GTK_WINDOW (dialog), "document-save");
 
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox),
@@ -554,8 +572,6 @@
 
   gtk_widget_show (progress_bar);
 
-  gtk_widget_show (dialog);
-
   g_signal_connect (dialog,
                     "response",
                     G_CALLBACK (cb_transfer_dialog_response),
@@ -568,22 +584,28 @@
                      cancellable,
                      (GFileProgressCallback)cb_progress_upload, progress_bar,
                      (GAsyncReadyCallback)cb_finished_upload, dialog);
+
+  gtk_dialog_run (GTK_DIALOG (dialog));
+
+  g_file_delete (save_file_temp, NULL, NULL);
                      
   g_object_unref (save_file_temp);
   g_free (save_basename);
   g_free (save_path);
 }
 
-static void
-save_screenshot_to (GdkPixbuf *screenshot, gchar *save_uri)
+static gchar
+*save_screenshot_to (GdkPixbuf *screenshot, gchar *save_uri)
 {
-  GFile *save_file = g_file_new_for_uri (save_uri); 
+  GFile *save_file = g_file_new_for_uri (save_uri);
+
+  gchar *result = NULL;
     
   /* If the URI is a local one, we save directly */
 
   if (!screenshooter_is_remote_uri (save_uri))
     {
-      save_screenshot_to_local_path (screenshot, save_file);
+      result = save_screenshot_to_local_path (screenshot, save_file);
     }
   else
     {
@@ -591,6 +613,8 @@
     }
   
   g_object_unref (save_file);
+
+  return result;
 }
 
 
@@ -1128,6 +1152,7 @@
 
       GtkWidget *preview;
       GtkWidget *chooser;
+      gchar *save_uri = NULL;
       gint dialog_response;
 
       /* If the user wants a save dialog, we run it, and grab the 
@@ -1182,23 +1207,24 @@
       /* The user pressed the save button */
 	    if (dialog_response == GTK_RESPONSE_ACCEPT)
 	      {
-          gchar *save_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
+          save_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
+        }
+	  
+	    gtk_widget_destroy (chooser);
 
-          gtk_widget_hide (chooser);
-                    
-          save_screenshot_to (screenshot, save_uri);
+      if (save_uri != NULL)
+        {
+          savename = save_screenshot_to (screenshot, save_uri);
 
           g_free (save_uri);
         }
-	  
-	    gtk_widget_destroy (chooser);
 	  }  
 	else
 	  {    
 	    /* Else, we just save the file in the default folder */
       gchar *save_uri = g_build_filename (default_dir, filename, NULL);
       
-      save_screenshot_to (screenshot, save_uri);
+      savename = save_screenshot_to (screenshot, save_uri);
 
       g_free (save_uri);
     }

Modified: xfce4-screenshooter/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/panel-plugin/Makefile.am	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/panel-plugin/Makefile.am	2009-03-14 14:10:58 UTC (rev 6901)
@@ -5,10 +5,12 @@
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
 	-I$(top_srcdir)								\
 	-I$(top_srcdir)/lib							\
-	@LIBXFCE4PANEL_CFLAGS@
+	@LIBXFCE4PANEL_CFLAGS@ \
+	@GTHREAD_CFLAGS@
 
 xfce4_screenshooter_plugin_LDFLAGS =						\
 	@LIBXFCE4PANEL_LIBS@ \
+	@GTHREAD_LIBS@ \
 	$(top_builddir)/lib/libscreenshooter.la
 
 xfce4_screenshooter_plugin_SOURCES =						\

Modified: xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c
===================================================================
--- xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/panel-plugin/screenshooter-plugin.c	2009-03-14 14:10:58 UTC (rev 6901)
@@ -313,6 +313,8 @@
   PluginData *pd = g_new0 (PluginData, 1);
   ScreenshotData *sd = g_new0 (ScreenshotData, 1);
 
+  g_thread_init (NULL);
+
   pd->sd = sd;
 
   TRACE ("Initialize the text domain");

Modified: xfce4-screenshooter/trunk/src/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/src/Makefile.am	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/src/Makefile.am	2009-03-14 14:10:58 UTC (rev 6901)
@@ -5,12 +5,14 @@
 	@GLIB_CFLAGS@ \
 	@LIBXFCE4UTIL_CFLAGS@ \
 	@LIBXFCEGUI4_CFLAGS@ \
+	@GTHREAD_CFLAGS@ \
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
 	-I$(top_srcdir)/lib
 	
 xfce4_screenshooter_LDFLAGS =                       \
 	@GTK_LIBS@ \
 	@GLIB_LIBS@ \
+	@GTHREAD_LIBS@ \
 	@LIBXFCE4UTIL_LIBS@ \
 	@LIBXFCEGUI4_LIBS@ \
 	$(top_builddir)/lib/libscreenshooter.la

Modified: xfce4-screenshooter/trunk/src/main.c
===================================================================
--- xfce4-screenshooter/trunk/src/main.c	2009-03-14 12:16:11 UTC (rev 6900)
+++ xfce4-screenshooter/trunk/src/main.c	2009-03-14 14:10:58 UTC (rev 6901)
@@ -182,6 +182,8 @@
         }
     }
 
+  g_thread_init (NULL);
+
   /* Read the preferences */
 
   rc_file = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, "xfce4/xfce4-screenshooter");




More information about the Goodies-commits mailing list