diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-04 14:51:11 -0300 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-04 14:51:11 -0300 | 
| commit | a67822f88fd8c67fbc49a1510669647d490e6ee0 (patch) | |
| tree | 063b9b6d6cda83f5367ad6a13d3101d23afe0da3 /hardinfo2 | |
| parent | 24d285d8dce5c51c708580bc01a563beba91bea3 (diff) | |
Make vendor list updatable
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/autopackage/default.apspec | 6 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.c | 4 | ||||
| -rw-r--r-- | hardinfo2/syncmanager.c | 2 | ||||
| -rw-r--r-- | hardinfo2/vendor.c | 92 | ||||
| -rw-r--r-- | hardinfo2/vendor.h | 2 | 
5 files changed, 91 insertions, 15 deletions
| diff --git a/hardinfo2/autopackage/default.apspec b/hardinfo2/autopackage/default.apspec index a1c0bbbe..2aea83a7 100644 --- a/hardinfo2/autopackage/default.apspec +++ b/hardinfo2/autopackage/default.apspec @@ -2,9 +2,9 @@  # Generated by mkapspec 0.2  [Meta]  ShortName: hardinfo -SoftwareVersion: 0.4.3-beta2 -DisplayName: HardInfo $SOFTWAREVERSION -RootName: @tia.mat.br/hardinfo:$SOFTWAREVERSION +SoftwareVersion: 0.5 +DisplayName: HardInfo +RootName: @hardinfo.org/hardinfo:$SOFTWAREVERSION  Summary: System profiler and benchmark tool  Maintainer: Leandro A. F. Pereira <leandro@hardinfo.org>  Packager: Leandro A. F. Pereira <leandro@hardinfo.org> diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index fedadc26..651a39e0 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -23,6 +23,7 @@  #include <hardinfo.h>  #include <iconcache.h>  #include <stock.h> +#include <vendor.h>  #include <binreloc.h> @@ -110,6 +111,9 @@ int main(int argc, char **argv)  	modules = modules_load_all();      } +    /* initialize vendor database */ +    vendor_init(); +      if (params.gui_running) {  	/* initialize gui and start gtk+ main loop */  	icon_cache_init(); diff --git a/hardinfo2/syncmanager.c b/hardinfo2/syncmanager.c index 12b0465e..d39d506b 100644 --- a/hardinfo2/syncmanager.c +++ b/hardinfo2/syncmanager.c @@ -107,7 +107,7 @@ void sync_manager_add_entry(SyncEntry * entry)      DEBUG("registering syncmanager entry ''%s''", entry->fancy_name);      entry->selected = TRUE; -    entries = g_slist_prepend(entries, entry); +    entries = g_slist_append(entries, entry);  #else      DEBUG("libsoup support is disabled.");  #endif				/* HAS_LIBSOUP */ diff --git a/hardinfo2/vendor.c b/hardinfo2/vendor.c index 6cfb8ee6..4a1a41a1 100644 --- a/hardinfo2/vendor.c +++ b/hardinfo2/vendor.c @@ -20,7 +20,11 @@  #include <string.h>  #include <gtk/gtk.h> +  #include "vendor.h" +#include "syncmanager.h" +#include "config.h" +#include "hardinfo.h"  static const Vendor vendors[] = {      {"ATI", "ATI Technologies", "www.ati.com"}, @@ -80,24 +84,88 @@ static const Vendor vendors[] = {      {"Vimicro", "Vimicro", "www.vimicro.com"},      {"OTi", "Ours Technology", "www.oti.com.tw"},      {"BENQ", "BenQ", "www.benq.com"}, -    // BIOS manufacturers +    /* BIOS manufacturers */      {"American Megatrends", "American Megatrends", "www.ami.com"},      {"Award", "Award Software International", "www.award-bios.com"},      {"Phoenix", "Phoenix Technologies", "www.phoenix.com"}, -    {NULL, NULL, NULL},  }; +static GSList *vendor_list = NULL; + +void vendor_init(void) +{ +    gint i; +    gchar *path; +    static SyncEntry se = { +       .fancy_name = "Update vendor list", +       .name = "RecvVendorList", +       .save_to = "vendor.conf", +       .get_data = NULL +    }; + +    DEBUG("initializing vendor list"); +    sync_manager_add_entry(&se); +     +    path = g_build_filename(g_get_home_dir(), ".hardinfo", "vendor.conf", NULL); +    if (!g_file_test(path, G_FILE_TEST_EXISTS)) { +      DEBUG("local vendor.conf not found, trying system-wise"); +      g_free(path); +      path = g_build_filename(params.path_data, "vendor.conf", NULL); +    } +     +    if (g_file_test(path, G_FILE_TEST_EXISTS)) { +      GKeyFile *vendors; +      gchar *tmp; +      gint num_vendors; +       +      DEBUG("loading vendor.conf"); +       +      vendors = g_key_file_new(); +      if (g_key_file_load_from_file(vendors, path, 0, NULL)) { +        num_vendors = g_key_file_get_integer(vendors, "vendors", "number", NULL); +         +        for (i = num_vendors; i >= 0; i--) { +          Vendor *v = g_new0(Vendor, 1); +           +          tmp = g_strdup_printf("vendor%d", i); +           +          v->id   = g_key_file_get_string(vendors, tmp, "id", NULL); +          v->name = g_key_file_get_string(vendors, tmp, "name", NULL); +          v->url  = g_key_file_get_string(vendors, tmp, "url", NULL); +           +          vendor_list = g_slist_prepend(vendor_list, v); +           +          g_free(tmp); +        } +      } +       +      g_key_file_free(vendors); +    } else { +      DEBUG("system-wise vendor.conf not found, using internal database"); +       +      for (i = G_N_ELEMENTS(vendors); i >= 0; i--) { +        vendor_list = g_slist_prepend(vendor_list, (gpointer) &vendors[i]); +      } +    }  + +    g_free(path); +} +  const gchar *vendor_get_name(const gchar * id)  { +    GSList *vendor;      int i;      if (!id) {        return NULL;      } - -    for (i = 0; vendors[i].id; i++) { -	if (strstr(id, vendors[i].id)) -	    return vendors[i].name; +     +    for (vendor = vendor_list; vendor; vendor = vendor->next) { +      Vendor *v = (Vendor *)vendor->data; +       +      if (v->id && id && strstr(id, v->id)) { +        return g_strdup(v->name); +      }      }      return id; @@ -105,15 +173,19 @@ const gchar *vendor_get_name(const gchar * id)  const gchar *vendor_get_url(const gchar * id)  { +    GSList *vendor;      int i;      if (!id) {        return NULL;      } - -    for (i = 0; vendors[i].id; i++) { -	if (strstr(id, vendors[i].id)) -	    return vendors[i].url; +     +    for (vendor = vendor_list; vendor; vendor = vendor->next) { +      Vendor *v = (Vendor *)vendor->data; +       +      if (v->id && id && strstr(id, v->id)) { +        return g_strdup(v->url); +      }      }      return NULL; diff --git a/hardinfo2/vendor.h b/hardinfo2/vendor.h index b40dafb1..778e2ea3 100644 --- a/hardinfo2/vendor.h +++ b/hardinfo2/vendor.h @@ -26,8 +26,8 @@ struct _Vendor {    char *url;  }; +void  vendor_init(void);  const gchar *vendor_get_name(const gchar *id);  const gchar *vendor_get_url(const gchar *id); -  #endif	/* __VENDOR_H__ */ | 
