Skip to content

Commit

Permalink
vendor: vendor_get_link_from_vendor() use wikipedia in some cases
Browse files Browse the repository at this point in the history
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 <pburt0@gmail.com>
  • Loading branch information
bp0 authored and lpereira committed Aug 15, 2019
1 parent 1e77715 commit d55a8f3
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions hardinfo/vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("<a href=\"%s%s\">%s</a>", prefix, v->url, v->name);
return g_strdup_printf("<a href=\"%s%s\">%s</a>", 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, ...) {
Expand Down

0 comments on commit d55a8f3

Please sign in to comment.