summaryrefslogtreecommitdiffstats
path: root/src/gs-vendor.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:18:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:18:46 +0000
commit56294d30a82ec2da6f9ce399740c1ef65a9ddef4 (patch)
treebbe3823e41495d026ba8edc6eeaef166edb7e2a2 /src/gs-vendor.c
parentInitial commit. (diff)
downloadgnome-software-56294d30a82ec2da6f9ce399740c1ef65a9ddef4.tar.xz
gnome-software-56294d30a82ec2da6f9ce399740c1ef65a9ddef4.zip
Adding upstream version 3.38.1.upstream/3.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/gs-vendor.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/gs-vendor.c b/src/gs-vendor.c
new file mode 100644
index 0000000..c87d7cd
--- /dev/null
+++ b/src/gs-vendor.c
@@ -0,0 +1,126 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2015 Kalev Lember <klember@redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "config.h"
+
+#include "gs-vendor.h"
+
+struct _GsVendor
+{
+ GObject parent_instance;
+
+ GKeyFile *file;
+};
+
+G_DEFINE_TYPE (GsVendor, gs_vendor, G_TYPE_OBJECT)
+
+#ifdef HAVE_PACKAGEKIT
+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";
+}
+#endif
+
+gchar *
+gs_vendor_get_not_found_url (GsVendor *vendor, GsVendorUrlType type)
+{
+#ifdef HAVE_PACKAGEKIT
+ const gchar *key;
+ gchar *url = NULL;
+
+ /* get data */
+ key = gs_vendor_type_to_string (type);
+ url = g_key_file_get_string (vendor->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->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;
+#else
+ return NULL;
+#endif
+}
+
+static void
+gs_vendor_init (GsVendor *vendor)
+{
+#ifdef HAVE_PACKAGEKIT
+ const gchar *fn = "/etc/PackageKit/Vendor.conf";
+ gboolean ret;
+
+ vendor->file = g_key_file_new ();
+ ret = g_key_file_load_from_file (vendor->file, fn, G_KEY_FILE_NONE, NULL);
+ if (!ret)
+ g_warning ("%s file not found", fn);
+#endif
+}
+
+static void
+gs_vendor_finalize (GObject *object)
+{
+ GsVendor *vendor = GS_VENDOR (object);
+
+ if (vendor->file != NULL)
+ g_key_file_free (vendor->file);
+
+ G_OBJECT_CLASS (gs_vendor_parent_class)->finalize (object);
+}
+
+static void
+gs_vendor_class_init (GsVendorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gs_vendor_finalize;
+}
+
+/**
+ * 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);
+}
+