summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2015-11-03 13:20:06 +0100
committerJan Holesovsky <kendy@collabora.com>2015-11-03 13:25:23 +0100
commit8c987fababbddb6e4f81b0cd717b59b9a9ff9be0 (patch)
tree269bb73e21a8afebd8ea916d1280d8f858a571bc /libreofficekit
parentc0f37892a24b202c0a28836ed1046c90c7631e03 (diff)
lok: Introduce LOK_CALLBACK_UNO_COMMAND_RESULT callback.
Posting of the .uno:Something commands is asynchronous. To be able to find out when eg. .uno:Save finished, this commit introduces a callback that fires when that happens. To be able to receive such a notification, the appropriate postUnoCommand() must be called with 'true' as the parameter for bNotifyWhenFinished (defaults to 'false'). Change-Id: I254939ebc8ea5f309ae39686dcaaeddd5148b0c9
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx15
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx34
-rw-r--r--libreofficekit/source/gtk/tilebuffer.hxx2
3 files changed, 47 insertions, 4 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 5f76e367c77d..e67db9f02460 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -596,7 +596,7 @@ static void doSearch(GtkWidget* pButton, bool bBackwards)
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
- lok_doc_view_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str());
+ lok_doc_view_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str(), false);
}
/// Click handler for the search next button.
@@ -672,6 +672,12 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD
}
}
+/// LOKDocView command finished -> just write it to the console, not that useful for the viewer.
+static void signalCommandResult(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/)
+{
+ fprintf(stderr, "Command finished: %s\n", pPayload);
+}
+
static void loadChanged(LOKDocView* /*pLOKDocView*/, gdouble fValue, gpointer pData)
{
GtkWidget* pProgressBar = GTK_WIDGET (pData);
@@ -774,7 +780,11 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
const std::string& rString = rWindow.m_aToolItemCommandNames[pItem];
g_info("toggleToolItem: lok_doc_view_post_command('%s')", rString.c_str());
- lok_doc_view_post_command(pLOKDocView, rString.c_str(), 0);
+
+ // notify about the finished Save
+ gboolean bNotify = (rString == ".uno:Save");
+
+ lok_doc_view_post_command(pLOKDocView, rString.c_str(), 0, bNotify);
}
}
@@ -1172,6 +1182,7 @@ static void setupDocView(GtkWidget* pDocView)
#endif
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
+ g_signal_connect(pDocView, "command-result", G_CALLBACK(signalCommandResult), NULL);
g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
g_signal_connect(pDocView, "search-result-count", G_CALLBACK(signalSearchResultCount), NULL);
g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 09fd672d3589..6a0adfafef66 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -180,6 +180,7 @@ enum
HYPERLINK_CLICKED,
CURSOR_CHANGED,
SEARCH_RESULT_COUNT,
+ COMMAND_RESULT,
LAST_SIGNAL
};
@@ -461,6 +462,11 @@ static void searchResultCount(LOKDocView* pDocView, const std::string& rString)
g_signal_emit(pDocView, doc_view_signals[SEARCH_RESULT_COUNT], 0, rString.c_str());
}
+static void commandResult(LOKDocView* pDocView, const std::string& rString)
+{
+ g_signal_emit(pDocView, doc_view_signals[COMMAND_RESULT], 0, rString.c_str());
+}
+
static void
setPart(LOKDocView* pDocView, const std::string& rString)
{
@@ -752,6 +758,11 @@ callback (gpointer pData)
searchResultCount(pDocView, std::to_string(nCount));
}
break;
+ case LOK_CALLBACK_UNO_COMMAND_RESULT:
+ {
+ commandResult(pDocView, pCallback->m_aPayload);
+ }
+ break;
default:
g_assert(false);
break;
@@ -1520,7 +1531,7 @@ postCommandInThread (gpointer data)
std::stringstream ss;
ss << "lok::Document::postUnoCommand(" << pLOEvent->m_pCommand << ", " << pLOEvent->m_pArguments << ")";
g_info(ss.str().c_str());
- priv->m_pDocument->pClass->postUnoCommand(priv->m_pDocument, pLOEvent->m_pCommand, pLOEvent->m_pArguments);
+ priv->m_pDocument->pClass->postUnoCommand(priv->m_pDocument, pLOEvent->m_pCommand, pLOEvent->m_pArguments, pLOEvent->m_bNotifyWhenFinished);
}
static void
@@ -2077,6 +2088,7 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
G_TYPE_NONE, 4,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
+
/**
* LOKDocView::search-result-count:
* @pDocView: the #LOKDocView on which the signal is emitted
@@ -2092,6 +2104,22 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
G_TYPE_NONE, 1,
G_TYPE_STRING);
+ /**
+ * LOKDocView::command-result:
+ * @pDocView: the #LOKDocView on which the signal is emitted
+ * @aCommand: JSON containing the info about the command that finished,
+ * and its success status.
+ */
+ doc_view_signals[COMMAND_RESULT] =
+ g_signal_new("command-result",
+ G_TYPE_FROM_CLASS(pGObjectClass),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
+
}
SAL_DLLPUBLIC_EXPORT GtkWidget*
@@ -2326,7 +2354,8 @@ lok_doc_view_get_edit (LOKDocView* pDocView)
SAL_DLLPUBLIC_EXPORT void
lok_doc_view_post_command (LOKDocView* pDocView,
const gchar* pCommand,
- const gchar* pArguments)
+ const gchar* pArguments,
+ gboolean bNotifyWhenFinished)
{
LOKDocViewPrivate& priv = getPrivate(pDocView);
GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
@@ -2334,6 +2363,7 @@ lok_doc_view_post_command (LOKDocView* pDocView,
GError* error = NULL;
pLOEvent->m_pCommand = pCommand;
pLOEvent->m_pArguments = g_strdup(pArguments);
+ pLOEvent->m_bNotifyWhenFinished = bNotifyWhenFinished;
g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error);
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index f74cae7ba42f..e7a794a8a283 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -169,6 +169,7 @@ struct LOEvent
///@{
const gchar* m_pCommand;
gchar* m_pArguments;
+ gboolean m_bNotifyWhenFinished;
///@}
/// @name open_document parameter
@@ -221,6 +222,7 @@ struct LOEvent
: m_nType(type)
, m_pCommand(0)
, m_pArguments(0)
+ , m_bNotifyWhenFinished(false)
, m_pPath(0)
, m_bEdit(false)
, m_nPartMode(0)