[gnome-software] Support the per-repo icon directories
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Support the per-repo icon directories
- Date: Mon, 30 Sep 2013 15:36:02 +0000 (UTC)
commit 6f0b279f5d2ba40c9b4fa55dee7be1bda5f50f50
Author: Richard Hughes <richard hughsie com>
Date: Mon Sep 30 16:20:08 2013 +0100
Support the per-repo icon directories
This is needed for two reasons:
* Different repos may want to ship different versions of the same application.
* If we install things to /var/cache/app-info/icons then we need to be able to
clean them up easily as they are not under the package manager control.
You can use old or new icon metadata styles as gnome-software will detect both
kinds at runtime. You can't mix metadata styles tho. Pick one or the other!
contrib/gnome-software.spec.in | 6 ++--
data/Makefile.am | 6 ++--
src/plugins/gs-plugin-appstream.c | 70 ++++++++++++++++++++++++++++++++-----
3 files changed, 67 insertions(+), 15 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index 882c8f1..2697738 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -45,8 +45,8 @@ make %{?_smp_mflags}
%__cp %{SOURCE1} %{buildroot}%{_datadir}/app-info/xmls
# decompress and install AppStream icons
-%__mkdir_p %{buildroot}%{_datadir}/app-info/icons
-cd %{buildroot}%{_datadir}/app-info/icons
+%__mkdir_p %{buildroot}%{_datadir}/app-info/icons/fedora-20
+cd %{buildroot}%{_datadir}/app-info/icons/fedora-20
%__tar xvzf %{SOURCE2}
cd -
@@ -77,7 +77,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%{_datadir}/gnome-software/*.png
%{_datadir}/appdata/*.appdata.xml
%{_datadir}/app-info/xmls/*.gz
-%{_datadir}/app-info/icons/*.png
+%{_datadir}/app-info/icons/fedora-20/*.png
%{_mandir}/man1/gnome-software.1.gz
%{_datadir}/icons/hicolor/*/apps/*
%{_datadir}/gnome-software/featured.ini
diff --git a/data/Makefile.am b/data/Makefile.am
index d0a4446..1bebd6c 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -28,9 +28,9 @@ install-sample-data:
mkdir -p $(DESTDIR)$(datadir)/app-info/xmls; \
cp fedora-20.xml.gz $(DESTDIR)$(datadir)/app-info/xmls/; \
wget -O fedora-20-icons.tar.gz http://people.freedesktop.org/~hughsient/temp/fedora-20-icons.tar.gz; \
- mkdir -p $(DESTDIR)$(datadir)/app-info/icons; \
- cp fedora-20-icons.tar.gz $(DESTDIR)$(datadir)/app-info/icons; \
- cd $(DESTDIR)$(datadir)/app-info/icons; \
+ mkdir -p $(DESTDIR)$(datadir)/app-info/icons/fedora-20; \
+ cp fedora-20-icons.tar.gz $(DESTDIR)$(datadir)/app-info/icons/fedora-20; \
+ cd $(DESTDIR)$(datadir)/app-info/icons/fedora-20; \
tar xvzf fedora-20-icons.tar.gz &> /dev/null; \
rm fedora-20-icons.tar.gz; \
cd -
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 7275cde..48efcc2 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -44,6 +44,25 @@ gs_plugin_get_name (void)
}
/**
+ * gs_plugin_appstream_icons_are_new_layout:
+ */
+static gboolean
+gs_plugin_appstream_icons_are_new_layout (const gchar *dirname)
+{
+ GDir *dir;
+ const gchar *tmp;
+ gboolean ret;
+
+ /* simply test if the first item is a file and if not, the icons are
+ * in the new /var/cache/app-info/icons/${repo}/gimp.png layout */
+ dir = g_dir_open (dirname, 0, NULL);
+ tmp = g_dir_read_name (dir);
+ ret = g_strstr_len (tmp, -1, ".") == NULL;
+ g_dir_close (dir);
+ return ret;
+}
+
+/**
* gs_plugin_parse_xml_file:
*/
static gboolean
@@ -53,24 +72,57 @@ gs_plugin_parse_xml_file (GsPlugin *plugin,
const gchar *path_icons,
GError **error)
{
- gboolean ret;
- gchar *path;
- GFile *file;
+ GFile *file = NULL;
+ gboolean ret = FALSE;
+ gchar *path_icons_full = NULL;
+ gchar *path_xml = NULL;
+ gchar *repo_id;
+ gchar *tmp;
+
+ /* the first component of the file (e.g. "fedora-20.xml.gz)
+ * is used for the icon directory as we might want to clean up
+ * the icons manually if they are installed in /var/cache */
+ repo_id = g_strdup (filename);
+ tmp = g_strstr_len (repo_id, -1, ".xml");
+ if (tmp == NULL) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "AppStream metadata name %s/%s not valid, "
+ "expected .xml[.*]",
+ parent_dir, filename);
+ goto out;
+ }
+ tmp[0] = '\0';
+
+ /* support both old and new layouts */
+ if (gs_plugin_appstream_icons_are_new_layout (path_icons)) {
+ path_icons_full = g_build_filename (path_icons,
+ repo_id,
+ NULL);
+ } else {
+ path_icons_full = g_strdup (path_icons);
+ }
/* load this specific file */
- path = g_build_filename (parent_dir, filename, NULL);
- g_debug ("Loading AppStream XML %s with icon path %s", path, path_icons);
- file = g_file_new_for_path (path);
+ path_xml = g_build_filename (parent_dir, filename, NULL);
+ g_debug ("Loading AppStream XML %s with icon path %s",
+ path_xml,
+ path_icons_full);
+ file = g_file_new_for_path (path_xml);
ret = appstream_cache_parse_file (plugin->priv->cache,
file,
- path_icons,
+ path_icons_full,
NULL,
error);
if (!ret)
goto out;
out:
- g_free (path);
- g_object_unref (file);
+ g_free (path_icons_full);
+ g_free (path_xml);
+ g_free (repo_id);
+ if (file != NULL)
+ g_object_unref (file);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]