summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorPranav Kant <pranavk@gnome.org>2015-06-18 21:52:22 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-06-22 12:33:24 +0200
commita2aaf911e2e7b63af920186acb2a5e03bc58bd54 (patch)
tree0701b92f9d1cb76e25f2afac348443615cdf217f /libreofficekit
parent35fd66e8648c6d82396486a9469dcb061c832b91 (diff)
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
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx2
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx49
2 files changed, 35 insertions, 16 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 575588ea8bcb..a583323e8bca 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -521,7 +521,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 9e8cabbad050..bc383c5c8651 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -137,12 +137,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
@@ -1103,14 +1107,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)
@@ -1121,7 +1141,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;
@@ -1343,18 +1362,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));
}
/**
@@ -1365,7 +1385,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 )
{
@@ -1374,8 +1394,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.