[libgda] report-docbook-document: ported to G_DECLARE/G_DEFINE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] report-docbook-document: ported to G_DECLARE/G_DEFINE
- Date: Wed, 10 Oct 2018 16:59:28 +0000 (UTC)
commit 9a79432dfc2bcc97f405f465796377cc6350c58a
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Oct 10 11:44:25 2018 -0500
report-docbook-document: ported to G_DECLARE/G_DEFINE
Added error domain
.../DocBook/gda-report-docbook-document.c | 216 ++++++++++-----------
.../DocBook/gda-report-docbook-document.h | 23 +--
2 files changed, 108 insertions(+), 131 deletions(-)
---
diff --git a/libgda-report/DocBook/gda-report-docbook-document.c
b/libgda-report/DocBook/gda-report-docbook-document.c
index 91853de06..61e2b7bd2 100644
--- a/libgda-report/DocBook/gda-report-docbook-document.c
+++ b/libgda-report/DocBook/gda-report-docbook-document.c
@@ -30,17 +30,29 @@
#include "gda-report-docbook-document.h"
#include <libgda/binreloc/gda-binreloc.h>
-struct _GdaReportDocbookDocumentPrivate {
+
+/* module error */
+GQuark gda_report_docbook_document_error_quark (void)
+{
+ static GQuark quark;
+ if (!quark)
+ quark = g_quark_from_static_string ("gda_report_docbook_document_error");
+ return quark;
+}
+
+typedef struct {
gchar *html_stylesheet;
gchar *fo_stylesheet;
gchar *java_home;
gchar *fop_path;
-};
+} GdaReportDocbookDocumentPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaReportDocbookDocument, gda_report_docbook_document, GDA_TYPE_REPORT_DOCUMENT)
/* properties */
enum
{
- PROP_0,
+ PROP_0,
PROP_HTML_STYLESHEET,
PROP_FO_STYLESHEET,
@@ -48,8 +60,6 @@ enum
PROP_FOP_PATH
};
-static void gda_report_docbook_document_class_init (GdaReportDocbookDocumentClass *klass);
-static void gda_report_docbook_document_init (GdaReportDocbookDocument *doc,
GdaReportDocbookDocumentClass *klass);
static void gda_report_docbook_document_dispose (GObject *object);
static void gda_report_docbook_document_set_property (GObject *object,
guint param_id,
@@ -63,8 +73,6 @@ static void gda_report_docbook_document_get_property (GObject *object,
static gboolean gda_report_docbook_document_run_as_html (GdaReportDocument *doc, const gchar *filename,
GError **error);
static gboolean gda_report_docbook_document_run_as_pdf (GdaReportDocument *doc, const gchar *filename,
GError **error);
-static GObjectClass *parent_class = NULL;
-
/*
* GdaReportDocbookDocument class implementation
*/
@@ -74,8 +82,6 @@ gda_report_docbook_document_class_init (GdaReportDocbookDocumentClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdaReportDocumentClass *doc_class = GDA_REPORT_DOCUMENT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
/* report methods */
object_class->dispose = gda_report_docbook_document_dispose;
@@ -102,11 +108,7 @@ gda_report_docbook_document_class_init (GdaReportDocbookDocumentClass *klass)
}
static void
-gda_report_docbook_document_init (GdaReportDocbookDocument *doc,
- G_GNUC_UNUSED GdaReportDocbookDocumentClass *klass)
-{
- doc->priv = g_new0 (GdaReportDocbookDocumentPrivate, 1);
-}
+gda_report_docbook_document_init (GdaReportDocbookDocument *doc) {}
static void
gda_report_docbook_document_dispose (GObject *object)
@@ -114,48 +116,28 @@ gda_report_docbook_document_dispose (GObject *object)
GdaReportDocbookDocument *doc = (GdaReportDocbookDocument *) object;
g_return_if_fail (GDA_IS_REPORT_DOCBOOK_DOCUMENT (doc));
+ GdaReportDocbookDocumentPrivate *priv = gda_report_docbook_document_get_instance_private (doc);
/* free memory */
- if (doc->priv) {
- g_free (doc->priv->html_stylesheet);
- g_free (doc->priv->fo_stylesheet);
- g_free (doc->priv->java_home);
- g_free (doc->priv->fop_path);
-
- g_free (doc->priv);
- doc->priv = NULL;
+ if (priv->html_stylesheet) {
+ g_free (priv->html_stylesheet);
+ priv->html_stylesheet = NULL;
}
-
- /* chain to parent class */
- parent_class->dispose (object);
-}
-
-GType
-gda_report_docbook_document_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static GTypeInfo info = {
- sizeof (GdaReportDocbookDocumentClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_report_docbook_document_class_init,
- NULL, NULL,
- sizeof (GdaReportDocbookDocument),
- 0,
- (GInstanceInitFunc) gda_report_docbook_document_init,
- 0
- };
-
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (GDA_TYPE_REPORT_DOCUMENT, "GdaReportDocbookDocument",
&info, 0);
- g_mutex_unlock (®istering);
+ if (priv->fo_stylesheet) {
+ g_free (priv->fo_stylesheet);
+ priv->fo_stylesheet = NULL;
+ }
+ if (priv->java_home) {
+ g_free (priv->java_home);
+ priv->java_home = NULL;
+ }
+ if (priv->fop_path) {
+ g_free (priv->fop_path);
+ priv->fop_path = NULL;
}
- return type;
+ /* chain to parent class */
+ G_OBJECT_CLASS (gda_report_docbook_document_parent_class)->dispose (object);
}
static void
@@ -164,48 +146,47 @@ gda_report_docbook_document_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GdaReportDocbookDocument *doc;
+ GdaReportDocbookDocument *doc;
- doc = GDA_REPORT_DOCBOOK_DOCUMENT (object);
- if (doc->priv) {
- switch (param_id) {
+ doc = GDA_REPORT_DOCBOOK_DOCUMENT (object);
+ GdaReportDocbookDocumentPrivate *priv = gda_report_docbook_document_get_instance_private (doc);
+ switch (param_id) {
case PROP_HTML_STYLESHEET:
- if (doc->priv->html_stylesheet) {
- g_free (doc->priv->html_stylesheet);
- doc->priv->html_stylesheet = NULL;
+ if (priv->html_stylesheet) {
+ g_free (priv->html_stylesheet);
+ priv->html_stylesheet = NULL;
}
if (g_value_get_string (value))
- doc->priv->html_stylesheet = g_strdup (g_value_get_string (value));
+ priv->html_stylesheet = g_strdup (g_value_get_string (value));
break;
case PROP_FO_STYLESHEET:
- if (doc->priv->fo_stylesheet) {
- g_free (doc->priv->fo_stylesheet);
- doc->priv->fo_stylesheet = NULL;
+ if (priv->fo_stylesheet) {
+ g_free (priv->fo_stylesheet);
+ priv->fo_stylesheet = NULL;
}
if (g_value_get_string (value))
- doc->priv->fo_stylesheet = g_strdup (g_value_get_string (value));
+ priv->fo_stylesheet = g_strdup (g_value_get_string (value));
break;
case PROP_JAVA_HOME:
- if (doc->priv->java_home) {
- g_free (doc->priv->java_home);
- doc->priv->java_home = NULL;
+ if (priv->java_home) {
+ g_free (priv->java_home);
+ priv->java_home = NULL;
}
if (g_value_get_string (value))
- doc->priv->java_home = g_strdup (g_value_get_string (value));
+ priv->java_home = g_strdup (g_value_get_string (value));
break;
case PROP_FOP_PATH:
- if (doc->priv->fop_path) {
- g_free (doc->priv->fop_path);
- doc->priv->fop_path = NULL;
+ if (priv->fop_path) {
+ g_free (priv->fop_path);
+ priv->fop_path = NULL;
}
if (g_value_get_string (value))
- doc->priv->fop_path = g_strdup (g_value_get_string (value));
+ priv->fop_path = g_strdup (g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
- }
- }
+ }
}
static void
@@ -214,28 +195,27 @@ gda_report_docbook_document_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GdaReportDocbookDocument *doc;
+ GdaReportDocbookDocument *doc;
- doc = GDA_REPORT_DOCBOOK_DOCUMENT (object);
- if (doc->priv) {
- switch (param_id) {
+ doc = GDA_REPORT_DOCBOOK_DOCUMENT (object);
+ GdaReportDocbookDocumentPrivate *priv = gda_report_docbook_document_get_instance_private (doc);
+ switch (param_id) {
case PROP_HTML_STYLESHEET:
- g_value_set_string (value, doc->priv->html_stylesheet);
+ g_value_set_string (value, priv->html_stylesheet);
break;
case PROP_FO_STYLESHEET:
- g_value_set_string (value, doc->priv->fo_stylesheet);
+ g_value_set_string (value, priv->fo_stylesheet);
break;
case PROP_JAVA_HOME:
- g_value_set_string (value, doc->priv->java_home);
+ g_value_set_string (value, priv->java_home);
break;
case PROP_FOP_PATH:
- g_value_set_string (value, doc->priv->fop_path);
+ g_value_set_string (value, priv->fop_path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
- }
- }
+ }
}
/**
@@ -269,7 +249,7 @@ gda_report_docbook_document_run_as_html (GdaReportDocument *doc, const gchar *fi
g_return_val_if_fail (GDA_IS_REPORT_DOCBOOK_DOCUMENT (doc), FALSE);
g_return_val_if_fail (filename && *filename, FALSE);
fdoc = GDA_REPORT_DOCBOOK_DOCUMENT (doc);
- g_return_val_if_fail (fdoc->priv, FALSE);
+ GdaReportDocbookDocumentPrivate *priv = gda_report_docbook_document_get_instance_private (fdoc);
g_mutex_lock (&init_mutex);
if (!xsltproc) {
@@ -282,22 +262,22 @@ gda_report_docbook_document_run_as_html (GdaReportDocument *doc, const gchar *fi
}
}
if (!xsltproc) {
- g_set_error (error, 0, 0,
+ g_set_error (error, GDA_REPORT_DOCBOOK_DOCUMENT_ERROR,
GDA_REPORT_DOCBOOK_DOCUMENT_GENERAL_ERROR,
_("Could not find the '%s' program"), "xsltproc");
g_mutex_unlock (&init_mutex);
return FALSE;
}
}
- if (!fdoc->priv->html_stylesheet) {
- fdoc->priv->html_stylesheet = gda_gbr_get_file_path (GDA_DATA_DIR, "xml", "docbook",
+ if (!priv->html_stylesheet) {
+ priv->html_stylesheet = gda_gbr_get_file_path (GDA_DATA_DIR, "xml", "docbook",
"stylesheet", "html", "docbook.xsl",
NULL);
- if (!g_file_test (fdoc->priv->html_stylesheet, G_FILE_TEST_EXISTS)) {
- g_free (fdoc->priv->html_stylesheet);
- fdoc->priv->html_stylesheet = NULL;
+ if (!g_file_test (priv->html_stylesheet, G_FILE_TEST_EXISTS)) {
+ g_free (priv->html_stylesheet);
+ priv->html_stylesheet = NULL;
}
- if (!fdoc->priv->html_stylesheet) {
- g_set_error (error, 0, 0, "%s",
+ if (!priv->html_stylesheet) {
+ g_set_error (error, GDA_REPORT_DOCBOOK_DOCUMENT_ERROR,
GDA_REPORT_DOCBOOK_DOCUMENT_GENERAL_ERROR, "%s",
_("Could not find the DocBook XSL stylesheet for HTML"));
g_mutex_unlock (&init_mutex);
return FALSE;
@@ -312,7 +292,7 @@ gda_report_docbook_document_run_as_html (GdaReportDocument *doc, const gchar *fi
argv[3] = g_strdup ("--stringparam");
argv[4] = g_strdup ("use.extensions");
argv[5] = g_strdup ("0");
- argv[6] = g_strdup (fdoc->priv->html_stylesheet);
+ argv[6] = g_strdup (priv->html_stylesheet);
argv[7] = NULL;
argv[8] = NULL;
@@ -332,51 +312,51 @@ gda_report_docbook_document_run_as_pdf (GdaReportDocument *doc, const gchar *fil
g_return_val_if_fail (GDA_IS_REPORT_DOCBOOK_DOCUMENT (doc), FALSE);
g_return_val_if_fail (filename && *filename, FALSE);
fdoc = GDA_REPORT_DOCBOOK_DOCUMENT (doc);
- g_return_val_if_fail (fdoc->priv, FALSE);
-
- if (!fdoc->priv->fop_path) {
- fdoc->priv->fop_path = g_find_program_in_path ("fop");
- if (!fdoc->priv->fop_path) {
- fdoc->priv->fop_path = gda_gbr_get_file_path (GDA_BIN_DIR, "fop", NULL);
- if (!g_file_test (fdoc->priv->fop_path, G_FILE_TEST_IS_EXECUTABLE)) {
- g_free (fdoc->priv->fop_path);
- fdoc->priv->fop_path = NULL;
+ GdaReportDocbookDocumentPrivate *priv = gda_report_docbook_document_get_instance_private (fdoc);
+
+ if (!priv->fop_path) {
+ priv->fop_path = g_find_program_in_path ("fop");
+ if (!priv->fop_path) {
+ priv->fop_path = gda_gbr_get_file_path (GDA_BIN_DIR, "fop", NULL);
+ if (!g_file_test (priv->fop_path, G_FILE_TEST_IS_EXECUTABLE)) {
+ g_free (priv->fop_path);
+ priv->fop_path = NULL;
}
}
- if (!fdoc->priv->fop_path && fdoc->priv->java_home) {
- fdoc->priv->fop_path = g_build_filename (fdoc->priv->java_home, "fop", NULL);
- if (!g_file_test (fdoc->priv->fop_path, G_FILE_TEST_IS_EXECUTABLE)) {
- g_free (fdoc->priv->fop_path);
- fdoc->priv->fop_path = NULL;
+ if (!priv->fop_path && priv->java_home) {
+ priv->fop_path = g_build_filename (priv->java_home, "fop", NULL);
+ if (!g_file_test (priv->fop_path, G_FILE_TEST_IS_EXECUTABLE)) {
+ g_free (priv->fop_path);
+ priv->fop_path = NULL;
}
}
- if (!fdoc->priv->fop_path) {
- g_set_error (error, 0, 0,
+ if (!priv->fop_path) {
+ g_set_error (error, GDA_REPORT_DOCBOOK_DOCUMENT_ERROR,
GDA_REPORT_DOCBOOK_DOCUMENT_GENERAL_ERROR,
_("Could not find the '%s' program"), "fop");
return FALSE;
}
}
- if (!fdoc->priv->fo_stylesheet) {
- fdoc->priv->fo_stylesheet = gda_gbr_get_file_path (GDA_DATA_DIR, "xml", "docbook",
+ if (!priv->fo_stylesheet) {
+ priv->fo_stylesheet = gda_gbr_get_file_path (GDA_DATA_DIR, "xml", "docbook",
"stylesheet", "fo", "docbook.xsl", NULL);
- if (!g_file_test (fdoc->priv->fo_stylesheet, G_FILE_TEST_EXISTS)) {
- g_free (fdoc->priv->fo_stylesheet);
- fdoc->priv->fo_stylesheet = NULL;
+ if (!g_file_test (priv->fo_stylesheet, G_FILE_TEST_EXISTS)) {
+ g_free (priv->fo_stylesheet);
+ priv->fo_stylesheet = NULL;
}
- if (!fdoc->priv->fo_stylesheet) {
- g_set_error (error, 0, 0, "%s",
+ if (!priv->fo_stylesheet) {
+ g_set_error (error, GDA_REPORT_DOCBOOK_DOCUMENT_ERROR,
GDA_REPORT_DOCBOOK_DOCUMENT_GENERAL_ERROR, "%s",
_("Could not find the DocBook XSL stylesheet for Formatting Objects"));
return FALSE;
}
}
argv = g_new (gchar *, 8);
- argv[0] = g_strdup (fdoc->priv->fop_path);
+ argv[0] = g_strdup (priv->fop_path);
argv[1] = g_strdup ("-xml");
argv[2] = NULL;
argv[3] = g_strdup ("-xsl");
- argv[4] = g_strdup (fdoc->priv->fo_stylesheet);
+ argv[4] = g_strdup (priv->fo_stylesheet);
argv[5] = g_strdup ("-pdf");
argv[6] = g_strdup (filename);
argv[7] = NULL;
diff --git a/libgda-report/DocBook/gda-report-docbook-document.h
b/libgda-report/DocBook/gda-report-docbook-document.h
index a457f50d6..88fa75179 100644
--- a/libgda-report/DocBook/gda-report-docbook-document.h
+++ b/libgda-report/DocBook/gda-report-docbook-document.h
@@ -22,22 +22,19 @@
#include <libgda-report/gda-report-document.h>
-#define GDA_TYPE_REPORT_DOCBOOK_DOCUMENT (gda_report_docbook_document_get_type())
-#define GDA_REPORT_DOCBOOK_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj,
GDA_TYPE_REPORT_DOCBOOK_DOCUMENT, GdaReportDocbookDocument))
-#define GDA_REPORT_DOCBOOK_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass,
GDA_TYPE_REPORT_DOCBOOK_DOCUMENT, GdaReportDocbookDocumentClass))
-#define GDA_IS_REPORT_DOCBOOK_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj,
GDA_TYPE_REPORT_DOCBOOK_DOCUMENT))
-#define GDA_IS_REPORT_DOCBOOK_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GDA_TYPE_REPORT_DOCBOOK_DOCUMENT))
-
G_BEGIN_DECLS
-typedef struct _GdaReportDocbookDocument GdaReportDocbookDocument;
-typedef struct _GdaReportDocbookDocumentClass GdaReportDocbookDocumentClass;
-typedef struct _GdaReportDocbookDocumentPrivate GdaReportDocbookDocumentPrivate;
-struct _GdaReportDocbookDocument {
- GdaReportDocument base;
- GdaReportDocbookDocumentPrivate *priv;
-};
+/* error reporting */
+extern GQuark gda_report_docbook_document_error_quark (void);
+#define GDA_REPORT_DOCBOOK_DOCUMENT_ERROR gda_report_docbook_document_error_quark ()
+
+typedef enum {
+ GDA_REPORT_DOCBOOK_DOCUMENT_GENERAL_ERROR
+} GdaReportDocbookDocumentError;
+
+#define GDA_TYPE_REPORT_DOCBOOK_DOCUMENT (gda_report_docbook_document_get_type())
+G_DECLARE_DERIVABLE_TYPE (GdaReportDocbookDocument, gda_report_docbook_document, GDA,
REPORT_DOCBOOK_DOCUMENT, GdaReportDocument)
struct _GdaReportDocbookDocumentClass {
GdaReportDocumentClass parent_class;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]