diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-10-15 21:57:09 +0000 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-10-15 21:57:09 +0000 |
commit | 3722c94e232b39d2a05ef359a60d25ac0cbe7887 (patch) | |
tree | 3212d41dd2db5e96fe09587a80f6606e9fb69317 | |
parent | 9949aa0b97e44d67713eed79859028c5ba92b1a3 (diff) |
Make menu shortcuts work, plug memory leaks, socket code cleanup
-rw-r--r-- | hardinfo2/Makefile.in | 1 | ||||
-rw-r--r-- | hardinfo2/arch/common/blowfish.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/md5.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/sha1.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/zlib.h | 2 | ||||
-rw-r--r-- | hardinfo2/benchmark.c | 2 | ||||
-rw-r--r-- | hardinfo2/devices.c | 10 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 5 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 3 | ||||
-rw-r--r-- | hardinfo2/iconcache.c | 7 | ||||
-rw-r--r-- | hardinfo2/loadgraph.c | 4 | ||||
-rw-r--r-- | hardinfo2/menu.c | 11 | ||||
-rw-r--r-- | hardinfo2/shell.c | 6 | ||||
-rw-r--r-- | hardinfo2/socket.c | 57 | ||||
-rw-r--r-- | hardinfo2/socket.h | 4 |
15 files changed, 76 insertions, 42 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index 554f42ba..780ba2b9 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -50,7 +50,6 @@ deb: dist-clean 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 diff --git a/hardinfo2/arch/common/blowfish.h b/hardinfo2/arch/common/blowfish.h index ad4bdb92..d4671e45 100644 --- a/hardinfo2/arch/common/blowfish.h +++ b/hardinfo2/arch/common/blowfish.h @@ -37,7 +37,7 @@ benchmark_fish(void) gchar *bdata_path; bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", - gbr_find_data_dir(PREFIX)); + path_data); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); diff --git a/hardinfo2/arch/common/md5.h b/hardinfo2/arch/common/md5.h index 256d6c3b..41a65e97 100644 --- a/hardinfo2/arch/common/md5.h +++ b/hardinfo2/arch/common/md5.h @@ -34,7 +34,7 @@ benchmark_md5(void) gchar *bdata_path; bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", - gbr_find_data_dir(PREFIX)); + path_data); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); return g_strdup("[Error]\n" diff --git a/hardinfo2/arch/common/sha1.h b/hardinfo2/arch/common/sha1.h index 4bd07276..53616bfc 100644 --- a/hardinfo2/arch/common/sha1.h +++ b/hardinfo2/arch/common/sha1.h @@ -33,7 +33,7 @@ benchmark_sha1(void) gchar *bdata_path; bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", - gbr_find_data_dir(PREFIX)); + path_data); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h index 2a1007ed..0b83a6a7 100644 --- a/hardinfo2/arch/common/zlib.h +++ b/hardinfo2/arch/common/zlib.h @@ -54,7 +54,7 @@ benchmark_zlib(void) gchar *bdata_path; bdata_path = g_strdup_printf("%s/hardinfo/benchmark.data", - gbr_find_data_dir(PREFIX)); + path_data); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index d66d0b8c..9bd1fc65 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -47,7 +47,7 @@ benchmark_include_results(gchar *results, const gchar *benchmark) conf = g_key_file_new(); bconf_path = g_strdup_printf("%s/hardinfo/benchmark.conf", - gbr_find_data_dir(PREFIX)); + path_data); g_key_file_load_from_file(conf, bconf_path, 0, NULL); machines = g_key_file_get_keys(conf, benchmark, NULL, NULL); diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index d5a1cefd..c43104d4 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -54,11 +54,11 @@ static gchar *battery_list = NULL; #define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++ -#define GET_STR(field_name,ptr) \ - if (!ptr && strstr(tmp[0], field_name)) { \ - ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \ - g_strfreev(tmp); \ - continue; \ +#define GET_STR(field_name,ptr) \ + if (!ptr && strstr(tmp[0], field_name)) { \ + ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \ + g_strfreev(tmp); \ + continue; \ } #include <vendor.h> diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index be203f1e..a1331948 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -24,6 +24,8 @@ #include <binreloc.h> +gchar *path_data, *path_lib; + int main(int argc, char **argv) { @@ -33,6 +35,9 @@ main(int argc, char **argv) if (!gbr_init(&error)) { g_error("BinReloc cannot be initialized: %s", error->message); + } else { + path_data = gbr_find_data_dir(PREFIX); + path_lib = gbr_find_lib_dir(PREFIX); } icon_cache_init(); diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 9734a21b..aab31389 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -35,4 +35,7 @@ inline void remove_linefeed(gchar *str); inline gchar *size_human_readable(gfloat size); void nonblock_sleep(guint msec); +extern gchar* path_lib; +extern gchar* path_data; + #endif /* __HARDINFO_H__ */ diff --git a/hardinfo2/iconcache.c b/hardinfo2/iconcache.c index fae641d1..ee5d2f4f 100644 --- a/hardinfo2/iconcache.c +++ b/hardinfo2/iconcache.c @@ -18,6 +18,7 @@ #include <iconcache.h> #include <config.h> #include <binreloc.h> +#include <hardinfo.h> static GHashTable *cache = NULL; @@ -36,8 +37,7 @@ GdkPixbuf *icon_cache_get_pixbuf(const gchar *file) if (!icon) { gchar *tmp = g_strdup_printf("%s/hardinfo/pixmaps/%s", - gbr_find_data_dir(PREFIX), - file); + path_data, file); icon = gdk_pixbuf_new_from_file(tmp, NULL); g_hash_table_insert(cache, g_strdup(file), icon); @@ -64,8 +64,7 @@ GdkPixbuf *icon_cache_get_pixbuf_at_size(const gchar *file, gint wid, gint hei) if (!icon) { gchar *tmp = g_strdup_printf("%s/hardinfo/pixmaps/%s", - gbr_find_data_dir(PREFIX), - file); + path_data, 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 18ae08c8..ac487c78 100644 --- a/hardinfo2/loadgraph.c +++ b/hardinfo2/loadgraph.c @@ -209,7 +209,7 @@ load_graph_update(LoadGraph *lg, gint value) if (value < 0) return; - if (lg->max_value > 0) { + if (lg->max_value < 0) { lg->scale = (gfloat)lg->height / (gfloat)_max(lg); } else { lg->scale = (gfloat)lg->height / (gfloat)lg->max_value; @@ -261,7 +261,7 @@ int main(int argc, char **argv) window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_show(window); - lg = load_graph_new(200); + lg = load_graph_new(50); 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); diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index d5303507..09ced371 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -27,6 +27,8 @@ #include <binreloc.h> #include <callbacks.h> +#include <hardinfo.h> + static GtkActionEntry entries[] = { @@ -84,6 +86,7 @@ void menu_init(Shell *shell) GtkUIManager *menu_manager; /* The magic widget! */ GError *error; /* For reporting exceptions or errors */ gchar *uidefs_path; + GtkAccelGroup *accel_group; /* Create our objects */ menu_box = shell->vbox; @@ -105,16 +108,20 @@ void menu_init(Shell *shell) /* Read in the UI from our XML file */ error = NULL; - uidefs_path = g_strdup_printf("%s/hardinfo/uidefs.xml", - gbr_find_data_dir(PREFIX)); + uidefs_path = g_strdup_printf("%s/hardinfo/uidefs.xml", path_data); 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); g_error_free(error); + return; } + /* Enable menu accelerators */ + accel_group = gtk_ui_manager_get_accel_group(menu_manager); + gtk_window_add_accel_group(GTK_WINDOW(shell->window), accel_group); + /* Connect up important signals */ /* This signal is necessary in order to place widgets from the UI manager * into the menu_box */ diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 8f051241..1990d0dc 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -305,8 +305,7 @@ shell_tree_modules_load(ShellTree * shelltree) keyfile = g_key_file_new(); - modules_conf = g_strdup_printf("%s/hardinfo/modules.conf", - gbr_find_data_dir(PREFIX)); + modules_conf = g_strdup_printf("%s/hardinfo/modules.conf", path_data); g_key_file_load_from_file(keyfile, modules_conf, 0, NULL); g_free(modules_conf); @@ -328,8 +327,7 @@ shell_tree_modules_load(ShellTree * shelltree) g_free(tmp); tmp = g_strdup_printf("%s/hardinfo/modules/%s.so", - gbr_find_lib_dir(PREFIX), - iname); + path_lib, iname); module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); g_free(tmp); diff --git a/hardinfo2/socket.c b/hardinfo2/socket.c index d1bd4af3..556466d0 100644 --- a/hardinfo2/socket.c +++ b/hardinfo2/socket.c @@ -42,27 +42,24 @@ Socket *sock_connect(gchar * host, gint port) server.sin_family = AF_INET; server.sin_addr.s_addr = inet_addr(host); server.sin_port = htons(port); - - if (connect(sock, (struct sockaddr *) (void *) &server, sizeof(server)) < 0) { + + if (connect + (sock, (struct sockaddr *) (void *) &server, + sizeof(server)) < 0) { return NULL; } s = g_new0(Socket, 1); s->sock = sock; - + return s; } return NULL; } -int sock_write(Socket * s, gchar * str) -{ - return write(s->sock, str, strlen(str)); -} - /* From: http://www.erlenstar.demon.co.uk/unix/faq_3.html#SEC26 */ -int sock_is_ready(Socket *s) +static inline int __sock_is_ready(Socket * s, int mode) { int rc, fd = s->sock; fd_set fds; @@ -72,27 +69,51 @@ int sock_is_ready(Socket *s) FD_SET(fd, &fds); tv.tv_sec = tv.tv_usec = 0; - rc = select(fd+1, &fds, NULL, NULL, &tv); + if (mode == 0) { + /* read */ + rc = select(fd + 1, &fds, NULL, NULL, &tv); + } else { + /* write */ + rc = select(fd + 1, NULL, &fds, NULL, &tv); + } + if (rc < 0) - return -1; + return -1; return FD_ISSET(fd, &fds) ? 1 : 0; } +int sock_ready_to_read(Socket * s) +{ + return __sock_is_ready(s, 0); +} + +int sock_ready_to_write(Socket * s) +{ + return __sock_is_ready(s, 1); +} + int sock_read(Socket * s, gchar * buffer, gint size) { - if (sock_is_ready(s)) { - gint n; + if (sock_ready_to_read(s)) { + gint n; - n = read(s->sock, buffer, size); - buffer[n] = '\0'; - - return n; + n = read(s->sock, buffer, size); + buffer[n] = '\0'; + + return n; } - + return 0; } +int sock_write(Socket * s, gchar * str) +{ + while (!sock_ready_to_write(s)); + + return write(s->sock, str, strlen(str)); +} + void sock_close(Socket * s) { close(s->sock); diff --git a/hardinfo2/socket.h b/hardinfo2/socket.h index 77938b3f..fca8d5b7 100644 --- a/hardinfo2/socket.h +++ b/hardinfo2/socket.h @@ -29,6 +29,8 @@ Socket *sock_connect(gchar * host, gint port); int sock_write(Socket * s, gchar * str); int sock_read(Socket * s, gchar * buffer, gint size); void sock_close(Socket * s); -int sock_is_ready(Socket *s); + +int sock_ready_to_read(Socket *s); +int sock_ready_to_write(Socket *s); #endif /* __HI_SOCKET_H__ */ |