[virt-tools-list] [libosinfo 2/3] API for getting product logo URLs

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Sat Feb 11 04:30:50 UTC 2012


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

While we'll most probably not be able to ship any product logos for legal
reasons, this patch still adds infra to easily be able to do so.
---
 configure.ac            |    1 +
 data/Makefile.am        |    2 +-
 data/icons/Makefile.am  |    3 +++
 osinfo/Makefile.am      |    3 ++-
 osinfo/libosinfo.syms   |    5 +++++
 osinfo/osinfo_loader.c  |   17 +++++++++++++++++
 osinfo/osinfo_product.c |   25 +++++++++++++++++++++++++
 osinfo/osinfo_product.h |    2 ++
 8 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 data/icons/Makefile.am

diff --git a/configure.ac b/configure.ac
index a5aec10..8dd472a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -156,6 +156,7 @@ AC_CONFIG_FILES([
 	data/devices/Makefile
 	data/hypervisors/Makefile
 	data/oses/Makefile
+	data/icons/Makefile
 	tools/Makefile
 	scripts/Makefile
 	test/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 28dbf5a..6f1aa93 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,5 +1,5 @@
 
-SUBDIRS = devices oses hypervisors
+SUBDIRS = devices oses hypervisors icons
 
 EXTRA_DIST = usb.ids pci.ids 95-osinfo.rules.in
 
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
new file mode 100644
index 0000000..3c2188a
--- /dev/null
+++ b/data/icons/Makefile.am
@@ -0,0 +1,3 @@
+imagesdir = $(pkgdatadir)/pixmaps
+images_DATA =               \
+        $(NULL)
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 4bf12ed..acb16e7 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -28,7 +28,8 @@ libosinfo_1_0_la_CFLAGS = \
 	$(LIBXML_CFLAGS) \
 	$(GOBJECT_CFLAGS) \
 	$(GIO_CFLAGS) \
-	-DDATA_DIR='"$(pkgdatadir)/data"'
+	-DDATA_DIR='"$(pkgdatadir)/data"' \
+	-DICON_DIR='"$(pkgdatadir)/pixmaps"'
 
 libosinfo_1_0_la_LDFLAGS = \
 	$(COVERAGE_LDFLAGS) \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 61893e4..57fed9e 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -201,6 +201,11 @@ LIBOSINFO_0.0.6 {
 	osinfo_os_get_devices_by_property;
 } LIBOSINFO_0.0.5;
 
+LIBOSINFO_0.1.1 {
+    global:
+	osinfo_product_get_logo;
+} LIBOSINFO_0.0.6;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 130472a..029cda8 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -31,6 +31,7 @@
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
 #include <libxml/xmlreader.h>
+#include <libxml/uri.h>
 
 G_DEFINE_TYPE (OsinfoLoader, osinfo_loader, G_TYPE_OBJECT);
 
@@ -369,14 +370,30 @@ static void osinfo_loader_product(OsinfoLoader *loader,
         OSINFO_PRODUCT_PROP_NAME,
         OSINFO_PRODUCT_PROP_VENDOR,
         OSINFO_PRODUCT_PROP_VERSION,
+        OSINFO_PRODUCT_PROP_LOGO,
         OSINFO_PRODUCT_PROP_SHORT_ID,
         NULL,
     };
+    const gchar *logo;
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(product), keys, ctxt, root, err);
     if (error_is_set(err))
         return;
 
+    logo = osinfo_product_get_logo (product);
+    if (logo != NULL && strstr(logo, "://") == NULL) {
+            gchar *path;
+            GFile *file;
+
+            path = g_build_filename(ICON_DIR, logo, NULL);
+            file = g_file_new_for_path(path);
+
+            osinfo_entity_set_param(OSINFO_ENTITY(product),
+                                    OSINFO_PRODUCT_PROP_LOGO,
+                                    g_file_get_uri(file));
+            g_object_unref(file);
+            g_free(path);
+    }
 
     osinfo_loader_product_relshp(loader, product,
                                  OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM,
diff --git a/osinfo/osinfo_product.c b/osinfo/osinfo_product.c
index 0b57c90..0d9afff 100644
--- a/osinfo/osinfo_product.c
+++ b/osinfo/osinfo_product.c
@@ -70,6 +70,7 @@ enum {
     PROP_SHORT_ID,
     PROP_VENDOR,
     PROP_VERSION,
+    PROP_LOGO,
 };
 
 static void osinfo_product_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
@@ -121,6 +122,11 @@ osinfo_product_get_property (GObject    *object,
                             osinfo_product_get_version (product));
         break;
 
+    case PROP_LOGO:
+        g_value_set_string (value,
+                            osinfo_product_get_logo (product));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -198,6 +204,21 @@ osinfo_product_class_init (OsinfoProductClass *klass)
                                  G_PARAM_STATIC_NICK |
                                  G_PARAM_STATIC_BLURB);
     g_object_class_install_property (g_klass, PROP_VERSION, pspec);
+
+    /**
+     * OsinfoProduct::logo:
+     *
+     * The URI of the logo of the product.
+     */
+    pspec = g_param_spec_string ("logo",
+                                 "Logo",
+                                 "URI of the logo",
+                                 NULL /* default value */,
+                                 G_PARAM_READABLE |
+                                 G_PARAM_STATIC_NAME |
+                                 G_PARAM_STATIC_NICK |
+                                 G_PARAM_STATIC_BLURB);
+    g_object_class_install_property (g_klass, PROP_LOGO, pspec);
 }
 
 static void
@@ -271,6 +292,10 @@ const gchar *osinfo_product_get_version(OsinfoProduct *prod)
 {
     return osinfo_entity_get_param_value(OSINFO_ENTITY(prod), OSINFO_PRODUCT_PROP_VERSION);
 }
+const gchar *osinfo_product_get_logo(OsinfoProduct *prod)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(prod), OSINFO_PRODUCT_PROP_LOGO);
+}
 const gchar *osinfo_product_get_short_id(OsinfoProduct *prod)
 {
     return osinfo_entity_get_param_value(OSINFO_ENTITY(prod), OSINFO_PRODUCT_PROP_SHORT_ID);
diff --git a/osinfo/osinfo_product.h b/osinfo/osinfo_product.h
index b06ffe0..ce3f4de 100644
--- a/osinfo/osinfo_product.h
+++ b/osinfo/osinfo_product.h
@@ -46,6 +46,7 @@ typedef struct _OsinfoProductPrivate OsinfoProductPrivate;
 
 #define OSINFO_PRODUCT_PROP_VENDOR   "vendor"
 #define OSINFO_PRODUCT_PROP_VERSION  "version"
+#define OSINFO_PRODUCT_PROP_LOGO     "logo"
 #define OSINFO_PRODUCT_PROP_SHORT_ID "short-id"
 #define OSINFO_PRODUCT_PROP_NAME     "name"
 
@@ -83,6 +84,7 @@ void osinfo_product_add_related(OsinfoProduct *product, OsinfoProductRelationshi
 
 const gchar *osinfo_product_get_vendor(OsinfoProduct *prod);
 const gchar *osinfo_product_get_version(OsinfoProduct *prod);
+const gchar *osinfo_product_get_logo(OsinfoProduct *prod);
 const gchar *osinfo_product_get_short_id(OsinfoProduct *prod);
 const gchar *osinfo_product_get_name(OsinfoProduct *prod);
 
-- 
1.7.7.6




More information about the virt-tools-list mailing list