From d55a8f33188eb35e918d5c6c355d686867315337 Mon Sep 17 00:00:00 2001 From: Burt P Date: Sun, 11 Aug 2019 14:20:53 -0500 Subject: vendor: vendor_get_link_from_vendor() use wikipedia in some cases Some vendors, like those defunct, may not have url, but may have a wikipedia article. Use wikipedia in the link in those cases. Also, Wikipedia offers more information than the vendor's site in most cases, and has the vendor's url right there in the sidebar to click, if desired. I think using wikipedia for links is prefereable, but this could be turned off by setting link_wikipedia to FALSE. Signed-off-by: Burt P --- hardinfo/vendor.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'hardinfo/vendor.c') diff --git a/hardinfo/vendor.c b/hardinfo/vendor.c index 88b7397d..fa3b4d96 100644 --- a/hardinfo/vendor.c +++ b/hardinfo/vendor.c @@ -422,33 +422,47 @@ gchar *vendor_get_link(const gchar *id_str) gchar *vendor_get_link_from_vendor(const Vendor *v) { - gboolean label_link_ok = FALSE; #if GTK_CHECK_VERSION(2, 18, 0) - label_link_ok = TRUE; + gboolean gtk_label_link_ok = TRUE; +#else + gboolean gtk_label_link_ok = FALSE; #endif + gboolean link_ok = params.markup_ok && gtk_label_link_ok; + /* If using a real link, and wikipedia is available, + * target that instead of url. There's usually much more + * information there, plus easily click through to company url. */ + gboolean link_wikipedia = TRUE; - if (!v) { + if (!v) return g_strdup(_("Unknown")); - } - if (!v->url) { + gchar *url = NULL; + + if (link_ok && link_wikipedia && v->wikipedia + || v->wikipedia && !v->url) + url = g_strdup_printf("http://wikipedia.com/wiki/%s", v->wikipedia); + else if (v->url) + url = g_strdup(v->url); + + if (!url) return g_strdup(v->name); - } - if (params.markup_ok && label_link_ok) { + auto_free(url); + + if (link_ok) { const gchar *prefix; - if (!strncmp(v->url, "http://", sizeof("http://") - 1) || - !strncmp(v->url, "https://", sizeof("https://") - 1)) { + if (!strncmp(url, "http://", sizeof("http://") - 1) || + !strncmp(url, "https://", sizeof("https://") - 1)) { prefix = ""; } else { prefix = "http://"; } - return g_strdup_printf("%s", prefix, v->url, v->name); + return g_strdup_printf("%s", prefix, url, v->name); } - return g_strdup_printf("%s (%s)", v->name, v->url); + return g_strdup_printf("%s (%s)", v->name, url); } vendor_list vendor_list_concat_va(int count, vendor_list vl, ...) { -- cgit v1.2.3