442 lines
11 KiB
Diff
442 lines
11 KiB
Diff
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
index 91c81f5..bcb3bc4 100644
|
|
--- a/src/Makefile.am
|
|
+++ b/src/Makefile.am
|
|
@@ -24,7 +24,8 @@ gnome_system_monitor_SOURCES = \
|
|
smooth_refresh.cpp smooth_refresh.h \
|
|
defaulttable.h \
|
|
disks.cpp disks.h \
|
|
hardware.cpp hardware.h \
|
|
+ acpiview.cpp acpiview.h \
|
|
selinux.h selinux.cpp \
|
|
procman_gnomesu.h procman_gnomesu.cpp \
|
|
procman_gksu.h procman_gksu.cpp \
|
|
diff --git a/src/acpiview.cpp b/src/acpiview.cpp
|
|
new file mode 100644
|
|
index 0000000..e0c320e
|
|
--- /dev/null
|
|
+++ b/src/acpiview.cpp
|
|
@@ -0,0 +1,310 @@
|
|
+/* Gnome System Monitor - acpiview.cpp
|
|
+ * Copyright (C) 2008 Novell, Inc.
|
|
+ *
|
|
+ * 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; either version 2
|
|
+ * of the License, or (at your option) any later version.
|
|
+ *
|
|
+ * 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 Library General Public
|
|
+ * License along with this program; if not, write to the Free Software
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
+ *
|
|
+ */
|
|
+
|
|
+#include <sys/types.h>
|
|
+#include <sys/stat.h>
|
|
+#include <unistd.h>
|
|
+#include <stdlib.h>
|
|
+#include <string.h>
|
|
+
|
|
+#include <glib/gi18n.h>
|
|
+
|
|
+#include <gtk/gtkvbox.h>
|
|
+#include <gtk/gtktable.h>
|
|
+#include <gtk/gtkmisc.h>
|
|
+#include <gtk/gtklabel.h>
|
|
+
|
|
+#include "interface.h"
|
|
+#include "acpiview.h"
|
|
+
|
|
+#define PROC_ACPI_IBM_DIR "/proc/acpi/ibm/"
|
|
+
|
|
+#define UNSUPPORTED -1
|
|
+#define DISABLED 0
|
|
+#define ENABLED 1
|
|
+#define OFF 0
|
|
+#define ON 1
|
|
+
|
|
+AcpiData *acpi_data_new ()
|
|
+{
|
|
+ AcpiData * d = (AcpiData *)calloc(sizeof(AcpiData), 1);
|
|
+ d->bluetooth = -1;
|
|
+ d->fan = -1;
|
|
+ d->brightness = -1;
|
|
+ d->in_dock = -1;
|
|
+ d->thinklight = -1;
|
|
+ d->cpu_temp = -1;
|
|
+ d->gpu_temp = -1;
|
|
+ d->battery_temp = -1;
|
|
+ return d;
|
|
+}
|
|
+
|
|
+static
|
|
+const char * enabled_value_to_string(int v)
|
|
+{
|
|
+ if (v == DISABLED)
|
|
+ {
|
|
+ return _("disabled");
|
|
+ }
|
|
+ else if (v == ENABLED)
|
|
+ {
|
|
+ return _("enabled");
|
|
+ }
|
|
+ return _("unsupported");
|
|
+}
|
|
+
|
|
+static
|
|
+const char * onoff_value_to_string(int v)
|
|
+{
|
|
+ if (v == ON)
|
|
+ {
|
|
+ return _("on");
|
|
+ }
|
|
+ else if (v == OFF)
|
|
+ {
|
|
+ return _("off");
|
|
+ }
|
|
+ return _("unsupported");
|
|
+}
|
|
+
|
|
+
|
|
+static
|
|
+char * read_value(const char *value, const char * format,
|
|
+ char * buffer)
|
|
+{
|
|
+ int ret;
|
|
+ char * rvalue = NULL;
|
|
+ FILE *file = fopen(value, "r");
|
|
+ if (file)
|
|
+ {
|
|
+ ret = fscanf (file, format, buffer);
|
|
+ if(ret == 1)
|
|
+ {
|
|
+ rvalue = buffer;
|
|
+ }
|
|
+ ret = fclose(file);
|
|
+ }
|
|
+ return rvalue;
|
|
+}
|
|
+
|
|
+/* MUST free() the return value */
|
|
+static
|
|
+char * read_value_line(const char *value)
|
|
+{
|
|
+ int ret;
|
|
+ char * rvalue = NULL;
|
|
+ size_t len = 0;
|
|
+ FILE *file = fopen(value, "r");
|
|
+ if (file)
|
|
+ {
|
|
+ ret = getline (&rvalue, &len, file);
|
|
+ ret = fclose(file);
|
|
+ }
|
|
+ return rvalue;
|
|
+}
|
|
+
|
|
+static int get_bluetooth ()
|
|
+{
|
|
+ int value = -1;
|
|
+ char s[10] = "";
|
|
+ char * svalue = read_value(PROC_ACPI_IBM_DIR "bluetooth", "status: %9s", s);
|
|
+ if(svalue)
|
|
+ {
|
|
+ if(strcmp(s,"enabled") == 0)
|
|
+ {
|
|
+ value = ENABLED;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ value = DISABLED;
|
|
+ }
|
|
+ }
|
|
+ return value;
|
|
+}
|
|
+
|
|
+
|
|
+static int get_fan ()
|
|
+{
|
|
+ int value = -1;
|
|
+ char s[10] = "";
|
|
+ char * svalue = read_value(PROC_ACPI_IBM_DIR "fan", "status: %9s", s);
|
|
+ if(svalue)
|
|
+ {
|
|
+ if(strcmp(s,"enabled") == 0)
|
|
+ {
|
|
+ value = ENABLED;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ value = DISABLED;
|
|
+ }
|
|
+ }
|
|
+ return value;
|
|
+}
|
|
+
|
|
+
|
|
+static int get_brightness ()
|
|
+{
|
|
+ int value = -1;
|
|
+ int ret;
|
|
+ char rvalue[512];
|
|
+ char *prvalue = rvalue;
|
|
+ size_t len = 512;
|
|
+ FILE *file = fopen("/proc/acpi/video/VID1/LCD0/brightness", "r");
|
|
+ if (file)
|
|
+ {
|
|
+ ret = getline (&prvalue, &len, file);
|
|
+ ret = fscanf (file, "current: %d", &value);
|
|
+ ret = fclose(file);
|
|
+ }
|
|
+
|
|
+ return value;
|
|
+}
|
|
+
|
|
+static int get_in_dock ()
|
|
+{
|
|
+ return -1;
|
|
+}
|
|
+
|
|
+static int get_thinklight ()
|
|
+{
|
|
+ int value = -1;
|
|
+ char s[10] = "";
|
|
+ char * svalue = read_value(PROC_ACPI_IBM_DIR "light", "status: %9s", s);
|
|
+ if(svalue)
|
|
+ {
|
|
+ if(strcmp(s,"on") == 0)
|
|
+ {
|
|
+ value = ON;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ value = OFF;
|
|
+ }
|
|
+ }
|
|
+ return value;
|
|
+}
|
|
+
|
|
+static void get_temps (int & cpu, int & gpu, int & batt)
|
|
+{
|
|
+ cpu = gpu = batt = -1;
|
|
+ char * svalue = read_value_line(PROC_ACPI_IBM_DIR "thermal");
|
|
+ if(svalue)
|
|
+ {
|
|
+ int t1, t2, t3, t4, t5, t6, t7, t8,
|
|
+ t9, t10, t11, t12, t13, t14, t15, t16;
|
|
+
|
|
+// printf("svalue -> %s\n", svalue);
|
|
+ sscanf(svalue, "temperatures: %d %d %d %d %d %d %d %d %d "
|
|
+ "%d %d %d %d %d %d %d", &t1, &t2, &t3, &t4, &t5,
|
|
+ &t6, &t7, &t8, &t9, &t10, &t11, &t12, &t13, &t14,
|
|
+ &t15, &t16);
|
|
+ // I'm not sure which one is what.
|
|
+ cpu = t1;
|
|
+ gpu = t2;
|
|
+ batt = t4;
|
|
+ free (svalue);
|
|
+ }
|
|
+}
|
|
+
|
|
+
|
|
+void acpi_data_init (AcpiData * d)
|
|
+{
|
|
+ d->bluetooth = get_bluetooth ();
|
|
+ d->fan = get_fan ();
|
|
+ d->brightness = get_brightness ();
|
|
+ d->in_dock = get_in_dock();
|
|
+ d->thinklight = get_thinklight ();
|
|
+ get_temps (d->cpu_temp, d->gpu_temp, d->battery_temp);
|
|
+}
|
|
+
|
|
+void acpi_data_free (AcpiData * d)
|
|
+{
|
|
+ free(d);
|
|
+}
|
|
+
|
|
+
|
|
+bool is_thinkpad ()
|
|
+{
|
|
+ struct stat s;
|
|
+ int r = stat(PROC_ACPI_IBM_DIR, &s);
|
|
+ return ((r == 0) && S_ISDIR(s.st_mode));
|
|
+}
|
|
+
|
|
+static
|
|
+void add_row (GtkTable *table, int row,
|
|
+ const gchar * label, const gchar * value)
|
|
+{
|
|
+ GtkWidget *header = gtk_label_new(label);
|
|
+ gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
|
|
+ gtk_table_attach(
|
|
+ table, header,
|
|
+ 0, 1, row, row + 1,
|
|
+ GTK_FILL, GTK_FILL, 6, 6
|
|
+ );
|
|
+
|
|
+ GtkWidget *label_widget = gtk_label_new(value);
|
|
+ gtk_misc_set_alignment(GTK_MISC(label_widget), 0.0, 0.5);
|
|
+ gtk_table_attach(
|
|
+ table, label_widget,
|
|
+ 1, 2, row, row + 1,
|
|
+ GTK_FILL, GTK_FILL, 6, 6
|
|
+ );
|
|
+}
|
|
+
|
|
+GtkWidget* create_acpi_view (AcpiData * d)
|
|
+{
|
|
+ GtkWidget *table;
|
|
+ GtkWidget *vbox;
|
|
+ GtkWidget *label;
|
|
+
|
|
+ vbox = gtk_vbox_new(FALSE, 6);
|
|
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
|
|
+
|
|
+ label = make_title_label(_("ThinkPad"));
|
|
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
|
|
+
|
|
+ table = gtk_table_new(5, 2, FALSE);
|
|
+
|
|
+ gtk_table_set_row_spacings(GTK_TABLE(table), 6);
|
|
+ gtk_table_set_col_spacings(GTK_TABLE(table), 6);
|
|
+ gtk_container_set_border_width(GTK_CONTAINER(table), 6);
|
|
+ gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 0);
|
|
+
|
|
+ int row = 0;
|
|
+ char buf[32];
|
|
+ add_row(GTK_TABLE(table), row++, _("Bluetooth"),
|
|
+ enabled_value_to_string (d->bluetooth));
|
|
+ add_row(GTK_TABLE(table), row++, _("Fan"),
|
|
+ enabled_value_to_string (d->fan));
|
|
+ snprintf(buf, 32, "%d", d->brightness);
|
|
+ add_row(GTK_TABLE(table), row++, _("Screen brightness"), buf);
|
|
+ add_row(GTK_TABLE(table), row++, _("In Docking station"), _("no"));
|
|
+ add_row(GTK_TABLE(table), row++, _("Lenovo ThinkLight"),
|
|
+ onoff_value_to_string (d->thinklight));
|
|
+
|
|
+ snprintf(buf, 32, "%d C", d->cpu_temp);
|
|
+ add_row(GTK_TABLE(table), row++, _("CPU Temp"), buf);
|
|
+ snprintf(buf, 32, "%d C", d->gpu_temp);
|
|
+ add_row(GTK_TABLE(table), row++, _("GPU Temp"), buf);
|
|
+ snprintf(buf, 32, "%d C", d->battery_temp);
|
|
+ add_row(GTK_TABLE(table), row++, _("Battery Temp"), buf);
|
|
+
|
|
+ return vbox;
|
|
+}
|
|
diff --git a/src/acpiview.h b/src/acpiview.h
|
|
new file mode 100644
|
|
index 0000000..276c1eb
|
|
--- /dev/null
|
|
+++ b/src/acpiview.h
|
|
@@ -0,0 +1,45 @@
|
|
+/* Gnome System Monitor - acpiview.h
|
|
+ * Copyright (C) 2008 Novell, Inc.
|
|
+ *
|
|
+ * 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; either version 2
|
|
+ * of the License, or (at your option) any later version.
|
|
+ *
|
|
+ * 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 Library General Public
|
|
+ * License along with this program; if not, write to the Free Software
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
+ *
|
|
+ */
|
|
+
|
|
+#ifndef _GSM_ACPIVIEW_H_
|
|
+#define _GSM_ACPIVIEW_H_
|
|
+
|
|
+#include <gtk/gtkwidget.h>
|
|
+
|
|
+
|
|
+struct AcpiData
|
|
+{
|
|
+ int bluetooth;
|
|
+ int fan;
|
|
+ int brightness;
|
|
+ int in_dock;
|
|
+ int thinklight;
|
|
+ int cpu_temp;
|
|
+ int gpu_temp;
|
|
+ int battery_temp;
|
|
+};
|
|
+
|
|
+AcpiData *acpi_data_new ();
|
|
+void acpi_data_init (AcpiData *);
|
|
+void acpi_data_free (AcpiData *);
|
|
+
|
|
+bool is_thinkpad ();
|
|
+GtkWidget* create_acpi_view (AcpiData *);
|
|
+
|
|
+#endif
|
|
diff --git a/src/interface.cpp b/src/interface.cpp
|
|
index 61b9bf1..057a77e 100644
|
|
--- a/src/interface.cpp
|
|
+++ b/src/interface.cpp
|
|
@@ -41,7 +41,8 @@
|
|
#include "disks.h"
|
|
#include "sysinfo.h"
|
|
#include "gsm_color_button.h"
|
|
#include "hardware.h"
|
|
+#include "acpiview.h"
|
|
|
|
static void cb_toggle_tree (GtkAction *action, gpointer data);
|
|
|
|
@@ -612,9 +613,9 @@ create_main_window (ProcData *procdata)
|
|
GtkWidget *menubar;
|
|
GtkWidget *main_box;
|
|
GtkWidget *notebook;
|
|
- GtkWidget *tab_label1, *tab_label2, *tab_label3 , *tab_label4;
|
|
+ GtkWidget *tab_label1, *tab_label2, *tab_label3, *tab_label4, *tab_label5;
|
|
GtkWidget *vbox1;
|
|
- GtkWidget *sys_box, *devices_box, *hardware_box;
|
|
+ GtkWidget *sys_box, *devices_box, *hardware_box, *acpi_box;
|
|
GtkWidget *sysinfo_box, *sysinfo_label;
|
|
|
|
app = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
@@ -708,6 +709,15 @@ create_main_window (ProcData *procdata)
|
|
tab_label3 = gtk_label_new (_("File Systems"));
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), devices_box, tab_label3);
|
|
|
|
+ if (is_thinkpad ())
|
|
+ {
|
|
+ procdata->acpi = acpi_data_new ();
|
|
+ acpi_data_init (procdata->acpi);
|
|
+ acpi_box = create_acpi_view (procdata->acpi);
|
|
+ tab_label5 = gtk_label_new (_("ThinkPad"));
|
|
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), acpi_box, tab_label5);
|
|
+ }
|
|
+
|
|
g_signal_connect (G_OBJECT (notebook), "switch-page",
|
|
G_CALLBACK (cb_switch_page), procdata);
|
|
g_signal_connect (G_OBJECT (notebook), "change-current-page",
|
|
diff --git a/src/procman.h b/src/procman.h
|
|
index 9d51eee..c38b681 100644
|
|
--- a/src/procman.h
|
|
+++ b/src/procman.h
|
|
@@ -36,6 +36,7 @@
|
|
struct ProcInfo;
|
|
struct ProcData;
|
|
struct LoadGraph;
|
|
+struct AcpiData;
|
|
|
|
#include "smooth_refresh.h"
|
|
#include "prettytable.h"
|
|
@@ -218,6 +219,7 @@ struct ProcData
|
|
guint64 cpu_total_time;
|
|
guint64 cpu_total_time_last;
|
|
|
|
+ AcpiData* acpi;
|
|
private:
|
|
ProcData();
|
|
/* undefined */ ProcData(const ProcData &);
|