]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Controllo se OpenOffice.org è in esecuzione.
authorAndrea Zagli <azagli@libero.it>
Sat, 23 Jul 2011 09:02:06 +0000 (11:02 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 23 Jul 2011 09:02:06 +0000 (11:02 +0200)
Da testare in windows.

src/ooo.c

index 30291cd01f5d0ef44ee856fe4b98bcfc5a6acd56..58f3f156881505dad5ea8c6553728de976977d82 100644 (file)
--- a/src/ooo.c
+++ b/src/ooo.c
@@ -273,6 +273,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        PyObject *obj;
 
+       gboolean in_esecuzione;
        gchar *ooo_path;
 
        SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
@@ -314,20 +315,37 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        if (obj == NULL)
                {
-                       /* TODO controllare se OpenOffice è già in esecuzione */
+                       /* controllo se OpenOffice è già in esecuzione */
+                       in_esecuzione = FALSE;
 
-                       dialog = gtk_message_dialog_new (priv->transient,
-                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                        GTK_MESSAGE_INFO,
-                                                        GTK_BUTTONS_OK_CANCEL,
-                                                        "Verranno chiuse tutte le sessioni attive di OpenOffice.org.\n"
-                                                        "Premere OK quando pronti.");
-                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
+#ifdef G_OS_WIN32
+                       pipa = popen (g_strdup_printf ("tasklist|>nul find /i %s.bin", priv->ooo_soffice), "r");
+#else
+                       pipa = popen (g_strdup_printf ("pidof %s.bin", priv->ooo_soffice), "r");
+#endif
+
+                       if (pipa != NULL)
+                               {
+                                       in_esecuzione = (fgetc (pipa) != EOF);
+                               }
+
+                       pclose (pipa);
+
+                       if (in_esecuzione)
                                {
+                                       dialog = gtk_message_dialog_new (priv->transient,
+                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                        GTK_MESSAGE_INFO,
+                                                                        GTK_BUTTONS_OK_CANCEL,
+                                                                        "Verranno chiuse tutte le sessioni attive di OpenOffice.org.\n"
+                                                                        "Premere OK quando pronti.");
+                                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
+                                               {
+                                                       gtk_widget_destroy (dialog);
+                                                       return FALSE;
+                                               }
                                        gtk_widget_destroy (dialog);
-                                       return FALSE;
                                }
-                       gtk_widget_destroy (dialog);
 
                        priv->dialog_response = FALSE;
                        dialog = gtk_message_dialog_new (priv->transient,
@@ -346,13 +364,16 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
                                        gtk_main_iteration ();
                                }
 
-                       /* chiudo le eventuali sessioni di openoffice attive */
+                       if (in_esecuzione)
+                               {
+                                       /* chiudo le eventuali sessioni di openoffice attive */
 #ifdef G_OS_WIN32
-                       pipa = popen (g_strdup_printf ("taskkill /T /F /IM %s.bin", priv->ooo_soffice), "r");
+                                       pipa = popen (g_strdup_printf ("taskkill /T /F /IM %s.bin", priv->ooo_soffice), "r");
 #else
-                       pipa = popen (g_strdup_printf ("killall %s.bin", priv->ooo_soffice), "r");
+                                       pipa = popen (g_strdup_printf ("killall %s.bin", priv->ooo_soffice), "r");
 #endif
-                       pclose (pipa);
+                                       pclose (pipa);
+                               }
 
                        /* apro openoffice in ascolto */
 #ifdef G_OS_WIN32
@@ -362,7 +383,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
                        pipa = popen (g_strconcat ("\"",
                                                   priv->ooo_soffice,
-                                                  g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" -no-restore -invisible\"", priv->ooo_port),
+                                                  g_strdup_printf (" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore -invisible\"", priv->ooo_port),
                                                   NULL),
                                      "r");
 
@@ -373,7 +394,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
                        pipa = popen (g_strconcat ("\"",
                                                   priv->ooo_soffice,
-                                                  g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" -no-restore -invisible", priv->ooo_port),
+                                                  g_strdup_printf ("\" -accept=\"socket,host=localhost,port=%d;urp;\" -norestore -invisible", priv->ooo_port),
                                                   NULL),
                                      "r");