diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-01-26 19:39:15 +0000 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-01-26 19:39:15 +0000 | 
| commit | e9906f6d9335ae96cd6afac714646b97edc469a5 (patch) | |
| tree | 956f3266766454f931e7d18e2fe78a6256d11039 /hardinfo2 | |
| parent | 53f455be1d85829551761dbcfcf6e5706606186b (diff) | |
Sync with internal svn
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/Makefile.in | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/linux/common/net.h | 204 | ||||
| l--------- | hardinfo2/arch/linux/x86/net.h | 1 | ||||
| -rw-r--r-- | hardinfo2/callbacks.c | 7 | ||||
| -rw-r--r-- | hardinfo2/computer.c | 18 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.c | 4 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.h | 3 | ||||
| -rw-r--r-- | hardinfo2/report.c | 467 | ||||
| -rw-r--r-- | hardinfo2/report.h | 48 | ||||
| -rw-r--r-- | hardinfo2/shell.c | 36 | ||||
| -rw-r--r-- | hardinfo2/shell.h | 5 | ||||
| -rw-r--r-- | hardinfo2/stock.c | 3 | ||||
| -rw-r--r-- | hardinfo2/util.c | 14 | 
13 files changed, 794 insertions, 18 deletions
| diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index b4284da1..8b367267 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -5,7 +5,7 @@ CFLAGS = -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 +		menu.o stock.o callbacks.o expr.o report.o  MODULES = computer.so devices.so benchmark.so   all:	$(OBJECTS) $(MODULES) diff --git a/hardinfo2/arch/linux/common/net.h b/hardinfo2/arch/linux/common/net.h new file mode 100644 index 00000000..d0738ce5 --- /dev/null +++ b/hardinfo2/arch/linux/common/net.h @@ -0,0 +1,204 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program 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. + * + *    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. + * + *    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 + */ + +static gchar *network_interfaces = NULL; + +#include <sys/ioctl.h> +#include <net/if.h> +#include <netinet/in.h> +#include <linux/sockios.h> +#include <sys/socket.h> + +typedef struct _NetInfo NetInfo; +struct _NetInfo { +    char                name[16];  +    int                 mtu; +    unsigned char       mac[8]; +}; + + +void get_net_info(char *if_name, NetInfo *netinfo) +{ +    struct ifreq ifr; +    int fd; + +    fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + +    strcpy(ifr.ifr_name, if_name); +    strcpy(netinfo->name, if_name); + +    strcpy(ifr.ifr_name, if_name); +    if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) { +        netinfo->mtu = 0; +    } else { +        netinfo->mtu = ifr.ifr_mtu; +    } +     +    strcpy(ifr.ifr_name, if_name); +    if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { +        memset(netinfo->mac, 0, 8); +    } else { +        memcpy(netinfo->mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 8); +    } + +    shutdown(fd, 0); +} + +static struct { +    char *type; +    char *label; +} netdev2type[] = { +    { "eth",	"Ethernet" }, +    { "lo",	"Loopback" }, +    { "ppp",	"Point-to-Point" }, +    { "ath",	"Wireless" }, +    { "wlan",	"Wireless" }, +    { "tun",    "Virtual Point-to-Point (TUN)" }, +    { "tap",    "Ethernet (TAP)" }, +    { "plip",   "Parallel Line Internet Protocol" }, +    { "irlan",  "Infrared" }, +    { "slip",   "Serial Line Internet Protocol" }, +    { "isdn",	"Integrated Services Digital Network" }, +    { "sit",	"IPv6-over-IPv4 Tunnel" }, +    { "vmnet8", "VMWare Virtual Network Interface (NAT)" }, +    { "vmnet",  "VMWare Virtual Network Interface" }, +    { NULL,	"Unknown" }, +}; + +static const gchar * +net_get_iface_type(gchar *name) +{ +    int i; +     +    for (i = 0; netdev2type[i].type; i++) { +        if (g_str_has_prefix(name, netdev2type[i].type)) +            break; +    } +     +    return netdev2type[i].label; +} + +static gboolean +remove_net_devices(gpointer key, gpointer value, gpointer data) +{ +    if (!strncmp((gchar *) key, "NET", 4)) { +	g_free((gchar *) key); +	g_free((GtkTreeIter *) value); +	return TRUE; +    } +    return FALSE; +} + +static void +scan_net_interfaces_24(void) +{ +    FILE *proc_net; +    NetInfo ni; +    gchar buffer[256]; +    gchar *devid, *detailed; +    gulong recv_bytes; +    gulong recv_errors; +    gulong recv_packets; +     +    gulong trans_bytes; +    gulong trans_errors; +    gulong trans_packets; +     +    if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) { +        if (network_interfaces) { +            g_free(network_interfaces); +            network_interfaces = g_strdup("[Network Interfaces]\n" +                                          "None found=\n"); +        } + +	return; +    } + +    if (network_interfaces) { +        g_free(network_interfaces); +    } +     +    network_interfaces = g_strdup("[Network Interfaces]\n"); + +    proc_net = fopen("/proc/net/dev", "r"); +    while (fgets(buffer, 256, proc_net)) { +	if (strchr(buffer, ':')) { +	    gint trash; +	    gchar ifacename[16]; +	    gchar *buf = buffer; +	    gint i; + +	    buf = g_strstrip(buf); + +	    memset(ifacename, 0, 16); + +	    for (i = 0; buffer[i] != ':' && i < 16; i++) { +		ifacename[i] = buffer[i]; +	    } + +	    buf = strchr(buf, ':') + 1; + +	    /* iface: bytes packets errs drop fifo frame compressed multicast */ +	    sscanf(buf, "%ld %ld %ld %d %d %d %d %d %ld %ld %ld", +		   &recv_bytes, &recv_packets, +		   &recv_errors, &trash, &trash, &trash, &trash, +		   &trash, &trans_bytes, &trans_packets, +		   &trans_errors); + +            gfloat recv_mb = recv_bytes / 1048576.0; +            gfloat trans_mb = trans_bytes / 1048576.0; +             +            devid = g_strdup_printf("NET%s", ifacename); +	    network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB\n", +                                                  network_interfaces, +                                                  devid, +                                                  ifacename, +                                                  trans_mb, +                                                  recv_mb); +             +            get_net_info(ifacename, &ni); +            detailed = g_strdup_printf("[Network Adapter Properties]\n" +                                        "Interface Type=%s\n" +                                        "Hardware Address=%02x:%02x:%02x:%02x:%02x:%02x\n" +                                        "MTU=%d\n" +                                        "Bytes Sent=%ld (%.2fMiB)\n" +                                        "Bytes Received=%ld (%.2fMiB)\n", +                                        net_get_iface_type(ifacename), +                                        ni.mac[0], ni.mac[1], +                                        ni.mac[2], ni.mac[3], +                                        ni.mac[4], ni.mac[5], +                                        ni.mtu, +                                        recv_bytes, recv_mb, +                                        trans_bytes, trans_mb); +            g_hash_table_insert(moreinfo, devid, detailed); +	} +    } +    fclose(proc_net); +} + +static void +scan_net_interfaces(void) +{ +    /* FIXME: See if we're running Linux 2.6 and if /sys is mounted, then use +              that instead of /proc/net/dev */ + +    /* remove old devices from global device table */ +    g_hash_table_foreach_remove(moreinfo, remove_net_devices, NULL); + +    scan_net_interfaces_24(); +} diff --git a/hardinfo2/arch/linux/x86/net.h b/hardinfo2/arch/linux/x86/net.h new file mode 120000 index 00000000..72d77b26 --- /dev/null +++ b/hardinfo2/arch/linux/x86/net.h @@ -0,0 +1 @@ +../../linux/common/net.h
\ No newline at end of file diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index b4d80244..4a3ed6a6 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -15,11 +15,14 @@   *    along with this program; if not, write to the Free Software   *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA   */ +  #include <gtk/gtk.h>  #include <callbacks.h>  #include <iconcache.h>  #include <config.h> +  #include <shell.h> +#include <report.h>  void cb_refresh()  { @@ -63,7 +66,9 @@ void cb_about()  void cb_generate_report()  { -    g_print("generate report\n"); +    Shell *shell = shell_get_main_shell(); + +    report_dialog_show(shell->tree->model, shell->window);  }  void cb_quit(void) diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index 9a721133..36bba973 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -40,6 +40,7 @@ enum {      COMPUTER_FILESYSTEMS,      COMPUTER_SHARES,      COMPUTER_DISPLAY, +    COMPUTER_NETWORK,  /*    COMPUTER_LOADGRAPH,*/  } Entries; @@ -52,6 +53,7 @@ static ModuleEntry hi_entries[] = {      {"Filesystems",		"dev_removable.png"},      {"Shared Directories",	"shares.png"},      {"Display",			"monitor.png"}, +    {"Network Interfaces",	"network.png"},  /*    {"<s>LoadGraph</s>",	"summary.png"}*/  }; @@ -70,6 +72,7 @@ static GHashTable *moreinfo = NULL;  #include <arch/this/filesystem.h>  #include <arch/this/samba.h>  #include <arch/this/sensors.h> +#include <arch/this/net.h>  static Computer *  computer_get_info(void) @@ -112,6 +115,9 @@ computer_get_info(void)      shell_status_update("Reading sensors...");      read_sensors(); +    shell_status_update("Obtaining network information..."); +    scan_net_interfaces(); +      computer->date_time = "...";      return computer;  } @@ -123,6 +129,9 @@ hi_reload(gint entry)      case COMPUTER_FILESYSTEMS:  	scan_filesystems();  	break; +    case COMPUTER_NETWORK: +	scan_net_interfaces(); +	break;      case COMPUTER_SENSORS:  	read_sensors();  	break; @@ -183,16 +192,21 @@ hi_info(gint entry)      static Computer *computer = NULL;      static gchar *tmp = NULL; -    if (tmp != NULL) { +    /*if (tmp != NULL) {         g_free(tmp);         tmp = NULL; -    }  +    } */      if (!computer) {  	computer = computer_get_info();      }      switch (entry) { +    case COMPUTER_NETWORK: +        return g_strdup_printf("[$ShellParam$]\n" +                               "ReloadInterval=3000\n" +                               "ViewType=1\n" +                               "%s", network_interfaces);      case COMPUTER_SENSORS:          return g_strdup_printf("[$ShellParam$]\n"                                 "ReloadInterval=3000\n" diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 80de3c87..fd605626 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -27,10 +27,6 @@ main(int argc, char **argv)  {      gtk_init(&argc, &argv); -#ifdef DEBUG -    g_log_set_always_fatal(G_LOG_LEVEL_MASK); -#endif -      icon_cache_init();      stock_icons_init();      shell_init(); diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 20697584..d8f62439 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -19,7 +19,7 @@  #ifndef __HARDINFO_H__  #define __HARDINFO_H__ -#include <glib.h> +#include <gtk/gtk.h>  typedef struct _ModuleEntry ModuleEntry; @@ -31,5 +31,6 @@ struct _ModuleEntry {  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);  #endif				/* __HARDINFO_H__ */ diff --git a/hardinfo2/report.c b/hardinfo2/report.c new file mode 100644 index 00000000..f3621276 --- /dev/null +++ b/hardinfo2/report.c @@ -0,0 +1,467 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program 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. + * + *    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. + * + *    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 + */ +  +#include <report.h> +#include <stdio.h> +#include <string.h> +#include <shell.h> +#include <hardinfo.h> + +static ReportDialog	*report_dialog_new(GtkTreeModel *model, GtkWidget *parent); +static void		 set_all_active(ReportDialog *rd, gboolean setting); + +static void +report_html_header(ReportContext *ctx) +{ +    fprintf(ctx->stream, +            "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" \ +	    "<html><head>\n" \ +	    "<title>HardInfo System Report</title>\n" \ +	    "<style>\n" \ +	    ".title  { font: bold 130%% serif; color: #0066FF; padding: 30px 0 10px 0 }\n" \ +	    ".stitle { font: bold 100%% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }\n" \ +	    ".sstitle{ font: bold 80%% serif; color: #000000; background: #efefef }\n" \ +	    ".field  { font: 80%% sans-serif; color: #000000; padding: 2px; padding-left: 50px }\n" \ +	    ".value  { font: 80%% sans-serif; color: #505050 }\n" \ +	    "</style>\n" \ +	    "</head><body>\n" \ +	    "<table width=\"100%%\"><tbody>"); +} + +static void +report_html_footer(ReportContext *ctx) +{ +    fprintf(ctx->stream, +            "</tbody></table></body></html>"); +} + +static void +report_html_title(ReportContext *ctx, gchar *text) +{ +    fprintf(ctx->stream, +            "<tr><td colspan=\"2\" class=\"title\">%s</td></tr>\n", text); +} + +static void +report_html_subtitle(ReportContext *ctx, gchar *text) +{ +    fprintf(ctx->stream, +            "<tr><td colspan=\"2\" class=\"stitle\">%s</td></tr>\n", text); +} +static void +report_html_subsubtitle(ReportContext *ctx, gchar *text) +{ +    fprintf(ctx->stream, +            "<tr><td colspan=\"2\" class=\"sstitle\">%s</td></tr>\n", text); +} + +static void +report_html_key_value(ReportContext *ctx, gchar *key, gchar *value) +{ +    fprintf(ctx->stream, +            "<tr><td class=\"field\">%s</td>" \ +            "<td class=\"value\">%s</td></tr>\n", key, value); +} + +static void +report_html_table(ReportContext *ctx, gchar *text) +{ +    GKeyFile	 *key_file = g_key_file_new(); +    gchar	**groups; +    gint          i; + +    g_key_file_load_from_data(key_file, text, strlen(text), 0, NULL); +    groups = g_key_file_get_groups(key_file, NULL); +     +    for (i = 0; groups[i]; i++) { +	gchar   *group, *tmpgroup; +	gchar **keys; +	gint    j; +	 +	if (groups[i][0] == '$') +	    continue; +	 +        group = groups[i]; +        keys = g_key_file_get_keys(key_file, group, NULL, NULL); + +        tmpgroup = g_strdup(group); +        strend(group, '#'); + +        report_html_subsubtitle(ctx, group); +	 +	for (j = 0; keys[j]; j++) { +            gchar *key = keys[j]; +            gchar *value; + +            value = g_key_file_get_value(key_file, tmpgroup, key, NULL); +        +            if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) { +                    strend(key, '#'); + +                    if (g_str_equal(value, "...")) { +                        g_free(value); +                        value = ctx->entry->fieldfunc(key); +                    } + +                    if (*key == '$') { +                        gchar **tmp; + +                        tmp = g_strsplit(++key, "$", 0); +                        report_html_key_value(ctx, tmp[1], value); +                        g_strfreev(tmp); +                    } else { +                        report_html_key_value(ctx, key, value); +                    } +                                         +            } + +            g_free(value); +	} +	 +	g_free(tmpgroup); +	g_strfreev(keys); +    } + +    g_strfreev(groups); +    g_key_file_free(key_file); +} + +static void +report_generate_child(ReportContext *ctx, GtkTreeIter *iter) +{ +    ShellModuleEntry *entry; +    gboolean selected; +     +    gtk_tree_model_get(ctx->rd->model, iter, TREE_COL_SEL, &selected, -1); +    if (!selected) +        return; +     +    gtk_tree_model_get(ctx->rd->model, iter, TREE_COL_DATA, &entry, -1); +     +    ctx->entry = entry; + +    report_html_subtitle(ctx, entry->name); +    report_html_table(ctx, entry->func(entry->number)); +} + +static void +report_generate_children(ReportContext *ctx, GtkTreeIter *iter) +{ +    GtkTreeModel *model = ctx->rd->model; +    gchar *name; + +    gtk_tree_model_get(model, iter, TREE_COL_NAME, &name, -1); +    report_html_title(ctx, name); + +    if (gtk_tree_model_iter_has_child(model, iter)) { +        gint children = gtk_tree_model_iter_n_children(model, iter); +        gint i; + +        for (i = 0; i < children; i++) { +            GtkTreeIter child; +             +            gtk_tree_model_iter_nth_child(model, &child, iter, i); +            report_generate_child(ctx, &child); +        } +    } +} + +static gchar * +report_get_filename(void) +{ +    GtkWidget *dialog; +    gchar *filename = NULL; + +    dialog = gtk_file_chooser_dialog_new("Save File", +	                                 NULL, +                                         GTK_FILE_CHOOSER_ACTION_SAVE, +                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, +                                         GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, +                                         NULL); +    gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), +                                                   TRUE); +    gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), +                                      "hardinfo report.html"); +     +    if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { +         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); +    } + +    gtk_widget_destroy (dialog); +    return filename; +} + +static gboolean +report_generate(ReportDialog *rd) +{ +    GtkTreeIter		 iter; +    GtkTreeModel	*model; +    ReportContext	*ctx; +    gchar		*file; +    FILE		*stream; +     +    file = report_get_filename(); +    if (!file) +        return FALSE; +    stream = fopen(file, "w+"); +    if (!stream) { +        /* FIXME complain */ +        return FALSE; +    } +     +    model	= rd->model; +    ctx		= g_new0(ReportContext, 1); +    ctx->rd	= rd; +    ctx->stream = stream; + +    report_html_header(ctx); +     +    gtk_tree_model_get_iter_first(model, &iter); +     +    do { +         report_generate_children(ctx, &iter); +    } while (gtk_tree_model_iter_next(model, &iter)); + +    report_html_footer(ctx); +     +    fclose(ctx->stream); +    g_free(ctx); +     +    return TRUE; +} + +void +report_dialog_show(GtkTreeModel *model, GtkWidget *parent) +{ +    gboolean success; +    ReportDialog *rd = report_dialog_new(model, parent); + +    if (gtk_dialog_run(GTK_DIALOG(rd->dialog)) == GTK_RESPONSE_ACCEPT) { +	shell_status_update("Generating report..."); +        gtk_widget_hide(rd->dialog); +        shell_view_set_enabled(FALSE); +        shell_status_set_enabled(TRUE); + +	success = report_generate(rd); + +        shell_status_set_enabled(FALSE); +         +        if (success)  +  	    shell_status_update("Report saved."); +        else +            shell_status_update("Error while creating the report."); +    } + +    set_all_active(rd, FALSE); +    gtk_widget_destroy(rd->dialog); +    g_free(rd); +} + +static void +set_children_active(GtkTreeModel *model, GtkTreeIter *iter, gboolean setting) +{ +    if (gtk_tree_model_iter_has_child(model, iter)) { +        gint children = gtk_tree_model_iter_n_children(model, iter); + +        gtk_tree_store_set(GTK_TREE_STORE(model), iter, TREE_COL_SEL, setting, -1); +         +        for (children--; children >= 0; children--) { +            GtkTreeIter child; +             +            gtk_tree_model_iter_nth_child(model, &child, iter, children); +            gtk_tree_store_set(GTK_TREE_STORE(model), &child, TREE_COL_SEL, setting, -1); +        } +    } +} + +static void +set_all_active(ReportDialog *rd, gboolean setting) +{ +    GtkTreeIter iter; +    GtkTreeModel *model = rd->model; +     +    gtk_tree_model_get_iter_first(model, &iter); +     +    do { +         set_children_active(model, &iter, setting); +    } while (gtk_tree_model_iter_next(model, &iter)); +} + +static void +report_dialog_sel_none(GtkWidget *widget, ReportDialog *rd) +{ +    set_all_active(rd, FALSE); +} + +static void +report_dialog_sel_all(GtkWidget *widget, ReportDialog *rd) +{ +    set_all_active(rd, TRUE); +} + +static void +report_dialog_sel_toggle(GtkCellRendererToggle *cellrenderertoggle, +			 gchar		       *path_str, +			 ReportDialog          *rd) +{ +    GtkTreeModel *model = rd->model; +    GtkTreeIter  iter; +    GtkTreePath *path = gtk_tree_path_new_from_string(path_str); +    gboolean active; +     +    gtk_tree_model_get_iter(model, &iter, path); +    gtk_tree_model_get(model, &iter, TREE_COL_SEL, &active, -1); +     +    active = !active; +    gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TREE_COL_SEL, active, -1); +    set_children_active(model, &iter, active); + +    gtk_tree_path_free(path); +} + +static ReportDialog +*report_dialog_new(GtkTreeModel *model, GtkWidget *parent) +{ +    ReportDialog *rd; +    GtkWidget *dlgReport; +    GtkWidget *dialog1_vbox; +    GtkWidget *scrolledwindow2; +    GtkWidget *treeview2; +    GtkWidget *hbuttonbox3; +    GtkWidget *button3; +    GtkWidget *button6; +    GtkWidget *dialog1_action_area; +    GtkWidget *button8; +    GtkWidget *button7; +    GtkWidget *label; +     +    GtkTreeViewColumn *column; +    GtkCellRenderer *cr_text, *cr_pbuf, *cr_toggle;  + +    rd = g_new0(ReportDialog, 1); + +    dlgReport = gtk_dialog_new(); +    gtk_window_set_title(GTK_WINDOW(dlgReport), "Generate Report"); +    gtk_window_set_default_size(GTK_WINDOW(dlgReport), 320, 260); +    gtk_window_set_transient_for(GTK_WINDOW(dlgReport), GTK_WINDOW(parent)); +    gtk_window_set_position(GTK_WINDOW(dlgReport), GTK_WIN_POS_CENTER_ON_PARENT); +    gtk_window_set_type_hint(GTK_WINDOW(dlgReport), +			     GDK_WINDOW_TYPE_HINT_DIALOG); + +    dialog1_vbox = GTK_DIALOG(dlgReport)->vbox; +    gtk_box_set_spacing(GTK_BOX(dialog1_vbox), 5); +    gtk_container_set_border_width(GTK_CONTAINER(dialog1_vbox), 4); +    gtk_widget_show(dialog1_vbox); +     +    label = gtk_label_new("<big><b>Generate Report</b></big>\n" \ +                          "Please choose the information that you wish " \ +                          "to view in your report:"); +    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); +    gtk_label_set_use_markup(GTK_LABEL(label), TRUE); +    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); +    gtk_widget_show(label); +    gtk_box_pack_start(GTK_BOX(dialog1_vbox), label, FALSE, FALSE, 0); +     +    scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL); +    gtk_widget_show(scrolledwindow2); +    gtk_box_pack_start(GTK_BOX(dialog1_vbox), scrolledwindow2, TRUE, TRUE, 0); +    gtk_widget_set_size_request(scrolledwindow2, -1, 200); +    GTK_WIDGET_UNSET_FLAGS(scrolledwindow2, GTK_CAN_FOCUS); +    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2), +				   GTK_POLICY_AUTOMATIC, +				   GTK_POLICY_ALWAYS); +    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW +					(scrolledwindow2), GTK_SHADOW_IN); + +    treeview2 = gtk_tree_view_new_with_model(model); +    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview2), FALSE); +    gtk_widget_show(treeview2); +    gtk_container_add(GTK_CONTAINER(scrolledwindow2), treeview2); +    GTK_WIDGET_UNSET_FLAGS(treeview2, GTK_CAN_FOCUS); +     +    column = gtk_tree_view_column_new(); +    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview2), column); + +    cr_toggle = gtk_cell_renderer_toggle_new(); +    gtk_tree_view_column_pack_start(column, cr_toggle, FALSE); +    g_signal_connect(cr_toggle, "toggled", G_CALLBACK(report_dialog_sel_toggle), rd); +    gtk_tree_view_column_add_attribute(column, cr_toggle, "active", +				       TREE_COL_SEL); + +    cr_pbuf = gtk_cell_renderer_pixbuf_new(); +    gtk_tree_view_column_pack_start(column, cr_pbuf, FALSE); +    gtk_tree_view_column_add_attribute(column, cr_pbuf, "pixbuf", +				       TREE_COL_PBUF); + +    cr_text = gtk_cell_renderer_text_new(); +    gtk_tree_view_column_pack_start(column, cr_text, TRUE); +    gtk_tree_view_column_add_attribute(column, cr_text, "markup", +				       TREE_COL_NAME); +     +    hbuttonbox3 = gtk_hbutton_box_new(); +    gtk_widget_show(hbuttonbox3); +    gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbuttonbox3, FALSE, TRUE, 0); +    gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox3), +			      GTK_BUTTONBOX_SPREAD); + +    button3 = gtk_button_new_with_mnemonic("Select _None"); +    gtk_widget_show(button3); +    gtk_container_add(GTK_CONTAINER(hbuttonbox3), button3); +    GTK_WIDGET_UNSET_FLAGS(button3, GTK_CAN_FOCUS); +    GTK_WIDGET_SET_FLAGS(button3, GTK_CAN_DEFAULT); +    g_signal_connect(button3, "clicked", G_CALLBACK(report_dialog_sel_none), rd); + +    button6 = gtk_button_new_with_mnemonic("Select _All"); +    gtk_widget_show(button6); +    gtk_container_add(GTK_CONTAINER(hbuttonbox3), button6); +    GTK_WIDGET_UNSET_FLAGS(button6, GTK_CAN_FOCUS); +    GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); +    g_signal_connect(button6, "clicked", G_CALLBACK(report_dialog_sel_all), rd); + +    dialog1_action_area = GTK_DIALOG(dlgReport)->action_area; +    gtk_widget_show(dialog1_action_area); +    gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog1_action_area), +			      GTK_BUTTONBOX_END); + +    button8 = gtk_button_new_from_stock("gtk-cancel"); +    gtk_widget_show(button8); +    gtk_dialog_add_action_widget(GTK_DIALOG(dlgReport), button8, +				 GTK_RESPONSE_CANCEL); +    GTK_WIDGET_UNSET_FLAGS(button8, GTK_CAN_FOCUS); +    GTK_WIDGET_SET_FLAGS(button8, GTK_CAN_DEFAULT); + +    button7 = gtk_button_new_with_mnemonic("Generate _Report"); +    gtk_widget_show(button7); +    gtk_dialog_add_action_widget(GTK_DIALOG(dlgReport), button7, +				 GTK_RESPONSE_ACCEPT); +    GTK_WIDGET_UNSET_FLAGS(button7, GTK_CAN_FOCUS); +    GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT); + +    rd->dialog		= dlgReport; +    rd->btn_cancel	= button8; +    rd->btn_generate	= button7; +    rd->btn_sel_all	= button6; +    rd->btn_sel_none	= button3; +    rd->treeview	= treeview2; +    rd->model		= model; + +    gtk_tree_view_collapse_all(GTK_TREE_VIEW(treeview2)); +    set_all_active(rd, TRUE); + +    return rd; +} diff --git a/hardinfo2/report.h b/hardinfo2/report.h new file mode 100644 index 00000000..e2bfc912 --- /dev/null +++ b/hardinfo2/report.h @@ -0,0 +1,48 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program 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. + * + *    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. + * + *    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 + */ +  +#ifndef __REPORT_H__ +#define __REPORT_H__ +#include <gtk/gtk.h> +#include <shell.h> + +typedef struct _ReportDialog	ReportDialog; +typedef struct _ReportContext	ReportContext; + +struct _ReportContext { +  ReportDialog		*rd; +  ShellModuleEntry	*entry; +   +  FILE			*stream; +}; + +struct _ReportDialog { +  GtkWidget *dialog; +  GtkWidget *filechooser; +  GtkWidget *btn_cancel; +  GtkWidget *btn_generate; +  GtkWidget *btn_sel_all; +  GtkWidget *btn_sel_none; +  GtkWidget *treeview; +   +  GtkTreeModel *model; +}; + +void report_dialog_show(); + +#endif	/* __REPORT_H__ */ diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 60863012..286c179b 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -53,6 +53,11 @@ static GHashTable	*update_tbl = NULL;  /*   * Code :) ********************************************************************   */ + +Shell *shell_get_main_shell(void) +{ +    return shell; +}  void shell_ui_manager_set_visible(const gchar *path,                                    gboolean setting) @@ -171,9 +176,16 @@ shell_status_set_percentage(gint percentage)  void  shell_view_set_enabled(gboolean setting)  { +    if (setting) { +        widget_set_cursor(shell->window, GDK_LEFT_PTR); +    } else { +        widget_set_cursor(shell->window, GDK_WATCH); +    } +      gtk_widget_set_sensitive(shell->hpaned, setting);      shell_action_set_enabled("ViewMenuAction", setting);      shell_action_set_enabled("RefreshAction", setting); +    shell_action_set_enabled("ReportAction", setting);  }  void @@ -191,6 +203,7 @@ void  shell_do_reload(void)  {      shell_action_set_enabled("RefreshAction", FALSE); +    shell_action_set_enabled("ReportAction", FALSE);      if (shell->selected && shell->selected->reloadfunc) {      	GtkTreeSelection *ts; @@ -203,6 +216,7 @@ shell_do_reload(void)      }      shell_action_set_enabled("RefreshAction", TRUE); +    shell_action_set_enabled("ReportAction", TRUE);  }  void @@ -215,6 +229,13 @@ shell_status_update(const gchar *message)  }  static void +destroy_me(void) +{ +    gtk_main_quit(); +    exit(0); +} + +static void  shell_create_window(void)  {      GtkWidget		*vbox, *hbox; @@ -225,7 +246,7 @@ shell_create_window(void)      gtk_window_set_icon(GTK_WINDOW(shell->window), icon_cache_get_pixbuf("logo.png"));      gtk_window_set_title(GTK_WINDOW(shell->window), "System Information");      gtk_widget_set_size_request(shell->window, 600, 400); -    g_signal_connect(G_OBJECT(shell->window), "destroy", gtk_main_quit, +    g_signal_connect(G_OBJECT(shell->window), "destroy", destroy_me,  		     NULL);      vbox = gtk_vbox_new(FALSE, 0); @@ -310,10 +331,10 @@ shell_tree_modules_load(ShellTree * shelltree)  		const gchar *(*shell_name) (gint);  		ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); -		if (g_module_symbol(module->dll, "hi_icon", &(shell_icon))) { +		if (g_module_symbol(module->dll, "hi_icon", (gpointer)&(shell_icon))) {  		    entry->icon = shell_icon(i);  		} -		if (g_module_symbol(module->dll, "hi_name", &(shell_name))) { +		if (g_module_symbol(module->dll, "hi_name", (gpointer)&(shell_name))) {  		    entry->name = g_strdup(shell_name(i));  		}  		g_module_symbol(module->dll, "hi_info", @@ -419,7 +440,8 @@ add_modules_to_gui(gpointer data, gpointer user_data)      gtk_tree_store_append(store, &parent, NULL);      gtk_tree_store_set(store, &parent, TREE_COL_NAME, module->name, -                       TREE_COL_DATA, NULL, -1); +                       TREE_COL_DATA, NULL, +                       TREE_COL_SEL, FALSE, -1);      if (module->icon) {  	gtk_tree_store_set(store, &parent, TREE_COL_PBUF, module->icon, -1); @@ -437,7 +459,8 @@ add_modules_to_gui(gpointer data, gpointer user_data)  	    gtk_tree_store_append(store, &child, &parent);  	    gtk_tree_store_set(store, &child, TREE_COL_NAME, entry->name, -			       TREE_COL_DATA, entry, -1); +			       TREE_COL_DATA, entry, +                               TREE_COL_SEL, FALSE, -1);  	    if (entry->icon) {  		gtk_tree_store_set(store, &child, TREE_COL_PBUF, @@ -498,7 +521,6 @@ shell_init(void)      gtk_widget_hide(shell->notebook);      shell_action_set_enabled("RefreshAction", FALSE); -    shell_action_set_enabled("ReportAction", FALSE);      shell_action_set_active("LeftPaneAction", TRUE);      shell_action_set_active("ToolbarAction", TRUE);      shell_action_set_property("RefreshAction", "is-important", TRUE); @@ -1036,7 +1058,7 @@ shell_tree_new()  				   GTK_POLICY_AUTOMATIC);      store = gtk_tree_store_new(TREE_NCOL, GDK_TYPE_PIXBUF, G_TYPE_STRING, -			       G_TYPE_POINTER); +			       G_TYPE_POINTER, G_TYPE_BOOLEAN);      model = GTK_TREE_MODEL(store);      treeview = gtk_tree_view_new_with_model(model);      gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index 6614b8e1..54745bb6 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -45,6 +45,7 @@ typedef enum {      TREE_COL_PBUF,      TREE_COL_NAME,      TREE_COL_DATA, +    TREE_COL_SEL,      TREE_NCOL  } ShellTreeColumns; @@ -116,6 +117,8 @@ struct _ShellFieldUpdate {  void		shell_init(void);  void		shell_do_reload(void); +Shell	       *shell_get_main_shell(); +  void		shell_action_set_enabled(const gchar *action_name,                                           gboolean setting);  gboolean	shell_action_get_active(const gchar *action_name); @@ -132,6 +135,8 @@ void		shell_ui_manager_set_visible(const gchar *path,  void		shell_status_update(const gchar *message);  void		shell_status_pulse(void);  void		shell_status_set_percentage(gint percentage); +void		shell_status_set_enabled(gboolean setting); +  void		shell_view_set_enabled(gboolean setting);  #endif				/* __SHELL_H__ */ diff --git a/hardinfo2/stock.c b/hardinfo2/stock.c index 614d1b8f..34aea2e9 100644 --- a/hardinfo2/stock.c +++ b/hardinfo2/stock.c @@ -24,8 +24,7 @@ static struct {      gchar *filename;      gchar *stock_id;  } stock_icons[] = { -    { "report.png", HI_STOCK_REPORT}, -    { "module.png", HI_STOCK_MODULE} +    { "report.png", HI_STOCK_REPORT}  };  static GtkIconFactory *icon_factory; diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 9df6fc75..79084c2c 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -17,6 +17,7 @@   */  #include <string.h>  #include <hardinfo.h> +#include <gtk/gtk.h>  inline void  remove_quotes(gchar *str) @@ -48,3 +49,16 @@ remove_linefeed(gchar * str)  {      strend(str, '\n');  } + +void +widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type) +{    +        GdkCursor *cursor; +  +        cursor = gdk_cursor_new(cursor_type); +        gdk_window_set_cursor(GDK_WINDOW(widget->window), cursor); +        gdk_cursor_unref(cursor); +         +        while(gtk_events_pending()) +                gtk_main_iteration(); +} | 
