[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - 2 commits - include/LibreOfficeKit libreofficekit/qa libreofficekit/source
Pranav Kant
pranavk at gnome.org
Tue Jul 7 08:50:04 PDT 2015
Rebased ref, commits from common ancestor:
commit 248926d58bdf9d53e8909daac08d1ba1429b6294
Author: Pranav Kant <pranavk at gnome.org>
Date: Tue Jul 7 21:16:45 2015 +0530
lokdocview: Emit load-changed signal showing load progress
Change-Id: I69b4c05d12c0c0b2ca6b7d1ad76ed74cc1f4346a
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index af3ba41..3b30e53 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,6 +30,7 @@ static int help()
}
static GtkWidget* pDocView;
+static GtkWidget* pStatusBar;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkToolItem* pItalic;
@@ -286,6 +287,12 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
}
}
+static void loadChanged(LOKDocView* /*pLOKDocView*/, gdouble fValue, gpointer pData)
+{
+ GtkWidget* pProgressBar = GTK_WIDGET (pData);
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(pProgressBar), fValue);
+}
+
/// LOKDocView found no search matches -> set the search label accordingly.
static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpointer /*pData*/)
{
@@ -402,6 +409,8 @@ static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpo
focusChain = g_list_append( focusChain, pDocView1 );
gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
+
+ gtk_widget_hide (pStatusBar);
}
int main( int argc, char* argv[] )
@@ -554,6 +563,7 @@ int main( int argc, char* argv[] )
g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
+
// Scrolled window for DocView
pScrolledWindow = gtk_scrolled_window_new(0, 0);
gtk_widget_set_hexpand (pScrolledWindow, TRUE);
@@ -562,6 +572,13 @@ int main( int argc, char* argv[] )
gtk_container_add(GTK_CONTAINER(pScrolledWindow), pDocView);
+ GtkWidget* pProgressBar = gtk_progress_bar_new ();
+ g_signal_connect(pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
+
+ pStatusBar = gtk_statusbar_new ();
+ gtk_container_add (GTK_CONTAINER(pVBox), pStatusBar);
+ gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
+
gtk_widget_show_all( pWindow );
// Hide the findbar by default.
gtk_widget_hide(pFindbar);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 2812ca0..2753844 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -40,7 +40,7 @@ struct _LOKDocViewPrivate
{
gchar* m_aLOPath;
gchar* m_aDocPath;
- guint m_nLoadProgress;
+ gdouble m_nLoadProgress;
gboolean m_bIsLoading;
gboolean m_bCanZoomIn;
gboolean m_bCanZoomOut;
@@ -108,6 +108,7 @@ struct _LOKDocViewPrivate
enum
{
+ LOAD_CHANGED,
EDIT_CHANGED,
COMMAND_CHANGED,
SEARCH_NOT_FOUND,
@@ -341,17 +342,20 @@ globalCallback (gpointer pData)
{
case LOK_CALLBACK_STATUS_INDICATOR_START:
{
- priv->m_nLoadProgress = 0;
+ priv->m_nLoadProgress = 0.0;
+ g_signal_emit (pCallback->m_pDocView, doc_view_signals[LOAD_CHANGED], 0, 0.0);
}
break;
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
{
- priv->m_nLoadProgress = std::stoi(pCallback->m_aPayload);
+ priv->m_nLoadProgress = static_cast<gdouble>(std::stoi(pCallback->m_aPayload)/100.0);
+ g_signal_emit (pCallback->m_pDocView, doc_view_signals[LOAD_CHANGED], 0, priv->m_nLoadProgress);
}
break;
case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
{
- priv->m_nLoadProgress = 100;
+ priv->m_nLoadProgress = 1.0;
+ g_signal_emit (pCallback->m_pDocView, doc_view_signals[LOAD_CHANGED], 0, 1.0);
}
break;
default:
@@ -1069,7 +1073,7 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va
g_value_set_boolean (value, priv->m_bEdit);
break;
case PROP_LOAD_PROGRESS:
- g_value_set_uint (value, priv->m_nLoadProgress);
+ g_value_set_double (value, priv->m_nLoadProgress);
break;
case PROP_ZOOM:
g_value_set_float (value, priv->m_fZoom);
@@ -1210,11 +1214,11 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
*/
g_object_class_install_property (pGObjectClass,
PROP_LOAD_PROGRESS,
- g_param_spec_int("load-progress",
- "Estimated Load Progress",
- "Whether the content is in edit mode or not",
- 0, 100, 0,
- G_PARAM_READABLE));
+ g_param_spec_double("load-progress",
+ "Estimated Load Progress",
+ "Whether the content is in edit mode or not",
+ 0.0, 1.0, 0.0,
+ G_PARAM_READABLE));
/**
* LOKDocView:zoom-level:
@@ -1300,6 +1304,21 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
| G_PARAM_STATIC_STRINGS)));
/**
+ * LOKDocView::load-changed:
+ * @pDocView: the #LOKDocView on which the signal is emitted
+ * @fLoadProgress: the new progress value
+ */
+ doc_view_signals[LOAD_CHANGED] =
+ g_signal_new("load-changed",
+ G_TYPE_FROM_CLASS (pGObjectClass),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__DOUBLE,
+ G_TYPE_NONE, 1,
+ G_TYPE_DOUBLE);
+
+ /**
* LOKDocView::edit-changed:
* @pDocView: the #LOKDocView on which the signal is emitted
* @bEdit: the new edit value of the view
commit d55503f445951ffba1f754a9ed9ca8724b8ab9ce
Author: Pranav Kant <pranavk at gnome.org>
Date: Mon Jul 6 22:01:30 2015 +0530
lokdocview: Call open_document in another thread
This is to keep the widget responsive during document load.
Change-Id: I81acaffc75ca7deddd6cc2de6abae22d009d40cd
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 962f9d9..ec28348 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -45,8 +45,15 @@ GtkWidget* lok_doc_view_new (const gchar*
GCancellable *cancellable,
GError **error);
-gboolean lok_doc_view_open_document (LOKDocView* pDocView,
- const gchar* pPath);
+void lok_doc_view_open_document (LOKDocView* pDocView,
+ const gchar* pPath,
+ GCancellable* cancellable,
+ GAsyncReadyCallback callback,
+ gpointer userdata);
+
+gboolean lok_doc_view_open_document_finish (LOKDocView* pDocView,
+ GAsyncResult* res,
+ GError** error);
/// Gets the document the viewer displays.
LibreOfficeKitDocument* lok_doc_view_get_document (LOKDocView* pDocView);
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index ec70a88..af3ba41 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -41,6 +41,7 @@ std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
static GtkComboBoxText* pPartSelector;
+static GtkWidget* pPartModeComboBox;
/// Should the part selector avoid calling lok::Document::setPart()?
static bool g_bPartSelectorBroadcast = true;
GtkWidget* pFindbar;
@@ -291,6 +292,7 @@ static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpoint
gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found");
}
+
static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*/)
{
g_bPartSelectorBroadcast = false;
@@ -380,6 +382,28 @@ static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
}
}
+static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer /*userdata*/)
+{
+ LOKDocView* pDocView1 = LOK_DOC_VIEW (source_object);
+ GError* error = NULL;
+ GList *focusChain = NULL;
+
+ if (!lok_doc_view_open_document_finish(pDocView1, res, &error))
+ {
+ g_warning ("Error occurred while opening the document : %s", error->message);
+ g_error_free (error);
+ }
+
+ populatePartSelector();
+ populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
+ // Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode.
+ g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
+ g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
+
+ focusChain = g_list_append( focusChain, pDocView1 );
+ gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
+}
+
int main( int argc, char* argv[] )
{
if( argc < 3 ||
@@ -435,7 +459,7 @@ int main( int argc, char* argv[] )
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new();
- GtkWidget* pPartModeComboBox = gtk_combo_box_text_new();
+ pPartModeComboBox = gtk_combo_box_text_new();
gtk_container_add( GTK_CONTAINER(pPartModeSelectorToolItem), pPartModeComboBox );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1 );
@@ -542,21 +566,7 @@ int main( int argc, char* argv[] )
// Hide the findbar by default.
gtk_widget_hide(pFindbar);
- int bOpened = lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2] );
- if (!bOpened)
- g_error("main: lok_doc_view_open_document() failed");
- assert(lok_doc_view_get_document(LOK_DOC_VIEW(pDocView)));
-
- populatePartSelector();
- populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
- // Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode.
- g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
- g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
-
- // Make only LOKDocView widget as focussable
- GList *focusChain = NULL;
- focusChain = g_list_append( focusChain, pDocView );
- gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
+ lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView );
gtk_main();
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index bf12ca0..2812ca0 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -108,8 +108,6 @@ struct _LOKDocViewPrivate
enum
{
- LOAD_CHANGED,
- LOAD_FAILED,
EDIT_CHANGED,
COMMAND_CHANGED,
SEARCH_NOT_FOUND,
@@ -337,19 +335,23 @@ static gboolean
globalCallback (gpointer pData)
{
CallbackData* pCallback = static_cast<CallbackData*>(pData);
+ LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pCallback->m_pDocView));
switch (pCallback->m_nType)
{
case LOK_CALLBACK_STATUS_INDICATOR_START:
{
+ priv->m_nLoadProgress = 0;
}
break;
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
{
+ priv->m_nLoadProgress = std::stoi(pCallback->m_aPayload);
}
break;
case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
{
+ priv->m_nLoadProgress = 100;
}
break;
default:
@@ -1389,15 +1391,30 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
}
/**
- * lok_doc_view_open_document:
+ * lok_doc_view_open_document_finish:
* @pDocView: The #LOKDocView instance
- * @pPath: The path of the document that #LOKDocView widget should try to open
+ * @res:
+ * @error:
*
* Returns: %TRUE if the document is loaded succesfully, %FALSE otherwise
*/
SAL_DLLPUBLIC_EXPORT gboolean
-lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
+lok_doc_view_open_document_finish (LOKDocView* pDocView, GAsyncResult* res, GError** error)
+{
+ GTask* task = G_TASK(res);
+
+ g_return_val_if_fail(g_task_is_valid(res, pDocView), NULL);
+ //FIXME: make source_tag workx
+ //g_return_val_if_fail(g_task_get_source_tag(task) == lok_doc_view_open_document, NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
+
+ return g_task_propagate_boolean(task, error);
+}
+
+static void
+lok_doc_view_open_document_func (GTask* task, gpointer source_object, gpointer task_data, GCancellable* cancellable)
{
+ LOKDocView* pDocView = LOK_DOC_VIEW(source_object);
LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
if ( priv->m_pDocument )
@@ -1407,13 +1424,13 @@ lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
}
priv->m_pOffice->pClass->registerCallback(priv->m_pOffice, globalCallbackWorker, pDocView);
- priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, pPath );
+ priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, priv->m_aDocPath );
if ( !priv->m_pDocument )
{
// FIXME: should have a GError parameter and populate it.
char *pError = priv->m_pOffice->pClass->getError( priv->m_pOffice );
fprintf( stderr, "Error opening document '%s'\n", pError );
- return FALSE;
+ g_task_return_new_error(task, 0, 0, pError);
}
else
{
@@ -1438,8 +1455,34 @@ lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
nDocumentHeightPixels);
gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
gtk_widget_grab_focus(GTK_WIDGET(pDocView));
+ g_task_return_boolean (task, true);
}
- return TRUE;
+}
+
+/**
+ * lok_doc_view_open_document:
+ * @pDocView: The #LOKDocView instance
+ * @pPath: The path of the document that #LOKDocView widget should try to open
+ *
+ * Returns: %TRUE if the document is loaded succesfully, %FALSE otherwise
+ */
+SAL_DLLPUBLIC_EXPORT void
+lok_doc_view_open_document (LOKDocView* pDocView,
+ const gchar* pPath,
+ GCancellable* cancellable,
+ GAsyncReadyCallback callback,
+ gpointer userdata)
+{
+ GTask *task;
+ LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
+ priv->m_aDocPath = g_strdup(pPath);
+
+ task = g_task_new(pDocView, cancellable, callback, userdata);
+ // FIXME: Use source_tag to check the task.
+ //g_task_set_source_tag(task, lok_doc_view_open_document);
+
+ g_task_run_in_thread(task, lok_doc_view_open_document_func);
+ g_object_unref(task);
}
/**
More information about the Libreoffice-commits
mailing list