aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2006-11-26 17:03:30 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2006-11-26 17:03:30 +0000
commit83b3021873da4bb34db92c95398164196be7b18a (patch)
treec6b9bb7d07a97293c2ba5884d4dddc126b24048d
parent2f4ae3a5d3404daff96fa70022f9e45d623fa720 (diff)
Remove the need for modules.conf
-rw-r--r--hardinfo2/Makefile.in1
-rw-r--r--hardinfo2/benchmark.c12
-rw-r--r--hardinfo2/computer.c12
-rw-r--r--hardinfo2/devices.c12
-rw-r--r--hardinfo2/hardinfo.c6
-rw-r--r--hardinfo2/modules.conf7
-rw-r--r--hardinfo2/shell.h2
-rw-r--r--hardinfo2/util.c79
8 files changed, 84 insertions, 47 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in
index f8fef304..c940f939 100644
--- a/hardinfo2/Makefile.in
+++ b/hardinfo2/Makefile.in
@@ -75,7 +75,6 @@ install: all
@echo '*** Installing misc data...'
cp uidefs.xml ${DESTDIR}/usr/share/hardinfo
- cp modules.conf ${DESTDIR}/usr/share/hardinfo
cp benchmark.conf ${DESTDIR}/usr/share/hardinfo
cp benchmark.data ${DESTDIR}/usr/share/hardinfo
diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c
index 367ea592..f5492bf7 100644
--- a/hardinfo2/benchmark.c
+++ b/hardinfo2/benchmark.c
@@ -163,3 +163,15 @@ hi_name(gint entry)
{
return hi_entries[entry].name;
}
+
+gchar *
+hi_module_name(void)
+{
+ return g_strdup("Benchmarks");
+}
+
+guchar
+hi_module_weight(void)
+{
+ return 240;
+}
diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c
index 7a33b673..14284bca 100644
--- a/hardinfo2/computer.c
+++ b/hardinfo2/computer.c
@@ -336,3 +336,15 @@ hi_name(gint entry)
{
return hi_entries[entry].name;
}
+
+gchar *
+hi_module_name(void)
+{
+ return g_strdup("Computer");
+}
+
+guchar
+hi_module_weight(void)
+{
+ return 80;
+}
diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c
index 6dc989b2..4eced276 100644
--- a/hardinfo2/devices.c
+++ b/hardinfo2/devices.c
@@ -210,3 +210,15 @@ hi_name(gint entry)
{
return hi_entries[entry].name;
}
+
+gchar *
+hi_module_name(void)
+{
+ return g_strdup("Devices");
+}
+
+guchar
+hi_module_weight(void)
+{
+ return 160;
+}
diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c
index e2a4a91c..32118cbc 100644
--- a/hardinfo2/hardinfo.c
+++ b/hardinfo2/hardinfo.c
@@ -55,11 +55,13 @@ main(int argc, char **argv)
if (params.list_modules) {
GSList *modules = modules_load_all();
- g_print("Module Name\t\tDynamic Loadable Module\n");
for (; modules; modules = modules->next) {
ShellModule *module = (ShellModule *) modules->data;
+ gchar *name = g_path_get_basename(g_module_name(module->dll));
- g_print("%s\t\t%s\n", module->name, g_module_name(module->dll));
+ g_print("%s (%s)\n", name, module->name);
+
+ g_free(name);
}
return 0;
diff --git a/hardinfo2/modules.conf b/hardinfo2/modules.conf
deleted file mode 100644
index 1dbaf07f..00000000
--- a/hardinfo2/modules.conf
+++ /dev/null
@@ -1,7 +0,0 @@
-[general]
-version=2
-
-[categories]
-Computer=computer
-Devices=devices
-Benchmarks=benchmark
diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h
index 3a0fd3b0..726ec3e9 100644
--- a/hardinfo2/shell.h
+++ b/hardinfo2/shell.h
@@ -94,6 +94,8 @@ struct _ShellModule {
gchar *name;
GdkPixbuf *icon;
GModule *dll;
+
+ guchar weight;
GSList *entries;
};
diff --git a/hardinfo2/util.c b/hardinfo2/util.c
index 67fd39e8..bf5926f0 100644
--- a/hardinfo2/util.c
+++ b/hardinfo2/util.c
@@ -366,32 +366,42 @@ gchar *strreplace(gchar * string, gchar * replace, gchar new_char)
return string;
}
-static ShellModule *module_load(gchar *name, gchar *filename) {
+static ShellModule *module_load(gchar *filename) {
ShellModule *module;
gchar *tmp;
module = g_new0(ShellModule, 1);
- module->name = g_strdup(name);
if (params.gui_running) {
+ gchar *dot = g_strrstr(filename, G_MODULE_SUFFIX) - 1;
+
+ *dot = '\0';
+
tmp = g_strdup_printf("%s.png", filename);
module->icon = icon_cache_get_pixbuf(tmp);
g_free(tmp);
+
+ *dot = '.';
}
- tmp = g_strdup_printf("%s.so", filename);
- filename = tmp;
-
tmp = g_build_filename(params.path_lib, "modules", filename, NULL);
module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY);
g_free(tmp);
-
+
if (module->dll) {
- gint(*n_entries) (void);
+ gint (*n_entries) (void);
+ gint (*weight_func) (void);
+ gchar *(*name_func) (void);
gint i;
- if (!g_module_symbol(module->dll, "hi_n_entries", (gpointer) & n_entries))
+ if (!g_module_symbol(module->dll, "hi_n_entries", (gpointer) & n_entries) ||
+ !g_module_symbol(module->dll, "hi_module_name", (gpointer) & name_func))
goto failed;
+
+ g_module_symbol(module->dll, "hi_module_weight", (gpointer) & weight_func);
+
+ module->weight = weight_func ? weight_func() : 0;
+ module->name = name_func();
gint j = n_entries();
for (i = 0; i <= j; i++) {
@@ -446,42 +456,37 @@ static gboolean module_in_module_list(gchar *module, gchar **module_list)
return FALSE;
}
+static gint module_cmp(gconstpointer m1, gconstpointer m2)
+{
+ ShellModule *a = (ShellModule *)m1;
+ ShellModule *b = (ShellModule *)m2;
+
+ return a->weight - b->weight;
+}
+
static GSList *modules_load(gchar **module_list)
{
- gchar *modules_conf;
- GKeyFile *keyfile = g_key_file_new();
- guint categories, i;
+ GDir *dir;
GSList *modules = NULL;
-
- keyfile = g_key_file_new();
-
- modules_conf = g_build_filename(params.path_data, "modules.conf", NULL);
- g_key_file_load_from_file(keyfile, modules_conf, 0, NULL);
- g_free(modules_conf);
-
- if (g_key_file_get_integer(keyfile, "general", "version", NULL) != 2) {
- g_error("Wrong version of modules.conf");
+ ShellModule *module;
+ gchar *filename;
+
+ filename = g_build_filename(params.path_lib, "modules", NULL);
+ dir = g_dir_open(filename, 0, NULL);
+ g_free(filename);
+
+ if (!dir) {
+ return NULL;
}
- gchar **cat = g_key_file_get_keys(keyfile, "categories", &categories, NULL);
- for (i = 0; i < categories; i++) {
- if (module_in_module_list(cat[i], module_list)) {
- ShellModule *module;
- gchar *name;
-
- name = g_key_file_get_value(keyfile, "categories", cat[i], NULL);
- module = module_load(cat[i], name);
-
- if (module)
+ while ((filename = (gchar*)g_dir_read_name(dir))) {
+ if (module_in_module_list(filename, module_list)) {
+ if ((module = module_load(filename))) {
modules = g_slist_append(modules, module);
-
- g_free(name);
+ }
}
}
- g_strfreev(cat);
- g_key_file_free(keyfile);
-
if (g_slist_length(modules) == 0) {
if (params.use_modules == NULL) {
g_error("No module could be loaded. Check permissions on \"%s\" and try again.",
@@ -492,8 +497,8 @@ static GSList *modules_load(gchar **module_list)
}
}
-
- return modules;
+
+ return g_slist_sort(modules, module_cmp);
}
GSList *modules_load_selected(void)