/*
- * Copyright (C) 2011-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2018 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
SolipaOOO *solipa_ooo;
SolipaOOOPrivate *priv;
- g_return_val_if_fail (GTK_IS_WINDOW (transient), NULL);
+ if (transient != NULL)
+ {
+ g_return_val_if_fail (GTK_IS_WINDOW (transient), NULL);
+ }
solipa_ooo = SOLIPA_OOO (g_object_new (solipa_ooo_get_type (), NULL));
"found.String = %s.replace(found.String, u\"%s\", u\"%s\")\n",
!priv->with_search ? "search = document.createSearchDescriptor()\n" : "",
_search,
- priv->ooo_version == NULL || zak_utils_compare_version (priv->ooo_version, "3.0.0", NULL, &part) > 0 ? "str" : "unicode",
+ priv->ooo_version == NULL || zak_utils_compare_version (priv->ooo_version, "3.0.0", NULL, &part) > 0 ? "str" : "unicode",
_search,
_replace);
priv->with_search = TRUE;
str = solipa_ooo_pycmd_string_replace (ooo, search, replace);
- /* controllo se SearchDescriptor esiste o no */
- if (priv->search == NULL)
- {
- priv->search = PyDict_GetItemString (priv->dict, "search");
- if (priv->search == NULL)
- {
- priv->search = PyDict_GetItemString (priv->dict, "search");
- if (priv->search == NULL)
- {
- g_warning ("Unable to create Search object.");
- return;
- }
- }
- }
-
PyRun_SimpleString (str);
g_free (str);
}
pclose (pipa);
- if (in_esecuzione)
+ if (in_esecuzione
+ && priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
dialog = gtk_message_dialog_new (priv->transient,
GTK_DIALOG_DESTROY_WITH_PARENT,
gtk_widget_destroy (dialog);
}
- priv->dialog_response = FALSE;
- dialog = gtk_message_dialog_new (priv->transient,
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_CANCEL,
- "Apertura di OpenOffice/LibreOffice in corso...");
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (dialog_response), ooo);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->transient);
- gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
- gtk_widget_show_now (dialog);
-
- while (gtk_events_pending ())
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
- gtk_main_iteration ();
+ priv->dialog_response = FALSE;
+ dialog = gtk_message_dialog_new (priv->transient,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CANCEL,
+ "Apertura di OpenOffice/LibreOffice in corso...");
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (dialog_response), ooo);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->transient);
+ gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_show_now (dialog);
+
+ while (gtk_events_pending ())
+ {
+ gtk_main_iteration ();
+ }
}
if (in_esecuzione)
#ifdef G_OS_WIN32
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);
+ priv->ooo_soffice,
+ g_strdup_printf (" %s-accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s%s\"",
+ dash,
+ priv->ooo_port,
+ dash,
+ dash,
+ priv->visible ? "-invisible" : "-headless"),
+ NULL);
#else
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);
+ priv->ooo_soffice,
+ g_strdup_printf ("\" %s-accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s%s",
+ dash,
+ priv->ooo_port,
+ dash,
+ dash,
+ priv->visible ? "-invisible" : "-headless"),
+ NULL);
#endif
pipa = popen (command, "r");
g_free (command);
+ g_free (dash);
+
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",
priv->ooo_port);
- gtk_widget_destroy (dialog);
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
+ {
+ gtk_widget_destroy (dialog);
+ }
if (g_chdir (curdir) == -1)
{
gboolean in_esecuzione;
gchar *ooo_path;
+ gchar *dash;
+ guint part;
+ gchar *command;
+
+ guint timeout;
+
+ GError *error;
+
SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
/* apro python */
pclose (pipa);
- if (in_esecuzione)
+ if (in_esecuzione
+ && priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
dialog = gtk_message_dialog_new (priv->transient,
GTK_DIALOG_DESTROY_WITH_PARENT,
gtk_widget_destroy (dialog);
}
- priv->dialog_response = FALSE;
- dialog = gtk_message_dialog_new (priv->transient,
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_CANCEL,
- "Apertura e connessione a OpenOffice.org in corso...");
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (dialog_response), ooo);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->transient);
- gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
- gtk_widget_show_now (dialog);
-
- while (gtk_events_pending ())
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
- gtk_main_iteration ();
+ priv->dialog_response = FALSE;
+ dialog = gtk_message_dialog_new (priv->transient,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CANCEL,
+ "Apertura e connessione a OpenOffice.org in corso...");
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (dialog_response), ooo);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->transient);
+ gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_show_now (dialog);
+
+ while (gtk_events_pending ())
+ {
+ gtk_main_iteration ();
+ }
}
if (in_esecuzione)
solipa_ooo_chiudi_openoffice (ooo);
}
+ if (priv->ooo_version == NULL
+ || zak_utils_compare_version (priv->ooo_version, "3.0.0", NULL, &part) > 0)
+ {
+ dash = g_strdup ("-");
+ }
+ else
+ {
+ dash = g_strdup ("");
+ }
+
/* apro openoffice in ascolto */
#ifdef G_OS_WIN32
gchar *curdir = g_get_current_dir ();
chdir (g_build_filename (priv->ooo_path, "program", NULL));
- pipa = popen (g_strconcat ("\"",
+ command = 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");
+ g_strdup_printf (" %s-accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s%s\"",
+ dash,
+ priv->ooo_port,
+ dash,
+ dash,
+ priv->visible ? "-invisible" : "-headless"),
+ NULL);
+
+ pipa = popen (command, "r");
chdir (curdir);
g_free (curdir);
#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 ("\" %s-accept=\"socket,host=localhost,port=%d;urp;\" %s-norestore %s%s",
+ dash,
+ priv->ooo_port,
+ dash,
+ dash,
+ priv->visible ? "-invisible" : "-headless"),
+ NULL);
+ if (!g_spawn_command_line_async (command, NULL))
+ {
+ g_warning ("Unable to run soffice");
+ }
#endif
- while (gtk_events_pending ())
+ g_free (command);
+ g_free (dash);
+
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
- gtk_main_iteration ();
+ while (gtk_events_pending ())
+ {
+ gtk_main_iteration ();
+ }
}
+ timeout = 0;
g_usleep (5000000);
do
{
PyRun_SimpleString (g_strdup_printf ("context = resolver.resolve(\"uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext\")\n", priv->ooo_port));
- while (gtk_events_pending ())
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
- gtk_main_iteration ();
+ while (gtk_events_pending ())
+ {
+ gtk_main_iteration ();
+ }
}
obj = PyDict_GetItemString (priv->dict, "context");
- if (obj != NULL || priv->dialog_response) break;
+ if (obj != NULL ||
+ priv->dialog_response) break;
+
+ if (++timeout > 15
+ && (priv->transient == NULL || !GTK_IS_WINDOW (priv->transient)))
+ {
+ break;
+ }
+
g_usleep (1000000);
} while (TRUE);
- gtk_widget_destroy (dialog);
- if (priv->dialog_response)
+
+ if (priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
- return FALSE;
+ gtk_widget_destroy (dialog);
+ if (priv->dialog_response)
+ {
+ return FALSE;
+ }
}
obj = PyDict_GetItemString (priv->dict, "context");
- if (obj == NULL)
+ if (obj == NULL
+ && priv->transient != NULL
+ && GTK_IS_WINDOW (priv->transient))
{
dialog = gtk_message_dialog_new (priv->transient,
GTK_DIALOG_DESTROY_WITH_PARENT,