From 4ee323a89a16239618db5526011df538bb58f6dd Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 24 Jan 2017 22:50:37 +0100 Subject: [PATCH] Load D-Bus interface XML data during runtime We already install the XML data anyway, so there is no reason to ship it twice (once in the binary and once as a file). Signed-off-by: Sebastian Ramacher --- Makefile | 19 +++++++--------- config.mk | 5 ++++ zathura/dbus-interface-definitions.h | 8 ------- zathura/dbus-interface.c | 34 +++++++++++++++++++++++++--- 4 files changed, 44 insertions(+), 22 deletions(-) delete mode 100644 zathura/dbus-interface-definitions.h diff --git a/Makefile b/Makefile index 046a750..49f4cba 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,7 @@ include common.mk # source files OSOURCE = $(sort $(wildcard ${PROJECT}/*.c) \ - ${PROJECT}/css-definitions.c \ - ${PROJECT}/dbus-interface-definitions.c) + ${PROJECT}/css-definitions.c) ifneq (${WITH_SQLITE},0) INCS += $(SQLITE_INC) @@ -43,6 +42,13 @@ endif ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS})) CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\" endif +ifeq (,$(findstring -DDBUSINTERFACEDIR,${CPPFLAGS})) +ifneq ($(WITH_LOCAL_DBUS_XML),0) +CPPFLAGS += -DDBUSINTERFACEDIR=\"${PWD}/data\" +else +CPPFLAGS += -DDBUSINTERFACEDIR=\"${DBUSINTERFACEDIR}\" +endif +endif OBJECTS = $(addprefix ${BUILDDIR_RELEASE}/,${SOURCE:.c=.o}) OBJECTS_DEBUG = $(addprefix ${BUILDDIR_DEBUG}/,${SOURCE:.c=.o}) @@ -78,13 +84,6 @@ ${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk -e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp $(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h -${PROJECT}/dbus-interface-definitions.c: data/org.pwmt.zathura.xml - $(QUIET)echo '#include "dbus-interface-definitions.h"' > $@.tmp - $(QUIET)echo 'const char* DBUS_INTERFACE_XML =' >> $@.tmp - $(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' data/org.pwmt.zathura.xml >> $@.tmp - $(QUIET)echo ';' >> $@.tmp - $(QUIET)mv $@.tmp $@ - ${PROJECT}/css-definitions.c: data/zathura.css_t $(QUIET)echo '#include "css-definitions.h"' > $@.tmp $(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp @@ -174,8 +173,6 @@ clean: ${PROJECT}.pc \ ${PROJECT}/version.h \ ${PROJECT}/version.h.tmp \ - ${PROJECT}/dbus-interface-definitions.c \ - ${PROJECT}/dbus-interface-definitions.c.tmp \ ${PROJECT}/css-definitions.c \ ${PROJECT}/css-definitions.c.tmp \ $(PROJECT).info \ diff --git a/config.mk b/config.mk index 4967656..a00f096 100644 --- a/config.mk +++ b/config.mk @@ -44,6 +44,11 @@ WITH_SYNCTEX ?= $(shell (${PKG_CONFIG} synctex && echo 1) || echo 0) # To disable support for mimetype detction with libmagic set WITH_MAGIC to 0. WITH_MAGIC ?= 1 +# use local D-Bus interface +# Enable this if the D-Bus interface XML from data should be used (useful for +# development). +WITH_LOCAL_DBUS_XML ?= 0 + # paths PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man diff --git a/zathura/dbus-interface-definitions.h b/zathura/dbus-interface-definitions.h deleted file mode 100644 index 9ebef64..0000000 --- a/zathura/dbus-interface-definitions.h +++ /dev/null @@ -1,8 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef ZATHURA_DBUS_INTERFACE_DEFINITIONS -#define ZATHURA_DBUS_INTERFACE_DEFINITIONS - -const char* DBUS_INTERFACE_XML; - -#endif diff --git a/zathura/dbus-interface.c b/zathura/dbus-interface.c index 2dd95ec..056c93a 100644 --- a/zathura/dbus-interface.c +++ b/zathura/dbus-interface.c @@ -1,7 +1,6 @@ /* See LICENSE file for license and copyright information */ #include "dbus-interface.h" -#include "dbus-interface-definitions.h" #include "synctex.h" #include "macros.h" #include "zathura.h" @@ -17,6 +16,26 @@ #include #include +static const char DBUS_XML_FILENAME[] = "org.pwmt.zathura.xml"; + +static char* load_xml_data(void) +{ +#ifdef DBUSINTERFACEDIR + char* file_path = g_build_filename(DBUSINTERFACEDIR, DBUS_XML_FILENAME, NULL); + if (file_path == NULL) { + return NULL; + } + + girara_debug("Loading D-Bus interface data from %s.", file_path); + char* content = girara_file_read(file_path); + g_free(file_path); + return content; +#else + girara_error("DBUSINTERFACEDIR is not defined. D-Bus interface will not be available."); + return NULL; +#endif +} + G_DEFINE_TYPE(ZathuraDbus, zathura_dbus, G_TYPE_OBJECT) /* template for bus name */ @@ -144,9 +163,18 @@ zathura_dbus_new(zathura_t* zathura) private_t* priv = GET_PRIVATE(dbus); priv->zathura = zathura; + char* xml_data = load_xml_data(); + if (xml_data == NULL) + { + girara_warning("Failed to load introspection data."); + g_object_unref(obj); + return NULL; + } + GError* error = NULL; - priv->introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTERFACE_XML, - &error); + priv->introspection_data = g_dbus_node_info_new_for_xml(xml_data, &error); + g_free(xml_data); + if (priv->introspection_data == NULL) { girara_warning("Failed to parse introspection data: %s", error->message); g_error_free(error);