[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - include/LibreOfficeKit libreofficekit/qa libreofficekit/source

Pranav Kant pranavk at gnome.org
Mon Jul 6 12:05:06 PDT 2015


Rebased ref, commits from common ancestor:
commit fc5c6e10757c7bf05e4f95bc190713ba2c4e43f7
Author: Pranav Kant <pranavk at gnome.org>
Date:   Tue Jul 7 00:30:41 2015 +0530

    lokdocview: [WIP] Superfluous signals
    
    Callback always gets invoked after the load finishes. So, lets
    use that.
    
    Change-Id: Ifa221684c7e6f286fe3434119ae5f21e2e02ea37

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index d536e4a..ec28348 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -45,7 +45,7 @@ GtkWidget*                     lok_doc_view_new                    (const gchar*
                                                                     GCancellable *cancellable,
                                                                     GError **error);
 
-gboolean                       lok_doc_view_open_document          (LOKDocView* pDocView,
+void                           lok_doc_view_open_document          (LOKDocView* pDocView,
                                                                     const gchar* pPath,
                                                                     GCancellable* cancellable,
                                                                     GAsyncReadyCallback callback,
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index fed62c4..af3ba41 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -382,15 +382,17 @@ static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
     }
 }
 
-
-static void loadStarted(LOKDocView* pDocView, gpointer pData)
+static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer /*userdata*/)
 {
-    g_info ("load started");
-}
+    LOKDocView* pDocView1 = LOK_DOC_VIEW (source_object);
+    GError* error = NULL;
+    GList *focusChain = NULL;
 
-static void loadFinished(LOKDocView* pDocView, gboolean status, gpointer pData)
-{
-    g_info ("load finished");
+    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) );
@@ -398,29 +400,10 @@ static void loadFinished(LOKDocView* pDocView, gboolean status, gpointer pData)
     g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
     g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
 
-    GList *focusChain = NULL;
-    focusChain = g_list_append( focusChain, pDocView );
+    focusChain = g_list_append( focusChain, pDocView1 );
     gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
 }
 
-static void open_document_cb (GObject* source_object, GAsyncResult* res, gpointer userdata)
-{
-    LOKDocView* pDocView = LOK_DOC_VIEW (source_object);
-    GError* error = NULL;
-
-    gboolean result = lok_doc_view_open_document_finish(pDocView, res, &error);
-    if (result){
-        g_info ("open_document results to true");
-    }else
-        g_info ("open document results to false");
-
-    if (error != NULL)
-    {
-        g_warning ("Error occurred while opening the document : %s", error->message);
-        g_error_free (error);
-    }
-}
-
 int main( int argc, char* argv[] )
 {
     if( argc < 3 ||
@@ -571,9 +554,6 @@ 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);
 
-    g_signal_connect(pDocView, "load-started", G_CALLBACK(loadStarted), NULL);
-    g_signal_connect(pDocView, "load-finished", G_CALLBACK(loadFinished), NULL);
-
     // Scrolled window for DocView
     pScrolledWindow = gtk_scrolled_window_new(0, 0);
     gtk_widget_set_hexpand (pScrolledWindow, TRUE);
@@ -586,9 +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], NULL, open_document_cb, pDocView );
-    if (!bOpened)
-        g_error("main: lok_doc_view_open_document() failed");
+    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 f9b332c..64aeb89 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -337,19 +337,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:
@@ -1298,34 +1302,6 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
                                                        | G_PARAM_STATIC_STRINGS)));
 
     /**
-     * LOKDocView::load-started:
-     * @pDocView: the #LOKDocView on which the signal is emitted
-     */
-    doc_view_signals[LOAD_STARTED] =
-        g_signal_new("load-started",
-                     G_TYPE_FROM_CLASS (pGObjectClass),
-                     G_SIGNAL_RUN_LAST,
-                     0,
-                     NULL, NULL,
-                     g_cclosure_marshal_VOID__VOID,
-                     G_TYPE_NONE, 0);
-
-    /**
-     * LOKDocView::load-finished:
-     * @pDocView: the #LOKDocView on which the signal is emitted
-     * @bStatus: whether the load finished successfully or it failed
-     */
-    doc_view_signals[LOAD_FINISHED] =
-        g_signal_new("load-finished",
-                     G_TYPE_FROM_CLASS(pGObjectClass),
-                     G_SIGNAL_RUN_LAST,
-                     0,
-                     NULL, NULL,
-                     g_cclosure_marshal_VOID__BOOLEAN,
-                     G_TYPE_NONE, 1,
-                     G_TYPE_BOOLEAN);
-
-    /**
      * LOKDocView::edit-changed:
      * @pDocView: the #LOKDocView on which the signal is emitted
      * @bEdit: the new edit value of the view
@@ -1419,7 +1395,8 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
 /**
  * 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
  */
@@ -1448,8 +1425,6 @@ lok_doc_view_open_document_func (GTask* task, gpointer source_object, gpointer t
         priv->m_pDocument = 0;
     }
 
-    g_signal_emit(pDocView, doc_view_signals[LOAD_STARTED], 0);
-
     priv->m_pOffice->pClass->registerCallback(priv->m_pOffice, globalCallbackWorker, pDocView);
     priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, priv->m_aDocPath );
     if ( !priv->m_pDocument )
@@ -1457,7 +1432,6 @@ lok_doc_view_open_document_func (GTask* task, gpointer source_object, gpointer t
         // 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 );
-        g_signal_emit(pDocView, doc_view_signals[LOAD_FINISHED], 0, false/* implies failure*/);
         g_task_return_new_error(task, 0, 0, pError);
     }
     else
@@ -1483,8 +1457,6 @@ lok_doc_view_open_document_func (GTask* task, gpointer source_object, gpointer t
                                     nDocumentHeightPixels);
         gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
         gtk_widget_grab_focus(GTK_WIDGET(pDocView));
-        g_signal_emit(pDocView, doc_view_signals[LOAD_FINISHED], 0, true/* implies
-                                                                           success */);
         g_task_return_boolean (task, true);
     }
 }
@@ -1496,7 +1468,7 @@ lok_doc_view_open_document_func (GTask* task, gpointer source_object, gpointer t
  *
  * Returns: %TRUE if the document is loaded succesfully, %FALSE otherwise
  */
-SAL_DLLPUBLIC_EXPORT gboolean
+SAL_DLLPUBLIC_EXPORT void
 lok_doc_view_open_document (LOKDocView* pDocView,
                             const gchar* pPath,
                             GCancellable* cancellable,
@@ -1513,8 +1485,6 @@ lok_doc_view_open_document (LOKDocView* pDocView,
 
     g_task_run_in_thread(task, lok_doc_view_open_document_func);
     g_object_unref(task);
-
-    return true;
 }
 
 /**


More information about the Libreoffice-commits mailing list