aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hardinfo2/Makefile.in1
-rw-r--r--hardinfo2/arch/linux/common/sensors.h538
-rw-r--r--hardinfo2/autopackage/default.apspec30
-rw-r--r--hardinfo2/callbacks.c21
-rw-r--r--hardinfo2/callbacks.h1
-rw-r--r--hardinfo2/hardinfo.desktop5
-rw-r--r--hardinfo2/menu.c5
-rw-r--r--hardinfo2/report.c329
-rw-r--r--hardinfo2/report.h20
-rw-r--r--hardinfo2/shell.c7
-rw-r--r--hardinfo2/shell.h2
-rw-r--r--hardinfo2/uidefs.xml4
12 files changed, 624 insertions, 339 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in
index 780ba2b9..554f42ba 100644
--- a/hardinfo2/Makefile.in
+++ b/hardinfo2/Makefile.in
@@ -50,6 +50,7 @@ deb: dist-clean
install: all
@echo '*** Creating directories...'
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/linux/common/sensors.h b/hardinfo2/arch/linux/common/sensors.h
index 652273d2..246c53e7 100644
--- a/hardinfo2/arch/linux/common/sensors.h
+++ b/hardinfo2/arch/linux/common/sensors.h
@@ -20,318 +20,352 @@ static gchar *sensors = NULL;
static GHashTable *sensor_labels = NULL;
static GHashTable *sensor_compute = NULL;
-static void
-read_sensor_labels(gchar *driver)
+static void read_sensor_labels(gchar * driver)
{
FILE *conf;
gchar buf[256], *line, *p;
gboolean lock = FALSE;
gint i;
-
+
sensor_labels = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, g_free);
+ g_free, g_free);
sensor_compute = g_hash_table_new(g_str_hash, g_str_equal);
-
+
conf = fopen("/etc/sensors.conf", "r");
if (!conf)
- return;
-
+ return;
+
while (fgets(buf, 256, conf)) {
- line = buf;
-
- remove_linefeed(line);
- strend(line, '#');
-
- if (*line == '\0') {
- continue;
- } else if (lock && strstr(line, "label")) { /* label lines */
- gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0);
- gchar *name = NULL, *value = NULL;
-
- for (i = 0; names[i]; i++) {
- if (names[i][0] == '\0')
- continue;
-
- if (!name) name = g_strdup(names[i]);
- else if (!value) value = g_strdup(names[i]);
- else value = g_strconcat(value, " ", names[i], NULL);
- }
-
- remove_quotes(value);
- g_hash_table_insert(sensor_labels, name, value);
-
- g_strfreev(names);
- } else if (lock && strstr(line, "ignore")) { /* ignore lines */
- p = strstr(line, "ignore") + 6;
- if (!strchr(p, ' '))
- continue;
-
- while (*p == ' ') p++;
- g_hash_table_insert(sensor_labels, g_strdup(p), "ignore");
- } else if (lock && strstr(line, "compute")) { /* compute lines */
- gchar **formulas = g_strsplit(strstr(line, "compute") + 7, " ", 0);
- gchar *name = NULL, *formula = NULL;
-
- for (i = 0; formulas[i]; i++) {
- if (formulas[i][0] == '\0')
- continue;
- if (formulas[i][0] == ',')
- break;
-
- if (!name) name = g_strdup(formulas[i]);
- else if (!formula) formula = g_strdup(formulas[i]);
- else formula = g_strconcat(formula, formulas[i], NULL);
- }
-
- g_strfreev(formulas);
- g_hash_table_insert(sensor_compute, name, math_string_to_postfix(formula));
- } else if (g_str_has_prefix(line, "chip")) { /* chip lines (delimiter) */
- if (lock == FALSE) {
- gchar **chips = g_strsplit(line, " ", 0);
-
- for (i = 1; chips[i]; i++) {
- strend(chips[i], '*');
-
- if (g_str_has_prefix(driver, chips[i] + 1)) {
- lock = TRUE;
- break;
- }
- }
-
- g_strfreev(chips);
- } else {
- break;
- }
- }
+ line = buf;
+
+ remove_linefeed(line);
+ strend(line, '#');
+
+ if (*line == '\0') {
+ continue;
+ } else if (lock && strstr(line, "label")) { /* label lines */
+ gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0);
+ gchar *name = NULL, *value = NULL;
+
+ for (i = 0; names[i]; i++) {
+ if (names[i][0] == '\0')
+ continue;
+
+ if (!name)
+ name = g_strdup(names[i]);
+ else if (!value)
+ value = g_strdup(names[i]);
+ else
+ value = g_strconcat(value, " ", names[i], NULL);
+ }
+
+ remove_quotes(value);
+ g_hash_table_insert(sensor_labels, name, value);
+
+ g_strfreev(names);
+ } else if (lock && strstr(line, "ignore")) { /* ignore lines */
+ p = strstr(line, "ignore") + 6;
+ if (!strchr(p, ' '))
+ continue;
+
+ while (*p == ' ')
+ p++;
+ g_hash_table_insert(sensor_labels, g_strdup(p), "ignore");
+ } else if (lock && strstr(line, "compute")) { /* compute lines */
+ gchar **formulas =
+ g_strsplit(strstr(line, "compute") + 7, " ", 0);
+ gchar *name = NULL, *formula = NULL;
+
+ for (i = 0; formulas[i]; i++) {
+ if (formulas[i][0] == '\0')
+ continue;
+ if (formulas[i][0] == ',')
+ break;
+
+ if (!name)
+ name = g_strdup(formulas[i]);
+ else if (!formula)
+ formula = g_strdup(formulas[i]);
+ else
+ formula = g_strconcat(formula, formulas[i], NULL);
+ }
+
+ g_strfreev(formulas);
+ g_hash_table_insert(sensor_compute, name,
+ math_string_to_postfix(formula));
+ } else if (g_str_has_prefix(line, "chip")) { /* chip lines (delimiter) */
+ if (lock == FALSE) {
+ gchar **chips = g_strsplit(line, " ", 0);
+
+ for (i = 1; chips[i]; i++) {
+ strend(chips[i], '*');
+
+ if (g_str_has_prefix(driver, chips[i] + 1)) {
+ lock = TRUE;
+ break;
+ }
+ }
+
+ g_strfreev(chips);
+ } else {
+ break;
+ }
+ }
}
-
+
fclose(conf);
}
-static gchar *
-get_sensor_label(gchar *sensor)
+static gchar *get_sensor_label(gchar * sensor)
{
gchar *ret;
-
+
ret = g_hash_table_lookup(sensor_labels, sensor);
- if (!ret) ret = g_strdup(sensor);
- else ret = g_strdup(ret);
+ if (!ret)
+ ret = g_strdup(sensor);
+ else
+ ret = g_strdup(ret);
return ret;
}
-static float
-adjust_sensor(gchar *name, float value)
+static float adjust_sensor(gchar * name, float value)
{
GSList *postfix;
-
+
postfix = g_hash_table_lookup(sensor_compute, name);
- if (!postfix) return value;
-
+ if (!postfix)
+ return value;
+
return math_postfix_eval(postfix, value);
}
-static void
-read_sensors_hwmon(void)
+static void read_sensors_hwmon(void)
{
int hwmon, count;
gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon;
hwmon = 0;
-
- path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon);
+
+ path_hwmon =
+ g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon);
while (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) {
- tmp = g_strdup_printf("%sdriver", path_hwmon);
- driver = g_file_read_link(tmp, NULL);
- g_free(tmp);
-
- tmp = g_path_get_basename(driver);
- g_free(driver);
- driver = tmp;
-
- if (!sensor_labels) {
- read_sensor_labels(driver);
- }
-
- sensors = g_strdup_printf("%s[Driver Info]\n"
- "Name=%s\n", sensors, driver);
-
- sensors = g_strconcat(sensors, "[Cooling Fans]\n", NULL);
- for (count = 1; ; count++) {
- path_sensor = g_strdup_printf("%sfan%d_input", path_hwmon, count);
- if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
- g_free(path_sensor);
- break;
- }
-
- mon = g_strdup_printf("fan%d", count);
- name = get_sensor_label(mon);
- if (!g_str_equal(name, "ignore")) {
- sensors = g_strdup_printf("%s%s=%.0fRPM\n",
- sensors, name,
- adjust_sensor(mon, atof(tmp)));
- }
-
- g_free(name);
- g_free(mon);
- g_free(tmp);
- g_free(path_sensor);
- }
-
- sensors = g_strconcat(sensors, "[Temperatures]\n", NULL);
- for (count = 1; ; count++) {
- path_sensor = g_strdup_printf("%stemp%d_input", path_hwmon, count);
- if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
- g_free(path_sensor);
- break;
- }
-
- mon = g_strdup_printf("temp%d", count);
- name = get_sensor_label(mon);
- if (!g_str_equal(name, "ignore")) {
- sensors = g_strdup_printf("%s%s=%.2f\302\260C\n",
- sensors, name,
- adjust_sensor(mon, atof(tmp) / 1000.0));
- }
-
- g_free(tmp);
- g_free(name);
- g_free(path_sensor);
- g_free(mon);
- }
-
- sensors = g_strconcat(sensors, "[Voltage Values]\n", NULL);
- for (count = 0; ; count++) {
- path_sensor = g_strdup_printf("%sin%d_input", path_hwmon, count);
- if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
- g_free(path_sensor);
- break;
- }
-
-
- mon = g_strdup_printf("in%d", count);
- name = get_sensor_label(mon);
- if (!g_str_equal(name, "ignore")) {
- sensors = g_strdup_printf("%s%s=%.3fV\n",
- sensors, name,
- adjust_sensor(mon, atof(tmp) / 1000.0));
- }
-
- g_free(tmp);
- g_free(mon);
- g_free(name);
- g_free(path_sensor);
- }
-
- g_free(path_hwmon);
- g_free(driver);
- path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", ++hwmon);
+ tmp = g_strdup_printf("%sdriver", path_hwmon);
+ driver = g_file_read_link(tmp, NULL);
+ g_free(tmp);
+
+ tmp = g_path_get_basename(driver);
+ g_free(driver);
+ driver = tmp;
+
+ if (!sensor_labels) {
+ read_sensor_labels(driver);
+ }
+
+ sensors = g_strdup_printf("%s[Driver Info]\n"
+ "Name=%s\n", sensors, driver);
+
+ sensors = g_strconcat(sensors, "[Cooling Fans]\n", NULL);
+ for (count = 1;; count++) {
+ path_sensor =
+ g_strdup_printf("%sfan%d_input", path_hwmon, count);
+ if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
+ g_free(path_sensor);
+ break;
+ }
+
+ mon = g_strdup_printf("fan%d", count);
+ name = get_sensor_label(mon);
+ if (!g_str_equal(name, "ignore")) {
+ sensors = g_strdup_printf("%s%s=%.0fRPM\n",
+ sensors, name,
+ adjust_sensor(mon, atof(tmp)));
+ }
+
+ g_free(name);
+ g_free(mon);
+ g_free(tmp);
+ g_free(path_sensor);
+ }
+
+ sensors = g_strconcat(sensors, "[Temperatures]\n", NULL);
+ for (count = 1;; count++) {
+ path_sensor =
+ g_strdup_printf("%stemp%d_input", path_hwmon, count);
+ if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
+ g_free(path_sensor);
+ break;
+ }
+
+ mon = g_strdup_printf("temp%d", count);
+ name = get_sensor_label(mon);
+ if (!g_str_equal(name, "ignore")) {
+ sensors = g_strdup_printf("%s%s=%.2f\302\260C\n",
+ sensors, name,
+ adjust_sensor(mon,
+ atof(tmp) /
+ 1000.0));
+ }
+
+ g_free(tmp);
+ g_free(name);
+ g_free(path_sensor);
+ g_free(mon);
+ }
+
+ sensors = g_strconcat(sensors, "[Voltage Values]\n", NULL);
+ for (count = 0;; count++) {
+ path_sensor =
+ g_strdup_printf("%sin%d_input", path_hwmon, count);
+ if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) {
+ g_free(path_sensor);
+ break;
+ }
+
+
+ mon = g_strdup_printf("in%d", count);
+ name = get_sensor_label(mon);
+ if (!g_str_equal(name, "ignore")) {
+ sensors = g_strdup_printf("%s%s=%.3fV\n",
+ sensors, name,
+ adjust_sensor(mon,
+ atof(tmp) /
+ 1000.0));
+ }
+
+ g_free(tmp);
+ g_free(mon);
+ g_free(name);
+ g_free(path_sensor);
+ }
+
+ g_free(path_hwmon);
+ g_free(driver);
+ path_hwmon =
+ g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", ++hwmon);
}
-
+
g_free(path_hwmon);
}
-static void
-read_sensors_acpi(void)
+static void read_sensors_acpi(void)
{
const gchar *path_tz = "/proc/acpi/thermal_zone";
-
+
if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) {
- GDir *tz;
-
- if ((tz = g_dir_open(path_tz, 0, NULL))) {
- const gchar *entry;
-
- sensors = g_strdup_printf("%s\n[ACPI Thermal Zone]\n", sensors);
-
- while ((entry = g_dir_read_name(tz))) {
- gchar *path = g_strdup_printf("%s/%s/temperature", path_tz, entry);
- gchar *contents;
-
- if (g_file_get_contents(path, &contents, NULL, NULL)) {
- int temperature;
-
- sscanf(contents, "temperature: %d C", &temperature);
-
- sensors = g_strdup_printf("%s\n%s=%d\302\260C\n",
- sensors, entry, temperature);
-
- g_free(contents);
- }
- }
-
- g_dir_close(tz);
- }
+ GDir *tz;
+
+ if ((tz = g_dir_open(path_tz, 0, NULL))) {
+ const gchar *entry;
+
+ sensors =
+ g_strdup_printf("%s\n[ACPI Thermal Zone]\n", sensors);
+
+ while ((entry = g_dir_read_name(tz))) {
+ gchar *path =
+ g_strdup_printf("%s/%s/temperature", path_tz, entry);
+ gchar *contents;
+
+ if (g_file_get_contents(path, &contents, NULL, NULL)) {
+ int temperature;
+
+ sscanf(contents, "temperature: %d C", &temperature);
+
+ sensors = g_strdup_printf("%s\n%s=%d\302\260C\n",
+ sensors, entry, temperature);
+
+ g_free(contents);
+ }
+ }
+
+ g_dir_close(tz);
+ }
}
}
-static void
-read_sensors_hddtemp(void)
+static void read_sensors_omnibook(void)
+{
+ const gchar *path_ob = "/proc/omnibook/temperature";
+ gchar *contents;
+
+ if (g_file_get_contents(path_ob, &contents, NULL, NULL)) {
+ int temperature;
+
+ sscanf(contents, "CPU temperature: %d C", &temperature);
+
+ sensors = g_strdup_printf("%s\n[Omnibook]\n"
+ "CPU temperature=%d\302\260C\n",
+ sensors, temperature);
+
+ g_free(contents);
+ }
+}
+
+static void read_sensors_hddtemp(void)
{
Socket *s;
static gchar *old = NULL;
gchar buffer[1024];
gint len = 0;
-
+
if ((s = sock_connect("127.0.0.1", 7634))) {
- while (!len)
- len = sock_read(s, buffer, sizeof(buffer));
- sock_close(s);
-
- if (len > 2 && buffer[0] == '|' && buffer[1] == '/') {
- gchar **disks;
- int i;
-
- if (old)
- g_free(old);
-
- old = g_strdup("[Hard Disk Temperature]\n");
-
- disks = g_strsplit(buffer, "\n", 0);
- for (i = 0; disks[i]; i++) {
- gchar **fields = g_strsplit(disks[i] + 1, "|", 5);
-
- /*
- * 0 -> /dev/hda
- * 1 -> FUJITSU MHV2080AH
- * 2 -> 41
- * 3 -> C
- */
- old = g_strdup_printf("%s\n"
- "%s (%s)=%s\302\260%s\n",
- old,
- fields[1], fields[0],
- fields[2], fields[3]);
-
- g_strfreev(fields);
- }
-
- g_strfreev(disks);
- }
+ while (!len)
+ len = sock_read(s, buffer, sizeof(buffer));
+ sock_close(s);
+
+ if (len > 2 && buffer[0] == '|' && buffer[1] == '/') {
+ gchar **disks;
+ int i;
+
+ if (old)
+ g_free(old);
+
+ old = g_strdup("[Hard Disk Temperature]\n");
+
+ disks = g_strsplit(buffer, "\n", 0);
+ for (i = 0; disks[i]; i++) {
+ gchar **fields = g_strsplit(disks[i] + 1, "|", 5);
+
+ /*
+ * 0 -> /dev/hda
+ * 1 -> FUJITSU MHV2080AH
+ * 2 -> 41
+ * 3 -> C
+ */
+ old = g_strdup_printf("%s\n"
+ "%s (%s)=%s\302\260%s\n",
+ old,
+ fields[1], fields[0],
+ fields[2], fields[3]);
+
+ g_strfreev(fields);
+ }
+
+ g_strfreev(disks);
+ }
} else {
- g_free(old);
- old = NULL;
+ g_free(old);
+ old = NULL;
}
-
+
if (old) {
- sensors = g_strconcat(sensors, "\n", old, NULL);
+ sensors = g_strconcat(sensors, "\n", old, NULL);
}
}
-static void
-read_sensors(void)
+static void read_sensors(void)
{
if (sensors)
- g_free(sensors);
-
+ g_free(sensors);
+
sensors = g_strdup("");
-
+
read_sensors_hwmon();
read_sensors_acpi();
- read_sensors_hddtemp();
-
- /* FIXME: Add support for omnibook, ibm acpi and more sensors */
-}
+ read_sensors_omnibook();
+ read_sensors_hddtemp();
+ /* FIXME: Add support for ibm acpi and more sensors */
+}
diff --git a/hardinfo2/autopackage/default.apspec b/hardinfo2/autopackage/default.apspec
index 58b9ae2a..cdb40b8c 100644
--- a/hardinfo2/autopackage/default.apspec
+++ b/hardinfo2/autopackage/default.apspec
@@ -2,7 +2,7 @@
# Generated by mkapspec 0.2
[Meta]
ShortName: hardinfo
-SoftwareVersion: 0.4.1-SVN26
+SoftwareVersion: 0.4.1+SVN37
DisplayName: HardInfo $SOFTWAREVERSION
RootName: @tia.mat.br/hardinfo:$SOFTWAREVERSION
Summary: System profiler and benchmark tool
@@ -10,34 +10,10 @@ Maintainer: Leandro A. F. Pereira <leandro@linuxmag.com.br>
Packager: Leandro A. F. Pereira <leandro@linuxmag.com.br>
PackageVersion: 1
CPUArchitectures: x86
-AutopackageTarget: 1.0
+AutopackageTarget: 1.2
Type: Application
License: GPL
-[Description]
-HardInfo is a system information and benchmark tool for Linux systems. Using HardInfo, you can:
-
- * Get information about your computer:
- o The Processor
- o Operating System
- o Languages
- o Sensors
- o Filesystems
- o Shared Directories
- o Display
- o Network Interfaces
- * Its devices (and what controls them):
- o Kernel Modules
- o PCI Devices
- o USB Devices
- o Printers
- o Input Devices
- o Storage
- * Benchmark:
- o ZLib
- o MD5 and SHA1
- * Generate nicely-formatted HTML reports
-
[BuildPrepare]
# If you're using autotools, the default should be enough.
# prepareBuild will set up apbuild and run configure for you. If you
@@ -69,7 +45,7 @@ installData share/*
copyFile lib/hardinfo/modules/benchmark.so $PREFIX/lib/hardinfo/modules/benchmark.so
copyFile lib/hardinfo/modules/computer.so $PREFIX/lib/hardinfo/modules/computer.so
copyFile lib/hardinfo/modules/devices.so $PREFIX/lib/hardinfo/modules/devices.so
-installDesktop "System" share/applications/hardinfo.desktop
+installMenuItem "System" share/applications/hardinfo.desktop
[Uninstall]
# Leaving this at the default is safe unless you use custom commands in
diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c
index 173d6fe7..1146bc50 100644
--- a/hardinfo2/callbacks.c
+++ b/hardinfo2/callbacks.c
@@ -32,6 +32,27 @@ void cb_refresh()
shell_do_reload();
}
+void cb_copy_to_clipboard()
+{
+ ShellModuleEntry *entry = shell_get_main_shell()->selected;
+ gchar *data = entry->func(entry->number);
+ GtkClipboard *clip = gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE));
+ gchar *fmtdata = g_strdup("");
+ ReportContext *ctx = report_context_string_new(NULL, fmtdata);
+
+ ctx->entry = entry;
+
+ report_header(ctx);
+ report_table(ctx, data);
+ report_footer(ctx);
+
+ gtk_clipboard_set_text(clip, ctx->stream, -1);
+
+ g_free((gchar*) ctx->stream);
+ g_free(ctx);
+ g_free(data);
+}
+
void cb_side_pane()
{
gboolean visible;
diff --git a/hardinfo2/callbacks.h b/hardinfo2/callbacks.h
index da1b3a65..d08c975c 100644
--- a/hardinfo2/callbacks.h
+++ b/hardinfo2/callbacks.h
@@ -23,6 +23,7 @@ void cb_about();
void cb_generate_report();
void cb_quit();
void cb_refresh();
+void cb_copy_to_clipboard();
void cb_side_pane();
void cb_toolbar();
diff --git a/hardinfo2/hardinfo.desktop b/hardinfo2/hardinfo.desktop
index e790da16..07ca568b 100644
--- a/hardinfo2/hardinfo.desktop
+++ b/hardinfo2/hardinfo.desktop
@@ -1,10 +1,11 @@
[Desktop Entry]
+Encoding=UTF-8
Name=System Profiler and Benchmark
-Name[pt_BR]=Informações e Testes do Sistema
+Name[pt_BR]=Informações e Testes do Sistema
Exec=hardinfo
Icon=/usr/share/hardinfo/pixmaps/logo.png
Terminal=false
MultipleArgs=false
Type=Application
StartupNotify=true
-Categories=Application;System
+Categories=Application;System;
diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c
index 2bf5e3db..0d9b64eb 100644
--- a/hardinfo2/menu.c
+++ b/hardinfo2/menu.c
@@ -40,6 +40,11 @@ static GtkActionEntry entries[] =
"Creates a report in HTML", /* tooltip */
G_CALLBACK(cb_generate_report) },
+ { "CopyAction", GTK_STOCK_COPY,
+ "_Copy to Clipboard", "<control>C",
+ NULL,
+ G_CALLBACK(cb_copy_to_clipboard) },
+
{ "RefreshAction", GTK_STOCK_REFRESH,
"_Refresh", "F5",
NULL,
diff --git a/hardinfo2/report.c b/hardinfo2/report.c
index db2a02e3..6304aacb 100644
--- a/hardinfo2/report.c
+++ b/hardinfo2/report.c
@@ -25,62 +25,44 @@
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)
+void
+report_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" \
- "body { background: #fff }\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>");
+ ctx->header(ctx);
}
-static void
-report_html_footer(ReportContext *ctx)
+void
+report_footer(ReportContext *ctx)
{
- fprintf(ctx->stream,
- "</tbody></table></body></html>");
+ ctx->footer(ctx);
}
-static void
-report_html_title(ReportContext *ctx, gchar *text)
+void
+report_title(ReportContext *ctx, gchar *text)
{
- fprintf(ctx->stream,
- "<tr><td colspan=\"2\" class=\"title\">%s</td></tr>\n", text);
+ ctx->title(ctx, text);
}
-static void
-report_html_subtitle(ReportContext *ctx, gchar *text)
+void
+report_subtitle(ReportContext *ctx, gchar *text)
{
- fprintf(ctx->stream,
- "<tr><td colspan=\"2\" class=\"stitle\">%s</td></tr>\n", text);
+ ctx->subtitle(ctx, text);
}
-static void
-report_html_subsubtitle(ReportContext *ctx, gchar *text)
+
+void
+report_subsubtitle(ReportContext *ctx, gchar *text)
{
- fprintf(ctx->stream,
- "<tr><td colspan=\"2\" class=\"sstitle\">%s</td></tr>\n", text);
+ ctx->subsubtitle(ctx, text);
}
-static void
-report_html_key_value(ReportContext *ctx, gchar *key, gchar *value)
+void
+report_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);
+ ctx->keyvalue(ctx, key, value);
}
-static void
-report_html_table(ReportContext *ctx, gchar *text)
+void
+report_table(ReportContext *ctx, gchar *text)
{
GKeyFile *key_file = g_key_file_new();
gchar **groups;
@@ -103,7 +85,7 @@ report_html_table(ReportContext *ctx, gchar *text)
tmpgroup = g_strdup(group);
strend(group, '#');
- report_html_subsubtitle(ctx, group);
+ report_subsubtitle(ctx, group);
for (j = 0; keys[j]; j++) {
gchar *key = keys[j];
@@ -125,10 +107,10 @@ report_html_table(ReportContext *ctx, gchar *text)
gchar **tmp;
tmp = g_strsplit(++key, "$", 0);
- report_html_key_value(ctx, tmp[1], value);
+ report_key_value(ctx, tmp[1], value);
g_strfreev(tmp);
} else {
- report_html_key_value(ctx, key, value);
+ report_key_value(ctx, key, value);
}
}
@@ -145,6 +127,189 @@ report_html_table(ReportContext *ctx, gchar *text)
}
static void
+report_html_header(ReportContext *ctx)
+{
+ FILE *stream = (FILE*)ctx->stream;
+ fprintf(stream,
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" \
+ "<html><head>\n" \
+ "<title>HardInfo System Report</title>\n" \
+ "<style>\n" \
+ "body { background: #fff }\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)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "</tbody></table></body></html>");
+}
+
+static void
+report_html_title(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "<tr><td colspan=\"2\" class=\"title\">%s</td></tr>\n", text);
+}
+
+static void
+report_html_subtitle(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "<tr><td colspan=\"2\" class=\"stitle\">%s</td></tr>\n", text);
+}
+
+static void
+report_html_subsubtitle(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "<tr><td colspan=\"2\" class=\"sstitle\">%s</td></tr>\n", text);
+}
+
+static void
+report_html_key_value(ReportContext *ctx, gchar *key, gchar *value)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "<tr><td class=\"field\">%s</td>" \
+ "<td class=\"value\">%s</td></tr>\n", key, value);
+}
+
+static void
+report_text_header(ReportContext *ctx)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream,
+ "HardInfo System Report\n" \
+ "----------------------\n\n");
+}
+
+static void
+report_text_footer(ReportContext *ctx)
+{
+}
+
+static void
+report_text_title(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+ int i = strlen(text);
+
+ fputs(text, stream);
+ fputc('\n', stream);
+ for (; i; i--)
+ fputc('*', stream);
+
+ fputc('\n', stream);
+}
+
+static void
+report_text_subtitle(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+ int i = strlen(text);
+
+ fputs(text, stream);
+ fputc('\n', stream);
+ for (; i; i--)
+ fputc('-', stream);
+
+ fputc('\n', stream);
+}
+
+static void
+report_text_subsubtitle(ReportContext *ctx, gchar *text)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fputc('-', stream);
+ fputs(text, stream);
+ fputc('-', stream);
+
+ fputc('\n', stream);
+}
+
+static void
+report_text_key_value(ReportContext *ctx, gchar *key, gchar *value)
+{
+ FILE *stream = (FILE*)ctx->stream;
+
+ fprintf(stream, "%s\t\t: %s\n", key, value);
+}
+
+static void
+report_string_header(ReportContext *ctx)
+{
+ if (ctx->stream)
+ g_free(ctx->stream);
+
+ ctx->stream = g_strdup("");
+}
+
+static void
+report_string_footer(ReportContext *ctx)
+{
+}
+
+static void
+report_string_title(ReportContext *ctx, gchar *text)
+{
+ gchar *str = (gchar*)ctx->stream;
+ int i = strlen(text);
+
+ str = g_strdup_printf("%s%s\n", str, text);
+ for (; i; i--)
+ str = g_strconcat(str, "*", NULL);
+
+ str = g_strconcat(str, "\n", NULL);
+ ctx->stream = str;
+}
+
+static void
+report_string_subtitle(ReportContext *ctx, gchar *text)
+{
+ gchar *str = (gchar*)ctx->stream;
+ int i = strlen(text);
+
+ str = g_strdup_printf("%s%s\n", str, text);
+ for (; i; i--)
+ str = g_strconcat(str, "-", NULL);
+
+ str = g_strconcat(str, "\n", NULL);
+ ctx->stream = str;
+}
+
+static void
+report_string_subsubtitle(ReportContext *ctx, gchar *text)
+{
+ ctx->stream = g_strdup_printf("%s-%s-\n", (gchar*)ctx->stream, text);
+}
+
+static void
+report_string_key_value(ReportContext *ctx, gchar *key, gchar *value)
+{
+ ctx->stream = g_strdup_printf("%s%s\t\t: %s\n", (gchar*)ctx->stream, key, value);
+}
+
+static void
report_generate_child(ReportContext *ctx, GtkTreeIter *iter)
{
ShellModuleEntry *entry;
@@ -158,8 +323,8 @@ report_generate_child(ReportContext *ctx, GtkTreeIter *iter)
ctx->entry = entry;
- report_html_subtitle(ctx, entry->name);
- report_html_table(ctx, entry->func(entry->number));
+ report_subtitle(ctx, entry->name);
+ report_table(ctx, entry->func(entry->number));
}
static void
@@ -169,7 +334,7 @@ report_generate_children(ReportContext *ctx, GtkTreeIter *iter)
gchar *name;
gtk_tree_model_get(model, iter, TREE_COL_NAME, &name, -1);
- report_html_title(ctx, name);
+ report_title(ctx, name);
if (gtk_tree_model_iter_has_child(model, iter)) {
gint children = gtk_tree_model_iter_n_children(model, iter);
@@ -212,6 +377,63 @@ report_get_filename(void)
return filename;
}
+ReportContext*
+report_context_html_new(ReportDialog *rd, gpointer stream)
+{
+ ReportContext *ctx;
+
+ ctx = g_new0(ReportContext, 1);
+ ctx->header = report_html_header;
+ ctx->footer = report_html_footer;
+ ctx->title = report_html_title;
+ ctx->subtitle = report_html_subtitle;
+ ctx->subsubtitle = report_html_subsubtitle;
+ ctx->keyvalue = report_html_key_value;
+
+ ctx->rd = rd;
+ ctx->stream = stream;
+
+ return ctx;
+}
+
+ReportContext*
+report_context_text_new(ReportDialog *rd, gpointer stream)
+{
+ ReportContext *ctx;
+
+ ctx = g_new0(ReportContext, 1);
+ ctx->header = report_text_header;
+ ctx->footer = report_text_footer;
+ ctx->title = report_text_title;
+ ctx->subtitle = report_text_subtitle;
+ ctx->subsubtitle = report_text_subsubtitle;
+ ctx->keyvalue = report_text_key_value;
+
+ ctx->rd = rd;
+ ctx->stream = stream;
+
+ return ctx;
+}
+
+ReportContext*
+report_context_string_new(ReportDialog *rd, gpointer string)
+{
+ ReportContext *ctx;
+
+ ctx = g_new0(ReportContext, 1);
+ ctx->header = report_string_header;
+ ctx->footer = report_string_footer;
+ ctx->title = report_string_title;
+ ctx->subtitle = report_string_subtitle;
+ ctx->subsubtitle = report_string_subsubtitle;
+ ctx->keyvalue = report_string_key_value;
+
+ ctx->rd = rd;
+ ctx->stream = string;
+
+ return ctx;
+}
+
static gboolean
report_generate(ReportDialog *rd)
{
@@ -221,19 +443,16 @@ report_generate(ReportDialog *rd)
gchar *file;
FILE *stream;
- file = report_get_filename();
- if (!file)
+ if (!(file = report_get_filename()))
return FALSE;
- stream = fopen(file, "w+");
- if (!stream)
+
+ if (!(stream = fopen(file, "w+")))
return FALSE;
- model = rd->model;
- ctx = g_new0(ReportContext, 1);
- ctx->rd = rd;
- ctx->stream = stream;
+ model = rd->model;
+ ctx = report_context_html_new(rd, stream);
- report_html_header(ctx);
+ report_header(ctx);
gtk_tree_model_get_iter_first(model, &iter);
@@ -241,7 +460,7 @@ report_generate(ReportDialog *rd)
report_generate_children(ctx, &iter);
} while (gtk_tree_model_iter_next(model, &iter));
- report_html_footer(ctx);
+ report_footer(ctx);
fclose(ctx->stream);
g_free(ctx);
diff --git a/hardinfo2/report.h b/hardinfo2/report.h
index e2bfc912..7a168d4a 100644
--- a/hardinfo2/report.h
+++ b/hardinfo2/report.h
@@ -27,8 +27,14 @@ typedef struct _ReportContext ReportContext;
struct _ReportContext {
ReportDialog *rd;
ShellModuleEntry *entry;
+ gpointer stream;
- FILE *stream;
+ void (*header) (ReportContext *ctx);
+ void (*footer) (ReportContext *ctx);
+ void (*title) (ReportContext *ctx, gchar *text);
+ void (*subtitle) (ReportContext *ctx, gchar *text);
+ void (*subsubtitle) (ReportContext *ctx, gchar *text);
+ void (*keyvalue) (ReportContext *ctx, gchar *key, gchar *value);
};
struct _ReportDialog {
@@ -45,4 +51,16 @@ struct _ReportDialog {
void report_dialog_show();
+void report_header(ReportContext *ctx);
+void report_footer(ReportContext *ctx);
+void report_title(ReportContext *ctx, gchar *text);
+void report_subtitle(ReportContext *ctx, gchar *text);
+void report_subsubtitle(ReportContext *ctx, gchar *text);
+void report_key_value(ReportContext *ctx, gchar *key, gchar *value);
+void report_table(ReportContext *ctx, gchar *text);
+
+ReportContext *report_context_html_new(ReportDialog *rd, gpointer stream);
+ReportContext *report_context_text_new(ReportDialog *rd, gpointer stream);
+ReportContext *report_context_string_new(ReportDialog *rd, gpointer string);
+
#endif /* __REPORT_H__ */
diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c
index 20cb31aa..aa8477de 100644
--- a/hardinfo2/shell.c
+++ b/hardinfo2/shell.c
@@ -192,6 +192,7 @@ shell_view_set_enabled(gboolean setting)
gtk_widget_set_sensitive(shell->hpaned, setting);
shell_action_set_enabled("ViewMenuAction", setting);
shell_action_set_enabled("RefreshAction", setting);
+ shell_action_set_enabled("CopyAction", setting);
shell_action_set_enabled("ReportAction", setting);
}
@@ -210,6 +211,7 @@ void
shell_do_reload(void)
{
shell_action_set_enabled("RefreshAction", FALSE);
+ shell_action_set_enabled("CopyAction", FALSE);
shell_action_set_enabled("ReportAction", FALSE);
if (shell->selected && shell->selected->reloadfunc) {
@@ -223,6 +225,7 @@ shell_do_reload(void)
}
shell_action_set_enabled("RefreshAction", TRUE);
+ shell_action_set_enabled("CopyAction", TRUE);
shell_action_set_enabled("ReportAction", TRUE);
}
@@ -535,8 +538,10 @@ shell_init(void)
gtk_widget_hide(shell->notebook);
shell_action_set_enabled("RefreshAction", FALSE);
+ shell_action_set_enabled("CopyAction", FALSE);
shell_action_set_active("SidePaneAction", TRUE);
shell_action_set_active("ToolbarAction", TRUE);
+ shell_action_set_property("CopyAction", "is-important", TRUE);
shell_action_set_property("RefreshAction", "is-important", TRUE);
shell_action_set_property("ReportAction", "is-important", TRUE);
}
@@ -953,9 +958,11 @@ module_selected(GtkTreeSelection * ts, gpointer data)
g_free(tmp);
shell_action_set_enabled("RefreshAction", entry->reloadfunc ? TRUE : FALSE);
+ shell_action_set_enabled("CopyAction", entry->reloadfunc ? TRUE : FALSE);
} else {
gtk_window_set_title(GTK_WINDOW(shell->window), "System Information");
shell_action_set_enabled("RefreshAction", FALSE);
+ shell_action_set_enabled("CopyAction", FALSE);
gtk_tree_store_clear(GTK_TREE_STORE(shell->info->model));
set_view_type(SHELL_VIEW_NORMAL);
diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h
index 23780da0..c73c62d9 100644
--- a/hardinfo2/shell.h
+++ b/hardinfo2/shell.h
@@ -100,9 +100,9 @@ struct _ShellModule {
struct _ShellModuleEntry {
gchar *name;
- gint number;
GdkPixbuf *icon;
gboolean selected;
+ gint number;
gchar *(*func) (gint entry);
gchar *(*reloadfunc) (gint entry);
diff --git a/hardinfo2/uidefs.xml b/hardinfo2/uidefs.xml
index 280c7951..77a67de2 100644
--- a/hardinfo2/uidefs.xml
+++ b/hardinfo2/uidefs.xml
@@ -1,7 +1,8 @@
<ui>
<menubar>
<menu name="FileMenu" action="FileMenuAction">
- <menuitem name="Generate Report..." action="ReportAction" />
+ <menuitem name="Copy" action="CopyAction" />
+ <menuitem name="Report" action="ReportAction" />
<separator/>
<menuitem name="Quit" action="QuitAction" />
<placeholder name="FileMenuAdditions" />
@@ -23,6 +24,7 @@
<placeholder name="ToolItems">
<toolitem name="Refresh" action="RefreshAction"/>
<separator/>
+ <toolitem name="Copy" action="CopyAction"/>
<toolitem name="Report" action="ReportAction"/>
</placeholder>
</toolbar>