[Goodies-commits] r7308 - in xfce4-screenshooter/trunk: . lib

Jerome Guelfucci jeromeg at xfce.org
Sat May 2 16:06:55 CEST 2009


Author: jeromeg
Date: 2009-05-02 14:06:55 +0000 (Sat, 02 May 2009)
New Revision: 7308

Modified:
   xfce4-screenshooter/trunk/ChangeLog
   xfce4-screenshooter/trunk/lib/screenshooter-actions.c
   xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
   xfce4-screenshooter/trunk/lib/screenshooter-dialogs.h
   xfce4-screenshooter/trunk/lib/screenshooter-utils.c
   xfce4-screenshooter/trunk/lib/screenshooter-utils.h
   xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
   xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
Log:
	* lib/screenshooter-zimagez.{c,h}:
	  - (warn_if_fault_occurred) should be static.
	  - add some comments.
	  - (screenshooter_upload_to_zimagez) now returns a gchar* containing
	    the name of the uploaded image and NULL is the upload failed.
	  - (screenshooter_display_zimagez_links) new function which shows a
	    dialog to present the different links to the uploaded image. At
	    the moment, plain GtkLinkButtons are used, this still needs to be
	    improved.
	  - (open_url_hook) hook to open the links using xdg-open.
	* lib/screenshooter-actions.c:
	  - use constants where possible.
	  - use (screenshooter_display_zimagez_links) to display the result of
	    the upload.
	* lib/screenshooter-utils.{c,h}, lib/screenshooter-dialogs.{c,h}:
	  use constants where possible.:wq



Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/ChangeLog	2009-05-02 14:06:55 UTC (rev 7308)
@@ -1,3 +1,22 @@
+2009-05-02 jeromeg
+
+	* lib/screenshooter-zimagez.{c,h}:
+	  - (warn_if_fault_occurred) should be static.
+	  - add some comments.
+	  - (screenshooter_upload_to_zimagez) now returns a gchar* containing
+	    the name of the uploaded image and NULL is the upload failed.
+	  - (screenshooter_display_zimagez_links) new function which shows a
+	    dialog to present the different links to the uploaded image. At
+	    the moment, plain GtkLinkButtons are used, this still needs to be
+	    improved.
+	  - (open_url_hook) hook to open the links using xdg-open.
+	* lib/screenshooter-actions.c:
+	  - use constants where possible.
+	  - use (screenshooter_display_zimagez_links) to display the result of
+	    the upload.
+	* lib/screenshooter-utils.{c,h}, lib/screenshooter-dialogs.{c,h}:
+	  use constants where possible.
+
 2009-05-01 jeromeg
 
 	This still needs a lot of polishment, but let's make things public.

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-05-02 14:06:55 UTC (rev 7308)
@@ -44,8 +44,8 @@
   else
     {
       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 =
+      const gchar *temp_dir_uri = g_file_get_uri (temp_dir);
+      const gchar *screenshot_path =
         screenshooter_save_screenshot (screenshot, FALSE, temp_dir_uri);
 
       if (screenshot_path != NULL)
@@ -56,18 +56,17 @@
             }
           else
             {
-              screenshooter_upload_to_zimagez (screenshot_path);
-            }
+              const gchar *upload_name =
+                screenshooter_upload_to_zimagez (screenshot_path);
 
-          g_free (screenshot_path);
+              if (upload_name != NULL)
+                screenshooter_display_zimagez_links (upload_name);
+            }
         }
 
-      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-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c	2009-05-02 14:06:55 UTC (rev 7308)
@@ -63,7 +63,7 @@
 cb_delay_spinner_changed           (GtkWidget          *spinner, 
                                     ScreenshotData     *sd);
 static gchar 
-*generate_filename_for_uri         (char               *uri);
+*generate_filename_for_uri         (const gchar        *uri);
 static void 
 cb_combo_active_item_changed       (GtkWidget          *box, 
                                     ScreenshotData     *sd);
@@ -244,7 +244,7 @@
  * @uri: uri of the folder for which the filename should be generated.
  * returns: the filename or NULL if *uri == NULL.
 */
