From: Andrea Zagli Date: Thu, 1 Oct 2015 13:41:30 +0000 (+0200) Subject: SolipaOOO: adjustments to work with openoffice 3. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=67bae5954f640220794f71709147a6b5bb4075bb;p=solipa%2Flibsolipa SolipaOOO: adjustments to work with openoffice 3. Added function SolipaOOO::set_version. --- diff --git a/src/Makefile.am b/src/Makefile.am index b6c5c93..db5a209 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,7 +56,8 @@ libsolipa_include_HEADERS = libsolipa.h \ progresswindow.h \ utils.h -libsolipaooo_la_LIBADD = $(PYTHON_LIBS) +libsolipaooo_la_LIBADD = libsolipa.la \ + $(PYTHON_LIBS) libsolipaooo_la_CFLAGS = $(PYTHON_CFLAGS) diff --git a/src/ooo.c b/src/ooo.c index 6d8adbf..f1c6d53 100644 --- a/src/ooo.c +++ b/src/ooo.c @@ -24,6 +24,7 @@ #include +#include "utils.h" #include "ooo.h" static void solipa_ooo_class_init (SolipaOOOClass *class); @@ -56,6 +57,7 @@ struct _SolipaOOOPrivate gchar *ooo_path; gchar *ooo_soffice; guint ooo_port; + gchar *ooo_version; gboolean dialog_response; @@ -92,6 +94,7 @@ solipa_ooo_init (SolipaOOO *solipa_ooo) priv->search = NULL; priv->ooo_port = 8100; + priv->ooo_version = NULL; priv->with_search = FALSE; } @@ -187,6 +190,20 @@ SolipaOOO return solipa_ooo; } +/** + * solipa_ooo_set_version: + * @ooo: + * @version: + * + */ +void +solipa_ooo_set_version (SolipaOOO *ooo, const gchar *version) +{ + SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo); + + priv->ooo_version = g_strdup (version); +} + /** * solipa_ooo_exec: * @ooo: @@ -294,6 +311,8 @@ gchar gchar *ret; + guint part; + SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo); _search = g_strdup (search); @@ -305,9 +324,10 @@ gchar ret = g_strdup_printf ("%s" "search.SearchString = u\"%s\"\n" "found = document.findFirst(search)\n" - "found.String = str.replace(found.String, u\"%s\", \"%s\")\n", + "found.String = %s.replace(found.String, u\"%s\", u\"%s\")\n", !priv->with_search ? "search = document.createSearchDescriptor()\n" : "", _search, + priv->ooo_version == NULL || solipa_compare_version (priv->ooo_version, "3.0.0", NULL, &part) > 0 ? "str" : "unicode", _search, _replace); priv->with_search = TRUE; @@ -519,24 +539,49 @@ solipa_ooo_pycmd_apri_openoffice (SolipaOOO *ooo) } /* apro openoffice in ascolto */ + gchar *dash; + gchar *command; + guint part; + + if (priv->ooo_version == NULL + || solipa_compare_version (priv->ooo_version, "3.0.0", NULL, &part) > 0) + { + dash = g_strdup ("-"); + } + else + { + dash = g_strdup (""); + } + #ifdef G_OS_WIN32 - pipa = popen (g_strconcat ("\"", - priv->ooo_soffice, - g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore %s\"", priv->ooo_port, priv->visible ? "-invisible" : "-headless"), - NULL), - "r"); + command = g_strconcat ("\"", + priv->ooo_soffice, + g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s\"", + priv->ooo_port, + dash, + g_strdup_printf ("%s%s", + dash, + priv->visible ? "-invisible" : "-headless")), + NULL); #else - pipa = popen (g_strconcat ("\"", - priv->ooo_soffice, - g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore %s", priv->ooo_port, priv->visible ? "-invisible" : "-headless"), - NULL), - "r"); + command = g_strconcat ("\"", + priv->ooo_soffice, + g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s", + priv->ooo_port, + dash, + g_strdup_printf ("%s%s", + dash, + priv->visible ? "-invisible" : "-headless")), + NULL); #endif + pipa = popen (command, "r"); + g_free (command); + g_string_append_printf (str, "context = resolver.resolve(\"uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext\")\n" "desktop = context.ServiceManager.createInstanceWithContext(\"com.sun.star.frame.Desktop\", context)\n", diff --git a/src/ooo.h b/src/ooo.h index 44d799d..7d4e0c5 100644 --- a/src/ooo.h +++ b/src/ooo.h @@ -63,6 +63,8 @@ SolipaOOO *solipa_ooo_new (GtkWindow *transient, guint ooo_port, gboolean visible); +void solipa_ooo_set_version (SolipaOOO *ooo, const gchar *version); + void solipa_ooo_exec (SolipaOOO *ooo, const gchar *statement); gchar *solipa_ooo_pycmd_header (SolipaOOO *ooo); diff --git a/tests/ooo_pycmd.c b/tests/ooo_pycmd.c index 502ad27..a0ac44d 100644 --- a/tests/ooo_pycmd.c +++ b/tests/ooo_pycmd.c @@ -37,18 +37,20 @@ main (int argc, char *argv[]) gchar *strtmp; GError *error; - + gchar *python_path; gchar *model; gchar *new_file; gchar *new_file_pdf; - - GOptionEntry entries[] = + gchar *ooo_version; + + GOptionEntry entries[] = { { "python_path", 'y', 0, G_OPTION_ARG_STRING, &python_path, "Python path", NULL }, { "model", 'm', 0, G_OPTION_ARG_STRING, &model, "OpenDocument model", NULL }, { "new", 'n', 0, G_OPTION_ARG_STRING, &new_file, "Save as", NULL }, { "new_pdf", 'p', 0, G_OPTION_ARG_STRING, &new_file_pdf, "Export to pdf", NULL }, + { "ooo_version", 'v', 0, G_OPTION_ARG_STRING, &ooo_version, "*Office version", NULL }, { NULL } }; @@ -60,7 +62,8 @@ main (int argc, char *argv[]) model = NULL; new_file = NULL; new_file_pdf = NULL; - + ooo_version = NULL; + /* gestione degli argomenti della riga di comando */ context = g_option_context_new (""); g_option_context_add_main_entries (context, entries, NULL); @@ -110,6 +113,11 @@ main (int argc, char *argv[]) g_error ("Unable to create SolipaOOO."); } + if (ooo_version != NULL) + { + solipa_ooo_set_version (ooo, ooo_version); + } + str = g_string_new (""); strtmp = solipa_ooo_pycmd_apri_documento (ooo, model); @@ -131,7 +139,7 @@ main (int argc, char *argv[]) strtmp = solipa_ooo_pycmd_chiudi_documento (ooo); g_string_append (str, strtmp); g_free (strtmp); - + solipa_ooo_pycmd_exec_script (ooo, str->str); g_message("%s", str->str); g_string_free (str, TRUE);