[gnome-software] Load all AppStream files from /usr/share/app-info/xmls
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Load all AppStream files from /usr/share/app-info/xmls
- Date: Wed, 4 Sep 2013 13:35:25 +0000 (UTC)
commit a51eabb6102d9e461f25c9b08ff1439739839f33
Author: Richard Hughes <richard hughsie com>
Date: Wed Sep 4 09:54:37 2013 +0100
Load all AppStream files from /usr/share/app-info/xmls
This means we're (more) compatible with libappstream and the Ubuntu metadata.
contrib/gnome-software.spec.in | 3 +-
data/Makefile.am | 19 +++++----
src/plugins/gs-plugin-appstream.c | 83 ++++++++++++++++++++++++++-----------
3 files changed, 72 insertions(+), 33 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index cf63224..5119cb6 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -62,7 +62,8 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%{_datadir}/applications/gnome-software.desktop
%dir %{_datadir}/gnome-software
%{_datadir}/gnome-software/*.png
-%{_datadir}/gnome-software/*.gz
+%{_datadir}/app-info/xmls/*.gz
+%{_datadir}/app-info/icons/*.gz
%{_mandir}/man1/gnome-software.1.gz
%dir %{_libdir}/gs-plugins
%{_libdir}/gs-plugins/*.so
diff --git a/data/Makefile.am b/data/Makefile.am
index ea41ccd..eb368d1 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -15,20 +15,23 @@ appdatadir = $(datadir)/appdata
appdata_files = gnome-software.appdata.xml
if ENABLE_OFFLINE_APPSTREAM_DATA
-appstream.xml.gz:
- wget -N http://people.freedesktop.org/~hughsient/temp/appstream.xml.gz
-appstream-icons.tar.gz:
- wget -N http://people.freedesktop.org/~hughsient/temp/appstream-icons.tar.gz
+fedora-20.xml.gz:
+ wget -O fedora-20.xml.gz http://people.freedesktop.org/~hughsient/temp/appstream.xml.gz
+fedora-20.tar.gz:
+ wget -O fedora-20.tar.gz http://people.freedesktop.org/~hughsient/temp/appstream-icons.tar.gz
-appstreamdir = $(datadir)/gnome-software
-dist_appstream_DATA = appstream.xml.gz appstream-icons.tar.gz
+appstreamxmldir = $(datadir)/app-info/xmls
+dist_appstreamxml_DATA = fedora-20.xml.gz
+appstreamiconsdir = $(datadir)/app-info/icons
+dist_appstreamicons_DATA = fedora-20.tar.gz
+endif
EXTRA_DIST = \
$(appdata_files)
-endif
CLEANFILES = \
- $(dist_appstream_DATA)
+ $(dist_appstreamxml_DATA) \
+ $(dist_appstreamicons_DATA)
MAINTAINERCLEANFILES = \
*~ \
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 104a95f..cd4d443 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -134,7 +134,7 @@ gs_plugin_decompress_icons (GsPlugin *plugin, GError **error)
/* decompress */
argv[0] = "tar";
argv[1] = "-zxvf";
- argv[2] = DATADIR "/gnome-software/appstream-icons.tar.gz";
+ argv[2] = DATADIR "/app-info/icons/fedora-20.tar.gz";
argv[3] = "-C";
argv[4] = plugin->priv->cachedir;
argv[5] = NULL;
@@ -494,19 +494,23 @@ gs_appstream_text_cb (GMarkupParseContext *context,
}
/**
- * gs_plugin_parse_xml:
+ * gs_plugin_parse_xml_file:
*/
static gboolean
-gs_plugin_parse_xml (GsPlugin *plugin, GError **error)
+gs_plugin_parse_xml_file (GsPlugin *plugin,
+ const gchar *parent_dir,
+ const gchar *filename,
+ GError **error)
{
- gboolean ret;
- GMarkupParseContext *ctx;
- gchar *data;
- gssize len;
+ gboolean ret = TRUE;
+ gchar *data = NULL;
+ gchar *path;
+ GConverter *converter = NULL;
GFile *file;
- GConverter *converter;
+ GInputStream *converter_stream = NULL;
GInputStream *file_stream;
- GInputStream *converter_stream;
+ GMarkupParseContext *ctx = NULL;
+ gssize len;
const GMarkupParser parser = {
gs_appstream_start_element_cb,
gs_appstream_end_element_cb,
@@ -514,43 +518,74 @@ gs_plugin_parse_xml (GsPlugin *plugin, GError **error)
NULL /* passthrough */,
NULL /* error */ };
- file = g_file_new_for_path (DATADIR "/gnome-software/appstream.xml.gz");
+ path = g_build_filename (parent_dir, filename, NULL);
+ file = g_file_new_for_path (path);
file_stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
- g_object_unref (file);
- if (!file_stream)
- return FALSE;
-
+ if (file_stream == NULL) {
+ ret = FALSE;
+ goto out;
+ }
converter = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
converter_stream = g_converter_input_stream_new (file_stream, converter);
-
ctx = g_markup_parse_context_new (&parser,
G_MARKUP_PREFIX_ERROR_POSITION,
plugin,
NULL);
-
- ret = TRUE;
data = g_malloc (32 * 1024);
while ((len = g_input_stream_read (converter_stream, data, 32 * 1024, NULL, error)) > 0) {
ret = g_markup_parse_context_parse (ctx, data, len, error);
if (!ret)
goto out;
}
-
if (len < 0)
ret = FALSE;
-
- out:
- /* Reset in case we failed parsing */
+out:
+ /* reset in case we failed parsing */
if (plugin->priv->item_temp) {
gs_appstream_item_free (plugin->priv->item_temp);
plugin->priv->item_temp = NULL;
}
- g_markup_parse_context_free (ctx);
g_free (data);
- g_object_unref (converter_stream);
+ g_free (path);
+ if (ctx != NULL)
+ g_markup_parse_context_free (ctx);
+ if (converter_stream != NULL)
+ g_object_unref (converter_stream);
+ if (converter != NULL)
+ g_object_unref (converter);
+ g_object_unref (file);
g_object_unref (file_stream);
- g_object_unref (converter);
+ return ret;
+}
+
+/**
+ * gs_plugin_parse_xml:
+ */
+static gboolean
+gs_plugin_parse_xml (GsPlugin *plugin, GError **error)
+{
+ GDir *dir;
+ gchar *parent_dir;
+ const gchar *tmp;
+ gboolean ret = TRUE;
+
+ /* search all files */
+ parent_dir = g_build_filename (DATADIR, "app-info", "xmls", NULL);
+ dir = g_dir_open (parent_dir, 0, error);
+ if (dir == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+ while ((tmp = g_dir_read_name (dir)) != NULL) {
+ ret = gs_plugin_parse_xml_file (plugin, parent_dir, tmp, error);
+ if (!ret)
+ goto out;
+ }
+out:
+ g_free (parent_dir);
+ if (dir != NULL)
+ g_dir_close (dir);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]