[gupnp-tools] Add utility function for XML pretty-printing



commit e64714aac25d8aca201a8c8fd30673ba5be56435
Author: Jens Georg <mail jensge org>
Date:   Mon May 9 20:06:41 2011 +0200

    Add utility function for XML pretty-printing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655563

 src/av-cp/Makefile.am         |    2 +-
 src/av-cp/playlist-treeview.c |    9 ++++++-
 src/common/Makefile.am        |    8 ++++--
 src/common/pretty-print.c     |   51 +++++++++++++++++++++++++++++++++++++++++
 src/common/pretty-print.h     |    7 +++++
 src/network-light/Makefile.am |    2 +-
 src/universal-cp/Makefile.am  |    2 +-
 7 files changed, 74 insertions(+), 7 deletions(-)
---
diff --git a/src/av-cp/Makefile.am b/src/av-cp/Makefile.am
index 2cea3ff..4747ce7 100644
--- a/src/av-cp/Makefile.am
+++ b/src/av-cp/Makefile.am
@@ -24,7 +24,7 @@ gupnp_av_cp_SOURCES = main.c \
 		      renderer-combo.h \
 		      renderer-controls.h
 
-gupnp_av_cp_LDADD = ../common/libicons.a \
+gupnp_av_cp_LDADD = ../common/libutil.a \
 		    $(LIBGUPNP_LIBS) \
 		    $(LIBGUPNP_AV_LIBS) \
 		    $(GTK_LIBS) \
diff --git a/src/av-cp/playlist-treeview.c b/src/av-cp/playlist-treeview.c
index 253154d..f23f297 100644
--- a/src/av-cp/playlist-treeview.c
+++ b/src/av-cp/playlist-treeview.c
@@ -27,6 +27,7 @@
 #include "renderer-combo.h"
 #include "renderer-controls.h"
 #include "icons.h"
+#include "pretty-print.h"
 #include "gui.h"
 
 #define CONTENT_DIR "urn:schemas-upnp-org:service:ContentDirectory"
@@ -307,11 +308,17 @@ static void display_metadata (const char *metadata,
                               gpointer    user_data)
 {
         GtkTextBuffer *buffer;
+        char *formatted;
+
+        formatted = pretty_print_xml (metadata);
 
         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (didl_textview));
-        gtk_text_buffer_set_text (buffer, metadata, -1);
+        gtk_text_buffer_set_text (buffer, formatted, -1);
+        gtk_widget_show (GTK_WIDGET (didl_textview));
 
         gtk_dialog_run (GTK_DIALOG (didl_dialog));
+
+        g_free (formatted);
 }
 
 G_MODULE_EXPORT
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 52e4fee..2a764c1 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -7,9 +7,11 @@ endif
 AM_CFLAGS = $(LIBGUPNP_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir) \
 	    -DDATA_DIR='"$(shareddir)"' -I$(top_builddir)/src/common
 
-noinst_LIBRARIES = libicons.a
+noinst_LIBRARIES = libutil.a
 
-libicons_a_SOURCES = icons.c \
-		     icons.h
+libutil_a_SOURCES = icons.c \
+		    icons.h \
+		    pretty-print.c \
+		    pretty-print.h
 
 MAINTAINERCLEANFILES = Makefile.in
diff --git a/src/common/pretty-print.c b/src/common/pretty-print.c
new file mode 100644
index 0000000..0691ab8
--- /dev/null
+++ b/src/common/pretty-print.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Jens Georg <mail jensge org>
+ *
+ * Authors: Jens Georg <mail jensge org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "pretty-print.h"
+
+#include <libxml/xmlreader.h>
+
+#include <string.h>
+
+char *
+pretty_print_xml (const char *xml)
+{
+        xmlDocPtr doc;
+        int old_value;
+        char *text;
+        int length;
+
+        doc = xmlRecoverMemory (xml, strlen (xml));
+
+        if (!doc)
+                return NULL;
+
+        old_value = xmlIndentTreeOutput;
+        xmlIndentTreeOutput = 1;
+        xmlDocDumpFormatMemoryEnc (doc,
+                                   (xmlChar **) &text,
+                                   &length,
+                                   "UTF-8",
+                                   1);
+        xmlIndentTreeOutput = old_value;
+        xmlFreeDoc (doc);
+
+        return text;
+}
diff --git a/src/common/pretty-print.h b/src/common/pretty-print.h
new file mode 100644
index 0000000..336f854
--- /dev/null
+++ b/src/common/pretty-print.h
@@ -0,0 +1,7 @@
+#ifndef __GUPNP_TOOLS_PRETTY_PRINT_H
+#define __GUPNP_TOOLS_PRETTY_PRINT_H
+
+char *
+pretty_print_xml (const char *xml);
+
+#endif /* __GUPNP_TOOLS_PRETTY_PRINT_H */
diff --git a/src/network-light/Makefile.am b/src/network-light/Makefile.am
index 02869cd..7c1f066 100644
--- a/src/network-light/Makefile.am
+++ b/src/network-light/Makefile.am
@@ -20,7 +20,7 @@ gupnp_network_light_SOURCES = main.c \
 			      main.h \
 			      gui.h \
 			      upnp.h
-gupnp_network_light_LDADD = ../common/libicons.a $(LIBGUPNP_LIBS) $(GTK_LIBS) $(GTHREAD_LIBS) $(UUID_LIBS)
+gupnp_network_light_LDADD = ../common/libutil.a $(LIBGUPNP_LIBS) $(GTK_LIBS) $(GTHREAD_LIBS) $(UUID_LIBS)
 
 gupnp_network_light_LDFLAGS = -export-dynamic
 
diff --git a/src/universal-cp/Makefile.am b/src/universal-cp/Makefile.am
index 9f88662..e38d12b 100644
--- a/src/universal-cp/Makefile.am
+++ b/src/universal-cp/Makefile.am
@@ -22,7 +22,7 @@ gupnp_universal_cp_SOURCES = main.c \
 			     details-treeview.h \
 			     event-treeview.h \
 			     action-dialog.h
-gupnp_universal_cp_LDADD = ../common/libicons.a $(GTK_LIBS) $(LIBGUPNP_LIBS) $(GTHREAD_LIBS)
+gupnp_universal_cp_LDADD = ../common/libutil.a $(GTK_LIBS) $(LIBGUPNP_LIBS) $(GTHREAD_LIBS)
 gupnp_universal_cp_LDFLAGS = -export-dynamic
 
 if OS_WIN32



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]