summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranav Kant <pranavk@gnome.org>2015-06-18 21:52:22 +0530
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2016-02-07 21:25:31 -0500
commit23ec60b59925913c84d457b98901d7e6a1a2db8a (patch)
tree9f49382756ef536c4f945cb82815c44d36d11cd3
parentgtktiledviewer: do HTML copying if possible (diff)
downloadcore-23ec60b59925913c84d457b98901d7e6a1a2db8a.tar.gz
core-23ec60b59925913c84d457b98901d7e6a1a2db8a.zip
lokdocview: Use GInitable
The construction of LokDocView widget can fail because it involves initializing the lok context via lok_init. Having lok_init calls in constructed virtual method is a bad idea since it assumes that construction will never fail. So, implement GInitable for this class, and move the object initialization from constructed to initable. Change-Id: Idf18a054cf8ef2e946392458ec52cb0107bd7454 (cherry picked from commit a2aaf911e2e7b63af920186acb2a5e03bc58bd54)
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitGtk.h6
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx2
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx49
3 files changed, 39 insertions, 18 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 7048dbefc0a1..3eaf28352a11 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -42,10 +42,12 @@ struct _LOKDocViewClass
GType lok_doc_view_get_type (void) G_GNUC_CONST;
-GtkWidget* lok_doc_view_new (const char* pPath);
+GtkWidget* lok_doc_view_new (const gchar* pPath,
+ GCancellable *cancellable,
+ GError **error);
gboolean lok_doc_view_open_document (LOKDocView* pDocView,
- char* pPath);
+ const gchar* pPath);
/// 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 26259cf316e5..4ff059f5f47c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -528,7 +528,7 @@ int main( int argc, char* argv[] )
gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
// Docview
- pDocView = lok_doc_view_new(argv[1]);
+ pDocView = lok_doc_view_new (argv[1], NULL, NULL);
if (pDocView == NULL)
g_error ("Error while creating LOKDocView widget");
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 55b88699e54f..4b5b67335845 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -138,12 +138,16 @@ enum
static guint doc_view_signals[LAST_SIGNAL] = { 0 };
+static void lok_doc_view_initable_iface_init (GInitableIface *iface);
+
SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type();
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
-G_DEFINE_TYPE_WITH_PRIVATE (LOKDocView, lok_doc_view, GTK_TYPE_DRAWING_AREA)
+G_DEFINE_TYPE_WITH_CODE (LOKDocView, lok_doc_view, GTK_TYPE_DRAWING_AREA,
+ G_ADD_PRIVATE (LOKDocView)
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, lok_doc_view_initable_iface_init));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
@@ -1123,14 +1127,30 @@ static void lok_doc_view_finalize (GObject* object)
G_OBJECT_CLASS (lok_doc_view_parent_class)->finalize (object);
}
-static void lok_doc_view_constructed (GObject* object)
+static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /*cancellable*/, GError **error)
{
- LOKDocView* pDocView = LOK_DOC_VIEW (object);
- LOKDocViewPrivate* priv = pDocView->priv;
+ LOKDocView *pDocView = LOK_DOC_VIEW (initable);
+
+ if (pDocView->priv->m_pOffice != NULL)
+ return TRUE;
+
+ pDocView->priv->m_pOffice = lok_init (pDocView->priv->m_aLOPath);
+
+ if (pDocView->priv->m_pOffice == NULL)
+ {
+ g_set_error (error,
+ g_quark_from_static_string ("LOK initialization error"), 0,
+ "Failed to get LibreOfficeKit context. Make sure path (%s) is correct",
+ pDocView->priv->m_aLOPath);
+ return FALSE;
+ }
- G_OBJECT_CLASS (lok_doc_view_parent_class)->constructed (object);
+ return TRUE;
+}
- pDocView->priv->m_pOffice = lok_init (priv->m_aLOPath);
+static void lok_doc_view_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = lok_doc_view_initable_init;
}
static void lok_doc_view_class_init (LOKDocViewClass* pClass)
@@ -1141,7 +1161,6 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
pGObjectClass->get_property = lok_doc_view_get_property;
pGObjectClass->set_property = lok_doc_view_set_property;
pGObjectClass->finalize = lok_doc_view_finalize;
- pGObjectClass->constructed = lok_doc_view_constructed;
pWidgetClass->draw = lok_doc_view_draw;
pWidgetClass->button_press_event = lok_doc_view_signal_button;
@@ -1373,18 +1392,19 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
G_TYPE_STRING);
}
-
-
/**
* lok_doc_view_new:
* @pPath: LibreOffice install path.
+ * @cancellable: The cancellable object that you can use to cancel this
+ * operation.
+ * @error: The error that will be set if the object fails to initialize.
*
- * Returns: The #LOKDocView widget instance.
+ * Returns: (transfer none): The #LOKDocView widget instance.
*/
SAL_DLLPUBLIC_EXPORT GtkWidget*
-lok_doc_view_new (const char* pPath)
+lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
{
- return GTK_WIDGET (g_object_new(LOK_TYPE_DOC_VIEW, "lopath", pPath, NULL));
+ return GTK_WIDGET (g_initable_new (LOK_TYPE_DOC_VIEW, cancellable, error, "lopath", pPath, NULL));
}
/**
@@ -1395,7 +1415,7 @@ lok_doc_view_new (const char* pPath)
* Returns: %TRUE if the document is loaded succesfully, %FALSE otherwise
*/
SAL_DLLPUBLIC_EXPORT gboolean
-lok_doc_view_open_document (LOKDocView* pDocView, char* pPath)
+lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
{
if ( pDocView->priv->m_pDocument )
{
@@ -1404,8 +1424,7 @@ lok_doc_view_open_document (LOKDocView* pDocView, char* pPath)
}
pDocView->priv->m_pOffice->pClass->registerCallback(pDocView->priv->m_pOffice, globalCallbackWorker, pDocView);
- pDocView->priv->m_pDocument = pDocView->priv->m_pOffice->pClass->documentLoad( pDocView->priv->m_pOffice,
- pPath );
+ pDocView->priv->m_pDocument = pDocView->priv->m_pOffice->pClass->documentLoad( pDocView->priv->m_pOffice, pPath );
if ( !pDocView->priv->m_pDocument )
{
// FIXME: should have a GError parameter and populate it.