[gnome-software] Port GpkVendor code for parsing /etc/PackageKit/Vendor.conf



commit 4c70d1abcb9c9177224458f50ee0aa36885e49a6
Author: Kalev Lember <kalevlember gmail com>
Date:   Mon Feb 16 11:10:18 2015 +0100

    Port GpkVendor code for parsing /etc/PackageKit/Vendor.conf
    
    No other changes besides simple search-and-replace Gpk -> Gs.

 src/Makefile.am |    2 +
 src/gs-vendor.c |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-vendor.h |   67 +++++++++++++++++++++++
 3 files changed, 227 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b27988b..91883ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -155,6 +155,8 @@ gnome_software_SOURCES =                            \
        gs-update-list.h                                \
        gs-update-monitor.c                             \
        gs-update-monitor.h                             \
+       gs-vendor.c                                     \
+       gs-vendor.h                                     \
        gs-proxy-settings.c                             \
        gs-proxy-settings.h                             \
        gs-offline-updates.c                            \
diff --git a/src/gs-vendor.c b/src/gs-vendor.c
new file mode 100644
index 0000000..f279a3c
--- /dev/null
+++ b/src/gs-vendor.c
@@ -0,0 +1,158 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gs-vendor.h"
+
+static void     gs_vendor_finalize     (GObject          *object);
+
+#define GS_VENDOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GS_TYPE_VENDOR, GsVendorPrivate))
+
+struct GsVendorPrivate
+{
+       GKeyFile                         *file;
+};
+
+G_DEFINE_TYPE (GsVendor, gs_vendor, G_TYPE_OBJECT)
+
+/**
+ * gs_vendor_class_init:
+ * @klass: The GsVendorClass
+ **/
+static void
+gs_vendor_class_init (GsVendorClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       object_class->finalize = gs_vendor_finalize;
+       g_type_class_add_private (klass, sizeof (GsVendorPrivate));
+}
+
+/**
+ * gs_vendor_type_to_string:
+ **/
+static const gchar *
+gs_vendor_type_to_string (GsVendorUrlType type)
+{
+       if (type == GS_VENDOR_URL_TYPE_CODEC)
+               return "CodecUrl";
+       if (type == GS_VENDOR_URL_TYPE_FONT)
+               return "FontUrl";
+       if (type == GS_VENDOR_URL_TYPE_MIME)
+               return "MimeUrl";
+       if (type == GS_VENDOR_URL_TYPE_HARDWARE)
+               return "HardwareUrl";
+       return "DefaultUrl";
+}
+
+/**
+ * gs_vendor_get_not_found_url:
+ **/
+gchar *
+gs_vendor_get_not_found_url (GsVendor *vendor, GsVendorUrlType type)
+{
+       const gchar *key;
+       gchar *url = NULL;
+
+       /* get data */
+       key = gs_vendor_type_to_string (type);
+       url = g_key_file_get_string (vendor->priv->file, "PackagesNotFound", key, NULL);
+
+       /* none is a special value */
+       if (g_strcmp0 (url, "none") == 0) {
+               g_free (url);
+               url = NULL;
+       }
+
+       /* got a valid URL */
+       if (url != NULL)
+               goto out;
+
+       /* default has no fallback */
+       if (type == GS_VENDOR_URL_TYPE_DEFAULT)
+               goto out;
+
+       /* get fallback data */
+       g_debug ("using fallback");
+       key = gs_vendor_type_to_string (GS_VENDOR_URL_TYPE_DEFAULT);
+       url = g_key_file_get_string (vendor->priv->file, "PackagesNotFound", key, NULL);
+
+       /* none is a special value */
+       if (g_strcmp0 (url, "none") == 0) {
+               g_free (url);
+               url = NULL;
+       }
+out:
+       g_debug ("url=%s", url);
+       return url;
+}
+
+/**
+ * gs_vendor_init:
+ * @vendor: This class instance
+ **/
+static void
+gs_vendor_init (GsVendor *vendor)
+{
+       gboolean ret;
+
+       vendor->priv = GS_VENDOR_GET_PRIVATE (vendor);
+
+       vendor->priv->file = g_key_file_new ();
+       ret = g_key_file_load_from_file (vendor->priv->file, "/etc/PackageKit/Vendor.conf", G_KEY_FILE_NONE, 
NULL);
+       if (!ret)
+               g_warning ("file not found");
+}
+
+/**
+ * gs_vendor_finalize:
+ * @object: The object to finalize
+ **/
+static void
+gs_vendor_finalize (GObject *object)
+{
+       GsVendor *vendor;
+
+       g_return_if_fail (PK_IS_VENDOR (object));
+
+       vendor = GS_VENDOR (object);
+       g_return_if_fail (vendor->priv != NULL);
+
+       g_key_file_free (vendor->priv->file);
+
+       G_OBJECT_CLASS (gs_vendor_parent_class)->finalize (object);
+}
+
+/**
+ * gs_vendor_new:
+ *
+ * Return value: a new GsVendor object.
+ **/
+GsVendor *
+gs_vendor_new (void)
+{
+       GsVendor *vendor;
+       vendor = g_object_new (GS_TYPE_VENDOR, NULL);
+       return GS_VENDOR (vendor);
+}
+
diff --git a/src/gs-vendor.h b/src/gs-vendor.h
new file mode 100644
index 0000000..47c3e8e
--- /dev/null
+++ b/src/gs-vendor.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ */
+
+#ifndef __GS_VENDOR_H
+#define __GS_VENDOR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_VENDOR         (gs_vendor_get_type ())
+#define GS_VENDOR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GS_TYPE_VENDOR, GsVendor))
+#define GS_VENDOR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GS_TYPE_VENDOR, GsVendorClass))
+#define PK_IS_VENDOR(o)                (G_TYPE_CHECK_INSTANCE_TYPE ((o), GS_TYPE_VENDOR))
+#define PK_IS_VENDOR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GS_TYPE_VENDOR))
+#define GS_VENDOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GS_TYPE_VENDOR, GsVendorClass))
+#define GS_VENDOR_ERROR                (gs_vendor_error_quark ())
+#define GS_VENDOR_TYPE_ERROR   (gs_vendor_error_get_type ())
+
+typedef struct GsVendorPrivate GsVendorPrivate;
+
+typedef struct
+{
+        GObject                 parent;
+        GsVendorPrivate        *priv;
+} GsVendor;
+
+typedef struct
+{
+       GObjectClass    parent_class;
+} GsVendorClass;
+
+typedef enum
+{
+       GS_VENDOR_URL_TYPE_CODEC,
+       GS_VENDOR_URL_TYPE_FONT,
+       GS_VENDOR_URL_TYPE_MIME,
+       GS_VENDOR_URL_TYPE_HARDWARE,
+       GS_VENDOR_URL_TYPE_DEFAULT
+} GsVendorUrlType;
+
+GType           gs_vendor_get_type                     (void);
+GsVendor       *gs_vendor_new                          (void);
+gchar          *gs_vendor_get_not_found_url            (GsVendor               *vendor,
+                                                        GsVendorUrlType         type);
+
+G_END_DECLS
+
+#endif /* __GS_VENDOR_H */


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