]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunta la funzione SolipaOOO::chiudi_documento.
authorAndrea Zagli <azagli@libero.it>
Thu, 17 Nov 2011 13:35:04 +0000 (14:35 +0100)
committerAndrea Zagli <azagli@libero.it>
Thu, 17 Nov 2011 13:35:04 +0000 (14:35 +0100)
Aggiunta la possibilità di non far visualizzare mai Ooo.
Aggiustamenti vari.

src/ooo.c
src/ooo.h
tests/ooo.c

index 4846a5afe1f58bc4cbd14fa7d86b1693f5e047c8..ab5dd870b1ee0a5306b54dd9963200689eac63c3 100644 (file)
--- 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");
+}
index f42f35931df0393594d2335b3b5c65ad6052a474..5d070c55e2b1b77375834f90e69aba7ce6ef44ad 100644 (file)
--- 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
 
index 92447cdc4f9c46f39005e9dcf525f7151b89babb..23fa9c50f89f642a991303c888456112e18ff1b1 100644 (file)
@@ -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;
 }