[Goodies-commits] r7299 - in xfce4-screenshooter/trunk: . lib panel-plugin src
Jerome Guelfucci
jeromeg at xfce.org
Fri May 1 10:22:48 CEST 2009
Author: jeromeg
Date: 2009-05-01 08:22:48 +0000 (Fri, 01 May 2009)
New Revision: 7299
Added:
xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
Modified:
xfce4-screenshooter/trunk/ChangeLog
xfce4-screenshooter/trunk/TODO
xfce4-screenshooter/trunk/configure.ac.in
xfce4-screenshooter/trunk/lib/Makefile.am
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-utils.c
xfce4-screenshooter/trunk/lib/screenshooter-utils.h
xfce4-screenshooter/trunk/panel-plugin/Makefile.am
xfce4-screenshooter/trunk/src/Makefile.am
xfce4-screenshooter/trunk/src/main.c
Log:
2009-05-01 jeromeg
This still needs a lot of polishment, but let's make things public.
* src/Makefile.am, panel-plugin/Makefile.am: change the linking order.
* lib/screenshooter-zimagez.c:
- (warn_if_fault_occurred) to warn if an error occured during the XML
transaction.
- (screenshooter_upload_to_zimagez) to upload the screenshot. Still needs
a lot of polish, but at least it works.
* TODO: updated.
2009-04-19 jeromeg
* src/main.c:
- sort the CLI options by alphabetical order.
- add an upload CLI option.
- add some G_LIKELY and G_UNLIKELY macros.
* lib/screenshooter-actions.c:
- add some G_LIKELY and G_UNLIKELY macros.
- call the upload function when the user requested it.
* lib/screenshooter-utils.{c,h}: add a (rot13) function to encode the
password before sending it.
* lib/screenshooter-zimagez.{c,h}: two new files to support the upload
of screenshots to ZimageZ.com, a free Web hosting solution.
* lib/screenshooter-global.h: add the upload option.
* lib/Makefile.am: add the two new files to the source.
* configure.ac.in: check for xmlrpc-c, this is a bit uggly, but xmlrpc-c
does not provide a .pc file...
Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/ChangeLog 2009-05-01 08:22:48 UTC (rev 7299)
@@ -1,3 +1,33 @@
+2009-05-01 jeromeg
+
+ This still needs a lot of polishment, but let's make things public.
+
+ * src/Makefile.am, panel-plugin/Makefile.am: change the linking order.
+ * lib/screenshooter-zimagez.c:
+ - (warn_if_fault_occurred) to warn if an error occured during the XML
+ transaction.
+ - (screenshooter_upload_to_zimagez) to upload the screenshot. Still needs
+ a lot of polish, but at least it works.
+ * TODO: updated.
+
+2009-04-19 jeromeg
+
+ * src/main.c:
+ - sort the CLI options by alphabetical order.
+ - add an upload CLI option.
+ - add some G_LIKELY and G_UNLIKELY macros.
+ * lib/screenshooter-actions.c:
+ - add some G_LIKELY and G_UNLIKELY macros.
+ - call the upload function when the user requested it.
+ * lib/screenshooter-utils.{c,h}: add a (rot13) function to encode the
+ password before sending it.
+ * lib/screenshooter-zimagez.{c,h}: two new files to support the upload
+ of screenshots to ZimageZ.com, a free Web hosting solution.
+ * lib/screenshooter-global.h: add the upload option.
+ * lib/Makefile.am: add the two new files to the source.
+ * configure.ac.in: check for xmlrpc-c, this is a bit uggly, but xmlrpc-c
+ does not provide a .pc file...
+
2009-04-18 jeromeg
* lib/screenshooter-utils.c: start to add G_LIKELY and G_UNLIKELY macros.
Modified: xfce4-screenshooter/trunk/TODO
===================================================================
--- xfce4-screenshooter/trunk/TODO 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/TODO 2009-05-01 08:22:48 UTC (rev 7299)
@@ -2,6 +2,10 @@
as in thunar and xfdesktop.
* Check for leaks using valgrind.
* Use Xshape to have a transparent background in the generated screenshots.
+* Remove every call to xfce_err with a gtk_message_dialog.
+* the Zimagez code needs a lot of error checking.
+* The login dialog is uggly.
+* the upload adress is only passed in the debug statements at the moment.
Low priority:
* Try to get borders captured with compiz.
Modified: xfce4-screenshooter/trunk/configure.ac.in
===================================================================
--- xfce4-screenshooter/trunk/configure.ac.in 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/configure.ac.in 2009-05-01 08:22:48 UTC (rev 7299)
@@ -58,6 +58,28 @@
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
dnl **************************
+dnl *** Check for xmlrpc-c ***
+dnl **************************
+
+XMLRPC_LIBS=""
+XMLRPC_CFLAGS=""
+AC_PATH_PROG([XMLRPC_CONFIG], [xmlrpc-c-config], [no])
+if test x"$XMLRPC_CONFIG" != x"no"; then
+ AC_MSG_CHECKING([XMLRPC_CFLAGS])
+ XMLRPC_CFLAGS="`$XMLRPC_CONFIG --cflags client`"
+ AC_MSG_RESULT([$XMLRPC_CFLAGS])
+
+ AC_MSG_CHECKING([XMLRPC_LIBS])
+ XMLRPC_LIBS="`$XMLRPC_CONFIG --libs client`"
+ AC_MSG_RESULT([$XMLRPC_LIBS])
+
+ AC_SUBST([XMLRPC_CFLAGS])
+ AC_SUBST([XMLRPC_LIBS])
+else
+ AC_MSG_ERROR(Xmlrpc was not found on your system.)
+fi
+
+dnl **************************
dnl *** Check for xsltproc ***
dnl **************************
AC_ARG_ENABLE([xsltproc], [AC_HELP_STRING([--enable-xsltproc], [Use xsltproc to build documentation @<:@default=no@:>@])],, [enable_xsltproc=no])
@@ -81,7 +103,6 @@
fi
AM_CONDITIONAL([ENABLE_XML2PO], [test x"$enable_xml2po" = x"yes"])
-
dnl ******************************
dnl *** Check for i18n support ***
dnl ******************************
Modified: xfce4-screenshooter/trunk/lib/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/lib/Makefile.am 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/Makefile.am 2009-05-01 08:22:48 UTC (rev 7299)
@@ -7,18 +7,21 @@
screenshooter-utils.c screenshooter-utils.h \
screenshooter-capture.c screenshooter-capture.h \
screenshooter-dialogs.c screenshooter-dialogs.h \
- screenshooter-actions.c screenshooter-actions.h
+ screenshooter-actions.c screenshooter-actions.h \
+ screenshooter-zimagez.c screenshooter-zimagez.h
libscreenshooter_la_CFLAGS = \
-I$(top_srcdir) \
+ $(XMLRPC_CFLAGS) \
@GTK_CFLAGS@ \
@GLIB_CFLAGS@ \
@LIBXFCE4UTIL_CFLAGS@ \
@LIBXFCEGUI4_CFLAGS@ \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
libscreenshooter_la_LIBADD = \
+ $(XMLRPC_LIBS) -lxmlrpc_client\
@GTK_LIBS@ \
@LIBXFCE4UTIL_LIBS@ \
@LIBXFCEGUI4_LIBS@ \
- @GLIB_LIBS@
+ @GLIB_LIBS@
Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c 2009-05-01 08:22:48 UTC (rev 7299)
@@ -24,43 +24,50 @@
GdkPixbuf *screenshot =
screenshooter_take_screenshot (sd->region, sd->delay, sd->show_mouse);
- if (screenshot != NULL)
+ g_return_if_fail (screenshot != NULL);
+
+ if (sd->action == SAVE)
{
- if (sd->action == SAVE)
+ if (sd->screenshot_dir == NULL)
{
- if (sd->screenshot_dir == NULL)
- {
- sd->screenshot_dir = screenshooter_get_home_uri ();
- }
+ sd->screenshot_dir = screenshooter_get_home_uri ();
+ }
- screenshooter_save_screenshot (screenshot,
- sd->show_save_dialog,
- sd->screenshot_dir);
- }
- else if (sd->action == CLIPBOARD)
+ screenshooter_save_screenshot (screenshot,
+ sd->show_save_dialog,
+ sd->screenshot_dir);
+ }
+ else if (sd->action == CLIPBOARD)
+ {
+ screenshooter_copy_to_clipboard (screenshot);
+ }
+ 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 =
+ screenshooter_save_screenshot (screenshot, FALSE, temp_dir_uri);
+
+ if (screenshot_path != NULL)
{
- screenshooter_copy_to_clipboard (screenshot);
- }
- 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 =
- screenshooter_save_screenshot (screenshot, FALSE, temp_dir_uri);
-
- if (screenshot_path != NULL)
+ if (sd->action == OPEN)
{
screenshooter_open_screenshot (screenshot_path, sd->app);
- g_free (screenshot_path);
}
+ else
+ {
+ screenshooter_upload_to_zimagez (screenshot_path);
+ }
- g_free (temp_dir_uri);
-
- g_object_unref (temp_dir);
+ g_free (screenshot_path);
}
- g_object_unref (screenshot);
+ g_free (temp_dir_uri);
+ g_object_unref (temp_dir);
}
+ g_object_unref (screenshot);
+
+
}
Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.h 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.h 2009-05-01 08:22:48 UTC (rev 7299)
@@ -24,6 +24,7 @@
#include "screenshooter-capture.h"
#include "screenshooter-global.h"
#include "screenshooter-dialogs.h"
+#include "screenshooter-zimagez.h"
void screenshooter_take_and_output_screenshot (ScreenshotData *sd);
Modified: xfce4-screenshooter/trunk/lib/screenshooter-global.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-global.h 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/screenshooter-global.h 2009-05-01 08:22:48 UTC (rev 7299)
@@ -32,6 +32,7 @@
SAVE,
CLIPBOARD,
OPEN,
+ UPLOAD,
};
Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.c 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.c 2009-05-01 08:22:48 UTC (rev 7299)
@@ -185,8 +185,7 @@
-gchar
-*screenshooter_get_home_uri ()
+gchar *screenshooter_get_home_uri ()
{
gchar *result = NULL;
const gchar *home_path = g_getenv ("HOME");
@@ -212,3 +211,19 @@
return FALSE;
}
+
+
+
+gchar *rot13 (gchar *string)
+{
+ gchar *result = string;
+
+ for (; *string; string++)
+ if (*string >= 'a' && *string <= 'z')
+ *string = (*string - 'a' + 13) % 26 + 'a';
+ else if (*string >= 'A' && *string <= 'Z')
+ *string = (*string - 'A' + 13) % 26 + 'A';
+
+ return result;
+}
+
Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.h 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.h 2009-05-01 08:22:48 UTC (rev 7299)
@@ -55,4 +55,7 @@
gboolean
screenshooter_is_remote_uri (const gchar *uri);
+gchar
+*rot13 (gchar *string);
+
#endif
Added: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c (rev 0)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c 2009-05-01 08:22:48 UTC (rev 7299)
@@ -0,0 +1,380 @@
+/* $Id$
+ *
+ * Copyright © 2009 Jérôme Guelfucci <jerome.guelfucci at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * */
+
+
+/* XML-RPC API for ZimageZ.com */
+
+/* URL of the API: http://www.zimagez.com/apiXml.php
+
+ xmlrpcLogin: Takes the user name and the password (encrypted using rot13 and
+ reversed using g_strrev.
+ Returns a string containing the ID for the user session if the couple was correct.
+ Returns a boolean set to FALSE if the couple was wrong.
+
+ xmlrpcLogout: destroys the current user session.
+
+ xmlrpcUpload: Takes the file content encoded in base64, the name of the file,
+ the title of the picture, a comment and the user session ID.
+ Returns the name of the file on the website if the upload was succesful.
+ Returns a boolean set to FALSE if the upload failed.
+
+ If the returned name is "wii0". The URLs will be:
+ * http://www.zimagez.com/zimage/wii0.php for the image.
+ * http://www.zimagez.com/miniature/wii0.jpg for the thumbnail.
+ * http://www.zimagez.com/avatar/wii0.jpg for the avatar.
+
+*/
+
+#include "screenshooter-zimagez.h"
+
+
+
+static gboolean
+warn_if_fault_occurred (xmlrpc_env * const envP);
+
+
+
+/* Private */
+
+
+
+gboolean warn_if_fault_occurred (xmlrpc_env * const envP)
+{
+ gboolean error_occured = FALSE;
+
+ if (envP->fault_occurred)
+ {
+ TRACE ("An error occured during the XML transaction %s, %d",
+ envP->fault_string, envP->fault_code );
+
+ xfce_err (_("An error occurred during the XML exchange: %s (%d).\n The screenshot "
+ "could not be uploaded."),
+ envP->fault_string, envP->fault_code );
+
+ error_occured = TRUE;
+ }
+
+ return error_occured;
+}
+
+
+
+/* Public */
+
+
+
+gboolean screenshooter_upload_to_zimagez (const gchar *image_path)
+{
+ xmlrpc_env env;
+ xmlrpc_value *resultP;
+
+ const gchar * const serverurl = "http://www.zimagez.com/apiXml.php";
+ const gchar * const method_login = "apiXml.xmlrpcLogin";
+ const gchar * const method_logout = "apiXml.xmlrpcLogout";
+ const gchar * const method_upload = "apiXml.xmlrpcUpload";
+
+ gchar *data;
+ gchar *password = NULL;
+ const gchar *user;
+ const gchar *title;
+ const gchar *comment;
+ const gchar *encoded_data;
+ const gchar *encoded_password;
+ const gchar *file_name = g_path_get_basename (image_path);
+ const gchar *online_file_name;
+ const gchar *login_response;
+ gsize data_length;
+
+ GtkWidget *dialog;
+ GtkWidget *information_label;
+ GtkWidget *user_hbox, *password_hbox, *title_hbox, *comment_hbox;
+ GtkWidget *user_entry, *password_entry, *title_entry, *comment_entry;
+ GtkWidget *user_label, *password_label, *title_label, *comment_label;
+
+ /* Get the user information */
+ /* Create the information dialog */
+ dialog =
+ xfce_titled_dialog_new_with_buttons (_("Details about the screenshot for ZimageZ©"),
+ NULL,
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_OK,
+ 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), "gtk-info");
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ /* Create the information label */
+
+ information_label =
+ gtk_label_new (_("Please file the following fields with your ZimageZ© user name and "
+ "password."));
+
+ /* Create the user box */
+
+ user_hbox = gtk_hbox_new (FALSE, 6);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), user_hbox);
+
+ /* Create the user label */
+ user_label = gtk_label_new (_("User:"));
+
+ gtk_container_add (GTK_CONTAINER (user_hbox), user_label);
+
+ /* Create the user entry */
+ user_entry = gtk_entry_new ();
+
+ gtk_container_add (GTK_CONTAINER (user_hbox), user_entry);
+
+ /* Create the password box */
+
+ password_hbox = gtk_hbox_new (FALSE, 6);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), password_hbox);
+
+ /* Create the password label */
+ password_label = gtk_label_new (_("Password:"));
+
+ gtk_container_add (GTK_CONTAINER (password_hbox), password_label);
+
+ /* Create the password entry */
+ password_entry = gtk_entry_new ();
+
+ gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);
+
+ gtk_container_add (GTK_CONTAINER (password_hbox), password_entry);
+
+ /* Create the title box */
+
+ title_hbox = gtk_hbox_new (FALSE, 6);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), title_hbox);
+
+ /* Create the title label */
+ title_label = gtk_label_new (_("Title:"));
+
+ gtk_container_add (GTK_CONTAINER (title_hbox), title_label);
+
+ /* Create the title entry */
+ title_entry = gtk_entry_new ();
+
+ gtk_container_add (GTK_CONTAINER (title_hbox), title_entry);
+
+ /* Create the comment box */
+
+ comment_hbox = gtk_hbox_new (FALSE, 6);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), comment_hbox);
+
+ /* Create the comment label */
+ comment_label = gtk_label_new (_("Comment:"));
+
+ gtk_container_add (GTK_CONTAINER (comment_hbox), comment_label);
+
+ /* Create the comment entry */
+ comment_entry = gtk_entry_new ();
+
+ gtk_container_add (GTK_CONTAINER (comment_hbox), comment_entry);
+
+ /* Show the dialog */
+
+ gtk_widget_show_all (GTK_DIALOG(dialog)->vbox);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ user = g_strdup (gtk_entry_get_text (GTK_ENTRY (user_entry)));
+ password = g_strdup (gtk_entry_get_text (GTK_ENTRY (password_entry)));
+ title = g_strdup (gtk_entry_get_text (GTK_ENTRY (title_entry)));
+ comment = g_strdup (gtk_entry_get_text (GTK_ENTRY (comment_entry)));
+
+ gtk_widget_destroy (dialog);
+
+ while (gtk_events_pending ())
+ gtk_main_iteration_do (FALSE);
+
+ encoded_password = g_strreverse (rot13 (password));
+
+ TRACE ("User: %s Password: %s", user, encoded_password);
+
+ /* Get the contents of the image file and encode it to base64 */
+ g_file_get_contents (image_path, &data, &data_length, NULL);
+
+ encoded_data = g_base64_encode ((guchar*)data, data_length);
+
+ g_free (data);
+
+ /* Start the user session */
+
+ TRACE ("Initiate the RPC environment");
+ xmlrpc_env_init(&env);
+
+ TRACE ("Initiate the RPC client");
+ xmlrpc_client_init2 (&env, XMLRPC_CLIENT_NO_FLAGS, PACKAGE_NAME, PACKAGE_VERSION,
+ NULL, 0);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ g_free (password);
+
+ return FALSE;
+ }
+
+ /* Start the user session */
+ TRACE ("Call the login method");
+
+ resultP = xmlrpc_client_call (&env, serverurl, method_login,
+ "(ss)", user, encoded_password);
+
+ g_free (password);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+
+ TRACE ("Read the login response");
+
+ /* If the response is a boolean, there was an error */
+ if (xmlrpc_value_type (resultP) == XMLRPC_TYPE_BOOL)
+ {
+ xmlrpc_bool response;
+
+ xmlrpc_read_bool (&env, resultP, &response);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+
+ if (!response)
+ {
+ xfce_err (_("The username or the password you gave is incorrect."));
+
+ TRACE ("Incorrect password/login");
+
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+ }
+ /* Else we read the string response to get the session ID */
+ else
+ {
+ TRACE ("Read the session ID");
+ xmlrpc_read_string (&env, resultP, (const gchar ** const)&login_response);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+ }
+
+ xmlrpc_DECREF (resultP);
+
+ TRACE ("Call the upload method");
+ resultP = xmlrpc_client_call (&env, serverurl, method_upload,
+ "(sssss)", encoded_data, file_name, title, comment,
+ login_response);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+
+ /* If the response is a boolean, there was an error */
+ if (xmlrpc_value_type (resultP) == XMLRPC_TYPE_BOOL)
+ {
+ xmlrpc_bool response;
+
+ xmlrpc_read_bool (&env, resultP, &response);
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+
+ if (!response)
+ {
+ xfce_err (_("An error occurred while uploading the screenshot."));
+
+ TRACE ("Error while uploading the screenshot.");
+
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+ }
+ /* Else we get the file name */
+ else
+ {
+ xmlrpc_read_string (&env, resultP, (const char **)&online_file_name);
+
+ TRACE ("The screenshot has been uploaded, get the file name.");
+
+ if (warn_if_fault_occurred (&env))
+ {
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return FALSE;
+ }
+
+ TRACE (_("The screenshot was uploaded to http://www.zimagez.com/zimage/%s.php"),
+ online_file_name);
+ }
+
+ xmlrpc_DECREF (resultP);
+
+ /* End the user session */
+
+ TRACE ("Closing the user session");
+
+ xmlrpc_client_call (&env, serverurl, method_logout, "(s)", login_response);
+
+ TRACE ("Cleanup the XMLRPC session");
+ xmlrpc_env_clean (&env);
+ xmlrpc_client_cleanup ();
+
+ return TRUE;
+}
Added: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h (rev 0)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h 2009-05-01 08:22:48 UTC (rev 7299)
@@ -0,0 +1,38 @@
+/* $Id$
+ *
+ * Copyright © 2009 Jérôme Guelfucci <jerome.guelfucci at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * */
+
+#ifndef __HAVE_ZIMAGEZ_H__
+#define __HAVE_ZIMAGEZ_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#include <xmlrpc-c/base.h>
+#include <xmlrpc-c/client.h>
+
+#include "screenshooter-utils.h"
+
+
+gboolean screenshooter_upload_to_zimagez (const gchar *image_path);
+
+#endif
Modified: xfce4-screenshooter/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/panel-plugin/Makefile.am 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/panel-plugin/Makefile.am 2009-05-01 08:22:48 UTC (rev 7299)
@@ -1,19 +1,19 @@
plugindir = $(libexecdir)/xfce4/panel-plugins
plugin_PROGRAMS = xfce4-screenshooter-plugin
-xfce4_screenshooter_plugin_CFLAGS = \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
- -I$(top_srcdir) \
- -I$(top_srcdir)/lib \
+xfce4_screenshooter_plugin_CFLAGS = \
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/lib \
@LIBXFCE4PANEL_CFLAGS@ \
@GTHREAD_CFLAGS@
-xfce4_screenshooter_plugin_LDFLAGS = \
+xfce4_screenshooter_plugin_LDFLAGS = \
@LIBXFCE4PANEL_LIBS@ \
@GTHREAD_LIBS@ \
$(top_builddir)/lib/libscreenshooter.la
-xfce4_screenshooter_plugin_SOURCES = \
+xfce4_screenshooter_plugin_SOURCES = \
screenshooter-plugin.c
# .desktop file
Modified: xfce4-screenshooter/trunk/src/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/src/Makefile.am 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/src/Makefile.am 2009-05-01 08:22:48 UTC (rev 7299)
@@ -1,21 +1,22 @@
bin_PROGRAMS = xfce4-screenshooter
xfce4_screenshooter_CFLAGS = \
+ -I$(top_srcdir)/lib \
@GTK_CFLAGS@ \
@GLIB_CFLAGS@ \
@LIBXFCE4UTIL_CFLAGS@ \
@LIBXFCEGUI4_CFLAGS@ \
@GTHREAD_CFLAGS@ \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
- -I$(top_srcdir)/lib
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
-xfce4_screenshooter_LDFLAGS = \
+xfce4_screenshooter_LDFLAGS = \
+ $(top_builddir)/lib/libscreenshooter.la \
@GTK_LIBS@ \
@GLIB_LIBS@ \
@GTHREAD_LIBS@ \
@LIBXFCE4UTIL_LIBS@ \
- @LIBXFCEGUI4_LIBS@ \
- $(top_builddir)/lib/libscreenshooter.la
+ @LIBXFCEGUI4_LIBS@
+
xfce4_screenshooter_SOURCES = \
main.c
Modified: xfce4-screenshooter/trunk/src/main.c
===================================================================
--- xfce4-screenshooter/trunk/src/main.c 2009-05-01 07:53:04 UTC (rev 7298)
+++ xfce4-screenshooter/trunk/src/main.c 2009-05-01 08:22:48 UTC (rev 7299)
@@ -32,6 +32,7 @@
gboolean fullscreen = FALSE;
gboolean no_save_dialog = FALSE;
gboolean hide_mouse = FALSE;
+gboolean upload = FALSE;
gchar *screenshot_dir;
gchar *application;
gint delay = 0;
@@ -41,45 +42,63 @@
/* Set cli options. */
static GOptionEntry entries[] =
{
- { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
- N_("Version information"),
- NULL
- },
- { "window", 'w', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &window,
- N_("Take a screenshot of the active window"),
- NULL
- },
- { "fullscreen", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &fullscreen,
- N_("Take a screenshot of the entire screen"),
- NULL
- },
- { "region", 'r', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, ®ion,
- N_("Select a region to be captured by clicking a point of the screen "
- "without releasing the mouse button, dragging your mouse to the "
- "other corner of the region, and releasing the mouse button."),
- NULL
- },
- { "delay", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &delay,
- N_("Delay in seconds before taking the screenshot"),
- NULL
- },
- { "hide", 'h', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_save_dialog,
- N_("Do not display the save dialog"),
- NULL
- },
- { "mouse", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &hide_mouse,
- N_("Do not display the mouse on the screenshot"),
- NULL
- },
- { "save", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_FILENAME, &screenshot_dir,
- N_("Directory where the screenshot will be saved"),
- NULL
- },
- { "open", 'o', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &application,
- N_("Application to open the screenshot"),
- NULL
- },
- { NULL, ' ', 0, 0, NULL, NULL, NULL }
+ {
+ "delay", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &delay,
+ N_("Delay in seconds before taking the screenshot"),
+ NULL
+ },
+ {
+ "fullscreen", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &fullscreen,
+ N_("Take a screenshot of the entire screen"),
+ NULL
+ },
+ {
+ "hide", 'h', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_save_dialog,
+ N_("Do not display the save dialog"),
+ NULL
+ },
+ {
+ "mouse", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &hide_mouse,
+ N_("Do not display the mouse on the screenshot"),
+ NULL
+ },
+ {
+ "open", 'o', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &application,
+ N_("Application to open the screenshot"),
+ NULL
+ },
+ {
+ "region", 'r', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, ®ion,
+ N_("Select a region to be captured by clicking a point of the screen "
+ "without releasing the mouse button, dragging your mouse to the "
+ "other corner of the region, and releasing the mouse button."),
+ NULL
+ },
+ {
+ "save", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_FILENAME, &screenshot_dir,
+ N_("Directory where the screenshot will be saved"),
+ NULL
+ },
+ {
+ "upload", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &upload,
+ N_("Upload the screenshot to ZimageZ©, a free Web hosting solution"),
+ NULL
+ },
+ {
+ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
+ N_("Version information"),
+ NULL
+ },
+ {
+ "window", 'w', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &window,
+ N_("Take a screenshot of the active window"),
+ NULL
+ },
+ {
+ NULL, ' ', 0, 0, NULL,
+ NULL,
+ NULL
+ }
};
static void
@@ -210,14 +229,14 @@
screenshooter_read_rc_file (rc_file, sd);
- if (rc_file != NULL)
+ if (G_LIKELY (rc_file != NULL))
g_free (rc_file);
/* Check if the directory read from the preferences is valid */
default_save_dir = g_file_new_for_uri (sd->screenshot_dir);
- if (!g_file_query_exists (default_save_dir, NULL))
+ if (G_UNLIKELY (!g_file_query_exists (default_save_dir, NULL)))
{
g_free (sd->screenshot_dir);
@@ -265,6 +284,11 @@
sd->app = application;
sd->action = OPEN;
}
+ else if (upload)
+ {
+ sd->app = g_strdup ("none");
+ sd->action = UPLOAD;
+ }
else
{
sd->app = g_strdup ("none");
@@ -276,7 +300,7 @@
{
default_save_dir = g_file_new_for_commandline_arg (screenshot_dir);
- if (g_file_query_exists (default_save_dir, NULL))
+ if (G_LIKELY (g_file_query_exists (default_save_dir, NULL)))
{
g_free (sd->screenshot_dir);
sd->screenshot_dir = g_file_get_uri (default_save_dir);
More information about the Goodies-commits
mailing list