diff options
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/Makefile.in | 41 | ||||
| -rw-r--r-- | hardinfo2/arch/common/blowfish.h | 10 | ||||
| -rw-r--r-- | hardinfo2/arch/common/languages.h | 4 | ||||
| -rw-r--r-- | hardinfo2/arch/common/md5.h | 9 | ||||
| -rw-r--r-- | hardinfo2/arch/common/sha1.h | 10 | ||||
| -rw-r--r-- | hardinfo2/arch/common/users.h | 63 | ||||
| -rw-r--r-- | hardinfo2/arch/common/zlib.h | 11 | ||||
| -rw-r--r-- | hardinfo2/benchmark.c | 8 | ||||
| -rw-r--r-- | hardinfo2/binreloc.c | 682 | ||||
| -rw-r--r-- | hardinfo2/binreloc.h | 68 | ||||
| -rw-r--r-- | hardinfo2/callbacks.c | 31 | ||||
| -rw-r--r-- | hardinfo2/callbacks.h | 2 | ||||
| -rw-r--r-- | hardinfo2/computer.c | 19 | ||||
| -rwxr-xr-x | hardinfo2/configure | 59 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.c | 10 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.h | 9 | ||||
| -rw-r--r-- | hardinfo2/iconcache.c | 9 | ||||
| -rw-r--r-- | hardinfo2/loadgraph.c | 48 | ||||
| -rw-r--r-- | hardinfo2/loadgraph.h | 3 | ||||
| -rw-r--r-- | hardinfo2/md5.c | 3 | ||||
| -rw-r--r-- | hardinfo2/menu.c | 15 | ||||
| -rw-r--r-- | hardinfo2/report.c | 9 | ||||
| -rw-r--r-- | hardinfo2/shell.c | 29 | ||||
| -rw-r--r-- | hardinfo2/shell.h | 4 | ||||
| -rw-r--r-- | hardinfo2/uidefs.xml | 2 | ||||
| -rw-r--r-- | hardinfo2/util.c | 35 | 
26 files changed, 1084 insertions, 109 deletions
| diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index a2496199..032b2629 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -1,12 +1,12 @@ -CC = gcc -fPIC -pipe -O3 $(ARCHOPTS) -CCSLOW = gcc -fPIC -pipe -O0 -CFLAGS = -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) -I. +CC = gcc -O3 $(ARCHOPTS)  +CCSLOW = gcc -O0 +CFLAGS = -fPIC -pipe -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) -I.  # ----------------------------------------------------------------------------  OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o sha1.o md5.o \ -		menu.o stock.o callbacks.o expr.o report.o blowfish.o +		menu.o stock.o callbacks.o expr.o report.o blowfish.o binreloc.o  MODULES = computer.so devices.so benchmark.so   all:	$(OBJECTS) $(MODULES) @@ -26,7 +26,7 @@ sha1.o:  	@echo "[01;34m--- Module: $< ($@)[00m"  	$(CC) $(CFLAGS) -o $@ -shared $< $(GTK_FLAGS) $(GTK_LIBS) \  		$(GLADE_LIBS) $(GLADE_FLAGS) -	mv $@ modules +	mv -f $@ modules  clean:  	rm -rf .xvpics pixmaps/.xvpics *.o *.so hardinfo modules/*.so report @@ -46,3 +46,34 @@ deb:	dist-clean  	@echo "Creating deb..."  	dpkg-buildpackage -rfakeroot -k${USER} +install:	all +	@echo '[01;34m*** Creating directories...[00m' +	mkdir -p ${DESTDIR}/usr/bin +	mkdir -p ${DESTDIR}/usr/local +	mkdir -p ${DESTDIR}/usr/share/applications +	mkdir -p ${DESTDIR}/usr/lib/hardinfo/modules +	mkdir -p ${DESTDIR}/usr/share/hardinfo/pixmaps + +	@echo '[01;34m*** Installing icon...[00m' +	cp hardinfo.desktop ${DESTDIR}/usr/share/applications + +	@echo '[01;34m*** Installing executable...[00m' +	cp hardinfo ${DESTDIR}/usr/bin/hardinfo + +	@echo '[01;34m*** Installing modules...[00m' +	cp -r modules/*.so ${DESTDIR}/usr/lib/hardinfo/modules + +	@echo '[01;34m*** Installing pixmaps...[00m' +	cp -r pixmaps/* ${DESTDIR}/usr/share/hardinfo/pixmaps + +	@echo '[01;34m*** Installing misc data...[00m' +	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 + +	@echo '[01;34m*** Fixing permissions...[00m' +	chmod -R 755 ${DESTDIR}/usr/share/hardinfo +	chmod 755 ${DESTDIR}/usr/bin/hardinfo + +	@echo '[01;34m*** Done installing.[00m' diff --git a/hardinfo2/arch/common/blowfish.h b/hardinfo2/arch/common/blowfish.h index 7333d069..ad4bdb92 100644 --- a/hardinfo2/arch/common/blowfish.h +++ b/hardinfo2/arch/common/blowfish.h @@ -34,8 +34,13 @@ benchmark_fish(void)      L = 0xBEBACAFE;      R = 0xDEADBEEF; -    if (!g_file_get_contents(PREFIX "benchmark.data", -                             &tmpsrc, NULL, NULL)) { +    gchar *bdata_path; +     +    bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", +                                 gbr_find_data_dir(PREFIX)); + +    if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { +        g_free(bdata_path);          return g_strdup("[Error]\n"                          PREFIX "benchmark.data not found=\n");      }      @@ -57,6 +62,7 @@ benchmark_fish(void)      }      g_timer_destroy(timer); +    g_free(bdata_path);      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); diff --git a/hardinfo2/arch/common/languages.h b/hardinfo2/arch/common/languages.h index 3a31ef7f..71e05dab 100644 --- a/hardinfo2/arch/common/languages.h +++ b/hardinfo2/arch/common/languages.h @@ -19,7 +19,7 @@ void  scan_languages(OperatingSystem * os)  {      FILE *locale; -    gchar buf[128], *retval = ""; +    gchar buf[512], *retval = "";      locale = popen("locale -va", "r");      if (!locale) @@ -36,7 +36,7 @@ scan_languages(OperatingSystem * os)  	  *date = NULL,  	  *codeset = NULL; -    while (fgets(buf, 128, locale)) { +    while (fgets(buf, 512, locale)) {  	if (!strncmp(buf, "locale:", 7)) {  	    sscanf(buf, "locale: %s", name);  	    fgets(buf, 128, locale); diff --git a/hardinfo2/arch/common/md5.h b/hardinfo2/arch/common/md5.h index f61aef0f..256d6c3b 100644 --- a/hardinfo2/arch/common/md5.h +++ b/hardinfo2/arch/common/md5.h @@ -31,8 +31,12 @@ benchmark_md5(void)      tmpsrc = src; -    if (!g_file_get_contents(PREFIX "benchmark.data", -                             &tmpsrc, NULL, NULL)) { +    gchar *bdata_path; +     +    bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", +                                 gbr_find_data_dir(PREFIX)); +    if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { +        g_free(bdata_path);          return g_strdup("[Error]\n"                          PREFIX "benchmark.data not found=\n");      }      @@ -54,6 +58,7 @@ benchmark_md5(void)      }      g_timer_destroy(timer); +    g_free(bdata_path);      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); diff --git a/hardinfo2/arch/common/sha1.h b/hardinfo2/arch/common/sha1.h index 521cbcae..4bd07276 100644 --- a/hardinfo2/arch/common/sha1.h +++ b/hardinfo2/arch/common/sha1.h @@ -30,8 +30,13 @@ benchmark_sha1(void)      tmpsrc = src; -    if (!g_file_get_contents(PREFIX "benchmark.data", -                             &tmpsrc, NULL, NULL)) { +    gchar *bdata_path; +     +    bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", +                                 gbr_find_data_dir(PREFIX)); + +    if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { +        g_free(bdata_path);          return g_strdup("[Error]\n"                          PREFIX "benchmark.data not found=\n");      }      @@ -53,6 +58,7 @@ benchmark_sha1(void)      }      g_timer_destroy(timer); +    g_free(bdata_path);      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); diff --git a/hardinfo2/arch/common/users.h b/hardinfo2/arch/common/users.h new file mode 100644 index 00000000..08acd97a --- /dev/null +++ b/hardinfo2/arch/common/users.h @@ -0,0 +1,63 @@ +static gchar *sys_users = NULL, +             *human_users = NULL; + +static gboolean +remove_users(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "USER", 4)) { +	/* +         * g_free((gchar *) key); +	 * g_free((GtkTreeIter *) value); +         */ +	return TRUE; +    } +    return FALSE; +} + +void scan_users(void) +{ +    FILE *passwd; +    char buffer[512]; +     +    passwd = fopen("/etc/passwd", "r"); +    if (!passwd) +      return; +     +    if (sys_users) { +      g_free(sys_users); +      g_free(human_users); + +      g_hash_table_foreach_remove(moreinfo, remove_users, NULL); +    } +   +    sys_users = g_strdup(""); +    human_users = g_strdup(""); +     +    while (fgets(buffer, 512, passwd)) { +      gchar **tmp; +      gint uid; +       +      tmp = g_strsplit(buffer, ":", 0); +       +      gchar *key = g_strdup_printf("USER%s", tmp[0]); +      gchar *val = g_strdup_printf("[User Information]\n" +                                   "User ID=%s\n" +                                   "Group ID=%s\n" +                                   "Home directory=%s\n" +                                   "Default shell=%s\n", +                                   tmp[2], tmp[3], tmp[5], tmp[6]); +      g_hash_table_insert(moreinfo, key, val); + +      uid = atoi(tmp[2]); +      strend(tmp[4], ','); +      if (uid >= 1000 && uid <= 65530) { +        human_users = g_strdup_printf("%s$%s$%s=%s\n", human_users, key, tmp[0], tmp[4]); +      } else { +        sys_users = g_strdup_printf("%s$%s$%s=%s\n", sys_users, key, tmp[0], tmp[4]); +      }       +       +      g_strfreev(tmp); +    } +     +    fclose(passwd); +} diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h index f68d60f4..2a1007ed 100644 --- a/hardinfo2/arch/common/zlib.h +++ b/hardinfo2/arch/common/zlib.h @@ -29,7 +29,7 @@ benchmark_zlib(void)  	if (!libz) {              libz = g_module_open("/lib/libz.so", G_MODULE_BIND_LAZY);              if (!libz) { -                g_print("%s\n", g_module_error()); +                g_warning("Cannot load ZLib: %s", g_module_error());                  return g_strdup("[Error]\n"                         "ZLib not found=");              } @@ -51,9 +51,13 @@ benchmark_zlib(void)      gdouble elapsed = 0;      gchar src[65536], *tmpsrc;      glong srclen = 65536; +    gchar *bdata_path; +     +    bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", +                                 gbr_find_data_dir(PREFIX)); -    if (!g_file_get_contents(PREFIX "benchmark.data", -                             &tmpsrc, NULL, NULL)) { +    if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { +        g_free(bdata_path);          return g_strdup("[Error]\n"                          PREFIX "benchmark.data not found=\n");      }      @@ -77,6 +81,7 @@ benchmark_zlib(void)      }      g_timer_destroy(timer); +    g_free(bdata_path);      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index f4cb904c..d66d0b8c 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -20,6 +20,7 @@  #include <iconcache.h>  #include <shell.h>  #include <config.h> +#include <binreloc.h>  enum {      BENCHMARK_ZLIB, @@ -41,11 +42,13 @@ static gchar *  benchmark_include_results(gchar *results, const gchar *benchmark)  {      GKeyFile *conf; -    gchar **machines; +    gchar **machines, *bconf_path;      int i;      conf = g_key_file_new(); -    g_key_file_load_from_file(conf, PREFIX "benchmark.conf", 0, NULL); +    bconf_path = g_strdup_printf("%s/hardinfo/benchmark.conf", +                                 gbr_find_data_dir(PREFIX)); +    g_key_file_load_from_file(conf, bconf_path, 0, NULL);      machines = g_key_file_get_keys(conf, benchmark, NULL, NULL);      for (i = 0; machines && machines[i]; i++) { @@ -56,6 +59,7 @@ benchmark_include_results(gchar *results, const gchar *benchmark)      g_strfreev(machines);      g_key_file_free(conf); +    g_free(bconf_path);      return g_strconcat(results, "[$ShellParam$]\n"                                  "Zebra=1\n", NULL); diff --git a/hardinfo2/binreloc.c b/hardinfo2/binreloc.c new file mode 100644 index 00000000..a3b95e3e --- /dev/null +++ b/hardinfo2/binreloc.c @@ -0,0 +1,682 @@ +/* + * BinReloc - a library for creating relocatable executables + * Written by: Hongli Lai <h.lai@chello.nl> + * http://autopackage.org/ + * + * This source code is public domain. You can relicense this code + * under whatever license you want. + * + * See http://autopackage.org/docs/binreloc/ for + * more information and how to use this. + */ + +#ifndef __BINRELOC_C__ +#define __BINRELOC_C__ + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <string.h> +#include "binreloc.h" + +G_BEGIN_DECLS + + +/** @internal + * Find the canonical filename of the executable. Returns the filename + * (which must be freed) or NULL on error. If the parameter 'error' is + * not NULL, the error code will be stored there, if an error occured. + */ +static char * +_br_find_exe (GbrInitError *error) +{ +	char *path, *path2, *line, *result; +	size_t buf_size; +	ssize_t size; +	struct stat stat_buf; +	FILE *f; + +	/* Read from /proc/self/exe (symlink) */ +	if (sizeof (path) > SSIZE_MAX) +		buf_size = SSIZE_MAX - 1; +	else +		buf_size = PATH_MAX - 1; +	path = (char *) g_try_malloc (buf_size); +	if (path == NULL) { +		/* Cannot allocate memory. */ +		if (error) +			*error = GBR_INIT_ERROR_NOMEM; +		return NULL; +	} +	path2 = (char *) g_try_malloc (buf_size); +	if (path2 == NULL) { +		/* Cannot allocate memory. */ +		if (error) +			*error = GBR_INIT_ERROR_NOMEM; +		g_free (path); +		return NULL; +	} + +	strncpy (path2, "/proc/self/exe", buf_size - 1); + +	while (1) { +		int i; + +		size = readlink (path2, path, buf_size - 1); +		if (size == -1) { +			/* Error. */ +			g_free (path2); +			break; +		} + +		/* readlink() success. */ +		path[size] = '\0'; + +		/* Check whether the symlink's target is also a symlink. +		 * We want to get the final target. */ +		i = stat (path, &stat_buf); +		if (i == -1) { +			/* Error. */ +			g_free (path2); +			break; +		} + +		/* stat() success. */ +		if (!S_ISLNK (stat_buf.st_mode)) { +			/* path is not a symlink. Done. */ +			g_free (path2); +			return path; +		} + +		/* path is a symlink. Continue loop and resolve this. */ +		strncpy (path, path2, buf_size - 1); +	} + + +	/* readlink() or stat() failed; this can happen when the program is +	 * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */ + +	buf_size = PATH_MAX + 128; +	line = (char *) g_try_realloc (path, buf_size); +	if (line == NULL) { +		/* Cannot allocate memory. */ +		g_free (path); +		if (error) +			*error = GBR_INIT_ERROR_NOMEM; +		return NULL; +	} + +	f = fopen ("/proc/self/maps", "r"); +	if (f == NULL) { +		g_free (line); +		if (error) +			*error = GBR_INIT_ERROR_OPEN_MAPS; +		return NULL; +	} + +	/* The first entry should be the executable name. */ +	result = fgets (line, (int) buf_size, f); +	if (result == NULL) { +		fclose (f); +		g_free (line); +		if (error) +			*error = GBR_INIT_ERROR_READ_MAPS; +		return NULL; +	} + +	/* Get rid of newline character. */ +	buf_size = strlen (line); +	if (buf_size <= 0) { +		/* Huh? An empty string? */ +		fclose (f); +		g_free (line); +		if (error) +			*error = GBR_INIT_ERROR_INVALID_MAPS; +		return NULL; +	} +	if (line[buf_size - 1] == 10) +		line[buf_size - 1] = 0; + +	/* Extract the filename; it is always an absolute path. */ +	path = strchr (line, '/'); + +	/* Sanity check. */ +	if (strstr (line, " r-xp ") == NULL || path == NULL) { +		fclose (f); +		g_free (line); +		if (error) +			*error = GBR_INIT_ERROR_INVALID_MAPS; +		return NULL; +	} + +	path = g_strdup (path); +	g_free (line); +	fclose (f); +	return path; +} + + +/** @internal + * Find the canonical filename of the executable which owns symbol. + * Returns a filename which must be freed, or NULL on error. + */ +static char * +_br_find_exe_for_symbol (const void *symbol, GbrInitError *error) +{ +	#define SIZE PATH_MAX + 100 +	FILE *f; +	size_t address_string_len; +	char *address_string, line[SIZE], *found; + +	if (symbol == NULL) +		return (char *) NULL; + +	f = fopen ("/proc/self/maps", "r"); +	if (f == NULL) +		return (char *) NULL; + +	address_string_len = 4; +	address_string = (char *) g_try_malloc (address_string_len); +	found = (char *) NULL; + +	while (!feof (f)) { +		char *start_addr, *end_addr, *end_addr_end, *file; +		void *start_addr_p, *end_addr_p; +		size_t len; + +		if (fgets (line, SIZE, f) == NULL) +			break; + +		/* Sanity check. */ +		if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL) +			continue; + +		/* Parse line. */ +		start_addr = line; +		end_addr = strchr (line, '-'); +		file = strchr (line, '/'); + +		/* More sanity check. */ +		if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-')) +			continue; + +		end_addr[0] = '\0'; +		end_addr++; +		end_addr_end = strchr (end_addr, ' '); +		if (end_addr_end == NULL) +			continue; + +		end_addr_end[0] = '\0'; +		len = strlen (file); +		if (len == 0) +			continue; +		if (file[len - 1] == '\n') +			file[len - 1] = '\0'; + +		/* Get rid of "(deleted)" from the filename. */ +		len = strlen (file); +		if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0) +			file[len - 10] = '\0'; + +		/* I don't know whether this can happen but better safe than sorry. */ +		len = strlen (start_addr); +		if (len != strlen (end_addr)) +			continue; + + +		/* Transform the addresses into a string in the form of 0xdeadbeef, +		 * then transform that into a pointer. */ +		if (address_string_len < len + 3) { +			address_string_len = len + 3; +			address_string = (char *) g_try_realloc (address_string, address_string_len); +		} + +		memcpy (address_string, "0x", 2); +		memcpy (address_string + 2, start_addr, len); +		address_string[2 + len] = '\0'; +		sscanf (address_string, "%p", &start_addr_p); + +		memcpy (address_string, "0x", 2); +		memcpy (address_string + 2, end_addr, len); +		address_string[2 + len] = '\0'; +		sscanf (address_string, "%p", &end_addr_p); + + +		if (symbol >= start_addr_p && symbol < end_addr_p) { +			found = file; +			break; +		} +	} + +	g_free (address_string); +	fclose (f); + +	if (found == NULL) +		return (char *) NULL; +	else +		return g_strdup (found); +} + + +static gchar *exe = NULL; + +static void set_gerror (GError **error, GbrInitError errcode); + + +/** Initialize the BinReloc library (for applications). + * + * This function must be called before using any other BinReloc functions. + * It attempts to locate the application's canonical filename. + * + * @note If you want to use BinReloc for a library, then you should call + *       gbr_init_lib() instead. + * + * @param error  If BinReloc failed to initialize, then the error report will + *               be stored in this variable. Set to NULL if you don't want an + *               error report. See the #GbrInitError for a list of error + *               codes. + * + * @returns TRUE on success, FALSE if BinReloc failed to initialize. + */ +gboolean +gbr_init (GError **error) +{ +	GbrInitError errcode = 0; + +	/* Locate the application's filename. */ +	exe = _br_find_exe (&errcode); +	if (exe != NULL) +		/* Success! */ +		return TRUE; +	else { +		/* Failed :-( */ +		set_gerror (error, errcode); +		return FALSE; +	} +} + + +/** Initialize the BinReloc library (for libraries). + * + * This function must be called before using any other BinReloc functions. + * It attempts to locate the calling library's canonical filename. + * + * @note The BinReloc source code MUST be included in your library, or this + *       function won't work correctly. + * + * @returns TRUE on success, FALSE if a filename cannot be found. + */ +gboolean +gbr_init_lib (GError **error) +{ +	GbrInitError errcode = 0; + +	exe = _br_find_exe_for_symbol ((const void *) "", &errcode); +	if (exe != NULL) +		/* Success! */ +		return TRUE; +	else { +		/* Failed :-( */ +		set_gerror (error, errcode); +		return exe != NULL; +	} +} + + +static void +set_gerror (GError **error, GbrInitError errcode) +{ +	gchar *error_message; + +	if (error == NULL) +		return; + +	switch (errcode) { +	case GBR_INIT_ERROR_NOMEM: +		error_message = "Cannot allocate memory."; +		break; +	case GBR_INIT_ERROR_OPEN_MAPS: +		error_message = "Unable to open /proc/self/maps for reading."; +		break; +	case GBR_INIT_ERROR_READ_MAPS: +		error_message = "Unable to read from /proc/self/maps."; +		break; +	case GBR_INIT_ERROR_INVALID_MAPS: +		error_message = "The file format of /proc/self/maps is invalid."; +		break; +	case GBR_INIT_ERROR_DISABLED: +		error_message = "Binary relocation support is disabled."; +		break; +	default: +		error_message = "Unknown error."; +		break; +	}; +	g_set_error (error, g_quark_from_static_string ("GBinReloc"), +		     errcode, "%s", error_message); +} + + +/** Find the canonical filename of the current application. + * + * @param default_exe  A default filename which will be used as fallback. + * @returns A string containing the application's canonical filename, + *          which must be freed when no longer necessary. If BinReloc is + *          not initialized, or if the initialization function failed, + *          then a copy of default_exe will be returned. If default_exe + *          is NULL, then NULL will be returned. + */ +gchar * +gbr_find_exe (const gchar *default_exe) +{ +	if (exe == NULL) { +		/* BinReloc is not initialized. */ +		if (default_exe != NULL) +			return g_strdup (default_exe); +		else +			return NULL; +	} +	return g_strdup (exe); +} + + +/** Locate the directory in which the current application is installed. + * + * The prefix is generated by the following pseudo-code evaluation: + * \code + * dirname(exename) + * \endcode + * + * @param default_dir  A default directory which will used as fallback. + * @return A string containing the directory, which must be freed when no + *         longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_dir + *         will be returned. If default_dir is NULL, then NULL will be + *         returned. + */ +gchar * +gbr_find_exe_dir (const gchar *default_dir) +{ +	if (exe == NULL) { +		/* BinReloc not initialized. */ +		if (default_dir != NULL) +			return g_strdup (default_dir); +		else +			return NULL; +	} + +	return g_path_get_dirname (exe); +} + + +/** Locate the prefix in which the current application is installed. + * + * The prefix is generated by the following pseudo-code evaluation: + * \code + * dirname(dirname(exename)) + * \endcode + * + * @param default_prefix  A default prefix which will used as fallback. + * @return A string containing the prefix, which must be freed when no + *         longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_prefix + *         will be returned. If default_prefix is NULL, then NULL will be + *         returned. + */ +gchar * +gbr_find_prefix (const gchar *default_prefix) +{ +	gchar *dir1, *dir2; + +	if (exe == NULL) { +		/* BinReloc not initialized. */ +		if (default_prefix != NULL) +			return g_strdup (default_prefix); +		else +			return NULL; +	} + +	dir1 = g_path_get_dirname (exe); +	dir2 = g_path_get_dirname (dir1); +	g_free (dir1); +	return dir2; +} + + +/** Locate the application's binary folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/bin" + * \endcode + * + * @param default_bin_dir  A default path which will used as fallback. + * @return A string containing the bin folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_bin_dir will + *         be returned. If default_bin_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_bin_dir (const gchar *default_bin_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_bin_dir != NULL) +			return g_strdup (default_bin_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "bin", NULL); +	g_free (prefix); +	return dir; +} + + +/** Locate the application's superuser binary folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/sbin" + * \endcode + * + * @param default_sbin_dir  A default path which will used as fallback. + * @return A string containing the sbin folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_sbin_dir will + *         be returned. If default_bin_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_sbin_dir (const gchar *default_sbin_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_sbin_dir != NULL) +			return g_strdup (default_sbin_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "sbin", NULL); +	g_free (prefix); +	return dir; +} + + +/** Locate the application's data folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/share" + * \endcode + * + * @param default_data_dir  A default path which will used as fallback. + * @return A string containing the data folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_data_dir + *         will be returned. If default_data_dir is NULL, then NULL will be + *         returned. + */ +gchar * +gbr_find_data_dir (const gchar *default_data_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_data_dir != NULL) +			return g_strdup (default_data_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "share", NULL); +	g_free (prefix); +	return dir; +} + + +/** Locate the application's localization folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/share/locale" + * \endcode + * + * @param default_locale_dir  A default path which will used as fallback. + * @return A string containing the localization folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_locale_dir will be returned. + *         If default_locale_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_locale_dir (const gchar *default_locale_dir) +{ +	gchar *data_dir, *dir; + +	data_dir = gbr_find_data_dir (NULL); +	if (data_dir == NULL) { +		/* BinReloc not initialized. */ +		if (default_locale_dir != NULL) +			return g_strdup (default_locale_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (data_dir, "locale", NULL); +	g_free (data_dir); +	return dir; +} + + +/** Locate the application's library folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/lib" + * \endcode + * + * @param default_lib_dir  A default path which will used as fallback. + * @return A string containing the library folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the + *         initialization function failed, then a copy of default_lib_dir will be returned. + *         If default_lib_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_lib_dir (const gchar *default_lib_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_lib_dir != NULL) +			return g_strdup (default_lib_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "lib", NULL); +	g_free (prefix); +	return dir; +} + + +/** Locate the application's libexec folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/libexec" + * \endcode + * + * @param default_libexec_dir  A default path which will used as fallback. + * @return A string containing the libexec folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the initialization + *         function failed, then a copy of default_libexec_dir will be returned. + *         If default_libexec_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_libexec_dir (const gchar *default_libexec_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_libexec_dir != NULL) +			return g_strdup (default_libexec_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "libexec", NULL); +	g_free (prefix); +	return dir; +} + + +/** Locate the application's configuration files folder. + * + * The path is generated by the following pseudo-code evaluation: + * \code + * prefix + "/etc" + * \endcode + * + * @param default_etc_dir  A default path which will used as fallback. + * @return A string containing the etc folder's path, which must be freed when + *         no longer necessary. If BinReloc is not initialized, or if the initialization + *         function failed, then a copy of default_etc_dir will be returned. + *         If default_etc_dir is NULL, then NULL will be returned. + */ +gchar * +gbr_find_etc_dir (const gchar *default_etc_dir) +{ +	gchar *prefix, *dir; + +	prefix = gbr_find_prefix (NULL); +	if (prefix == NULL) { +		/* BinReloc not initialized. */ +		if (default_etc_dir != NULL) +			return g_strdup (default_etc_dir); +		else +			return NULL; +	} + +	dir = g_build_filename (prefix, "etc", NULL); +	g_free (prefix); +	return dir; +} + + +G_END_DECLS + +#endif /* __BINRELOC_C__ */ diff --git a/hardinfo2/binreloc.h b/hardinfo2/binreloc.h new file mode 100644 index 00000000..3bf48bc6 --- /dev/null +++ b/hardinfo2/binreloc.h @@ -0,0 +1,68 @@ +/* + * BinReloc - a library for creating relocatable executables + * Written by: Hongli Lai <h.lai@chello.nl> + * http://autopackage.org/ + * + * This source code is public domain. You can relicense this code + * under whatever license you want. + * + * See http://autopackage.org/docs/binreloc/ for + * more information and how to use this. + */ + +#ifndef __BINRELOC_H__ +#define __BINRELOC_H__ + +#include <glib.h> + +G_BEGIN_DECLS + + +/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */ +typedef enum { +	/** Cannot allocate memory. */ +	GBR_INIT_ERROR_NOMEM, +	/** Unable to open /proc/self/maps; see errno for details. */ +	GBR_INIT_ERROR_OPEN_MAPS, +	/** Unable to read from /proc/self/maps; see errno for details. */ +	GBR_INIT_ERROR_READ_MAPS, +	/** The file format of /proc/self/maps is invalid; kernel bug? */ +	GBR_INIT_ERROR_INVALID_MAPS, +	/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */ +	GBR_INIT_ERROR_DISABLED +} GbrInitError; + + +#ifndef BINRELOC_RUNNING_DOXYGEN +/* Mangle symbol names to avoid symbol collisions with other ELF objects. */ +	#define gbr_find_exe         UfUy21856259474323_gbr_find_exe +	#define gbr_find_exe_dir     UfUy21856259474323_gbr_find_exe_dir +	#define gbr_find_prefix      UfUy21856259474323_gbr_find_prefix +	#define gbr_find_bin_dir     UfUy21856259474323_gbr_find_bin_dir +	#define gbr_find_sbin_dir    UfUy21856259474323_gbr_find_sbin_dir +	#define gbr_find_data_dir    UfUy21856259474323_gbr_find_data_dir +	#define gbr_find_locale_dir  UfUy21856259474323_gbr_find_locale_dir +	#define gbr_find_lib_dir     UfUy21856259474323_gbr_find_lib_dir +	#define gbr_find_libexec_dir UfUy21856259474323_gbr_find_libexec_dir +	#define gbr_find_etc_dir     UfUy21856259474323_gbr_find_etc_dir + + +#endif +gboolean gbr_init             (GError **error); +gboolean gbr_init_lib         (GError **error); + +gchar   *gbr_find_exe         (const gchar *default_exe); +gchar   *gbr_find_exe_dir     (const gchar *default_dir); +gchar   *gbr_find_prefix      (const gchar *default_prefix); +gchar   *gbr_find_bin_dir     (const gchar *default_bin_dir); +gchar   *gbr_find_sbin_dir    (const gchar *default_sbin_dir); +gchar   *gbr_find_data_dir    (const gchar *default_data_dir); +gchar   *gbr_find_locale_dir  (const gchar *default_locale_dir); +gchar   *gbr_find_lib_dir     (const gchar *default_lib_dir); +gchar   *gbr_find_libexec_dir (const gchar *default_libexec_dir); +gchar   *gbr_find_etc_dir     (const gchar *default_etc_dir); + + +G_END_DECLS + +#endif /* __BINRELOC_H__ */ diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index cfab4b2c..fd862984 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -32,12 +32,12 @@ void cb_refresh()      shell_do_reload();  } -void cb_left_pane() +void cb_side_pane()  {      gboolean visible; -    visible = shell_action_get_active("LeftPaneAction"); -    shell_set_left_pane_visible(visible); +    visible = shell_action_get_active("SidePaneAction"); +    shell_set_side_pane_visible(visible);  }  void cb_toolbar() @@ -51,6 +51,14 @@ void cb_toolbar()  void cb_about()  {      GtkWidget *about; +    const gchar *authors[] = { +        "Leandro A. F. Pereira", +        "SCSI support by Pascal F. Martin", +        "MD5 implementation by Colin Plumb", +        "SHA1 implementation by Steve Raid", +        "Blowfish implementation by Paul Kocher", +        NULL +    };      about = gtk_about_dialog_new();      gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "HardInfo"); @@ -63,6 +71,23 @@ void cb_about()      gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about),  			      icon_cache_get_pixbuf("logo.png")); +    gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about), +       "HardInfo is free software; you can redistribute it and/or modify " \ +       "it under the terms of the GNU General Public License as published by " \ +       "the Free Software Foundation, version 2.\n\n" +       "This program is distributed in the hope that it will be useful, " \ +       "but WITHOUT ANY WARRANTY; without even the implied warranty of " \ +       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the " \ +       "GNU General Public License for more details.\n\n" +       "You should have received a copy of the GNU General Public License " \ +       "along with this program; if not, write to the Free Software " \ +       "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA"); +#if GTK_CHECK_VERSION(2,8,0) +    gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about), TRUE); +#endif +     +    gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about), authors); +      gtk_dialog_run(GTK_DIALOG(about));      gtk_widget_destroy(about);  } diff --git a/hardinfo2/callbacks.h b/hardinfo2/callbacks.h index f0f28322..da1b3a65 100644 --- a/hardinfo2/callbacks.h +++ b/hardinfo2/callbacks.h @@ -23,7 +23,7 @@ void cb_about();  void cb_generate_report();  void cb_quit();  void cb_refresh(); -void cb_left_pane(); +void cb_side_pane();  void cb_toolbar();  #endif	/* __CALLBACKS_H__ */ diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index 7ae9ee8d..f672f0e3 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -41,6 +41,7 @@ enum {      COMPUTER_SHARES,      COMPUTER_DISPLAY,      COMPUTER_NETWORK, +    COMPUTER_USERS,  } Entries;  static ModuleEntry hi_entries[] = { @@ -53,6 +54,7 @@ static ModuleEntry hi_entries[] = {      {"Shared Directories",	"shares.png"},      {"Display",			"monitor.png"},      {"Network Interfaces",	"network.png"}, +    {"Users",			"users.png"},  };  #include "computer.h" @@ -71,6 +73,7 @@ static GHashTable *moreinfo = NULL;  #include <arch/this/samba.h>  #include <arch/this/sensors.h>  #include <arch/this/net.h> +#include <arch/common/users.h>  static Computer *  computer_get_info(void) @@ -116,6 +119,9 @@ computer_get_info(void)      shell_status_update("Obtaining network information...");      scan_net_interfaces(); +    shell_status_update("Obtaining users information..."); +    scan_users(); +      computer->date_time = "...";      return computer;  } @@ -133,6 +139,9 @@ hi_reload(gint entry)      case COMPUTER_SENSORS:  	read_sensors();  	break; +    case COMPUTER_USERS: +        scan_users(); +        break;      }  } @@ -159,8 +168,6 @@ hi_get_field(gchar * field)  	tmp = g_strdup_printf("%dMB (%dMB used)", mi->total, mi->used);  	g_free(mi); -    } else if (!strcmp(field, "Random")) { -        return g_strdup_printf("%d", rand() % 200);      } else if (!strcmp(field, "Uptime")) {  	tmp = computer_get_formatted_uptime();      } else if (!strcmp(field, "Date/Time")) { @@ -198,6 +205,14 @@ hi_info(gint entry)                                 "ReloadInterval=3000\n"                                 "ViewType=1\n"                                 "%s", network_interfaces); +    case COMPUTER_USERS: +        return g_strdup_printf("[$ShellParam$]\n" +                               "ReloadInterval=10000\n" +                               "ViewType=1\n" +                               "[Human Users]\n" +                               "%s\n" +                               "[System Users]\n" +                               "%s\n", human_users, sys_users);      case COMPUTER_SENSORS:          return g_strdup_printf("[$ShellParam$]\n"                                 "ReloadInterval=3000\n" diff --git a/hardinfo2/configure b/hardinfo2/configure index 58f791c5..d70efbf2 100755 --- a/hardinfo2/configure +++ b/hardinfo2/configure @@ -23,18 +23,22 @@  PACKAGE=`basename ${PWD} | cut -d"-" -f1`;  VERSION=`basename ${PWD} | cut -d"-" -f2`; -[ "$PACKAGE" == "$VERSION" ] && VERSION="SVN_$(date)" +if [ "$PACKAGE" == "$VERSION" ]; then +	VERSION=$( printf "SVN_%d" $( svn info|grep Revision|cut -d":" -f2 )) +	RELEASE=0 +else +	RELEASE=1 +fi  echo "ToscoConf (version 0.04) for $PACKAGE version $VERSION"  # --------------------------------------------------------------------------- -echo -n "Running: " +echo "Determining system architecture."  OS=`uname` -echo -n $OS  case $OS in		  	Linux) -		echo -n " (OK) " ;; +		;;  	*)  		echo " (not supported, yet!)"  		exit ;; @@ -45,13 +49,13 @@ case $PROC in  	i?86)  		ln -sf linux/x86 arch/this  		ARCH="ARCH_i386" ;; -	ppc) +	ppc*)  		ln -sf linux/ppc arch/this  		ARCH="ARCH_PPC" ;;  	x86_64)  		ln -sf linux/x86_64 arch/this  		ARCH="ARCH_x86_64" ;; -	mips) +	mips*)  		ln -sf linux/mips arch/this  		ARCH="ARCH_MIPS" ;;  	parisc*) @@ -74,7 +78,10 @@ case $PROC in  		;;  esac -echo "$PROC ($ARCH)" +# --------------------------------------------------------------------------- + +echo "Compiling $PACKAGE for $OS $PROC ($ARCH)." +echo ""  # --------------------------------------------------------------------------- @@ -82,8 +89,8 @@ echo -n "Checking for lspci... "  LSPCIPATH="/sbin/lspci /usr/sbin/lspci /bin/lspci /usr/bin/lspci `which lspci`"  for i in $LSPCIPATH; do  	if [ -x "$i" ]; then -	LSPCI=$i -		break; +		LSPCI=$i +		break  	fi  done @@ -98,7 +105,7 @@ fi  GTK2=-1  MIN_VERSION="2.6.0" -echo -n "Checking for GTK ${MIN_VERSION}... " +echo -n "Checking for GTK version >= ${MIN_VERSION}... "  for i in `which pkg-config`; do  	pkg-config --errors-to-stdout gtk+-2.0 \  		--atleast-version=$MIN_VERSION > /dev/null @@ -106,7 +113,7 @@ for i in `which pkg-config`; do  		0)  			GTK_FLAGS=`pkg-config gtk+-2.0 --cflags`  			GTK_LIBS=`pkg-config gtk+-2.0 --libs` -			echo "OK (pkgconfig)" +			echo "found `pkg-config gtk+-2.0 --modversion`"  			GTK2=1 ;;  		*)  			echo "not found." ;; @@ -131,18 +138,17 @@ echo -e "#ifndef __CONFIG_H__\n#define __CONFIG_H__\n" > config.h  echo "#define VERSION \"$VERSION\"" >> config.h -if [ "$LSPCI" ]; then -	echo "#define LSPCI \"$LSPCI -v\"" >> config.h -fi - +echo "#define LSPCI \"$LSPCI -v\"" >> config.h  echo "#define $ARCH" >> config.h  echo "#define PLATFORM \"`uname`\"" >> config.h  echo "#define KERNEL   \"`uname -r`\"" >> config.h  echo "#define HOSTNAME \"`hostname`\"" >> config.h -echo "#define PREFIX \"./\"" >> config.h +echo "#define PREFIX \"/usr/share/hardinfo/\"" >> config.h +echo "#define LIBPREFIX \"/usr/lib/hardinfo/\"" >> config.h  echo "#define DEBUG 1" >> config.h +echo "#define ENABLE_BINRELOC" >> config.h  echo -e "\n#endif	/* __CONFIG_H__ */" >> config.h @@ -159,6 +165,21 @@ echo "ARCHOPTS = " >> Makefile  cat Makefile.in >> Makefile  echo -e "\nDone. Type \"make\" to compile the program.\n" -echo "If you get errors, probably you don't have the right libraries," -echo "includes or utilities. However, if you're sure this is a bug in my" -echo -e "code, please send a patch (use \"diff -u\") to <leandro@linuxmag.com.br>.\n" + + +if [ "$RELEASE" == 0 ]; then +	cat << EOF +********************************************************* +* This is work in progress! Please report bugs at:      * +*      http://developer.berlios.de/bugs/?group_id=5897  * +* Or send patches to:                                   * +*      http://developer.berlios.de/patch/?group_id=5897 * +********************************************************* +EOF +else +	cat << EOF +If you get errors, probably you don't have the right libraries, +includes or utilities. However, if you're sure this is a bug in my +code, please send a patch (use \"diff -u\") to <leandro@linuxmag.com.br>. +EOF +fi diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index fd605626..7f61d6ee 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -22,11 +22,19 @@  #include <iconcache.h>  #include <stock.h> +#include <binreloc.h> +  int  main(int argc, char **argv)  { -    gtk_init(&argc, &argv); +    GError *error; +    gtk_init(&argc, &argv); +     +    if (!gbr_init(&error)) { +      g_error("BinReloc cannot be initialized: %s", error->message);       +    } +          icon_cache_init();      stock_icons_init();      shell_init(); diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index d8f62439..287119a5 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -28,9 +28,10 @@ struct _ModuleEntry {      gchar *icon;  }; -inline void remove_quotes(gchar *str); -inline void strend(gchar *str, gchar chr); -inline void remove_linefeed(gchar *str); -       void widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type); +inline  void  remove_quotes(gchar *str); +inline  void  strend(gchar *str, gchar chr); +inline  void  remove_linefeed(gchar *str); +        void  widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type); +inline gchar *size_human_readable(gfloat size);  #endif				/* __HARDINFO_H__ */ diff --git a/hardinfo2/iconcache.c b/hardinfo2/iconcache.c index 5ef2bc3c..fae641d1 100644 --- a/hardinfo2/iconcache.c +++ b/hardinfo2/iconcache.c @@ -17,6 +17,7 @@   */  #include <iconcache.h>  #include <config.h> +#include <binreloc.h>  static GHashTable *cache = NULL; @@ -34,7 +35,9 @@ GdkPixbuf *icon_cache_get_pixbuf(const gchar *file)      icon = g_hash_table_lookup(cache, file);      if (!icon) { -        gchar *tmp = g_strdup_printf(PREFIX "pixmaps/%s", file); +        gchar *tmp = g_strdup_printf("%s/hardinfo/pixmaps/%s", +                                     gbr_find_data_dir(PREFIX), +                                     file);          icon = gdk_pixbuf_new_from_file(tmp, NULL);          g_hash_table_insert(cache, g_strdup(file), icon); @@ -60,7 +63,9 @@ GdkPixbuf *icon_cache_get_pixbuf_at_size(const gchar *file, gint wid, gint hei)      icon = g_hash_table_lookup(cache, file);      if (!icon) { -        gchar *tmp = g_strdup_printf(PREFIX "pixmaps/%s", file); +        gchar *tmp = g_strdup_printf("%s/hardinfo/pixmaps/%s", +                                     gbr_find_data_dir(PREFIX), +                                     file);          icon = gdk_pixbuf_new_from_file_at_size(tmp, wid, hei, NULL);          g_hash_table_insert(cache, g_strdup(file), icon); diff --git a/hardinfo2/loadgraph.c b/hardinfo2/loadgraph.c index a15af347..53fb54f7 100644 --- a/hardinfo2/loadgraph.c +++ b/hardinfo2/loadgraph.c @@ -161,9 +161,9 @@ _draw(LoadGraph *lg)              gdk_draw_line(draw, lg->grid, i, 0, i, lg->height);      /* the graph */ -    for (i = 0; i < lg->size; i++) { -          gint this = lg->height - lg->data[i]; -          gint next = lg->height - lg->data[i+1]; +    for (i = 0; i < lg->size; i++) {     +          gint this = lg->height - lg->data[i] * lg->scale; +          gint next = lg->height - lg->data[i+1] * lg->scale;            gdk_draw_line(draw, lg->trace, i * 4, this, i * 4 + 2,                          (this + next) / 2); @@ -178,7 +178,7 @@ static inline int  _max(LoadGraph *lg)  {      gint i; -    gint max = 0; +    gint max = 1.0;      for (i = 0; i < lg->size; i++) {          if (lg->data[i] > max) @@ -195,25 +195,9 @@ load_graph_update(LoadGraph *lg, gint value)      if (value < 0)          return; -    else if (value > _max(lg) && value > lg->height) { -        /* FIXME: make scale work correctly :P */ -        gfloat nscale = (gfloat)lg->height / ceilf((float)value * lg->scale); - -        while (value * nscale > lg->height) { -            nscale *= .90; -        } -         -        if (nscale < lg->scale) { -            lg->scale = nscale; - -            for (i = 0; i < lg->size; i++) { -                lg->data[i] = (int)((float)lg->data[i] * lg->scale); -            } -        } -    } - -    value = (int)ceilf((float)value * lg->scale); +    lg->scale = (gfloat)lg->height / (gfloat)_max(lg); +      /* shift-right our data */      for (i = 0; i < lg->size; i++) {          lg->data[i] = lg->data[i+1]; @@ -231,12 +215,19 @@ gboolean lg_update(gpointer d)  {      LoadGraph *lg = (LoadGraph *)d; -    int i = 0; -    if ((rand() % 10) == 0) { -        i = rand() % 1000 + 500; +    static int i = 0; +    static int j = 1; +     +    if (i > 150) { +        j = -1; +    } else if (i < 0) { +        j = 1;      } -    load_graph_update(lg, rand() % 200 + i); +    i += j; +    if (rand() % 10 > 8) i*= 2; +    if (rand() % 10 < 2) i/= 2; +    load_graph_update(lg, i + rand() % 50);      return TRUE;  } @@ -251,8 +242,9 @@ int main(int argc, char **argv)      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);      gtk_widget_show(window); -    lg = load_graph_new(100); -    gtk_container_add(GTK_CONTAINER(window), lg->area); +    lg = load_graph_new(200); +    gtk_container_add(GTK_CONTAINER(window), load_graph_get_framed(lg)); +    gtk_container_set_border_width(GTK_CONTAINER(window), 20);      load_graph_configure_expose(lg);      lg_update(lg); diff --git a/hardinfo2/loadgraph.h b/hardinfo2/loadgraph.h index 81bdcde4..fdd967f0 100644 --- a/hardinfo2/loadgraph.h +++ b/hardinfo2/loadgraph.h @@ -45,8 +45,7 @@ struct _LoadGraph {      gint	   size;      gint	   width, height; -    LoadGraphColor color; -     +    LoadGraphColor color;      };  LoadGraph 	*load_graph_new(gint size); diff --git a/hardinfo2/md5.c b/hardinfo2/md5.c index 1047bf89..60df4b06 100644 --- a/hardinfo2/md5.c +++ b/hardinfo2/md5.c @@ -315,4 +315,7 @@ int main(int argc, char **argv)      return 0;  }  #endif				/* TEST */ + + +   
\ No newline at end of file diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index bc66189b..d5303507 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -24,6 +24,7 @@  #include <config.h>  #include <stock.h> +#include <binreloc.h>  #include <callbacks.h> @@ -57,10 +58,10 @@ static GtkActionEntry entries[] =  static GtkToggleActionEntry toggle_entries[] =  { -  { "LeftPaneAction", NULL, -    "_Left Pane", NULL,     -    "Toggles left pane visibility", -    G_CALLBACK(cb_left_pane) }, +  { "SidePaneAction", NULL, +    "_Side Pane", NULL,     +    "Toggles side pane visibility", +    G_CALLBACK(cb_side_pane) },    { "ToolbarAction", NULL,      "_Toolbar", NULL,          NULL, @@ -82,6 +83,7 @@ void menu_init(Shell *shell)      GtkActionGroup      *action_group;          /* Packing group for our Actions */      GtkUIManager        *menu_manager;          /* The magic widget! */      GError              *error;                 /* For reporting exceptions or errors */ +    gchar               *uidefs_path;      /* Create our objects */      menu_box = shell->vbox; @@ -103,7 +105,10 @@ void menu_init(Shell *shell)      /* Read in the UI from our XML file */      error = NULL; -    gtk_ui_manager_add_ui_from_file(menu_manager, PREFIX "uidefs.xml", &error); +    uidefs_path = g_strdup_printf("%s/hardinfo/uidefs.xml", +                                  gbr_find_data_dir(PREFIX)); +    gtk_ui_manager_add_ui_from_file(menu_manager, uidefs_path, &error); +    g_free(uidefs_path);      if (error) {          g_error("building menus failed: %s", error->message); diff --git a/hardinfo2/report.c b/hardinfo2/report.c index ca5f1afa..c3f49dbc 100644 --- a/hardinfo2/report.c +++ b/hardinfo2/report.c @@ -116,7 +116,9 @@ report_html_table(ReportContext *ctx, gchar *text)                      if (g_str_equal(value, "...")) {                          g_free(value); -                        value = ctx->entry->fieldfunc(key); +                        if (!(value = ctx->entry->fieldfunc(key))) { +                            value = g_strdup("..."); +                        }                      }                      if (*key == '$') { @@ -194,10 +196,11 @@ report_get_filename(void)                                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,                                           GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,                                           NULL); -#if GTK_CHECK_VERSION(2,8,0)     +#if GTK_CHECK_VERSION(2,8,0)      gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog),                                                     TRUE); -#endif +#endif                                                    +                                                         gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),                                        "hardinfo report.html"); diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index e8ac1f5e..ed73cfa7 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -28,6 +28,8 @@  #include <menu.h>  #include <stock.h> +#include <binreloc.h> +  /*   * Internal Prototypes ********************************************************   */ @@ -103,7 +105,7 @@ void shell_action_set_enabled(const gchar *action_name, gboolean setting)      }  } -void shell_set_left_pane_visible(gboolean setting) +void shell_set_side_pane_visible(gboolean setting)  {      if (setting)  	gtk_widget_show(shell->tree->scroll); @@ -159,6 +161,12 @@ void shell_action_set_active(const gchar *action_name, gboolean setting)  void  shell_status_pulse(void)  { +    if (shell->_pulses++ == 20) { +        /* we're pulsing for some time, disable the interface and change the cursor +           to a hourglass */ +        shell_view_set_enabled(FALSE); +    } +      gtk_progress_bar_pulse(GTK_PROGRESS_BAR(shell->progress));      while (gtk_events_pending())  	gtk_main_iteration(); @@ -177,9 +185,10 @@ void  shell_view_set_enabled(gboolean setting)  {      if (setting) { -        widget_set_cursor(shell->window, GDK_LEFT_PTR); +      shell->_pulses = 0; +      widget_set_cursor(shell->window, GDK_LEFT_PTR);      } else { -        widget_set_cursor(shell->window, GDK_WATCH); +      widget_set_cursor(shell->window, GDK_WATCH);      }      gtk_widget_set_sensitive(shell->hpaned, setting); @@ -238,7 +247,7 @@ destroy_me(void)  static void  create_window(void)  { -    GtkWidget		*vbox, *hbox; +    GtkWidget	*vbox, *hbox;      shell = g_new0(Shell, 1); @@ -312,7 +321,9 @@ shell_tree_modules_load(ShellTree * shelltree)  	module->icon = icon_cache_get_pixbuf(tmp);  	g_free(tmp); -	tmp = g_strdup_printf(PREFIX "modules/%s.so", iname); +	tmp = g_strdup_printf("%s/hardinfo/modules/%s.so", +	                      gbr_find_lib_dir(PREFIX), +	                      iname);  	module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY);  	g_free(tmp); @@ -519,7 +530,7 @@ shell_init(void)      gtk_widget_hide(shell->notebook);      shell_action_set_enabled("RefreshAction", FALSE); -    shell_action_set_active("LeftPaneAction", TRUE); +    shell_action_set_active("SidePaneAction", TRUE);      shell_action_set_active("ToolbarAction", TRUE);      shell_action_set_property("RefreshAction", "is-important", TRUE);      shell_action_set_property("ReportAction", "is-important", TRUE); @@ -539,10 +550,10 @@ update_field(gpointer data)             SHELL_VIEW_LOAD_GRAPH */          if (fu->loadgraph && shell->view_type == SHELL_VIEW_LOAD_GRAPH) {                GtkTreeSelection *ts; -    	       +      	      ts = gtk_tree_view_get_selection(GTK_TREE_VIEW              					 (shell->info->view)); -               +            					                 if (iter && gtk_tree_selection_iter_is_selected(ts, iter)) {                    load_graph_update(shell->loadgraph, atoi(value));                } @@ -667,7 +678,7 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry,  		fu->field_name = g_strdup(strchr(key, '$') + 1);  		fu->entry = entry;  		fu->loadgraph = TRUE; - +		  		g_timeout_add(ms, update_field, fu);  	    } else if (g_str_equal(key, "ReloadInterval")) {  		gint ms; diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index 54745bb6..23780da0 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -72,6 +72,8 @@ struct _Shell {      GtkUIManager	*ui_manager;      ShellViewType	 view_type; +     +    gint		_pulses;  };  struct _ShellTree { @@ -128,7 +130,7 @@ void		shell_action_set_property(const gchar *action_name,                                            const gchar *property,                                            gboolean setting); -void		shell_set_left_pane_visible(gboolean setting); +void		shell_set_side_pane_visible(gboolean setting);  void		shell_ui_manager_set_visible(const gchar *path,                                               gboolean setting); diff --git a/hardinfo2/uidefs.xml b/hardinfo2/uidefs.xml index f70031c8..280c7951 100644 --- a/hardinfo2/uidefs.xml +++ b/hardinfo2/uidefs.xml @@ -7,7 +7,7 @@        <placeholder name="FileMenuAdditions" />      </menu>      <menu name="ViewMenu" action="ViewMenuAction"> -      <menuitem name="LeftPane" action="LeftPaneAction"/> +      <menuitem name="SidePane" action="SidePaneAction"/>        <menuitem name="Toolbar" action="ToolbarAction"/>        <separator/>        <menuitem name="Refresh" action="RefreshAction"/> diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 79084c2c..ee6040b2 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -19,18 +19,21 @@  #include <hardinfo.h>  #include <gtk/gtk.h> -inline void -remove_quotes(gchar *str) -{ -    if (!str) -        return; +#define KiB 1024 +#define MiB 1048576 +#define GiB 1073741824 -    while (*str == '"') -        *(str++) = ' '; +inline gchar * +size_human_readable(gfloat size) +{ +    if (size < KiB) +	return g_strdup_printf("%.1f B", size); +    if (size < MiB) +	return g_strdup_printf("%.1f KiB", size / KiB); +    if (size < GiB) +	return g_strdup_printf("%.1f MiB", size / MiB); -    gchar *p; -    if ((p = strchr(str, '"'))) -        *p = 0; +    return g_strdup_printf("%.1f GiB", size / GiB);  }  inline void @@ -45,6 +48,18 @@ strend(gchar *str, gchar chr)  }  inline void +remove_quotes(gchar *str) +{ +    if (!str) +        return; + +    while (*str == '"') +        *(str++) = ' '; +     +    strend(str, '"'); +} + +inline void  remove_linefeed(gchar * str)  {      strend(str, '\n'); | 
