summaryrefslogtreecommitdiff
path: root/obt
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2013-08-10 20:46:27 -0400
committerDana Jansens <danakj@orodu.net>2013-08-10 21:59:12 -0400
commit4e6c0086a657399d989f2e4849f7b397d7d4efbc (patch)
tree64cb34f3a3ee63df40443e39661c33a060953860 /obt
parenta5eb363f48b75b6eae0a1dc4a6c8e079c9831f92 (diff)
Add support for loading SVG icons using librsvg.
This adds a configure option --disable-librsvg, but defaults to using the library if it is present during configure. When enabled, Openbox will attempt to load svg image files using the library, similar to how Imlib2 is used for other image formats. Since librsvg uses the libXml2 library, their errors end up in the same global namespace as Openbox config file parsing. To avoid this, we reset the libXml current error whenever we start loading a file, and save the last error that occurred when we are finished, by storing the error in the ObtXmlInst.
Diffstat (limited to 'obt')
-rw-r--r--obt/xml.c58
-rw-r--r--obt/xml.h6
2 files changed, 64 insertions, 0 deletions
diff --git a/obt/xml.c b/obt/xml.c
index 5b7e77b5..223ad02b 100644
--- a/obt/xml.c
+++ b/obt/xml.c
@@ -48,8 +48,13 @@ struct _ObtXmlInst {
xmlDocPtr doc;
xmlNodePtr root;
gchar *path;
+ gchar *last_error_file;
+ gint last_error_line;
+ gchar *last_error_message;
};
+static void obt_xml_save_last_error(ObtXmlInst* inst);
+
static void destfunc(struct Callback *c)
{
g_free(c->tag);
@@ -66,6 +71,9 @@ ObtXmlInst* obt_xml_instance_new(void)
i->doc = NULL;
i->root = NULL;
i->path = NULL;
+ i->last_error_file = NULL;
+ i->last_error_line = -1;
+ i->last_error_message = NULL;
return i;
}
@@ -79,6 +87,8 @@ void obt_xml_instance_unref(ObtXmlInst *i)
if (i && --i->ref == 0) {
obt_paths_unref(i->xdg_paths);
g_hash_table_destroy(i->callbacks);
+ g_free(i->last_error_file);
+ g_free(i->last_error_message);
g_slice_free(ObtXmlInst, i);
}
}
@@ -128,6 +138,8 @@ static gboolean load_file(ObtXmlInst *i,
g_assert(i->doc == NULL); /* another doc isn't open already? */
+ xmlResetLastError();
+
for (it = paths; !r && it; it = g_slist_next(it)) {
gchar *path;
struct stat s;
@@ -169,6 +181,8 @@ static gboolean load_file(ObtXmlInst *i,
g_free(path);
}
+ obt_xml_save_last_error(i);
+
return r;
}
@@ -264,6 +278,8 @@ gboolean obt_xml_load_mem(ObtXmlInst *i,
g_assert(i->doc == NULL); /* another doc isn't open already? */
+ xmlResetLastError();
+
i->doc = xmlParseMemory(data, len);
if (i) {
i->root = xmlDocGetRootElement(i->doc);
@@ -282,9 +298,51 @@ gboolean obt_xml_load_mem(ObtXmlInst *i,
else
r = TRUE; /* ok ! */
}
+
+ obt_xml_save_last_error(i);
+
return r;
}
+static void obt_xml_save_last_error(ObtXmlInst* inst)
+{
+ xmlErrorPtr error = xmlGetLastError();
+ if (error) {
+ inst->last_error_file = g_strdup(error->file);
+ inst->last_error_line = error->line;
+ inst->last_error_message = g_strdup(error->message);
+ xmlResetError(error);
+ }
+}
+
+gboolean obt_xml_last_error(ObtXmlInst *inst)
+{
+ return inst->last_error_file &&
+ inst->last_error_line >= 0 &&
+ inst->last_error_message;
+}
+
+gchar* obt_xml_last_error_file(ObtXmlInst *inst)
+{
+ if (!obt_xml_last_error(inst))
+ return NULL;
+ return inst->last_error_file;
+}
+
+gint obt_xml_last_error_line(ObtXmlInst *inst)
+{
+ if (!obt_xml_last_error(inst))
+ return -1;
+ return inst->last_error_line;
+}
+
+gchar* obt_xml_last_error_message(ObtXmlInst *inst)
+{
+ if (!obt_xml_last_error(inst))
+ return NULL;
+ return inst->last_error_message;
+}
+
gboolean obt_xml_save_file(ObtXmlInst *inst,
const gchar *path,
gboolean pretty)
diff --git a/obt/xml.h b/obt/xml.h
index 831aba63..f6b5dc23 100644
--- a/obt/xml.h
+++ b/obt/xml.h
@@ -51,6 +51,12 @@ gboolean obt_xml_load_theme_file(ObtXmlInst *inst,
gboolean obt_xml_load_mem(ObtXmlInst *inst,
gpointer data, guint len, const gchar *root_node);
+/* Returns true if an error is present. */
+gboolean obt_xml_last_error(ObtXmlInst *inst);
+gchar* obt_xml_last_error_file(ObtXmlInst *inst);
+gint obt_xml_last_error_line(ObtXmlInst *inst);
+gchar* obt_xml_last_error_message(ObtXmlInst *inst);
+
gboolean obt_xml_save_file(ObtXmlInst *inst,
const gchar *path,
gboolean pretty);