]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Alcuni controlli.
authorAndrea Zagli <azagli@libero.it>
Sat, 23 Jul 2011 06:59:09 +0000 (08:59 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 23 Jul 2011 06:59:09 +0000 (08:59 +0200)
src/ooo.c

index 32b109874da2ddf66a231367d3ecb25e9c2f8202..631c2554d81b94987938614a2c4a16786e40c151 100644 (file)
--- a/src/ooo.c
+++ b/src/ooo.c
@@ -53,6 +53,9 @@ struct _SolipaOOOPrivate
                guint ooo_port;
 
                gboolean dialog_response;
+
+               PyObject *m_main;
+               PyObject *dict;
        };
 
 G_DEFINE_TYPE (SolipaOOO, solipa_ooo, G_TYPE_OBJECT)
@@ -135,11 +138,23 @@ solipa_ooo_exec (SolipaOOO *ooo, const gchar *statement)
 gboolean
 solipa_ooo_apri_documento (SolipaOOO *ooo, const gchar *filename)
 {
-       PyRun_SimpleString (g_strdup_printf ("document = desktop.loadComponentFromURL(\"file:///%s\", \"_default\", 0, ())\n", filename));
+       PyObject *obj;
 
-       /* TODO ritornare TRUE/FALSE se document è stato creato o meno */
+       SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
+
+       PyRun_SimpleString (g_strdup_printf ("document = desktop.loadComponentFromURL(\"file:///%s\", \"_default\", 0, ())\n", filename));
 
-       return TRUE;
+       /* ritorna TRUE/FALSE se document è stato creato o meno */
+       obj = PyDict_GetItemString (priv->dict, "document");
+       if (obj == NULL)
+               {
+                       g_warning ("Impossibile aprire il documento «%s».", filename);
+                       return FALSE;
+               }
+       else
+               {
+                       return TRUE;
+               }
 }
 
 void
@@ -148,14 +163,22 @@ solipa_ooo_string_replace (SolipaOOO *ooo, const gchar *search, const gchar *rep
        gchar *_search;
        gchar *_replace;
 
+       PyObject *obj;
+
+       SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
+
        _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 ("search = document.createSearchDescriptor()\n");
+       /* controllo se SearchDescriptor esiste o no */
+       obj = PyDict_GetItemString (priv->dict, "search");
+       if (obj == NULL)
+               {
+                       PyRun_SimpleString ("search = document.createSearchDescriptor()\n");
+               }
 
        PyRun_SimpleString (g_strdup_printf (
                            "search.SearchString = u\"%s\"\n"
@@ -248,8 +271,6 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        FILE *pipa;
 
-       PyObject *m_main;
-       PyObject *dict;
        PyObject *obj;
 
        gchar *ooo_path;
@@ -258,8 +279,8 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        /* apro python */
        Py_Initialize ();
-       m_main = PyImport_AddModule ("__main__");
-       dict = PyModule_GetDict (m_main);
+       priv->m_main = PyImport_AddModule ("__main__");
+       priv->dict = PyModule_GetDict (priv->m_main);
 
 #ifdef G_OS_WIN32
 
@@ -285,10 +306,11 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                "resolver = local.ServiceManager.createInstanceWithContext(\"com.sun.star.bridge.UnoUrlResolver\", local)\n"
        );
 
-       /* TODO controllare se OpenOffice è già in ascolto */
-       PyRun_SimpleString (g_strdup_printf ("context = resolver.resolve(\"uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext\")\n", priv->ooo_port));
+       /* controllo se OpenOffice è già in ascolto */
+       PyRun_SimpleString (g_strdup_printf ("context = resolver.resolve(\"uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext\")\n",
+                                            priv->ooo_port));
 
-       obj = PyDict_GetItemString (dict, "context");
+       obj = PyDict_GetItemString (priv->dict, "context");
 
        if (obj == NULL)
                {
@@ -372,7 +394,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                                                        gtk_main_iteration ();
                                                }
 
-                                       obj = PyDict_GetItemString (dict, "context");
+                                       obj = PyDict_GetItemString (priv->dict, "context");
 
                                        if (obj != NULL || priv->dialog_response) break;
                                        g_usleep (1000000);
@@ -383,7 +405,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                                        return FALSE;
                                }
 
-                       obj = PyDict_GetItemString (dict, "context");
+                       obj = PyDict_GetItemString (priv->dict, "context");
                        if (obj == NULL)
                                {
                                        dialog = gtk_message_dialog_new (priv->transient,
@@ -400,7 +422,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
        PyRun_SimpleString ("desktop = context.ServiceManager.createInstanceWithContext(\"com.sun.star.frame.Desktop\", context)\n");
 
        /* ritorno TRUE/FALSE se desktop è stato creato o meno */
-       obj = PyDict_GetItemString (dict, "desktop");
+       obj = PyDict_GetItemString (priv->dict, "desktop");
 
        if (obj == NULL)
                {