From: Andrea Zagli Date: Thu, 17 Nov 2011 13:35:04 +0000 (+0100) Subject: Aggiunta la funzione SolipaOOO::chiudi_documento. X-Git-Tag: 0.5.0~24 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=41046a4debdada03cc2614d6fa07121ad88b4687;p=solipa%2Flibsolipa Aggiunta la funzione SolipaOOO::chiudi_documento. Aggiunta la possibilità di non far visualizzare mai Ooo. Aggiustamenti vari. --- diff --git a/src/ooo.c b/src/ooo.c index 4846a5a..ab5dd87 100644 --- a/src/ooo.c +++ b/src/ooo.c @@ -48,6 +48,8 @@ struct _SolipaOOOPrivate { GtkWindow *transient; + gboolean visible; + gchar *ooo_path; gchar *ooo_soffice; guint ooo_port; @@ -56,6 +58,7 @@ struct _SolipaOOOPrivate PyObject *m_main; PyObject *dict; + PyObject *search; }; G_DEFINE_TYPE (SolipaOOO, solipa_ooo, G_TYPE_OBJECT) @@ -78,6 +81,10 @@ solipa_ooo_init (SolipaOOO *solipa_ooo) { SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (solipa_ooo); + priv->m_main = NULL; + priv->dict = NULL; + priv->search = NULL; + priv->ooo_port = 8100; } @@ -87,6 +94,7 @@ solipa_ooo_init (SolipaOOO *solipa_ooo) * @ooo_path: * @ooo_soffice: * @ooo_port: + * @visible: * * Returns: the newly created #SolipaOOO object. */ @@ -94,7 +102,8 @@ SolipaOOO *solipa_ooo_new (GtkWindow *transient, const gchar *ooo_path, const gchar *ooo_soffice, - guint ooo_port) + guint ooo_port, + gboolean visible) { SolipaOOO *solipa_ooo; SolipaOOOPrivate *priv; @@ -105,6 +114,7 @@ SolipaOOO priv = SOLIPA_OOO_GET_PRIVATE (solipa_ooo); + priv->visible = visible; priv->transient = transient; /* TODO controllare i valori */ @@ -174,10 +184,19 @@ solipa_ooo_string_replace (SolipaOOO *ooo, const gchar *search, const gchar *rep _replace = g_strjoinv ("\\\"", g_strsplit (_replace, "\"", -1)); /* controllo se SearchDescriptor esiste o no */ - obj = PyDict_GetItemString (priv->dict, "search"); - if (obj == NULL) + if (priv->search == NULL) { - PyRun_SimpleString ("search = document.createSearchDescriptor()\n"); + priv->search = PyDict_GetItemString (priv->dict, "search"); + if (priv->search == NULL) + { + PyRun_SimpleString ("search = document.createSearchDescriptor()\n"); + priv->search = PyDict_GetItemString (priv->dict, "search"); + if (priv->search == NULL) + { + g_warning ("Unable to create Search object."); + return; + } + } } PyRun_SimpleString (g_strdup_printf ( @@ -327,7 +346,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo) #ifdef G_OS_WIN32 pipa = popen (g_strdup_printf ("tasklist | findstr /i soffice.bin"), "r"); #else - pipa = popen (g_strdup_printf ("pidof soffice.bin", priv->ooo_soffice), "r"); + pipa = popen (g_strdup_printf ("pidof soffice.bin"), "r"); #endif if (pipa != NULL) @@ -390,7 +409,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo) pipa = popen (g_strconcat ("\"", priv->ooo_soffice, - g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore -invisible\"", priv->ooo_port), + g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore %s\"", priv->ooo_port, priv->visible ? "-invisible" : "-headless"), NULL), "r"); @@ -401,7 +420,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo) pipa = popen (g_strconcat ("\"", priv->ooo_soffice, - g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore -invisible", priv->ooo_port), + g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore %s", priv->ooo_port, priv->visible ? "-invisible" : "-headless"), NULL), "r"); @@ -521,3 +540,9 @@ solipa_ooo_salva_documento_pdf (SolipaOOO *ooo, return TRUE; } + +void +solipa_ooo_chiudi_documento (SolipaOOO *ooo) +{ + solipa_ooo_exec (ooo, "document.dispose()\n"); +} diff --git a/src/ooo.h b/src/ooo.h index f42f359..5d070c5 100644 --- a/src/ooo.h +++ b/src/ooo.h @@ -58,7 +58,8 @@ GType solipa_ooo_get_type (void) G_GNUC_CONST; SolipaOOO *solipa_ooo_new (GtkWindow *transient, const gchar *ooo_path, const gchar *ooo_soffice, - guint ooo_port); + guint ooo_port, + gboolean visible); void solipa_ooo_exec (SolipaOOO *ooo, const gchar *statement); @@ -75,6 +76,8 @@ gboolean solipa_ooo_salva_documento (SolipaOOO *ooo, gboolean solipa_ooo_salva_documento_pdf (SolipaOOO *ooo, const gchar *filename); +void solipa_ooo_chiudi_documento (SolipaOOO *ooo); + G_END_DECLS diff --git a/tests/ooo.c b/tests/ooo.c index 92447cd..23fa9c5 100644 --- a/tests/ooo.c +++ b/tests/ooo.c @@ -46,7 +46,7 @@ main (int argc, char *argv[]) ooo = solipa_ooo_new (GTK_WINDOW (w), NULL, NULL, - 0); + 0, argc <= 2); if (ooo == NULL) { @@ -66,7 +66,18 @@ main (int argc, char *argv[]) solipa_ooo_salva_documento_pdf (ooo, argv[3]); } + if (argc >= 3) + { + solipa_ooo_chiudi_documento (ooo); + } + + GtkWidget *lbl = gtk_label_new ("FINE"); + gtk_container_add (GTK_CONTAINER (w), lbl); + gtk_widget_show_all (w); + gtk_main (); + g_object_unref (ooo); + return 0; }