-static gchar *generate_filename_for_uri (char *uri)
+static gchar *generate_filename_for_uri (const gchar *uri)
 {
   gboolean exists = TRUE;
   GFile *directory;
@@ -1218,7 +1218,7 @@
 gchar 
 *screenshooter_save_screenshot     (GdkPixbuf      *screenshot, 
                                     gboolean        show_save_dialog,
-                                    gchar          *default_dir)
+                                    const gchar    *default_dir)
 {
   gchar *filename = generate_filename_for_uri (default_dir);
   gchar *savename = NULL;

Modified: xfce4-screenshooter/trunk/lib/screenshooter-dialogs.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-dialogs.h	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-dialogs.h	2009-05-02 14:06:55 UTC (rev 7308)
@@ -43,5 +43,5 @@
 gchar 
 *screenshooter_save_screenshot     (GdkPixbuf           *screenshot, 
                                     gboolean             show_save_dialog,
-                                    gchar               *default_dir);
+                                    const gchar         *default_dir);
 #endif                                    

Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.c	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.c	2009-05-02 14:06:55 UTC (rev 7308)
@@ -153,7 +153,7 @@
 @application: the command to run the application.
 */
 void
-screenshooter_open_screenshot (gchar *screenshot_path, gchar *application)
+screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *application)
 {
   gchar *command;
   GError *error = NULL;
@@ -172,7 +172,7 @@
   
   /* Execute the command and show an error dialog if there was 
   * an error. */
-  if (G_UNLIKELY (!g_spawn_command_line_async (command, &error)))
+  if (!g_spawn_command_line_async (command, &error))
     {
       TRACE ("An error occured");
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.h	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.h	2009-05-02 14:06:55 UTC (rev 7308)
@@ -46,8 +46,8 @@
                                   ScreenshotData       *sd);
 
 void
-screenshooter_open_screenshot    (gchar                *screenshot_path,
-                                  gchar                *application);
+screenshooter_open_screenshot    (const gchar          *screenshot_path,
+                                  const gchar          *application);
 
 gchar
 *screenshooter_get_home_uri      ();

Modified: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-05-02 14:06:55 UTC (rev 7308)
@@ -48,13 +48,18 @@
 static gboolean
 warn_if_fault_occurred      (xmlrpc_env * const    envP);
 
+static void
+open_url_hook               (GtkLinkButton        *button,
+                             const gchar          *link,
+                             gpointer             user_data);
 
 
+
 /* Private */
 
 
 
-gboolean warn_if_fault_occurred (xmlrpc_env * const envP)
+static gboolean warn_if_fault_occurred (xmlrpc_env * const envP)
 {
   gboolean error_occured = FALSE;
 
@@ -73,13 +78,41 @@
   return error_occured;
 }
 
+
+static void
+open_url_hook (GtkLinkButton *button, const gchar *link, gpointer user_data)
+{
+  const gchar *command = g_strconcat ("xdg-open ", link, NULL);
+  GError *error = NULL;
+
+  if (!g_spawn_command_line_async (command, &error))
+    {
+      TRACE ("An error occured");
+
+      xfce_err (error->message);
+      g_error_free (error);
+    }
+}
   
 
 /* Public */
 
 
 
-gboolean screenshooter_upload_to_zimagez (const gchar *image_path)
+/**
+ * screenshooter_upload_to_zimagez:
+ * @image_path: the local path of the image that should be uploaded to
+ * ZimageZ.com.
+ *
+ * Uploads the image whose path is @image_path: a dialog asks for the user
+ * login, password, a title for the image and a comment; then the image is
+ * uploaded.
+ *
+ * Returns: NULL is the upload fail, a #gchar* with the name of the image on
+ * Zimagez.com (see the API at the beginning of this file for more details).
+ **/
+   
+gchar *screenshooter_upload_to_zimagez (const gchar *image_path)
 {
   xmlrpc_env env;
   xmlrpc_value *resultP;
@@ -240,7 +273,7 @@
 
       g_free (password);
 
-      return FALSE;
+      return NULL;
     }
 
   /* Start the user session */
@@ -256,7 +289,7 @@
       xmlrpc_env_clean (&env);
       xmlrpc_client_cleanup ();
 
-      return FALSE;
+      return NULL;
     }
 
   TRACE ("Read the login response");
@@ -273,7 +306,7 @@
           xmlrpc_env_clean (&env);
           xmlrpc_client_cleanup ();
 
-          return FALSE;
+          return NULL;
         }
 
        if (!response)
@@ -285,7 +318,7 @@
            xmlrpc_env_clean (&env);
            xmlrpc_client_cleanup ();
 
-           return FALSE;
+           return NULL;
          }
     }
   /* Else we read the string response to get the session ID */
