gtranslator r3503 - in trunk: . plugins/open-tran
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtranslator r3503 - in trunk: . plugins/open-tran
- Date: Mon, 3 Mar 2008 13:57:43 +0000 (GMT)
Author: icq
Date: Mon Mar 3 13:57:42 2008
New Revision: 3503
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3503&view=rev
Log:
2008-03-03 Ignacio Casal Quinteiro <nacho resa gmail com>
* configure.ac: Fixed soup library look up.
* plugins/open-tran/open-tran-panel.c:
Now open tran supports libsoup 2.4 and libsoup 2.2.
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/plugins/open-tran/open-tran-panel.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Mar 3 13:57:42 2008
@@ -172,20 +172,23 @@
if test "x$enable_opentran" != "xno"; then
PKG_CHECK_MODULES(SOUP, \
libsoup-2.2,
- have_libsoup=yes,
- have_libsoup=no)
+ have_libsoup_2_2=yes,
+ have_libsoup_2_2=no)
if test x"$have_libsoup" = "xno"; then
PKG_CHECK_MODULES(SOUP,
libsoup-2.4,
- have_libsoup=yes,
- have_libsoup=no)
+ have_libsoup_2_4=yes,
+ have_libsoup_2_4=no)
fi
- if test x"$have_libsoup" = "xyes"; then
- AC_DEFINE(HAVE_LIBSOUP, 1, [Define if libsoup support is enabled])
+ if test x"$have_libsoup_2_2" = "xyes"; then
+ AC_DEFINE(LIBSOUP_2_2, 1, [Define if libsoup support is enabled])
+ elif test x"$have_libsoup_2_4" = "xyes"; then
+ AC_DEFINE(LIBSOUP_2_4, 1, [Define if libsoup support is enabled])
fi
fi
-AM_CONDITIONAL(USE_LIBSOUP, test x"$have_libsoup" = "xyes")
+AM_CONDITIONAL(USE_LIBSOUP, test x"$have_libsoup_2_2" = "xyes")
+AM_CONDITIONAL(USE_LIBSOUP, test x"$have_libsoup_2_4" = "xyes")
# ================================================================
# gdict
Modified: trunk/plugins/open-tran/open-tran-panel.c
==============================================================================
--- trunk/plugins/open-tran/open-tran-panel.c (original)
+++ trunk/plugins/open-tran/open-tran-panel.c Mon Mar 3 13:57:42 2008
@@ -25,14 +25,19 @@
#include "header.h"
#include "plugin.h"
+#include <string.h>
+
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include <gconf/gconf-client.h>
#include <gtk/gtk.h>
#include <libsoup/soup.h>
+
+#ifdef LIBSOUP_2_2
#include <libsoup/soup-xmlrpc-message.h>
#include <libsoup/soup-xmlrpc-response.h>
+#endif
#define GTR_OPEN_TRAN_PANEL_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
(object), \
@@ -117,15 +122,25 @@
print_struct_to_tree_view(gpointer value,
GtranslatorOpenTranPanel *panel)
{
+#ifdef LIBSOUP_2_2
gchar *str;
+#elif LIBSOUP_2_4
+ const gchar *str;
+#endif
GdkPixbuf *icon;
GtkTreeIter iter;
-
+
/*
* Text value
*/
+#ifdef LIBSOUP_2_2
if (soup_xmlrpc_value_get_string (value, &str))
{
+#elif LIBSOUP_2_4
+ if (G_VALUE_HOLDS_STRING (value))
+ {
+ str = g_value_get_string (value);
+#endif
/*
* We have to parse the first character of str:
* G - Gnome
@@ -153,6 +168,8 @@
ICON_COLUMN, icon,
TEXT_COLUMN, panel->priv->text,
-1);
+
+ g_free (panel->priv->text);
}
}
@@ -166,12 +183,19 @@
gpointer data)
{
GtranslatorOpenTranPanel *panel = GTR_OPEN_TRAN_PANEL(data);
+ GHashTable *hash;
+ GList *values;
+#ifdef LIBSOUP_2_2
gchar *str;
SoupXmlrpcValue *result;
SoupXmlrpcValueArrayIterator *ar_iter;
- GHashTable *hash;
- GList *values;
+#elif LIBSOUP_2_4
+ GValueArray *array;
+ const gchar *str;
+#endif
+
+#ifdef LIBSOUP_2_2
/*
* Text value
*/
@@ -201,8 +225,32 @@
if((values = g_list_next(values)))
print_struct_to_tree_view(values->data, panel);
}
+#elif LIBSOUP_2_4
+ if (G_VALUE_HOLDS_STRING (value))
+ {
+ str = g_value_get_string (value);
+ panel->priv->text = g_strdup (str);
+ }
+
+ if (G_VALUE_HOLDS (value, G_TYPE_VALUE_ARRAY))
+ {
+ array = g_value_get_boxed (value);
+
+ if (G_VALUE_HOLDS (array->values, G_TYPE_HASH_TABLE))
+ {
+ hash = g_value_get_boxed (array->values);
+ g_value_array_free (array);
+ }
+ else return;
+
+ values = g_hash_table_get_values(hash);
+ if((values = g_list_next(values)))
+ print_struct_to_tree_view(values->data, panel);
+ }
+#endif
}
+#ifdef LIBSOUP_2_2
static void
got_response (SoupMessage *msg,
gpointer data)
@@ -278,7 +326,7 @@
g_object_unref (response);
/*
- * We have to check we didn't found any text
+ * We have to check if we didn't find any text
*/
if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(panel->priv->store),
&treeiter))
@@ -290,6 +338,25 @@
-1);
}
}
+#endif
+
+#ifdef LIBSOUP_2_4
+static void
+check_xmlrpc (GValue *value, GType type, ...)
+{
+ va_list args;
+
+ if (!G_VALUE_HOLDS (value, type)) {
+ g_warning (_("ERROR: could not parse response\n"));
+ g_value_unset (value);
+ return;
+ }
+
+ va_start (args, type);
+ SOUP_VALUE_GETV (value, type, args);
+ va_end (args);
+}
+#endif
static void
open_connection(GtranslatorOpenTranPanel *panel,
@@ -297,10 +364,12 @@
const gchar *search_code,
const gchar *own_code)
{
- SoupUri *proxy = NULL; //This can be useful in a future
- SoupXmlrpcMessage *msg;
const gchar *uri = "http://open-tran.eu/RPC2";
+#ifdef LIBSOUP_2_2
+ SoupXmlrpcMessage *msg;
+ SoupUri *proxy = NULL; //This can be useful in a future
+
panel->priv->session = soup_session_async_new_with_options (
SOUP_SESSION_PROXY_URI, proxy,
NULL);
@@ -323,6 +392,88 @@
soup_xmlrpc_message_persist (msg);
soup_session_queue_message (panel->priv->session, SOUP_MESSAGE (msg),
got_response, panel);
+#elif LIBSOUP_2_4
+ SoupMessage *msg;
+ gchar *body;
+ GValueArray *array;
+ GError *err = NULL;
+ GValue retval;
+ GHashTable *result;
+ GtkTreeIter treeiter;
+ gint i;
+
+ panel->priv->session = soup_session_async_new ();
+
+ array = soup_value_array_new_with_vals (G_TYPE_STRING, text,
+ G_TYPE_STRING, search_code,
+ G_TYPE_STRING, own_code,
+ G_TYPE_INVALID);
+
+ body = soup_xmlrpc_build_method_call ("suggest2", array->values,
+ array->n_values);
+
+ g_value_array_free (array);
+
+ if (!body)
+ return;
+
+ msg = soup_message_new ("POST", uri);
+ soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE,
+ body, strlen (body));
+ soup_session_send_message (panel->priv->session, msg);
+
+ if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+ show_error_dialog (panel->priv->window,
+ _("ERROR: %d %s\n"), msg->status_code,
+ msg->reason_phrase);
+ g_object_unref (msg);
+ return;
+ }
+
+ if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
+ msg->response_body->length,
+ &retval, &err)) {
+ if (err) {
+ show_error_dialog (panel->priv->window,
+ _("FAULT: %d %s\n"), err->code,
+ err->message);
+ g_error_free (err);
+ } else
+ show_error_dialog (panel->priv->window,
+ _("ERROR: could not parse response\n"));
+ }
+ g_object_unref (msg);
+
+ check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &array);
+
+ for (i = 0; i < array->n_values; i++)
+ {
+ if (!soup_value_array_get_nth (array, i, G_TYPE_HASH_TABLE, &result))
+ {
+ show_error_dialog(panel->priv->window,
+ _("WRONG! Can't get result element %d\n"), i + 1);
+ break;
+ }
+
+ g_hash_table_foreach(result, print_struct_field, panel);
+ }
+
+ /*
+ * We have to check if we didn't find any text
+ */
+ if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(panel->priv->store),
+ &treeiter))
+ {
+ gtk_list_store_append(panel->priv->store, &treeiter);
+ gtk_list_store_set(panel->priv->store, &treeiter,
+ ICON_COLUMN, NULL,
+ TEXT_COLUMN, _("Phrase not found"),
+ -1);
+ }
+
+ soup_session_abort (panel->priv->session);
+ g_object_unref (panel->priv->session);
+#endif
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]