[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - libreofficekit/qa libreofficekit/source
Pranav Kant
pranavk at gnome.org
Wed Jul 8 09:47:40 PDT 2015
Rebased ref, commits from common ancestor:
commit 9ef8b40815d6645dfc272d4ecb403f9f583fd000
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..0ab7f6e 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",
+ "Shows the progress of the document load operation",
+ 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
@@ -1403,16 +1422,16 @@ lok_doc_view_open_document_finish (LOKDocView* pDocView, GAsyncResult* res, GErr
{
GTask* task = G_TASK(res);
- g_return_val_if_fail(g_task_is_valid(res, pDocView), NULL);
+ g_return_val_if_fail(g_task_is_valid(res, pDocView), false);
//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);
+ g_return_val_if_fail(error == NULL || *error == NULL, false);
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)
+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));
More information about the Libreoffice-commits
mailing list