diff options
| author | Dana Jansens <danakj@orodu.net> | 2013-08-10 20:46:27 -0400 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2013-08-10 21:59:12 -0400 |
| commit | 4e6c0086a657399d989f2e4849f7b397d7d4efbc (patch) | |
| tree | 64cb34f3a3ee63df40443e39661c33a060953860 /obt/xml.c | |
| parent | a5eb363f48b75b6eae0a1dc4a6c8e079c9831f92 (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/xml.c')
| -rw-r--r-- | obt/xml.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -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) |