@@ -299,7 +332,7 @@
           xmlrpc_env_clean (&env);
           xmlrpc_client_cleanup ();
 
-          return FALSE;
+          return NULL;
         }
     }
 
@@ -315,7 +348,7 @@
       xmlrpc_env_clean (&env);
       xmlrpc_client_cleanup ();
 
-      return FALSE;
+      return NULL;
     }
 
   /* If the response is a boolean, there was an error */
@@ -330,7 +363,7 @@
           xmlrpc_env_clean (&env);
           xmlrpc_client_cleanup ();
 
-          return FALSE;
+          return NULL;
         }
 
        if (!response)
@@ -342,7 +375,7 @@
            xmlrpc_env_clean (&env);
            xmlrpc_client_cleanup ();
 
-           return FALSE;
+           return NULL;
          }
     }
   /* Else we get the file name */
@@ -357,11 +390,8 @@
           xmlrpc_env_clean (&env);
           xmlrpc_client_cleanup ();
 
-          return FALSE;
+          return NULL;
         }
-
-      TRACE (_("The screenshot was uploaded to http://www.zimagez.com/zimage/%s.php"),
-                 online_file_name);
     }
 
   xmlrpc_DECREF (resultP);
@@ -376,5 +406,80 @@
   xmlrpc_env_clean (&env);
   xmlrpc_client_cleanup ();
 
-  return TRUE;
+  return g_strdup (online_file_name);
 }
+
+
+
+void screenshooter_display_zimagez_links (const gchar *upload_name)
+{
+  GtkWidget *dialog;
+  GtkWidget *image_link, *thumbnail_link, *small_thumbnail_link;
+
+  gchar *image_url =
+    g_strdup_printf ("http://www.zimagez.com/zimage/%s.php", upload_name);
+  gchar *thumbnail_url =
+    g_strdup_printf ("http://www.zimagez.com/miniature/%s.php", upload_name);
+  gchar *small_thumbnail_url =
+    g_strdup_printf ("http://www.zimagez.com/avatar/%s.php", upload_name);
+
+  dialog =
+    xfce_titled_dialog_new_with_buttons (_("My screenshot on ZimageZ©"),
+                                         NULL,
+                                         GTK_DIALOG_NO_SEPARATOR,
+                                         GTK_STOCK_CLOSE,
+                                         GTK_RESPONSE_CLOSE,
+                                         NULL);
+
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), 20);
+  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG(dialog)->vbox), 12);
+
+  gtk_window_set_icon_name (GTK_WINDOW (dialog), "applications-internet");
+
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+  /* Create the image link */
+                                          
+  image_link =
+    gtk_link_button_new_with_label (image_url, _("Link to the full-size screenshot"));
+
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), image_link);
+
+  /* Create the thumbnail link */
+
+  thumbnail_link =
+    gtk_link_button_new_with_label (thumbnail_url,
+                                    _("Link to a thumbnail of the screenshot"));
+
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), thumbnail_link);
+
+  /* Create the small thumbnail link */
+
+  small_thumbnail_link =
+    gtk_link_button_new_with_label (small_thumbnail_url,
+                                    _("Link to a small thumbnail of the screenshot"));
+
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), small_thumbnail_link);
+
+  /* Set the url hook for the buttons */
+
+  gtk_link_button_set_uri_hook ((GtkLinkButtonUriFunc) open_url_hook, NULL, NULL);
+
+  /* Show the dialog and run it */
+  gtk_widget_show_all (GTK_DIALOG(dialog)->vbox);
+
+  gtk_dialog_run (GTK_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
+
+  /* Ugly hack to make sure the dialog is not displayed anymore */
+  while (gtk_events_pending ())
+    gtk_main_iteration_do (FALSE);
+
+  g_free (image_url);
+  g_free (thumbnail_url);
+  g_free (small_thumbnail_url);
+}
+
+  

Modified: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h	2009-05-02 11:16:09 UTC (rev 7307)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h	2009-05-02 14:06:55 UTC (rev 7308)
@@ -33,6 +33,7 @@
 #include "screenshooter-utils.h"
 
 
-gboolean screenshooter_upload_to_zimagez (const gchar *image_path);
+gchar *screenshooter_upload_to_zimagez     (const gchar *image_path);
+void   screenshooter_display_zimagez_links (const gchar *upload_name);
 
 #endif




More information about the Goodies-commits mailing list