]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunto il test per SolipaOOO.\n\nCorrezioni e aggiustamenti.
authorAndrea Zagli <azagli@libero.it>
Mon, 18 Jul 2011 09:39:22 +0000 (11:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 18 Jul 2011 09:39:22 +0000 (11:39 +0200)
.gitignore
src/ooo.c
tests/Makefile.am
tests/ooo.c [new file with mode: 0644]
tests/ooo.odt [new file with mode: 0644]

index d0b2e54c95e161ae76a3a27ab720c227e21a3940..18d6412e4146802c1767baf166c323e90db62285 100644 (file)
@@ -51,6 +51,7 @@ tests/allegato
 tests/mail
 tests/mail_get_addresses_from_string
 tests/mailui
+tests/ooo
 tests/progresswindow
 tests/utils
 tests/utils_codfisc_piva
index 2379a6fb98e4076ff0857759f88b50ad1136d5a1..53f32373e68156fbedffc9815c09c2175c13d314 100644 (file)
--- a/src/ooo.c
+++ b/src/ooo.c
@@ -101,7 +101,15 @@ SolipaOOO
 
        /* TODO controllare i valori */
        priv->ooo_path = g_strdup (ooo_path);
-       priv->ooo_soffice = g_strdup (ooo_soffice);
+
+       if (ooo_soffice == NULL)
+               {
+                       priv->ooo_soffice = g_strdup ("soffice");
+               }
+       else
+               {
+                       priv->ooo_soffice = g_strdup (ooo_soffice);
+               }
 
        solipa_ooo_apri_openoffice (solipa_ooo);
 
@@ -119,14 +127,25 @@ solipa_ooo_apri_documento (SolipaOOO *ooo, const gchar *filename)
 void
 solipa_ooo_string_replace (SolipaOOO *ooo, const gchar *search, const gchar *replace)
 {
+       gchar *_search;
+       gchar *_replace;
+
+       _search = g_strdup (search);
+       _replace = g_strdup (replace);
+
+       _search = g_strjoinv ("\\\"", g_strsplit (_search, "\"", -1));
+       _replace = g_strjoinv ("\\\"", g_strsplit (_replace, "\"", -1));
+
        /* TODO controllare se SearchDescriptor esiste o no */
-       PyRun_SimpleString (g_strdup_printf ("search = document.createSearchDescriptor()\n"
+       PyRun_SimpleString ("search = document.createSearchDescriptor()\n");
+
+       PyRun_SimpleString (g_strdup_printf (
                            "search.SearchString = u\"%s\"\n"
                            "found = document.findFirst(search)\n"
                            "found.String = string.replace(found.String, u\"%s\", u\"%s\")\n",
-                           search,
-                           search,
-                           replace));
+                           _search,
+                           _search,
+                           _replace));
 }
 
 /* PRIVATE */
@@ -253,32 +272,36 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        /* chiudo le eventuali sessioni di openoffice attive */
 #ifdef G_OS_WIN32
-       pipa = popen ("taskkill /T /F /IM soffice.bin", "r");
+       pipa = popen (g_strdup_printf ("taskkill /T /F /IM %s.bin", priv->ooo_soffice), "r");
 #else
-       pipa = popen ("killall soffice.bin", "r");
+       pipa = popen (g_strdup_printf ("killall %s.bin", priv->ooo_soffice), "r");
 #endif
        pclose (pipa);
 
        /* apro openoffice in ascolto */
+#ifdef G_OS_WIN32
+
        gchar *curdir = g_get_current_dir ();
        chdir (g_build_filename (priv->ooo_path, "program", NULL));
 
-#ifdef G_OS_WIN32
        pipa = popen (g_strconcat ("\"",
                                   priv->ooo_soffice,
                                   " -accept=\"socket,host=localhost,port=8100;urp;\" -no-restore -invisible\"",
                                   NULL),
                      "r");
+
+       chdir (curdir);
+       g_free (curdir);
+
 #else
+
        pipa = popen (g_strconcat ("\"",
                                   priv->ooo_soffice,
                                   "\" -accept=\"socket,host=localhost,port=8100;urp;\" -no-restore -invisible",
                                   NULL),
                      "r");
-#endif
 
-       chdir (curdir);
-       g_free (curdir);
+#endif
 
        while (gtk_events_pending ())
                {
@@ -290,6 +313,8 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
        m_main = PyImport_AddModule ("__main__");
        dict = PyModule_GetDict (m_main);
 
+#ifdef G_OS_WIN32
+
        ooo_path = g_strjoinv ("\\\\", g_strsplit (priv->ooo_path, "\\", -1));
        PyRun_SimpleString (g_strdup_printf (
                "import os\n"
@@ -303,6 +328,9 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                ooo_path,
                g_strjoinv ("%20", g_strsplit (g_strjoinv ("/", g_strsplit (priv->ooo_path, "\\", -1)), " ", -1)))
        );
+
+#endif
+
        PyRun_SimpleString ("import uno\n"
                "import string\n"
                "local = uno.getComponentContext()\n"
@@ -314,6 +342,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                        gtk_main_iteration ();
                }
 
+       g_usleep (5000000);
        do
                {
                        PyRun_SimpleString ("context = resolver.resolve(\"uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext\")\n");
@@ -326,9 +355,13 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                        obj = PyDict_GetItemString (dict, "context");
 
                        if (obj != NULL || priv->dialog_response) break;
+                       g_usleep (1000000);
                } while (TRUE);
        gtk_widget_destroy (dialog);
-       if (priv->dialog_response) return FALSE;
+       if (priv->dialog_response)
+               {
+                       return FALSE;
+               }
 
        obj = PyDict_GetItemString (dict, "context");
        if (obj == NULL)
index fe29ea6649d586c52a788c83a75dcdd282d4bd27..4dccda128f3b2cbae61a74b7d771a028ef88c665 100644 (file)
@@ -9,10 +9,13 @@ LIBS = $(SOLIPA_LIBS) \
 
 LDADD = $(top_builddir)/src/libsolipa.la
 
+ooo_LDADD = $(top_builddir)/src/libsolipaooo.la
+
 noinst_PROGRAMS = allegato \
                   mail \
                   mail_get_addresses_from_string \
                   mailui \
+                  ooo \
                   progresswindow \
                   utils \
                   utils_codfisc_piva \
diff --git a/tests/ooo.c b/tests/ooo.c
new file mode 100644 (file)
index 0000000..4c78d35
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <ooo.h>
+
+GtkWidget *w;
+
+SolipaOOO *ooo;
+
+gboolean
+on_w_delete_event (GtkWidget *widget,
+                   GdkEvent *event,
+                   gpointer user_data)
+{
+       return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+       GtkWidget *infobar;
+
+       gtk_init (&argc, &argv);
+
+       w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL);
+       g_signal_connect (w, "destroy", gtk_main_quit, NULL);
+
+       gtk_widget_show (w);
+
+       ooo = solipa_ooo_new (GTK_WINDOW (w),
+                             NULL,
+                             NULL);
+
+       if (ooo == NULL)
+               {
+                       g_error ("Unable to create SolipaOOO.");
+               }
+
+       solipa_ooo_apri_documento (ooo, argv[1]);
+
+       solipa_ooo_string_replace (ooo, "{prg::replace}", "\"blah blah blah\"");
+
+       gtk_main ();
+
+       return 0;
+}
diff --git a/tests/ooo.odt b/tests/ooo.odt
new file mode 100644 (file)
index 0000000..05fc6d2
Binary files /dev/null and b/tests/ooo.odt differ