diff options
Diffstat (limited to 'src/themes/standard')
-rw-r--r-- | src/themes/standard/Makefile.am | 4 | ||||
-rw-r--r-- | src/themes/standard/theme.c | 59 |
2 files changed, 56 insertions, 7 deletions
diff --git a/src/themes/standard/Makefile.am b/src/themes/standard/Makefile.am index 7f82f54..42476a4 100644 --- a/src/themes/standard/Makefile.am +++ b/src/themes/standard/Makefile.am @@ -5,8 +5,8 @@ engine_LTLIBRARIES = libstandard.la libstandard_la_SOURCES = theme.c libstandard_la_CFLAGS = $(WARN_CFLAGS) libstandard_la_LDFLAGS = -module -avoid-version -no-undefined -libstandard_la_LIBADD = $(NOTIFICATION_DAEMON_LIBS) +libstandard_la_LIBADD = $(NOTIFICATION_DAEMON_LIBS) $(THEME_LIBS) -AM_CPPFLAGS = $(NOTIFICATION_DAEMON_CFLAGS) +AM_CPPFLAGS = $(NOTIFICATION_DAEMON_CFLAGS) $(THEME_CFLAGS) -include $(top_srcdir)/git.mk diff --git a/src/themes/standard/theme.c b/src/themes/standard/theme.c index c81ac34..4ab72de 100644 --- a/src/themes/standard/theme.c +++ b/src/themes/standard/theme.c @@ -24,6 +24,8 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> +#include <libxml/xpath.h> + typedef void (*ActionInvokedCb) (GtkWindow* nw, const char* key); typedef void (*UrlClickedCb) (GtkWindow* nw, const char* url); @@ -844,7 +846,6 @@ void set_notification_text(GtkWindow* nw, const char* summary, const char* body) { char* str; char* quoted; - const char *body_label_text; GtkRequisition req; WindowData* windata; @@ -858,10 +859,58 @@ void set_notification_text(GtkWindow* nw, const char* summary, const char* body) gtk_label_set_markup(GTK_LABEL(windata->summary_label), str); g_free(str); - gtk_label_set_markup (GTK_LABEL (windata->body_label), body); - body_label_text = gtk_label_get_text (GTK_LABEL (windata->body_label)); - if ((body_label_text == NULL) || (strlen (body_label_text) == 0)) - gtk_label_set_text (GTK_LABEL (windata->body_label), body); + /* body */ + xmlDocPtr doc; + xmlInitParser(); + str = g_strconcat ("<markup>", body, "</markup>", NULL); + /* parse notification body */ + doc = xmlReadMemory(str, strlen (str), "noname.xml", NULL, 0); + g_free (str); + if (doc != NULL) { + xmlXPathContextPtr xpathCtx; + xmlXPathObjectPtr xpathObj; + xmlNodeSetPtr nodes; + const char *body_label_text; + int i, size; + + /* filterout img nodes */ + xpathCtx = xmlXPathNewContext(doc); + xpathObj = xmlXPathEvalExpression((unsigned char *)"//img", xpathCtx); + nodes = xpathObj->nodesetval; + size = (nodes) ? nodes->nodeNr : 0; + for(i = size - 1; i >= 0; i--) { + xmlUnlinkNode (nodes->nodeTab[i]); + xmlFreeNode (nodes->nodeTab[i]); + } + + /* write doc to string */ + xmlBufferPtr buf = xmlBufferCreate(); + (void) xmlNodeDump(buf, doc, xmlDocGetRootElement (doc), 0, 0); + str = (char *)buf->content; + gtk_label_set_markup (GTK_LABEL (windata->body_label), str); + + /* cleanup */ + xmlBufferFree (buf); + xmlXPathFreeObject (xpathObj); + xmlXPathFreeContext (xpathCtx); + xmlFreeDoc (doc); + + /* Does it render properly? */ + body_label_text = gtk_label_get_text (GTK_LABEL (windata->body_label)); + if ((body_label_text == NULL) || (strlen (body_label_text) == 0)) { + goto render_fail; + } + goto renrer_ok; + } + +render_fail: + /* could not parse notification body */ + quoted = g_markup_escape_text(body, -1); + gtk_label_set_markup (GTK_LABEL (windata->body_label), quoted); + g_free (quoted); + +renrer_ok: + xmlCleanupParser (); if (body == NULL || *body == '\0') gtk_widget_hide(windata->body_label); |