[Goodies-commits] r5516 - in xfce4-sensors-plugin/trunk: . include lib panel-plugin src
Fabian Nowak
timystery at xfce.org
Sun Oct 5 19:32:35 CEST 2008
Author: timystery
Date: 2008-10-05 17:32:34 +0000 (Sun, 05 Oct 2008)
New Revision: 5516
Added:
xfce4-sensors-plugin/trunk/include/
xfce4-sensors-plugin/trunk/include/acpi.h
xfce4-sensors-plugin/trunk/include/hddtemp.h
xfce4-sensors-plugin/trunk/include/lmsensors.h
xfce4-sensors-plugin/trunk/include/middlelayer.h
xfce4-sensors-plugin/trunk/include/types.h
xfce4-sensors-plugin/trunk/lib/
xfce4-sensors-plugin/trunk/lib/Makefile.am
xfce4-sensors-plugin/trunk/lib/acpi.c
xfce4-sensors-plugin/trunk/lib/hddtemp.c
xfce4-sensors-plugin/trunk/lib/lmsensors.c
xfce4-sensors-plugin/trunk/lib/middlelayer.c
xfce4-sensors-plugin/trunk/lib/sensors-interface-common.c
xfce4-sensors-plugin/trunk/lib/sensors-interface-common.h
xfce4-sensors-plugin/trunk/lib/sensors-interface.c
xfce4-sensors-plugin/trunk/lib/sensors-interface.h
xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c
xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.h
Removed:
xfce4-sensors-plugin/trunk/panel-plugin/acpi.c
xfce4-sensors-plugin/trunk/panel-plugin/acpi.h
xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c
xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h
xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c
xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h
xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c
xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h
xfce4-sensors-plugin/trunk/panel-plugin/sensors.c
xfce4-sensors-plugin/trunk/panel-plugin/sensors.h
xfce4-sensors-plugin/trunk/panel-plugin/types.h
Modified:
xfce4-sensors-plugin/trunk/Makefile.am
xfce4-sensors-plugin/trunk/TODO
xfce4-sensors-plugin/trunk/configure.in.in
xfce4-sensors-plugin/trunk/panel-plugin/Makefile.am
xfce4-sensors-plugin/trunk/panel-plugin/configuration.c
xfce4-sensors-plugin/trunk/panel-plugin/configuration.h
xfce4-sensors-plugin/trunk/src/Makefile.am
xfce4-sensors-plugin/trunk/src/actions.c
xfce4-sensors-plugin/trunk/src/actions.h
xfce4-sensors-plugin/trunk/src/callbacks.c
xfce4-sensors-plugin/trunk/src/callbacks.h
xfce4-sensors-plugin/trunk/src/interface.c
xfce4-sensors-plugin/trunk/src/interface.h
xfce4-sensors-plugin/trunk/src/main.c
Log:
- added new folders lib and include with the makefile scripts
- removed files from panel-plugin
- began to reorganise compilation process
- new folder for plain sensors application with some first lines of code
Modified: xfce4-sensors-plugin/trunk/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/Makefile.am 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/Makefile.am 2008-10-05 17:32:34 UTC (rev 5516)
@@ -1,8 +1,11 @@
# $Id$
-SUBDIRS = panel-plugin \
- po \
- icons
+SUBDIRS = \
+ lib \
+ panel-plugin \
+ src \
+ po \
+ icons
distclean-local:
rm -rf *.cache *~
@@ -20,18 +23,18 @@
@rm -f $(PACKAGE)-$(VERSION).tar.gz
EXTRA_DIST = \
- AUTHORS \
- COPYING \
- ChangeLog \
- INSTALL \
- NEWS \
- README \
- TODO \
- NOTES \
- xfce4-sensors-plugin.spec.in \
- intltool-extract.in \
- intltool-merge.in \
- intltool-update.in
+ AUTHORS \
+ COPYING \
+ ChangeLog \
+ INSTALL \
+ NEWS \
+ README \
+ TODO \
+ NOTES \
+ xfce4-sensors-plugin.spec.in \
+ intltool-extract.in \
+ intltool-merge.in \
+ intltool-update.in
DISTCLEANFILES = \
intltool-extract \
@@ -55,4 +58,4 @@
mv $(PACKAGE)-$(VERSION).tar.bz2* releases/
-rm $(PACKAGE)-$(VERSION).tar.gz
-# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
+# vi:set ts=4 sw=4 noet ai nocindent syntax=automake:
Modified: xfce4-sensors-plugin/trunk/TODO
===================================================================
--- xfce4-sensors-plugin/trunk/TODO 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/TODO 2008-10-05 17:32:34 UTC (rev 5516)
@@ -1,6 +1,10 @@
TODO
======
+- Build separate application replacing recommendation for xsensors.
+ * Build libraries for backends that are used from both the plugin and the program
+ * Use a separate include folder for the building process
+
- Add tooltip onto sensors items list: "You can change values, names and colours by double-clicking the entry, editing the content, and pressing »Return« or selecting a different field."
- Use notfication messages when alert is on; when maximum is reached.
Modified: xfce4-sensors-plugin/trunk/configure.in.in
===================================================================
--- xfce4-sensors-plugin/trunk/configure.in.in 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/configure.in.in 2008-10-05 17:32:34 UTC (rev 5516)
@@ -183,6 +183,12 @@
AC_CHECK_LIB(nsl, kstat_open, SOLLIBS="$SOLLIBS -linet_ntop", SOLLIBS="$SOLLIBS")
AC_SUBST(SOLLIBS)
+XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.10.0])
+XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.6.0])
+dnl XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.12.0])
+XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
+XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
+
dnl configure the panel plugin
XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.4.0])
@@ -195,7 +201,9 @@
AC_OUTPUT([
Makefile
xfce4-sensors-plugin.spec
+lib/Makefile
panel-plugin/Makefile
+src/Makefile
icons/Makefile
po/Makefile.in
])
@@ -213,7 +221,8 @@
echo
echo "The following sensor interfaces will be built into the plugin:"
if test x"$enable_hddtemp" = x"yes"; then
-echo "* hddtemp: $HDDTEMP"
+echo "* hddtemp: $HDDTEMP (Make sure it is user-executable with UID bit set "
+echo " and user member of the respective group)"
fi
if test x"$enable_libsensors" = x"yes"; then
echo "* libsensors"
Copied: xfce4-sensors-plugin/trunk/include/acpi.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/acpi.h)
===================================================================
--- xfce4-sensors-plugin/trunk/include/acpi.h (rev 0)
+++ xfce4-sensors-plugin/trunk/include/acpi.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,135 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#ifndef XFCE4_SENSORS_ACPI_H
+#define XFCE4_SENSORS_ACPI_H
+
+#define ACPI_PATH "/proc/acpi"
+#define ACPI_DIR_THERMAL "thermal_zone"
+#define ACPI_DIR_BATTERY "battery"
+#define ACPI_DIR_FAN "fan"
+#define ACPI_FILE_THERMAL "temperature"
+#define ACPI_FILE_BATTERY_STATE "state"
+#define ACPI_FILE_BATTERY_INFO "info"
+#define ACPI_FILE_FAN "state"
+
+#define ACPI_INFO "info_"
+
+#include <glib/garray.h>
+
+#include <dirent.h> /* directory listing and reading */
+
+#include "types.h"
+
+/*
+ * Initialize ACPI by ?
+ * @Return: Number of initialized chips
+ * @Param: Pointer to array of chips
+ */
+int initialize_ACPI (GPtrArray *chips);
+
+
+/**
+ * Refreshs an ACPI chip's feature in sense of raw and formatted value
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_acpi (gpointer chip_feature, gpointer data);
+
+
+/**
+ * Read a double value from zone. Calls get_acpi_value with prolonged path.
+ * @Param zone: zone name under /proc/acpi including the subdir for one zone.
+ * @Param file: file to read information from, e.g. info.
+ * @Return: value read in first line of file after keyword and colon.
+ */
+double get_acpi_zone_value (char *zone, char *file);
+
+
+/**
+ * Read a double value from status file for fans.
+ * When status is on, result is 1.0; else it is 0.0.
+ * @Param zone: file to read information from, e.g. state.
+ * @Return: valued read in any line starting with "status:", converted to 1 or 0
+ */
+double get_fan_zone_value (char *zone);
+
+/**
+ * Read a double value from special subzone denoted by name.
+ * @Param name: name in the /pro/acpi/battery directory.
+ * @Param chipfeature: pointer to chipfeature to get a max value.
+ */
+void get_battery_max_value (char *name, t_chipfeature *chipfeature);
+
+/**
+ * Read information from the thermal zone.
+ * @Param chip: Pointer to already allocated chip, where values can be added.
+ * @Return: 0 on success
+ */
+int read_thermal_zone (t_chip *chip);
+
+
+/**
+ * Read information from the battery zone.
+ * @Param chip: Pointer to already allocated chip, where values can be added.
+ * @Return: 0 on success
+ */
+int read_battery_zone (t_chip *chip);
+
+
+/**
+ * Read information from the fan zone.
+ * @Param chip: Pointer to already allocated chip, where values can be added.
+ * @Return: 0 on success
+ */
+int read_fan_zone (t_chip *chip);
+
+
+/**
+ * Returns the ACPI version number from /proc/acpi/info file.
+ * @Return: versionnumber as string!
+ */
+char * get_acpi_info ();
+
+
+/**
+ * Get the string found in filename after the colon. To make a double out of
+ * it, strtod is suitable.
+ * @Param filename: Complete path to file to be inspected.
+ * @Return: String of value found, "<Unknown>" otherwise.
+ */
+char * get_acpi_value (char *filename);
+
+
+/**
+ * Get the battery percentage from the battery information.
+ * @Param zone: Complete zone path including both e.g. "battery" and "BAT0"
+ * @Return double value of current battery power
+ */
+double get_battery_zone_value (char *zone);
+
+
+/**
+ * Indicates whether a given directory entry should be ignored as it's not
+ * "temperature".
+ * @Param de: pointer to directory entry.
+ * @Return: 1 on ignore, else 0
+ */
+int acpi_ignore_directory_entry (struct dirent *de);
+
+#endif /* XFCE4_SENSORS_ACPI_H */
Property changes on: xfce4-sensors-plugin/trunk/include/acpi.h
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/include/hddtemp.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h)
===================================================================
--- xfce4-sensors-plugin/trunk/include/hddtemp.h (rev 0)
+++ xfce4-sensors-plugin/trunk/include/hddtemp.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,47 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#ifndef XFCE4_SENSORS_HDDTEMP_H
+#define XFCE4_SENSORS_HDDTEMP_H
+
+#include <glib/garray.h>
+
+
+#define ZERO_KELVIN -273 /*.15 */
+
+
+/*
+ * Initialize hddtemp by finding disks to monitor
+ * @Return: Number of initialized chips
+ * @Param: Pointer to array of chips
+ */
+int initialize_hddtemp (GPtrArray *chips, gboolean *suppressmessage);
+
+
+/*
+ * Refreshs a hddtemp chip's feature in sense of raw and formatted value
+
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_hddtemp (gpointer chip_feature, gpointer data);
+
+
+double get_hddtemp_value (char* disk, gboolean *suppressmessage);
+
+#endif /* XFCE4_SENSORS_HDDTEMP_H */
Property changes on: xfce4-sensors-plugin/trunk/include/hddtemp.h
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/include/lmsensors.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h)
===================================================================
--- xfce4-sensors-plugin/trunk/include/lmsensors.h (rev 0)
+++ xfce4-sensors-plugin/trunk/include/lmsensors.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,45 @@
+#ifndef XFCE4_SENSORS_LMSENSORS_H
+#define XFCE4_SENSORS_LMSENSORS_H
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <glib/garray.h>
+
+#include <sensors/sensors.h>
+
+#include "types.h"
+
+/*
+ * Initialize libsensors by reading sensor config and other stuff
+ * @Param chips: Pointer to array of chips
+ * @Return: Number of found chip_features
+ */
+int initialize_libsensors (GPtrArray *chips);
+
+/*
+ * Refreshs an lmsensors chip's feature in sense of raw and formatted value
+
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_lmsensors (gpointer chip_feature, gpointer data);
+
+/*
+ * Get the value of subsensor/feature that is number in array of sensors.
+ * @Param name: Structure of sensor description.
+ * @Param number: number of feature to read the value from
+ * @Param value: pointer where the double feature value is to be stored
+ * @Return: 0 on success
+ */
+int sensors_get_feature_wrapper (const sensors_chip_name *name, int number,
+ double *value);
+
+/*
+ * Free the additionally allocated structures in the sensors_chip_name
+ * according to the version of libsensors.
+ * @Param chip: Pointer to t_chip
+ */
+void free_lmsensors_chip (gpointer chip);
+
+#endif /* XFCE4_SENSORS_LMSENSORS_H */
Property changes on: xfce4-sensors-plugin/trunk/include/lmsensors.h
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/include/middlelayer.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h)
===================================================================
--- xfce4-sensors-plugin/trunk/include/middlelayer.h (rev 0)
+++ xfce4-sensors-plugin/trunk/include/middlelayer.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,90 @@
+/*
+ * middlelayer.h
+ *
+ * Copyright 2006, 2007 Fabian Nowak <timytery at arcor.de>
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef XFCE4_SENSORS_MIDDLELAYER_H
+#define XFCE4_SENSORS_MIDDLELAYER_H
+
+#include "types.h"
+
+#include <glib/garray.h>
+#include <glib/gtypes.h>
+
+#define NO_VALID_HDDTEMP -2
+
+/**
+ * Initialize all sensors detected by iterating and calling init-routines
+ * @Return: Number of initialized features
+ * @Param: Double-pointer to array of chips
+ */
+int initialize_all (GPtrArray **chips, gboolean *suppressmessage);
+
+
+/**
+ * Refresh all features of a chip
+ *
+ * @Param chip: Pointer to chip
+ */
+void refresh_chip (gpointer chip, gpointer data);
+
+
+/**
+ * Refresh all features of a chip
+ * @Param: Pointer to chip pointers
+ */
+void refresh_all_chips (GPtrArray *chips);
+
+
+/**
+ * Classifies sensor type
+ * @Param: Pointer to feature
+ */
+void categorize_sensor_type (t_chipfeature *chipfeature);
+
+
+/**
+ * Gets value of specified number in chip_name
+ * @Param chip_name: takten from libsensors3, it specifies bus and stuff of
+ * the sensors chip feature
+ * @Param number: number of chipfeature to look for
+ * @Param value: address where double value can be stored
+ * @Return: 0 on success, >0 else.
+ */
+int sensor_get_value (t_chip *chip, int number, double *value);
+
+
+/**
+ * Free data in chipfeatures
+ */
+void free_chipfeature (gpointer chipfeature, gpointer data);
+
+
+/**
+ * Free reamining structures in chips and associated chipfeatures
+ */
+void free_chip (gpointer chip, gpointer data);
+
+
+/**
+ * Clean up structures and call library routines for ending "session".
+ */
+void sensor_interface_cleanup ();
+
+#endif /* XFCE4_SENSORS_MIDDLELAYER_H */
Property changes on: xfce4-sensors-plugin/trunk/include/middlelayer.h
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/include/types.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/types.h)
===================================================================
--- xfce4-sensors-plugin/trunk/include/types.h (rev 0)
+++ xfce4-sensors-plugin/trunk/include/types.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,109 @@
+/*
+ * middlelayer.h
+ *
+ * Copyright 2006, 2007 Fabian Nowak <timytery at arcor.de>
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef XFCE4_SENSORS_TYPES_H
+#define XFCE4_SENSORS_TYPES_H
+
+#include <glib/garray.h>
+#include <glib/gtypes.h>
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <libxfce4util/libxfce4util.h>
+
+#ifdef HAVE_LIBSENSORS
+ #include <sensors/sensors.h>
+#else
+ typedef struct sensors_chip_name {
+ char *prefix;
+ int bus;
+ int addr;
+ char *busname; /* if dummy */
+ } sensors_chip_name;
+#endif
+
+
+/*
+ * temperature scale to show values in
+ */
+typedef enum {
+ CELSIUS,
+ FAHRENHEIT
+} t_tempscale;
+
+
+/* #define NUM_SENSOR_CHIPS 10
+#define FEATURES_PER_SENSOR 256 */
+
+typedef enum {
+ LMSENSOR,
+ HDD,
+ ACPI
+} t_chiptype;
+
+/*
+ * Indicates whether chipfeature is a temperature, a voltage or a speed
+ * value
+ */
+typedef enum {
+ TEMPERATURE,
+ VOLTAGE,
+ SPEED,
+ ENERGY,
+ STATE,
+ OTHER
+} t_chipfeature_class;
+
+/*
+ * Information about a special feature on a chip
+ */
+typedef struct {
+ gchar *name;
+ gchar *devicename;
+ /* gchar *description; */
+ double raw_value; /* unformatted sensor feature values */
+ gchar *formatted_value; /* formatted (%f5.2) sensor feature values */
+ float min_value;
+ float max_value;
+ gchar *color;
+ gboolean show;
+ gint address; /* specifies the mapping to the internal number in chip_name */
+ gboolean valid;
+ t_chipfeature_class class;
+} t_chipfeature;
+
+
+/*
+ * Information about a whole chip, like asb-1-45
+ */
+typedef struct {
+ gchar *sensorId;
+ gchar *name;
+ gchar *description;
+ gint num_features;
+ const sensors_chip_name *chip_name;
+ GPtrArray *chip_features;
+ t_chiptype type;
+} t_chip;
+
+#endif /* XFCE4_SENSORS_TYPES_H */
Property changes on: xfce4-sensors-plugin/trunk/include/types.h
___________________________________________________________________
Name: svn:mergeinfo
+
Added: xfce4-sensors-plugin/trunk/lib/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/lib/Makefile.am (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/Makefile.am 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,63 @@
+plugindir = $(libdir)/xfce4/modules
+
+plugin_LTLIBRARIES = libxfce4sensors.la
+
+if HAVE_LIBSENSORS
+SENSORS_SOURCES = lmsensors.c
+# lmsensors.h
+endif
+
+if HAVE_HDDTEMP
+HDDTEMP_SOURCES = hddtemp.c
+#hddtemp.h
+endif
+
+if HAVE_ACPI
+ACPI_SOURCES = acpi.c
+#acpi.h
+endif
+
+libxfce4sensors_la_SOURCES = \
+ middlelayer.c \
+ sensors-interface-common.c \
+ sensors-interface.c \
+ $(SENSORS_SOURCES) \
+ $(HDDTEMP_SOURCES) \
+ $(ACPI_SOURCES)
+
+# configuration.h \
+# sensors-plugin.h
+# types.h \
+# middlelayer.h
+
+INCLUDES = \
+ -I$(top_srcdir)/include
+
+libxfce4sensors_la_CFLAGS = \
+ @GTK_CFLAGS@ \
+ @GLIB_CFLAGS@ \
+ @PLATFORM_CFLAGS@ \
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ @LIBSENSORS_CFLAGS@ \
+ @LIBXFCE4UTIL_CFLAGS@
+
+
+libxfce4sensors_la_LDFLAGS = \
+ -export-dynamic \
+ -avoid-version \
+ -module
+
+libxfce4sensors_la_LIBADD = \
+ @GTK_LIBS@ \
+ @GLIB_LIBS@ \
+ @SOLLIBS@ \
+ @LIBSENSORS_LDFLAGS@ \
+ @LIBXFCE4UTIL_LIBS@
+
+# -fPIC -shared
+
+# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
+# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+
+DISTCLEANFILES =
+
Copied: xfce4-sensors-plugin/trunk/lib/acpi.c (from rev 5494, xfce4-sensors-plugin/trunk/panel-plugin/acpi.c)
===================================================================
--- xfce4-sensors-plugin/trunk/lib/acpi.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/acpi.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,586 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#include <acpi.h>
+#include <types.h>
+
+#include <glib/gmessages.h>
+#include <glib/gmem.h>
+#include <glib/gprintf.h>
+#include <glib/gstrfuncs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+
+static char *
+strip_key_colon_spaces (char *buf)
+{
+ char *p;
+ p = buf;
+
+ /* Skip everything before the ':' */
+ while (*(p++)) {
+ if (*p == ':') {
+ break;
+ }
+ }
+ p++;
+ /* Skip all the spaces */
+ while (*(p++)) {
+ if (*p != ' ') {
+ break;
+ }
+ }
+
+ return p;
+}
+
+
+int
+read_thermal_zone (t_chip *chip)
+{
+ DIR *d;
+ FILE *file;
+ char *zone, *filename;
+ struct dirent *de;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters read_thermal_zone");
+
+ if ((chdir (ACPI_PATH) == 0) && (chdir (ACPI_DIR_THERMAL) == 0))
+ {
+ d = opendir (".");
+ if (!d) {
+ closedir (d);
+ return -1;
+ }
+
+ while ((de = readdir (d)))
+ {
+ //printf ("reading %s\n", de->d_name);
+ if (strncmp(de->d_name, ".", 1)==0)
+ continue;
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH,
+ ACPI_DIR_THERMAL, de->d_name,
+ ACPI_FILE_THERMAL);
+ file = fopen (filename, "r");
+ if (file)
+ {
+ //printf ("parsing temperature file...\n");
+ /* if (acpi_ignore_directory_entry (de))
+ continue; */
+
+ chipfeature = g_new0 (t_chipfeature, 1);
+
+ chipfeature->color = g_strdup("#0000B0");
+ chipfeature->address = chip->chip_features->len;
+ chipfeature->devicename = g_strdup (de->d_name);
+ chipfeature->name = g_strdup (chipfeature->devicename);
+ chipfeature->formatted_value = NULL; /* Gonna refresh it in
+ sensors_get_wrapper or some
+ other functions */
+ zone = g_strdup_printf ("%s/%s", ACPI_DIR_THERMAL, de->d_name);
+ chipfeature->raw_value = get_acpi_zone_value (zone, ACPI_FILE_THERMAL);
+ g_free (zone);
+
+ chipfeature->valid = TRUE;
+ chipfeature->min_value = 20.0;
+ chipfeature->max_value = 60.0;
+ chipfeature->class = TEMPERATURE;
+
+ g_ptr_array_add (chip->chip_features, chipfeature);
+
+ chip->num_features++; /* FIXME: actually I am just the same as
+ chip->chip_features->len */
+
+ fclose(file);
+ }
+ //else
+ //printf ("not parsing temperature file...\n");
+
+ g_free (filename);
+ }
+
+ closedir (d);
+ TRACE ("leaves read_thermal_zone");
+
+ return 0;
+ }
+ else {
+ TRACE ("leaves read_thermal_zone");
+ return -2;
+ }
+}
+
+
+double get_fan_zone_value (char *zone)
+{
+ double value;
+
+ FILE *file;
+ char buf [1024], *filename, *tmp;
+
+ TRACE ("enters get_fan_zone_value for %s", zone);
+
+ value = 0.0;
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH, ACPI_DIR_FAN,
+ zone, ACPI_FILE_FAN);
+ DBG("filename=%s", filename);
+ file = fopen (filename, "r");
+ if (file) {
+ while (fgets (buf, 1024, file)!=NULL)
+ {
+ if (strncmp (buf, "status:", 7)==0)
+ {
+ tmp = strip_key_colon_spaces(buf);
+ DBG ("tmp=%s", tmp);
+ if (strncmp (tmp, "on", 2)==0)
+ value = 1.0;
+ else
+ value = 0.0;
+
+ break;
+ }
+ }
+ /* g_free (tmp); */ /* points to inside the buffer! */
+ fclose (file);
+ }
+
+ g_free (filename);
+
+ return value;
+}
+
+double get_battery_zone_value (char *zone)
+{
+ double value;
+
+ FILE *file;
+ char buf [1024], *filename, *tmp;
+
+ TRACE ("enters get_battery_zone_value for %s", zone);
+
+ value = 0.0;
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH, ACPI_DIR_BATTERY,
+ zone, ACPI_FILE_BATTERY_STATE);
+ file = fopen (filename, "r");
+ if (file) {
+ while (fgets (buf, 1024, file)!=NULL)
+ {
+ if (strncmp (buf, "remaining capacity:", 19)==0)
+ {
+ tmp = strip_key_colon_spaces(buf);
+ value = strtod (tmp, NULL);
+ break;
+ }
+ }
+ /* g_free (tmp); */ /* points to inside the buffer! */
+ fclose (file);
+ }
+
+ g_free (filename);
+
+ return value;
+}
+
+
+int read_battery_zone (t_chip *chip)
+{
+ DIR *d;
+ FILE *file;
+ char *filename, *tmp, buf[1024];
+ struct dirent *de;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters read_battery_zone");
+
+ if ((chdir (ACPI_PATH) == 0) && (chdir (ACPI_DIR_BATTERY) == 0)) {
+ d = opendir (".");
+ if (!d) {
+ closedir (d);
+ return -1;
+ }
+
+ while ((de = readdir (d)))
+ {
+ if (strncmp(de->d_name, "BAT", 3)==0)
+ { /* have a battery subdirectory */
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH,
+ ACPI_DIR_BATTERY, de->d_name,
+ ACPI_FILE_BATTERY_STATE);
+ DBG ("filename=%s\n", filename);
+ file = fopen (filename, "r");
+ if (file) {
+ chipfeature = g_new0 (t_chipfeature, 1);
+ chipfeature->address = chip->chip_features->len;
+ chipfeature->devicename = g_strdup (de->d_name);
+ chipfeature->name = g_strdup (chipfeature->devicename);
+ chipfeature->valid = TRUE;
+ chipfeature->min_value = 0.0;
+ chipfeature->raw_value = 0.0;
+ chipfeature->class = ENERGY;
+ chipfeature->formatted_value = NULL;
+ chipfeature->color = g_strdup("#0000B0");
+ while (fgets (buf, 1024, file)!=NULL)
+ {
+ if (strncmp (buf, "design capacity low:", 20)==0)
+ {
+ tmp = strip_key_colon_spaces(buf);
+ chipfeature->min_value = strtod (tmp, NULL);
+ }
+ else if (strncmp (buf, "remaining capacity:", 19)==0)
+ {
+ tmp = strip_key_colon_spaces(buf);
+ chipfeature->raw_value = strtod (tmp, NULL);
+ }
+ }
+ /* g_free (tmp); */ /* points to inside of the buffer */
+ fclose (file);
+
+ /* chipfeature->raw_value = get_battery_zone_value (de->d_name); */
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ chip->num_features++; /* FIXME: actually I am just the same
+ as chip->chip_features->len */
+ }
+ else {
+ g_free (filename);
+ continue; /* because, what would we want to do with only
+ a maxval and no real value inside? */
+ }
+
+ g_free (filename);
+
+ get_battery_max_value (de->d_name, chipfeature);
+
+ }
+
+ }
+
+ closedir (d);
+ TRACE ("leaves read_battery_zone");
+
+ return 0;
+
+ }
+ else
+ {
+ TRACE ("leaves read_battery_zone");
+ return -2;
+ }
+}
+
+
+void
+get_battery_max_value (char *name, t_chipfeature *chipfeature)
+{
+ FILE *file;
+ char *filename, *tmp, buf[1024];
+
+ TRACE ("enters get_battery_max_value");
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH,
+ ACPI_DIR_BATTERY, name,
+ ACPI_FILE_BATTERY_INFO);
+ file = fopen (filename, "r");
+ if (file)
+ {
+ while (fgets (buf, 1024, file)!=NULL)
+ {
+ if (strncmp (buf, "last full capacity:", 19)==0)
+ {
+
+ tmp = strip_key_colon_spaces(buf);
+ chipfeature->max_value = strtod (tmp, NULL);
+ }
+ }
+ fclose (file);
+ }
+
+ g_free (filename);
+
+ TRACE ("leaves get_battery_max_value");
+}
+
+
+int read_fan_zone (t_chip *chip)
+{
+ DIR *d;
+ FILE *file;
+ char *filename;
+ struct dirent *de;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters read_fan_zone");
+
+ if ((chdir (ACPI_PATH) == 0) && (chdir (ACPI_DIR_FAN) == 0))
+ {
+ d = opendir (".");
+ if (!d) {
+ closedir (d);
+ return -1;
+ }
+
+ while ((de = readdir (d)))
+ {
+ //printf ("reading %s\n", de->d_name);
+ if (strncmp(de->d_name, ".", 1)==0)
+ continue;
+
+ filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH,
+ ACPI_DIR_FAN, de->d_name,
+ ACPI_FILE_FAN);
+ file = fopen (filename, "r");
+ if (file)
+ {
+ //printf ("parsing temperature file...\n");
+ /* if (acpi_ignore_directory_entry (de))
+ continue; */
+
+ chipfeature = g_new0 (t_chipfeature, 1);
+
+ chipfeature->color = g_strdup("#0000B0");
+ chipfeature->address = chip->chip_features->len;
+ chipfeature->devicename = g_strdup (de->d_name);
+ chipfeature->name = g_strdup (chipfeature->devicename);
+ chipfeature->formatted_value = NULL; /* Gonna refresh it in
+ sensors_get_wrapper or some
+ other functions */
+ chipfeature->raw_value = get_fan_zone_value (de->d_name);
+
+ chipfeature->valid = TRUE;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 2.0;
+ chipfeature->class = STATE;
+
+ g_ptr_array_add (chip->chip_features, chipfeature);
+
+ chip->num_features++; /* FIXME: actually I am just the same as
+ chip->chip_features->len */
+
+ fclose(file);
+ }
+ //else
+ //printf ("not parsing temperature file...\n");
+
+ g_free (filename);
+ }
+
+ closedir (d);
+ TRACE ("leaves read_fan_zone");
+
+ return 0;
+ }
+ else {
+ TRACE ("leaves read_fan_zone");
+ return -2;
+ }
+ return -7;
+}
+
+
+int initialize_ACPI (GPtrArray *chips)
+{
+ t_chip *chip;
+
+ TRACE ("enters initialize_ACPI");
+
+ chip = g_new0 (t_chip, 1);
+ chip->name = g_strdup(_("ACPI")); /* to be displayed */
+ /* chip->description = g_strdup(_("Advanced Configuration and Power Interface")); */
+ chip->description = g_strdup_printf (_("ACPI v%s zones"), get_acpi_info());
+ chip->sensorId = g_strdup ("ACPI"); /* used internally */
+
+ chip->type = ACPI;
+
+ chip->chip_name = (const sensors_chip_name *)
+ ( g_strdup(_("ACPI")), 0, 0, g_strdup(_("ACPI")) );
+
+ chip->chip_features = g_ptr_array_new ();
+
+ chip->num_features = 0;
+
+ read_battery_zone (chip);
+ read_thermal_zone (chip);
+ read_fan_zone (chip);
+
+ g_ptr_array_add (chips, chip);
+
+ /* int i = 0;
+ t_chipfeature *chipfeature;
+ printf ("chip->chip_features->len=%d\n", chip->chip_features->len);
+ while (i<chip->chip_features->len ) {
+ chipfeature = g_ptr_array_index(chip->chip_features, i++);
+ g_printf ("chips val=%f\n", chipfeature->raw_value);
+ } */
+
+ TRACE ("leaves initialize_ACPI");
+
+ return 4;
+}
+
+void
+refresh_acpi (gpointer chip_feature, gpointer data)
+{
+ char *file, *zone, *state;
+ t_chipfeature *cf;
+
+ TRACE ("enters refresh_acpi");
+
+ g_assert(chip_feature!=NULL);
+
+ cf = (t_chipfeature *) chip_feature;
+
+ switch (cf->class) {
+ case TEMPERATURE:
+ zone = g_strdup_printf ("%s/%s", ACPI_DIR_THERMAL, cf->devicename);
+ cf->raw_value = get_acpi_zone_value (zone, ACPI_FILE_THERMAL);
+ g_free (zone);
+ /* g_free (cf->formatted_value);
+ cf->formatted_value = g_strdup_printf (_("%+5.1f °C"), cf->raw_value); */
+ break;
+
+ case ENERGY:
+ /* zone = g_strdup_printf ("%s/%s", ACPI_DIR_BATTERY, cf->devicename); */
+ cf->raw_value = get_battery_zone_value (cf->devicename); /* zone */
+ /* g_free (zone); */
+ /* g_free (cf->formatted_value);
+ cf->formatted_value = g_strdup_printf (_("%.0f mWh"), cf->raw_value); */
+ break;
+
+ case STATE:
+ file = g_strdup_printf ("%s/%s/%s/state", ACPI_PATH, ACPI_DIR_FAN, cf->devicename);
+
+ state = get_acpi_value(file);
+ if (state==NULL)
+ {
+ DBG("Could not determine fan state.");
+ cf->raw_value = 0.0;
+ }
+ else
+ {
+ cf->raw_value = strncmp(state, "on", 2)==0 ? 1.0 : 0.0;
+ /* g_free (state); Anyone with a fan state please check that, should be necessary to free this string as well */
+ }
+ g_free (file);
+
+ /* g_free (cf->formatted_value);
+ cf->formatted_value = g_strdup_printf (_("%.0f"), cf->raw_value); */
+ break;
+
+ default:
+ printf ("Unknown ACPI type. Please check your ACPI installation "
+ "and restart the plugin.\n");
+ }
+
+ TRACE ("leaves refresh_acpi");
+}
+
+
+int
+acpi_ignore_directory_entry (struct dirent *de)
+{
+ TRACE ("enters and leaves acpi_ignore_directory_entry");
+
+ /*return !strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."); */
+ return strcmp (de->d_name, "temperature");
+}
+
+
+char *
+get_acpi_info ()
+{
+ char *filename, *version;
+
+ TRACE ("enters get_acpi_info");
+
+ filename = g_strdup_printf ("%s/%s", ACPI_PATH, ACPI_INFO);
+
+ TRACE ("leaves get_acpi_info");
+
+ version = get_acpi_value (filename);
+ if (version!=NULL)
+ version = g_strchomp (version);
+
+ if (version==NULL)
+ version = _("<Unknown>");
+
+ return version;
+}
+
+
+/* Note that zone will have to consist of two paths, e.g.
+ * thermal_zone and THRM.
+ */
+double
+get_acpi_zone_value (char *zone, char *file)
+{
+ char *filename, *value;
+ double retval;
+
+ TRACE ("enters get_acpi_zone_value for %s/%s", zone, file);
+
+ filename = g_strdup_printf ("%s/%s/%s", ACPI_PATH, zone, file);
+ value = get_acpi_value (filename);
+
+ TRACE ("leaves get_acpi_zone_value with correctly converted value");
+
+ /* Return it as a double */
+ retval = strtod (value, NULL);
+ g_free (value);
+
+ return retval;
+}
+
+
+/**
+ * Get the value from inside an acpi's file.
+ * @param filename An absolute filename, most likely starting with /proc/acpi...
+ * @return value found inside as a character
+ */
+char *
+get_acpi_value (char *filename)
+{
+ FILE *file;
+ char buf [1024], *p;
+
+ TRACE ("enters get_acpi_value for %s", filename);
+
+ file = fopen (filename, "r");
+ if (!file)
+ return NULL;
+
+ (void) fgets (buf, 1024, file);
+ fclose (file);
+
+ p = strip_key_colon_spaces (buf);
+
+ TRACE ("leaves get_acpi_value with %s", p);
+
+ /* Have read the data */
+ return g_strdup (p);
+}
+
Property changes on: xfce4-sensors-plugin/trunk/lib/acpi.c
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/lib/hddtemp.c (from rev 5494, xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c)
===================================================================
--- xfce4-sensors-plugin/trunk/lib/hddtemp.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/hddtemp.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,450 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#include <config.h>
+#include <hddtemp.h>
+#include <middlelayer.h>
+#include <types.h>
+
+#include <glib/garray.h>
+#include <glib/gdir.h>
+#include <glib/gerror.h>
+#include <glib/gmem.h>
+#include <glib/gmessages.h>
+#include <glib/gprintf.h>
+#include <glib/gspawn.h>
+#include <glib/gstrfuncs.h>
+
+#include <gtk/gtkbox.h>
+#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkstock.h>
+
+/* #include <stdio.h> */
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/utsname.h>
+
+#include <unistd.h>
+
+
+void quick_message (gchar *message) {
+
+ GtkWidget *dialog; /*, *label; */
+
+ TRACE ("enters quick_message");
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CLOSE,
+ message);
+
+ /* dialog = gtk_dialog_new_with_buttons (_("Could not run \"hddtemp\""),
+ NULL, 0, // GTK DIALOG NO MODAL ;-)
+ GTK_STOCK_CLOSE, GTK_RESPONSE_NONE,
+ NULL);
+ label = gtk_label_new (message);
+ gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
+ gtk_label_set_width_chars (GTK_LABEL(label), 60); */
+
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), dialog);
+
+ /*
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
+ gtk_widget_show_all (dialog); */
+ gtk_dialog_run(GTK_DIALOG(dialog));
+
+ TRACE ("leaves quick_message");
+}
+
+
+gboolean quick_message_with_checkbox (gchar *message, gchar *checkboxtext) {
+
+ GtkWidget *dialog, *checkbox; /*, *label; */
+ gboolean is_active;
+
+ TRACE ("enters quick_message");
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CLOSE,
+ message);
+
+ gtk_window_set_title(GTK_WINDOW(dialog), _("Xfce 4 Sensors Plugin"));
+
+ checkbox = gtk_check_button_new_with_mnemonic (checkboxtext);
+
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), checkbox, FALSE, FALSE, 0);
+ gtk_widget_show(checkbox);
+
+ gtk_dialog_run(GTK_DIALOG(dialog));
+
+ is_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbox));
+
+ gtk_widget_destroy (dialog);
+
+ TRACE ("leaves quick_message");
+
+ return is_active;
+}
+
+
+void
+read_disks_fallback (t_chip *chip)
+{
+ GError *error;
+ GDir *gdir;
+ t_chipfeature *chipfeature;
+ const gchar* dirname;
+
+ TRACE ("enters read_disks_fallback");
+
+ /* read from /proc/ide */
+ error = NULL;
+ gdir = g_dir_open ("/proc/ide/", 0, &error);
+
+ while ( (dirname = g_dir_read_name (gdir))!=NULL ) {
+ if ( strncmp (dirname, "hd", 2)==0 || strncmp (dirname, "sd", 2)==0) {
+ /* TODO: look, if /dev/dirname exists? */
+ chipfeature = g_new0 (t_chipfeature, 1);
+ chipfeature->devicename = g_strconcat ("/dev/", dirname, NULL);
+ chipfeature->name = g_strdup(chipfeature->devicename);
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ chip->num_features++;
+ }
+ }
+
+ g_dir_close (gdir);
+
+ /* FIXME: read SCSI info from where? SATA? */
+
+ TRACE ("leaves read_disks_fallback");
+}
+
+
+void
+read_disks_linux26 (t_chip *chip)
+{
+ GDir *gdir;
+ t_chipfeature *chipfeature;
+ const gchar* dirname;
+
+ TRACE ("enters read_disks_linux26");
+
+ /* read from /sys/block */
+ gdir = g_dir_open ("/sys/block/", 0, NULL);
+ while ( (dirname = g_dir_read_name (gdir))!=NULL ) {
+ /* if ( strncmp (dirname, "ram", 3)!=0 &&
+ strncmp (dirname, "loop", 4)!=0 &&
+ strncmp (dirname, "md", 2)!=0 &&
+ strncmp (dirname, "fd", 2)!=0 &&
+ strncmp (dirname, "mmc", 3)!=0 &&
+ strncmp (dirname, "dm-", 3)!=0 ) { */
+ if ( strncmp (dirname, "hd", 2)==0 ||
+ strncmp (dirname, "sd", 2)==0 ) {
+ /* TODO: look, if /dev/dirname exists? */
+ chipfeature = g_new0 (t_chipfeature, 1);
+ chipfeature->devicename = g_strconcat ("/dev/", dirname, NULL); /* /proc/ide/hda/model ?? */
+ chipfeature->name = g_strdup(chipfeature->devicename);
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ chip->num_features++;
+ }
+ }
+
+ g_dir_close (gdir);
+
+ TRACE ("leaves read_disks_linux26");
+}
+
+
+void
+remove_unmonitored_drives (t_chip *chip, gboolean *suppressmessage)
+{
+ int i, result;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters remove_unmonitored_drives");
+
+ for (i=0; i<chip->num_features; i++)
+ {
+ chipfeature = g_ptr_array_index (chip->chip_features, i);
+ result = get_hddtemp_value (chipfeature->devicename, suppressmessage);
+ if (result == 0.0)
+ {
+ DBG ("removing single disk");
+ free_chipfeature ( (gpointer) chipfeature, NULL);
+ g_ptr_array_remove_index (chip->chip_features, i);
+ i--;
+ chip->num_features--;
+ }
+ else if (result == ZERO_KELVIN)
+ {
+ for (i=0; i < chip->num_features; i++) {
+ DBG ("remove %d\n", i);
+ chipfeature = g_ptr_array_index (chip->chip_features, i);
+ free_chipfeature ( (gpointer) chipfeature, NULL);
+ }
+ g_ptr_array_free (chip->chip_features, TRUE);
+ // chip->chip_features = g_ptr_array_new();
+ chip->num_features=0;
+ DBG ("Returning because of bad hddtemp.\n");
+ return;
+ }
+ }
+
+ TRACE ("leaves remove_unmonitored_drives");
+}
+
+
+void
+populate_detected_drives (t_chip *chip)
+{
+ int diskIndex;
+ /* double value; */
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters populate_detected_drives");
+
+ chip->sensorId = g_strdup(_("Hard disks"));
+
+ for (diskIndex=0; diskIndex < chip->num_features; diskIndex++)
+ {
+ chipfeature = g_ptr_array_index (chip->chip_features, diskIndex);
+ g_assert (chipfeature!=NULL);
+
+ chipfeature->address = diskIndex;
+
+ /* chipfeature->name = g_strdup(chipfeature->devicename); */
+
+ chipfeature->color = g_strdup("#B000B0");
+ chipfeature->valid = TRUE;
+ chipfeature->formatted_value = g_strdup ("0.0"); /* _printf("%+5.1f", 0.0); */
+ chipfeature->raw_value = 0.0;
+
+ chipfeature->class = TEMPERATURE;
+ chipfeature->min_value = 10.0;
+ chipfeature->max_value = 50.0;
+
+ chipfeature->show = FALSE;
+ }
+
+ TRACE ("leaves populate_detected_drives");
+}
+
+
+int
+initialize_hddtemp (GPtrArray *chips, gboolean *suppressmessage)
+{
+ int generation, major, result, retval;
+ struct utsname *p_uname;
+ t_chip *chip;
+
+ g_assert (chips!=NULL);
+
+ TRACE ("enters initialize_hddtemp");
+
+ chip = g_new (t_chip, 1);
+
+ chip->chip_name = (const sensors_chip_name *)
+ ( _("Hard disks"), 0, 0, _("Hard disks") );
+
+ chip->chip_features = g_ptr_array_new ();
+ chip->num_features = 0;
+ chip->description = g_strdup(_("S.M.A.R.T. harddisk temperatures"));
+ chip->name = g_strdup(_("Hard disks"));
+ chip->sensorId = g_strdup("Hard disks");
+ chip->type = HDD;
+
+ p_uname = (struct utsname *) malloc (sizeof(struct utsname));
+ result = uname (p_uname);
+ if (result!=0) {
+ g_free(p_uname);
+ return -1;
+ }
+
+ generation = atoi ( p_uname->release ); /* this might cause trouble on */
+ major = atoi ( p_uname->release+2 ); /* other systems than Linux! */
+ /* actually, wanted to use build time configuration therefore */
+
+ /* Note: This is actually supposed to be carried out by ifdef HAVE_LINUX
+ and major/minor number stuff from compile time*/
+ if (strcmp(p_uname->sysname, "Linux")==0 && major>=5)
+ read_disks_linux26 (chip);
+ else
+ read_disks_fallback (chip); /* hopefully, that's a safe variant */
+
+ g_free(p_uname);
+
+ remove_unmonitored_drives (chip, suppressmessage);
+ DBG ("numfeatures=%d\n", chip->num_features);
+ if ( chip->num_features>0 ) { /* if (1) */
+
+ populate_detected_drives (chip);
+ g_ptr_array_add (chips, chip);
+ retval = 2;
+ }
+ else {
+ retval = 0;
+ }
+
+ TRACE ("leaves initialize_hddtemp");
+
+ return retval;
+}
+
+
+double
+get_hddtemp_value (char* disk, gboolean *suppressmessage)
+{
+ gchar *standard_output, *standard_error;
+ gchar *cmd_line, *msg_text, *checktext;
+ gint exit_status=0;
+ double value;
+ gboolean result, nevershowagain;
+ GError *error;
+
+ if (suppressmessage!=NULL)
+ nevershowagain = *suppressmessage;
+ else
+ nevershowagain = FALSE;
+
+ TRACE ("enters get_hddtemp_value for %s with suppress=%d", disk, nevershowagain); /* *suppressmessage); */
+
+ cmd_line = g_strdup_printf ( "%s -n -q %s", PATH_HDDTEMP, disk);
+
+ msg_text = NULL;
+
+ error = NULL;
+ result = g_spawn_command_line_sync ( (const gchar*) cmd_line,
+ &standard_output, &standard_error, &exit_status, &error);
+
+ DBG ("Exit code %d on %s with stdout of %s.\n", exit_status, disk, standard_output);
+
+ /* filter those with no sensors out */
+ if (exit_status==0 && strncmp(disk, "/dev/fd", 6)==0) { /* is returned for floppy disks */
+ DBG("exit_status==0 && strncmp(disk, \"/dev/fd\", 6)==0");
+ value = 0.0;
+ }
+ else if ((exit_status==256 || (standard_error && strlen(standard_error)>0))
+ && access (PATH_HDDTEMP, X_OK)==0) /* || strlen(standard_error)>0) */
+ {
+ /* note that this check does only work for some versions of hddtemp. */
+ if (!nevershowagain) {
+ msg_text = g_strdup_printf(_("\"hddtemp\" was not executed correctly, "
+ "although it is executable. This is most probably due "
+ "to the disks requiring root privileges to read their "
+ "temperatures, and \"hddtemp\" not being setuid root."
+ "\n\n"
+ "An easy but dirty solution is to run \"chmod u+s %s"
+ "\" as root user and restart this plugin "
+ "or its panel.\n\n"
+ "Calling \"%s\" gave the following error:\n%s\nwith a return value of %d.\n"),
+ PATH_HDDTEMP, cmd_line, standard_error, exit_status);
+ checktext = g_strdup(_("Suppress this message in future"));
+ /* quick_message (msg_text); */
+ nevershowagain = quick_message_with_checkbox(msg_text, checktext);
+
+ if (suppressmessage!=NULL)
+ *suppressmessage = nevershowagain;
+ }
+ else {
+ DBG ("Suppressing dialog with exit_code=256 or output on standard_error");
+ }
+
+ value = ZERO_KELVIN;
+ }
+ /* else if (strlen(standard_error)>0) {
+ msg_text = g_strdup_printf (_("An error occurred when executing"
+ " \"%s\":\n%s"), cmd_line, standard_error);
+ quick_message (msg_text);
+ value = ZERO_KELVIN;
+ } */
+
+ else if (error && (!result || exit_status!=0))
+ {
+ DBG ("error %s\n", error->message);
+ if (!nevershowagain) {
+ msg_text = g_strdup_printf (_("An error occurred when executing"
+ " \"%s\":\n%s"), cmd_line, error->message);
+ checktext = g_strdup(_("Suppress this message in future"));
+ nevershowagain = quick_message_with_checkbox (msg_text, checktext);
+
+ if (suppressmessage!=NULL)
+ *suppressmessage = nevershowagain;
+ }
+ else {
+ DBG ("Suppressing dialog because of error in g_spawn_cl");
+ }
+ value = 0.0;
+ }
+ else if (standard_output && strlen(standard_output) > 0)
+ {
+ DBG("got the only useful return value of 0 and value of %s.\n", standard_output);
+ /* hddtemp does not return floating values, but only integer ones.
+ So have an easier life with atoi.
+ FIXME: Use strtod() instead?*/
+ value = (double) (atoi ( (const char*) standard_output) );
+ }
+ else {
+ DBG("No condition applied.");
+ value = 0.0;
+ }
+
+ g_free (cmd_line);
+ g_free (standard_output);
+ g_free (standard_error);
+ g_free (msg_text);
+
+ TRACE ("leaves get_hddtemp_value");
+
+ return value;
+}
+
+
+void
+refresh_hddtemp (gpointer chip_feature, gpointer data)
+{
+ t_chipfeature *cf;
+ double value;
+
+ g_assert (chip_feature!=NULL);
+
+ TRACE ("enters refresh_hddtemp");
+
+ cf = (t_chipfeature *) chip_feature;
+
+ value = get_hddtemp_value (cf->devicename, NULL);
+
+ /* actually, that's done in the gui part */
+ g_free (cf->formatted_value);
+ /* if (scale == FAHRENHEIT) {
+ cf->formatted_value = g_strdup_printf(_("%5.1f °F"), (float) (value * 9/5 + 32) );
+ } else { // Celsius */
+ cf->formatted_value = g_strdup_printf(_("%5.1f °C"), value);
+ /* } */
+ cf->raw_value = value;
+
+ TRACE ("leaves refresh_hddtemp");
+}
+
Property changes on: xfce4-sensors-plugin/trunk/lib/hddtemp.c
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/lib/lmsensors.c (from rev 5494, xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c)
===================================================================
--- xfce4-sensors-plugin/trunk/lib/lmsensors.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/lmsensors.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,445 @@
+
+#include <lmsensors.h>
+#include <middlelayer.h>
+#include <types.h>
+
+#include <errno.h>
+
+#include <glib/garray.h>
+#include <glib/gmessages.h>
+#include <glib/gmem.h>
+#include <glib/gprintf.h>
+#include <glib/gstrfuncs.h>
+
+#include <stdio.h>
+#include <string.h>
+
+/* Unused
+int get_number_chip_features (const sensors_chip_name *name)
+{
+ int nr1 = 0, nr2 = 0, numer = 0;
+ const sensors_feature_data *sfd;
+
+ TRACE("enters get_number_chip_features");
+
+ do {
+ sfd = sensors_get_all_features (*name, &nr1, &nr2);
+ if (sfd!=NULL)
+ number++;
+ } while (sfd!=NULL);
+
+ TRACE("leaves get_number_chip_features");
+
+ return number-1;
+} */
+
+
+int sensors_get_feature_wrapper (const sensors_chip_name *name, int number, double *value)
+{
+ #if SENSORS_API_VERSION < 0x400 /* libsensors3 */
+ return sensors_get_feature (*name, number, value);
+ #else
+ return sensors_get_value (name, number, value);
+ #endif
+}
+
+
+t_chip *setup_chip (GPtrArray *chips, const sensors_chip_name *name, int num_sensorchips)
+{
+ t_chip* chip;
+
+ TRACE ("enters setup_chip");
+
+ chip = g_new0 (t_chip, 1);
+
+ g_ptr_array_add (chips, chip);
+
+ chip->chip_name = (sensors_chip_name *) g_malloc (sizeof(sensors_chip_name));
+ memcpy ( (void *) (chip->chip_name), (void *) name, sizeof(sensors_chip_name) );
+
+ #if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
+ chip->sensorId = g_strdup_printf ("%s-%x-%x", name->prefix, name->bus,
+ name->addr);
+ #else
+ switch (name->bus.type) {
+ case SENSORS_BUS_TYPE_I2C:
+ case SENSORS_BUS_TYPE_SPI:
+ chip->sensorId = g_strdup_printf ("%s-%x-%x", name->prefix,
+ name->bus.nr, name->addr);
+ break;
+ default:
+ chip->sensorId = g_strdup_printf ("%s-%x", name->prefix,
+ name->addr);
+ }
+ #endif
+
+ chip->num_features=0;
+ chip->name = g_strdup(_("LM Sensors"));
+ chip->chip_features = g_ptr_array_new();
+
+ #if SENSORS_API_VERSION < 0x400 /* libsensors3 */
+ chip->description = g_strdup (
+ sensors_get_adapter_name (num_sensorchips-1));
+ #else
+ chip->description = g_strdup (sensors_get_adapter_name (&name->bus));
+ #endif
+
+ TRACE ("leaves setup_chip");
+
+ return chip;
+}
+
+
+#if SENSORS_API_VERSION >= 0x400 /* libsensors4 */
+void
+categorize_sensor_type_libsensors4 (t_chipfeature *chipfeature,
+ const sensors_feature *feature,
+ const sensors_chip_name *name,
+ int number)
+{
+ const sensors_subfeature *sub_feature = NULL;
+ double sensorFeature;
+
+ switch (feature->type) {
+ case SENSORS_FEATURE_IN:
+ chipfeature->class = VOLTAGE;
+ chipfeature->min_value = 1.0;
+ chipfeature->max_value = 12.2;
+
+ if ((sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_IN_MIN)) &&
+ !sensors_get_value (name, number, &sensorFeature))
+ chipfeature->min_value = sensorFeature;
+
+ if ((sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_IN_MAX)) &&
+ !sensors_get_value (name, number, &sensorFeature))
+ chipfeature->max_value = sensorFeature;
+
+ break;
+
+ case SENSORS_FEATURE_FAN:
+ chipfeature->class = SPEED;
+ chipfeature->min_value = 1000.0;
+ chipfeature->max_value = 3500.0;
+
+ if ((sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_FAN_MIN)) &&
+ !sensors_get_value (name, number, &sensorFeature))
+ chipfeature->min_value = sensorFeature;
+
+ break;
+
+ case SENSORS_FEATURE_TEMP:
+ chipfeature->class = TEMPERATURE;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 80.0;
+
+ if ((sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_TEMP_MIN)) &&
+ !sensors_get_value (name, number, &sensorFeature))
+ chipfeature->min_value = sensorFeature;
+
+ if (((sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_TEMP_MAX)) ||
+ (sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_TEMP_CRIT))) &&
+ !sensors_get_value (name, number, &sensorFeature))
+ chipfeature->max_value = sensorFeature;
+ break;
+
+ case SENSORS_FEATURE_VID:
+ chipfeature->class = VOLTAGE;
+ chipfeature->min_value = 1.0;
+ chipfeature->max_value = 3.5;
+ break;
+
+ case SENSORS_FEATURE_BEEP_ENABLE:
+ chipfeature->class = STATE;
+ chipfeature->min_value = 1.0;
+ chipfeature->max_value = 3.5;
+ break;
+
+ default: /* UNKNOWN */
+ chipfeature->class = OTHER;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 7000.0;
+ }
+}
+#endif
+
+
+void setup_chipfeature_common (t_chipfeature *chipfeature, int number,
+ double sensorFeature)
+{
+ g_free (chipfeature->color);
+ chipfeature->color = g_strdup("#00B000");
+ chipfeature->valid = TRUE;
+
+ chipfeature->raw_value = sensorFeature;
+ chipfeature->address = number;
+ chipfeature->show = FALSE;
+}
+
+
+#if SENSORS_API_VERSION < 0x400 /* libsensors3 */
+void setup_chipfeature (t_chipfeature *chipfeature, int number,
+ double sensorFeature)
+{
+ TRACE ("enters setup_chipfeature");
+
+ setup_chipfeature_common (chipfeature, number, sensorFeature);
+
+ /* g_free (chipfeature->formatted_value);
+ chipfeature->formatted_value = g_strdup_printf ("%+5.1f", sensorFeature); */
+
+ categorize_sensor_type (chipfeature);
+
+ TRACE ("leaves setup_chipfeature");
+}
+#else
+void setup_chipfeature_libsensors4 (t_chipfeature *chipfeature,
+ const sensors_feature *feature, int number,
+ double sensorFeature,
+ const sensors_chip_name *name)
+{
+
+ setup_chipfeature_common (chipfeature, number, sensorFeature);
+
+ categorize_sensor_type_libsensors4 (chipfeature, feature, name, number);
+}
+#endif
+
+
+#if SENSORS_API_VERSION < 0x400 /* libsensors3 */
+t_chipfeature *find_chipfeature (const sensors_chip_name *name, t_chip *chip,
+ int number)
+{
+ int res;
+ double sensorFeature;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters find_chipfeature");
+
+ chipfeature = g_new0 (t_chipfeature, 1);
+
+ if (sensors_get_ignored (*(name), number)==1) {
+ g_free (chipfeature->name); /* ? */
+ res = sensors_get_label (*(name), number, &(chipfeature->name));
+
+ if (res==0) {
+ res = sensors_get_feature (*(name), number, &sensorFeature);
+
+ if (res==0) {
+ setup_chipfeature (chipfeature, number, sensorFeature);
+ chip->num_features++;
+ TRACE("leaves find_chipfeature");
+ return chipfeature;
+ }
+ }
+ }
+
+ g_free (chipfeature);
+ TRACE ("leaves find_chipfeature with null");
+ return NULL;
+}
+#else
+t_chipfeature *find_chipfeature (const sensors_chip_name *name, t_chip *chip,
+ const sensors_feature *feature)
+{
+ const sensors_subfeature *sub_feature = NULL;
+ int res, number = -1;
+ double sensorFeature;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters find_chipfeature");
+
+ switch (feature->type) {
+ case SENSORS_FEATURE_IN:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_IN_INPUT);
+ break;
+ case SENSORS_FEATURE_FAN:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_FAN_INPUT);
+ break;
+ case SENSORS_FEATURE_TEMP:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_TEMP_INPUT);
+ break;
+ case SENSORS_FEATURE_VID:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_VID);
+ break;
+ case SENSORS_FEATURE_BEEP_ENABLE:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_BEEP_ENABLE);
+ break;
+ default:
+ sub_feature = sensors_get_subfeature (name, feature,
+ SENSORS_SUBFEATURE_UNKNOWN);
+ }
+ if (sub_feature)
+ number = sub_feature->number;
+
+ if (number==-1)
+ return NULL;
+
+ chipfeature = g_new0 (t_chipfeature, 1);
+
+ chipfeature->name = sensors_get_label (name, feature);
+
+ if (!chipfeature->name)
+ chipfeature->name = feature->name;
+
+ if (chipfeature->name)
+ {
+ res = sensors_get_value (name, number, &sensorFeature);
+ if (res==0)
+ {
+ setup_chipfeature_libsensors4 (chipfeature, feature, number,
+ sensorFeature, name);
+ chip->num_features++;
+ TRACE("leaves find_chipfeature");
+ return chipfeature;
+ }
+ }
+
+ g_free(chipfeature);
+
+ TRACE("leaves find_chipfeature with null");
+ return NULL;
+}
+#endif
+
+
+int initialize_libsensors (GPtrArray *chips)
+{
+ int sensorsInit, nr1, nr2, num_sensorchips; /* , numchips; */
+ t_chip *chip;
+ t_chipfeature *chipfeature; /* , *furtherchipfeature; */
+ const sensors_chip_name *detected_chip;
+#if SENSORS_API_VERSION < 0x400 /* libsensors3 */
+ FILE *file;
+ const sensors_feature_data *sfd;
+
+ TRACE("enters initialize_libsensors");
+
+ errno = 0;
+ file = fopen("/etc/sensors.conf", "r");
+
+ if (errno != ENOENT) /* the file actually exists */
+ {
+ sensorsInit = sensors_init (file);
+ if (sensorsInit != 0)
+ {
+ g_printf(_("Error: Could not connect to sensors!"));
+ /* FIXME: better popup window? write to special logfile? */
+ fclose (file);
+ return -2;
+ }
+
+ num_sensorchips = 0;
+ detected_chip = sensors_get_detected_chips ( &num_sensorchips);
+
+ /* iterate over chips on mainboard */
+ while (detected_chip!=NULL)
+ {
+ chip = setup_chip (chips, detected_chip, num_sensorchips);
+
+ nr1 = 0;
+ nr2 = 0;
+ /* iterate over chip features, i.e. id, cpu temp, mb temp... */
+ /* numchips = get_number_chip_features (detected_chip); */
+ sfd = sensors_get_all_features (*detected_chip, &nr1, &nr2);
+ while (sfd != NULL)
+ {
+ chipfeature = find_chipfeature (detected_chip, chip, sfd->number);
+ if (chipfeature!=NULL) {
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ }
+ sfd = sensors_get_all_features (*detected_chip, &nr1, &nr2);
+ }
+
+ detected_chip = sensors_get_detected_chips (&num_sensorchips);
+ } /* end while sensor chipNames */
+
+ fclose (file);
+ TRACE ("leaves initialize_libsensors with 1");
+ return 1;
+ }
+ else {
+ fclose (file);
+ TRACE ("leaves initialize_libsensors with -1");
+ return -1;
+ }
+#else
+ const sensors_feature *sfd;
+ TRACE("enters initialize_libsensors");
+
+ sensorsInit = sensors_init (NULL);
+ if (sensorsInit != 0)
+ {
+ g_printf(_("Error: Could not connect to sensors!"));
+ /* FIXME: better popup window? write to special logfile? */
+ return -2;
+ }
+
+ num_sensorchips = 0;
+ detected_chip = sensors_get_detected_chips (NULL, &num_sensorchips);
+ /* iterate over chips on mainboard */
+ while (detected_chip!=NULL)
+ {
+ chip = setup_chip (chips, detected_chip, num_sensorchips);
+
+ nr1 = 0;
+ nr2 = 0;
+ /* iterate over chip features, i.e. id, cpu temp, mb temp... */
+ /* numchips = get_number_chip_features (detected_chip); */
+ sfd = sensors_get_features (detected_chip, &nr1);
+ while (sfd != NULL)
+ {
+ chipfeature = find_chipfeature (detected_chip, chip, sfd);
+ if (chipfeature!=NULL) {
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ }
+ sfd = sensors_get_features (detected_chip, &nr1);
+ }
+
+ detected_chip = sensors_get_detected_chips (NULL, &num_sensorchips);
+ } /* end while sensor chipNames */
+
+ TRACE ("leaves initialize_libsensors with 1");
+ return 1;
+#endif
+}
+
+void
+refresh_lmsensors (gpointer chip_feature, gpointer data)
+{
+ t_chipfeature *cf;
+
+ TRACE ("leaves refresh_lmsensors");
+
+ g_assert(chip_feature!=NULL);
+
+ cf = (t_chipfeature *) chip_feature;
+
+ TRACE ("leaves refresh_lmsensors");
+}
+
+void
+free_lmsensors_chip (gpointer chip)
+{
+ t_chip *c;
+
+ c = (t_chip *) chip;
+
+ g_free (c->name);
+ g_free (c->chip_name->prefix);
+
+ #if SENSORS_API_VERSION < 0x400
+ g_free (c->chip_name->busname);
+ #endif
+
+}
Property changes on: xfce4-sensors-plugin/trunk/lib/lmsensors.c
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: xfce4-sensors-plugin/trunk/lib/middlelayer.c (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c)
===================================================================
--- xfce4-sensors-plugin/trunk/lib/middlelayer.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/middlelayer.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,247 @@
+/*
+ * middlelayer.c
+ *
+ * Copyright 2006, 2007 Fabian Nowak <timytery at arcor.de>
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/* #ifdef HAVE_CONFIG_H */
+ #include <config.h>
+/* #endif */
+
+
+#ifdef HAVE_LINUX
+#include <sys/utsname.h>
+#endif
+
+#include <glib/gdir.h>
+#include <glib/gerror.h>
+#include <glib/gmem.h>
+#include <glib/gmessages.h>
+#include <glib/gprintf.h>
+
+#include <string.h>
+
+#include <middlelayer.h>
+
+#ifdef HAVE_LIBSENSORS
+ #include <lmsensors.h>
+#endif
+#ifdef HAVE_HDDTEMP
+ #include <hddtemp.h>
+#endif
+#ifdef HAVE_ACPI
+ #include <acpi.h>
+#endif
+
+int
+initialize_all (GPtrArray **chips, gboolean *suppressmessage)
+{
+ int res = 0;
+
+ TRACE ("enters initialize_all");
+
+ *chips = g_ptr_array_new();
+
+ #ifdef HAVE_LIBSENSORS
+ res += initialize_libsensors (*chips);
+ #endif
+
+ #ifdef HAVE_HDDTEMP
+ res += initialize_hddtemp (*chips, suppressmessage);
+ #endif
+
+ #ifdef HAVE_ACPI
+ res += initialize_ACPI (*chips);
+ #endif
+
+ TRACE ("leaves initialize_all, chips->len=%d", (*chips)->len);
+
+ return res;
+}
+
+
+void
+refresh_chip (gpointer chip, gpointer data)
+{
+ t_chip *c;
+
+ g_assert (chip!=NULL);
+
+ TRACE ("enters refresh_chip");
+
+ c = (t_chip*) chip;
+
+ #ifdef HAVE_ACPI
+ if (c->type==ACPI) {
+ g_ptr_array_foreach (c->chip_features, refresh_acpi, NULL );
+ return;
+ }
+ #endif
+
+ #ifdef HAVE_LIBSENSORS
+ if (c->type==LMSENSOR) {
+ g_ptr_array_foreach (c->chip_features, refresh_lmsensors, NULL );
+ return;
+ }
+ #endif
+
+ #ifdef HAVE_HDDTEMP
+ if (c->type==HDD) {
+ g_ptr_array_foreach (c->chip_features, refresh_hddtemp, NULL );
+ return;
+ }
+ #endif
+
+ TRACE ("leaves refresh_chip");
+}
+
+
+void
+refresh_all_chips (GPtrArray *chips )
+{
+ TRACE ("enters refresh_all_chips");
+
+ g_ptr_array_foreach (chips, refresh_chip, NULL );
+
+ TRACE ("leaves refresh_all_chips");
+}
+
+
+void
+categorize_sensor_type (t_chipfeature* chipfeature)
+{
+ TRACE ("enters categorize_sensor_type");
+
+ if ( strstr(chipfeature->name, "Temp")!=NULL
+ || strstr(chipfeature->name, "temp")!=NULL ) {
+ chipfeature->class = TEMPERATURE;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 80.0;
+ } else if ( strstr(chipfeature->name, "VCore")!=NULL
+ || strstr(chipfeature->name, "3V")!=NULL
+ || strstr(chipfeature->name, "5V")!=NULL
+ || strstr(chipfeature->name, "12V")!=NULL ) {
+ chipfeature->class = VOLTAGE;
+ chipfeature->min_value = 1.0;
+ chipfeature->max_value = 12.2;
+ } else if ( strstr(chipfeature->name, "Fan")!=NULL
+ || strstr(chipfeature->name, "fan")!=NULL ) {
+ chipfeature->class = SPEED;
+ chipfeature->min_value = 1000.0;
+ chipfeature->max_value = 3500.0;
+ } else if ( strstr(chipfeature->name, "alarm")!=NULL
+ || strstr(chipfeature->name, "Alarm")!=NULL ) {
+ chipfeature->class = STATE;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 1.0;
+ } else {
+ chipfeature->class = OTHER;
+ chipfeature->min_value = 0.0;
+ chipfeature->max_value = 7000.0;
+ }
+
+ TRACE ("leaves categorize_sensor_type");
+}
+
+
+int
+sensor_get_value (t_chip *chip, int number, double *value)
+{
+ t_chipfeature *feature;
+ /* TRACE ("enters sensor_get_value %d", number); */
+
+ g_assert (chip!=NULL);
+
+ if (chip->type==LMSENSOR ) {
+ #ifdef HAVE_LIBSENSORS
+ return sensors_get_feature_wrapper (chip->chip_name, number, value);
+ #else
+ return -1;
+ #endif
+ }
+ if (chip->type==HDD ) {
+ #ifdef HAVE_HDDTEMP
+ g_assert (number<chip->num_features);
+ feature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, number);
+ g_assert (feature!=NULL);
+ *value = get_hddtemp_value (feature->devicename, NULL);
+ if (*value==ZERO_KELVIN) {
+ return NO_VALID_HDDTEMP;
+ }
+ return 0;
+ #else
+ return -1;
+ #endif
+ }
+ if (chip->type==ACPI ) {
+ #ifdef HAVE_ACPI
+ g_assert (number<chip->num_features);
+ feature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, number);
+ g_assert (feature!=NULL);
+ refresh_acpi ((gpointer) feature, NULL);
+ *value = feature->raw_value;
+ return 0; /* HERE I AM, I WANNA BE FIXED */
+ #else
+ return -1;
+ #endif
+ }
+ else {
+ feature = NULL;
+ return -1;
+ }
+}
+
+
+void
+free_chipfeature (gpointer chipfeature, gpointer data)
+{
+ t_chipfeature *cf;
+ cf = (t_chipfeature *) chipfeature;
+
+ g_free (cf->name);
+ g_free (cf->devicename);
+ g_free (cf->formatted_value);
+ g_free (cf->color);
+}
+
+
+void
+free_chip (gpointer chip, gpointer data)
+{
+ t_chip *c;
+ c = (t_chip *) chip;
+
+ g_free (c->sensorId);
+ g_free (c->description);
+ #ifdef HAVE_LIBSENSORS
+ if (c->type==LMSENSOR) {
+ free_lmsensors_chip (chip);
+ }
+ #endif
+ /* g_free (c->chip_name); */ /* is a _copied_ structure of libsensors */
+ g_ptr_array_foreach (c->chip_features, free_chipfeature, NULL);
+ g_ptr_array_free (c->chip_features, TRUE);
+}
+
+
+void
+sensor_interface_cleanup()
+{
+ #ifdef HAVE_LIBSENSORS
+ sensors_cleanup();
+ #endif
+}
Property changes on: xfce4-sensors-plugin/trunk/lib/middlelayer.c
___________________________________________________________________
Name: svn:mergeinfo
+
Added: xfce4-sensors-plugin/trunk/lib/sensors-interface-common.c
===================================================================
--- xfce4-sensors-plugin/trunk/lib/sensors-interface-common.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/sensors-interface-common.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,97 @@
+/* Copyright 2004-2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+/* Xfce includes */
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+/* Local/package includes */
+#include "sensors-interface-common.h"
+
+t_sensors * sensors_new (XfcePanelPlugin *plugin)
+{
+ t_sensors *sensors;
+ gint result;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters sensors_new");
+
+ sensors = g_new (t_sensors, 1);
+
+ /* init xfce sensors stuff width default values */
+ sensors_init_default_values (sensors, plugin);
+
+ /* get suppressmessages */
+ sensors_read_preliminary_config(plugin, sensors);
+
+ /* read all sensors from libraries */
+ result = initialize_all (&(sensors->chips), &(sensors->suppressmessage));
+
+ sensors->num_sensorchips = sensors->chips->len;
+
+ /* error handling for no sensors */
+ if (!sensors->chips || sensors->num_sensorchips <= 0) {
+ if (!sensors->chips)
+ sensors->chips = g_ptr_array_new ();
+
+ chip = g_new ( t_chip, 1);
+ g_ptr_array_add (sensors->chips, chip);
+ chip->chip_features = g_ptr_array_new();
+ chipfeature = g_new (t_chipfeature, 1);
+
+ chipfeature->address = 0;
+ chip->sensorId = g_strdup(_("No sensors found!"));
+ chip->num_features = 1;
+ chipfeature->color = g_strdup("#000000");
+ g_free (chipfeature->name);
+ chipfeature->name = g_strdup("No sensor");
+ chipfeature->valid = TRUE;
+ g_free (chipfeature->formatted_value);
+ chipfeature->formatted_value = g_strdup("0.0");
+ chipfeature->raw_value = 0.0;
+ chipfeature->min_value = 0;
+ chipfeature->max_value = 7000;
+ chipfeature->show = FALSE;
+
+ g_ptr_array_add (chip->chip_features, chipfeature);
+ }
+
+
+ /* Add tooltip to show extended current sensors status */
+ sensors_create_tooltip ((gpointer) sensors);
+
+ /* fill panel widget with boxes, strings, values, ... */
+ create_panel_widget (sensors);
+
+ /* finally add panel "sensors" to eventbox */
+ gtk_container_add (GTK_CONTAINER (sensors->eventbox),
+ sensors->widget_sensors);
+
+
+ /* #if GTK_VERSION >= 2.11
+ * g_signal_connect(G_OBJECT(sensors->eventbox),
+ "query-tooltip",
+ G_CALLBACK(handle_tooltip_query),
+ (gpointer) sensors); */
+
+
+ TRACE ("leaves sensors_new");
+
+ return sensors;
+}
Added: xfce4-sensors-plugin/trunk/lib/sensors-interface-common.h
===================================================================
Added: xfce4-sensors-plugin/trunk/lib/sensors-interface.c
===================================================================
--- xfce4-sensors-plugin/trunk/lib/sensors-interface.c (rev 0)
+++ xfce4-sensors-plugin/trunk/lib/sensors-interface.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,122 @@
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+/* Definitions */
+
+/* Global includes */
+/* #include <stdlib.h> */
+
+/* Glib/Gtk includes */
+#include <glib/gtree.h>
+#include <gtk/gtk.h>
+
+/* Xfce includes */
+#include <libxfcegui4/libxfcegui4.h>
+
+/* Package includes */
+#include <sensors-interface-common.h>
+#include <sensors-interface.h>
+
+
+void
+add_sensors_frame (GtkWidget * notebook, t_sensors_dialog * sd)
+{
+ GtkWidget *_vbox, *_label;
+
+ TRACE ("enters add_sensors_frame");
+
+ _vbox = gtk_vbox_new (FALSE, 4);
+ gtk_container_set_border_width (GTK_CONTAINER(_vbox), 4);
+ gtk_widget_show (_vbox);
+
+ _label = gtk_label_new_with_mnemonic(_("_Sensors"));
+ gtk_widget_show (_label);
+
+ gtk_container_set_border_width (GTK_CONTAINER (_vbox), BORDER<<1);
+
+ gtk_notebook_append_page (GTK_NOTEBOOK(notebook), _vbox, _label);
+
+ add_type_box (_vbox, sd);
+
+ add_sensor_settings_box (_vbox, sd);
+
+ add_temperature_unit_box (_vbox, sd);
+
+ TRACE ("leaves add_sensors_frame");
+}
+
+void
+init_widgets (t_sensors_dialog *sd)
+{
+ int chipindex;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ GtkTreeIter *iter;
+ t_sensors *sensors;
+ GtkTreeStore *model;
+
+ TRACE ("enters init_widgets");
+
+ sensors = sd->sensors;
+
+ for (chipindex=0; chipindex < sensors->num_sensorchips; chipindex++) {
+ sd->myListStore[chipindex] = gtk_tree_store_new (6, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING,
+ G_TYPE_FLOAT, G_TYPE_FLOAT);
+
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, chipindex);
+ gtk_combo_box_append_text ( GTK_COMBO_BOX(sd->myComboBox),
+ chip->sensorId );
+ model = GTK_TREE_STORE (sd->myListStore[chipindex]);
+
+ fill_gtkTreeStore (model, chip, sensors->scale);
+ }
+
+ if(sd->sensors->num_sensorchips == 0) {
+ chip = (t_chip *) g_ptr_array_index(sensors->chips, 0);
+ g_assert (chip!=NULL);
+ gtk_combo_box_append_text ( GTK_COMBO_BOX(sd->myComboBox),
+ chip->sensorId );
+ sd->myListStore[0] = gtk_tree_store_new (6, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_BOOLEAN,
+ G_TYPE_STRING, G_TYPE_DOUBLE,
+ G_TYPE_DOUBLE);
+ chipfeature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, 0);
+ g_assert (chipfeature!=NULL);
+
+ g_free(chipfeature->formatted_value);
+ chipfeature->formatted_value = g_strdup ("0.0");
+ chipfeature->raw_value = 0.0;
+
+ iter = g_new0 (GtkTreeIter, 1);
+ gtk_tree_store_append ( GTK_TREE_STORE (sd->myListStore[0]),
+ iter, NULL);
+ gtk_tree_store_set ( GTK_TREE_STORE (sd->myListStore[0]),
+ iter,
+ 0, chipfeature->name,
+ 1, "0.0", /* chipfeature->formatted_value */
+ 2, False, /* chipfeature->show */
+ 3, "#000000", /* chipfeature->color */
+ 3, "#000000", /* chipfeature->color */
+ 4, 0.0, /* chipfeature->min_value */
+ 5, 0.0, /* chipfeature->max_value */
+ -1);
+ }
+ TRACE ("leaves init_widgets");
+}
Added: xfce4-sensors-plugin/trunk/lib/sensors-interface.h
===================================================================
Modified: xfce4-sensors-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/Makefile.am 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/panel-plugin/Makefile.am 2008-10-05 17:32:34 UTC (rev 5516)
@@ -1,48 +1,36 @@
plugindir = $(libexecdir)/xfce4/panel-plugins
plugin_PROGRAMS = xfce4-sensors-plugin
-# LIBS = @LIBS@ @SOLLIBS@
+INCLUDES = \
+ -I$(top_builddir)/include \
+ -I$(top_builddir)/lib
-if HAVE_LIBSENSORS
-SENSORS_SOURCES = lmsensors.c lmsensors.h
-endif
+# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
+# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
-if HAVE_HDDTEMP
-HDDTEMP_SOURCES = hddtemp.c hddtemp.h
-endif
-
-if HAVE_ACPI
-ACPI_SOURCES = acpi.c acpi.h
-endif
-
-
xfce4_sensors_plugin_SOURCES = \
- middlelayer.c \
- middlelayer.h \
- $(SENSORS_SOURCES) \
- $(HDDTEMP_SOURCES) \
- $(ACPI_SOURCES) \
configuration.c \
- configuration.h \
- sensors.c \
- sensors.h \
- types.h
+ sensors-plugin.c
+# types.h
+# middlelayer.c \
+# middlelayer.h
+
xfce4_sensors_plugin_CFLAGS = \
+ @GTK_CFLAGS@ \
+ @GLIB_CFLAGS@ \
@LIBXFCE4PANEL_CFLAGS@ \
@PLATFORM_CFLAGS@ \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
@LIBSENSORS_CFLAGS@
xfce4_sensors_plugin_LDFLAGS = \
+ @GTK_LIBS@ \
+ @GLIB_LIBS@ \
@LIBXFCE4PANEL_LIBS@ \
@SOLLIBS@ \
@LIBSENSORS_LDFLAGS@
-# INCLUDES = \
-# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
-# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
-
# .desktop file
#
# Some automake trickery here. Because we cannot use $(libexecdir) in the
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/acpi.c
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/acpi.h
Modified: xfce4-sensors-plugin/trunk/panel-plugin/configuration.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/configuration.c 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/panel-plugin/configuration.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -227,6 +227,9 @@
TRACE ("enters sensors_read_preliminary_config");
+ if (plugin==NULL)
+ return;
+
if (!(file = xfce_panel_plugin_lookup_rc_file (plugin)))
return;
Modified: xfce4-sensors-plugin/trunk/panel-plugin/configuration.h
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/configuration.h 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/panel-plugin/configuration.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -23,7 +23,7 @@
#define XFCE4_SENSORS_CONFIGURATION_H
-#include "sensors.h"
+#include "sensors-plugin.h"
gint get_Id_from_address (gint chipnumber, gint addr, t_sensors *sensors);
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h
Copied: xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c (from rev 5494, xfce4-sensors-plugin/trunk/panel-plugin/sensors.c)
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,2211 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* This plugin requires libsensors-3 and its headers in order to monitor
+ * ordinary mainboard sensors!
+ *
+ * It also works with solely ACPI or hddtemp, but then with more limited
+ * functionality.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+
+#include "sensors-plugin.h"
+#include "configuration.h"
+
+#include <math.h>
+#include <stdlib.h>
+
+
+/*
+ * Tooltips to display for any part of this plugin
+ */
+static GtkTooltips *tooltips = NULL;
+
+
+static void
+sensors_set_bar_size (GtkWidget *bar, int size, int orientation)
+{
+ //TRACE ("enters sensors_set_bar_size");
+
+ /* check arguments */
+ g_return_if_fail (G_IS_OBJECT(bar));
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ gtk_widget_set_size_request (bar, BORDER, size-BORDER);
+ } else {
+ gtk_widget_set_size_request (bar, size-BORDER, BORDER);
+ }
+
+ //TRACE ("leaves sensors_set_bar_size");
+}
+
+
+static void
+sensors_set_bar_color (GtkWidget *bar, double fraction, gchar* user_bar_color,
+ t_sensors *sensors)
+{
+ GdkColor color;
+
+ //TRACE ("enters sensors_set_bar_color");
+
+ g_return_if_fail (G_IS_OBJECT(bar));
+
+ if (fraction >= 1 || fraction<=0)
+ gdk_color_parse(COLOR_ERROR, &color);
+
+ else if ((fraction < .2) || (fraction > .8))
+ gdk_color_parse(COLOR_WARN, &color);
+
+ else {
+ if (sensors->show_colored_bars)
+ gdk_color_parse(user_bar_color, &color);
+ else
+ gdk_color_parse(COLOR_NORMAL, &color);
+ }
+
+ gtk_widget_modify_bg (bar, GTK_STATE_PRELIGHT, &color);
+ gtk_widget_modify_bg (bar, GTK_STATE_SELECTED, &color);
+ gtk_widget_modify_base (bar, GTK_STATE_SELECTED, &color);
+
+ //TRACE ("leaves sensors_set_bar_color");
+}
+
+static double
+sensors_get_percentage (t_chipfeature *chipfeature)
+{
+ double value, min, max, percentage;
+
+ //TRACE ("enters sensors_get_percentage");
+
+ value = chipfeature->raw_value;
+ min = chipfeature->min_value;
+ max = chipfeature->max_value;
+ percentage = (value - min) / (max - min);
+
+ if (percentage > 1.0)
+ percentage = 1.0;
+
+ else if (percentage <= 0.0)
+ percentage = 0.0;
+
+ //TRACE ("leaves sensors_get_percentage with %f", percentage);
+ return percentage;
+}
+
+
+static void
+sensors_remove_graphical_panel (t_sensors *sensors)
+{
+ int chipNum, feature;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ t_barpanel *panel;
+
+ TRACE ("enters sensors_remove_graphical_panel");
+
+ for (chipNum=0; chipNum < sensors->num_sensorchips; chipNum++) {
+ chip = (t_chip *) g_ptr_array_index(sensors->chips, chipNum);
+ g_assert (chip != NULL);
+
+ for (feature=0; feature<chip->num_features; feature++) {
+ chipfeature = g_ptr_array_index(chip->chip_features, feature);
+ g_assert (chipfeature != NULL);
+
+ if (chipfeature->show == TRUE) {
+ panel = (t_barpanel*) sensors->panels[chipNum][feature];
+
+ if (sensors->show_labels == TRUE)
+ gtk_widget_destroy (panel->label);
+
+ gtk_widget_destroy (panel->progressbar);
+ gtk_widget_destroy (panel->databox);
+
+ g_free (panel);
+ }
+ }
+ }
+ sensors->bars_created = FALSE;
+ gtk_widget_hide (sensors->panel_label_text);
+
+ TRACE ("leaves sensors_remove_graphical_panel");
+}
+
+
+static void
+sensors_update_graphical_panel (t_sensors *sensors)
+{
+ int chipNum, feature;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ t_barpanel *panel;
+ double fraction;
+ GtkWidget *bar;
+
+ //TRACE("enters sensors_update_graphical_panel");
+
+ for (chipNum=0; chipNum < sensors->num_sensorchips; chipNum++) {
+ chip = (t_chip *) g_ptr_array_index(sensors->chips, chipNum);
+ g_assert (chip != NULL);
+
+ for (feature=0; feature<chip->num_features; feature++) {
+ chipfeature = g_ptr_array_index(chip->chip_features, feature);
+ g_assert (chipfeature != NULL);
+
+ if (chipfeature->show == TRUE) {
+ panel = (t_barpanel*) sensors->panels[chipNum][feature];
+
+ bar = panel->progressbar;
+ g_return_if_fail (G_IS_OBJECT(bar));
+
+ sensors_set_bar_size (bar, (int) sensors->panel_size,
+ sensors->orientation);
+ fraction = sensors_get_percentage (chipfeature);
+ sensors_set_bar_color (bar, fraction, chipfeature->color,
+ sensors);
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar),
+ fraction);
+ }
+ }
+ }
+
+ //TRACE("leaves sensors_update_graphical_panel");
+}
+
+
+static void
+sensors_add_graphical_display (t_sensors *sensors)
+{
+ int chipNum, feature;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ t_barpanel *panel;
+ gboolean has_bars = FALSE;
+ GtkWidget *progbar, *databox, *label;
+ gchar *caption, *text;
+
+ TRACE ("enters sensors_add_graphical_display");
+
+ text = g_strdup (_("<span foreground=\"#000000\">"
+ "<b>Sensors</b></span>"));
+ gtk_label_set_markup (GTK_LABEL(sensors->panel_label_text), text);
+ g_free (text);
+
+ for (chipNum=0; chipNum < sensors->num_sensorchips; chipNum++) {
+ chip = (t_chip *) g_ptr_array_index(sensors->chips, chipNum);
+ g_assert (chip != NULL);
+
+ for (feature=0; feature<chip->num_features; feature++) {
+ chipfeature = g_ptr_array_index (chip->chip_features, feature);
+ g_assert (chipfeature != NULL);
+
+ if (chipfeature->show == TRUE) {
+ has_bars = TRUE;
+
+ progbar = gtk_progress_bar_new();
+
+ if (sensors->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_progress_bar_set_orientation (
+ GTK_PROGRESS_BAR (progbar),
+ GTK_PROGRESS_BOTTOM_TO_TOP);
+ else
+ gtk_progress_bar_set_orientation (
+ GTK_PROGRESS_BAR (progbar),
+ GTK_PROGRESS_LEFT_TO_RIGHT);
+
+ sensors_set_bar_size (progbar, (int) sensors->panel_size,
+ sensors->orientation);
+ gtk_widget_show (progbar);
+
+ if (sensors->orientation == GTK_ORIENTATION_HORIZONTAL)
+ databox = gtk_hbox_new (FALSE, 0);
+
+ else
+ databox = gtk_vbox_new (FALSE, 0);
+
+ gtk_widget_show (databox);
+
+ /* save the panel elements */
+ panel = g_new (t_barpanel, 1);
+ panel->progressbar = progbar;
+
+ /* create the label stuff only if needed - saves some memory! */
+ if (sensors->show_labels == TRUE) {
+ caption = g_strdup (chipfeature->name);
+ label = gtk_label_new (caption);
+ g_free(caption);
+ gtk_label_set_max_width_chars (GTK_LABEL(label), 12);
+ gtk_label_set_ellipsize (GTK_LABEL(label),
+ PANGO_ELLIPSIZE_END);
+ gtk_widget_show (label);
+ panel->label = label;
+
+ gtk_box_pack_start (GTK_BOX(databox), label, FALSE, FALSE, INNER_BORDER);
+ }
+ else
+ panel->label = NULL;
+
+ gtk_box_pack_start (GTK_BOX(databox), progbar, FALSE, FALSE, 0);
+
+ panel->databox = databox;
+ sensors->panels[chipNum][feature] = (GtkWidget*) panel;
+
+ gtk_container_set_border_width (GTK_CONTAINER(sensors->widget_sensors), 0);
+ gtk_box_pack_start (GTK_BOX (sensors->widget_sensors),
+ databox, FALSE, FALSE, INNER_BORDER);
+ }
+ }
+ }
+ if (has_bars && !sensors->show_title)
+ gtk_widget_hide (sensors->panel_label_text);
+ else
+ gtk_widget_show (sensors->panel_label_text);
+
+ gtk_widget_hide (sensors->panel_label_data);
+
+ sensors->bars_created = TRUE;
+ sensors_update_graphical_panel (sensors);
+
+ TRACE ("leaves sensors_add_graphical_display");
+}
+
+
+static gboolean
+sensors_show_graphical_display (t_sensors *sensors)
+{
+ TRACE ("enters sensors_show_graphical_display");
+
+ if (sensors->bars_created == TRUE)
+ sensors_update_graphical_panel (sensors);
+ else
+ sensors_add_graphical_display (sensors);
+
+ TRACE ("leaves sensors_show_graphical_display");
+
+ return TRUE;
+}
+
+
+static int
+determine_number_of_rows (t_sensors *sensors)
+{
+ gint numRows, gtk_font_size, additional_offset, avail_height;
+ gdouble divisor;
+ GtkStyle *style;
+ PangoFontDescription *descr;
+ PangoFontMask mask;
+ gboolean is_absolute;
+
+ TRACE ("enters determine_number_of_rows");
+
+ style = gtk_widget_get_style (sensors->panel_label_data);
+
+ descr = style->font_desc; /* Note that stupid GTK guys forgot the 'r' */
+
+ is_absolute = FALSE;
+ mask = pango_font_description_get_set_fields (descr);
+ if (mask>=PANGO_FONT_MASK_SIZE) {
+ is_absolute = pango_font_description_get_size_is_absolute (descr);
+ if (!is_absolute) {
+ gtk_font_size = pango_font_description_get_size (descr) / 1000;
+ }
+ }
+
+ if (mask<PANGO_FONT_MASK_SIZE || is_absolute) {
+ gtk_font_size = 10; /* not many people will want a bigger font size,
+ and so only few rows are gonna be displayed. */
+ }
+
+ g_assert (gtk_font_size!=0);
+
+ if (sensors->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ switch (gtk_font_size) {
+ case 8:
+ switch (sensors->font_size_numerical) {
+ case 0: additional_offset=10; divisor = 12; break;
+ case 1: additional_offset=11; divisor = 12; break;
+ case 2: additional_offset=12; divisor = 12; break;
+ case 3: additional_offset=13; divisor = 13; break;
+ default: additional_offset=16; divisor = 17;
+ }
+ break;
+
+ case 9:
+ switch (sensors->font_size_numerical) {
+ case 0: additional_offset=12; divisor = 13; break;
+ case 1: additional_offset=13; divisor = 13; break;
+ case 2: additional_offset=14; divisor = 14; break;
+ case 3: additional_offset=14; divisor = 17; break;
+ default: additional_offset=16; divisor = 20;
+ }
+ break;
+
+ default: /* case 10 */
+ switch (sensors->font_size_numerical) {
+ case 0: additional_offset=13; divisor = 14; break;
+ case 1: additional_offset=14; divisor = 14; break;
+ case 2: additional_offset=14; divisor = 14; break;
+ case 3: additional_offset=16; divisor = 17; break;
+ default: additional_offset=20; divisor = 20;
+ }
+ }
+ avail_height = sensors->panel_size - additional_offset;
+ if (avail_height < 0)
+ avail_height = 0;
+
+ numRows = (int) floor (avail_height / divisor);
+ if (numRows < 0)
+ numRows = 0;
+
+ numRows++;
+ }
+ else numRows = 1 << 30; /* that's enough, MAXINT would be nicer */
+
+ /* fail-safe */
+ if (numRows<=0)
+ numRows = 1;
+
+ TRACE ("leaves determine_number_of_rows with rows=%d", numRows);
+
+ return numRows;
+}
+
+
+static int
+determine_number_of_cols (gint numRows, gint itemsToDisplay)
+{
+ gint numCols;
+
+ TRACE ("enters determine_number_of_cols");
+
+ if (numRows > 1) {
+ if (itemsToDisplay > numRows)
+ numCols = (gint) ceil (itemsToDisplay/ (float)numRows);
+ else
+ numCols = (gint) 1;
+ }
+ else
+ numCols = itemsToDisplay;
+
+ TRACE ("leaves determine_number_of_cols width cols=%d", numCols);
+
+ return numCols;
+}
+
+
+static void
+sensors_set_text_panel_label (t_sensors *sensors, gint numCols, gint itemsToDisplay)
+{
+ gint currentColumn, chipNum, feature;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ gchar *myLabelText, *tmpstring;
+
+ TRACE ("enters sensors_set_text_panel_label");
+
+ if (itemsToDisplay==0) {
+ gtk_widget_hide (sensors->panel_label_data);
+ return;
+ }
+
+ currentColumn = 0;
+ myLabelText = g_strdup (""); /* don't use NULL because of g_strconcat */
+
+ for (chipNum=0; chipNum < sensors->num_sensorchips; chipNum++) {
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, chipNum);
+ g_assert (chip != NULL);
+
+ for (feature=0; feature<chip->num_features; feature++) {
+ chipfeature = g_ptr_array_index (chip->chip_features, feature);
+ g_assert (chipfeature != NULL);
+
+ if (chipfeature->show == TRUE) {
+ if (sensors->show_units) {
+ tmpstring = g_strconcat (myLabelText,
+ "<span foreground=\"",
+ chipfeature->color, "\" size=\"",
+ sensors->font_size, "\">",
+ chipfeature->formatted_value,
+ "</span>", NULL);
+ }
+ else {
+ tmpstring = g_strdup_printf("%s<span foreground=\"%s\" size=\"%s\">%.1f</span>", myLabelText,
+ chipfeature->color, sensors->font_size,
+ chipfeature->raw_value);
+ myLabelText = g_strconcat (myLabelText, tmpstring, NULL);
+ }
+
+ g_free (myLabelText);
+
+ myLabelText = tmpstring;
+
+ if (currentColumn < numCols-1) {
+ if (sensors->show_smallspacings)
+ myLabelText = g_strconcat (myLabelText, " ", NULL);
+ else
+ myLabelText = g_strconcat (myLabelText, " \t", NULL);
+ currentColumn++;
+ }
+ else if (itemsToDisplay > 1) { /* do NOT add \n if last item */
+ myLabelText = g_strconcat (myLabelText, " \n", NULL);
+ currentColumn = 0;
+ }
+ itemsToDisplay--;
+ }
+ }
+ }
+
+ g_assert (itemsToDisplay==0);
+
+ gtk_label_set_markup (GTK_LABEL(sensors->panel_label_data), myLabelText);
+ /* if (sensors->show_units) */
+ g_free(myLabelText);
+ /* else: with sprintf, we cannot free the string. how bad. */
+
+ gtk_misc_set_alignment(GTK_MISC(sensors->panel_label_data), 0.0, 0.5);
+ gtk_widget_show (sensors->panel_label_data);
+
+ TRACE ("leaves sensors_set_text_panel_label");
+}
+
+
+static int
+count_number_checked_sensor_features (t_sensors *sensors)
+{
+ gint chipNum, feature, itemsToDisplay;
+ t_chipfeature *chipfeature;
+ t_chip *chip;
+
+ TRACE ("enters count_number_checked_sensor_features");
+
+ itemsToDisplay = 0;
+
+
+ for (chipNum=0; chipNum < sensors->num_sensorchips; chipNum++) {
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, chipNum);
+ g_assert (chip!=NULL);
+
+ for (feature=0; feature<chip->num_features; /* none */ ) {
+ chipfeature = g_ptr_array_index (chip->chip_features, feature);
+ g_assert (chipfeature!=NULL);
+
+ if (chipfeature->show == TRUE)
+ itemsToDisplay++;
+
+ if (chipfeature->valid == TRUE)
+ feature++;
+ }
+ }
+
+ TRACE ("leaves count_number_checked_sensor_features with %d", itemsToDisplay);
+
+ return itemsToDisplay;
+}
+
+/* draw label with sensor values into panel's vbox */
+static gboolean
+sensors_show_text_display (t_sensors *sensors)
+{
+ gint itemsToDisplay, numRows, numCols;
+
+ TRACE ("enters sensors_show_text_display");
+
+ /* count number of checked sensors to display.
+ this could also be done by every toggle/untoggle action
+ by putting this variable into t_sensors */
+ itemsToDisplay = count_number_checked_sensor_features (sensors);
+
+ numRows = determine_number_of_rows (sensors);
+
+ if (sensors->show_title == TRUE || itemsToDisplay==0)
+ gtk_widget_show (sensors->panel_label_text);
+ else
+ gtk_widget_hide (sensors->panel_label_text);
+
+ numCols = determine_number_of_cols (numRows, itemsToDisplay);
+
+ sensors_set_text_panel_label (sensors, numCols, itemsToDisplay);
+
+ TRACE ("leaves sensors_show_text_display\n");
+
+ return TRUE;
+}
+
+
+static void
+format_sensor_value (t_tempscale scale, t_chipfeature *chipfeature,
+ double sensorFeature, gchar **help)
+{
+ /* TRACE ("enters format_sensor_value"); */
+
+ switch (chipfeature->class) {
+ case TEMPERATURE:
+ if (scale == FAHRENHEIT) {
+ *help = g_strdup_printf(_("%5.1f °F"),
+ (float) (sensorFeature * 9/5 + 32) );
+ } else { /* Celsius */
+ *help = g_strdup_printf(_("%5.1f °C"), sensorFeature);
+ }
+ break;
+
+ case VOLTAGE:
+ *help = g_strdup_printf(_("%+5.2f V"), sensorFeature);
+ break;
+
+ case ENERGY:
+ *help = g_strdup_printf(_("%.0f mWh"), sensorFeature);
+ break;
+
+ case STATE:
+ if (sensorFeature==0.0)
+ *help = g_strdup (_("off"));
+ else
+ *help = g_strdup (_("on"));
+ break;
+
+ case SPEED:
+ *help = g_strdup_printf(_("%5.0f rpm"), sensorFeature);
+ break;
+
+ default:
+ *help = g_strdup_printf("%+5.2f", sensorFeature);
+ break;
+ } /* end switch */
+
+ /* TRACE ("leaves format_sensor_value"); */
+}
+
+
+/* create tooltip
+Updates the sensor values, see lines 440 and following */
+static gboolean
+sensors_create_tooltip (gpointer data)
+{
+ TRACE ("enters sensors_create_tooltip");
+
+ t_sensors *sensors;
+ GtkWidget *widget;
+ int i, index_feature, res;
+ double sensorFeature;
+ gboolean first, prependedChipName;
+ gchar *myToolTipText, *myToolTipText2, *tmp;
+ t_chipfeature *chipfeature;
+ t_chip *chip;
+
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ sensors = (t_sensors *) data;
+ widget = sensors->eventbox;
+ myToolTipText = g_strdup (_("No sensors selected!"));
+ first = TRUE;
+
+ for (i=0; i < sensors->num_sensorchips; i++) {
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, i);
+ g_assert (chip!=NULL);
+
+ prependedChipName = FALSE;
+
+ for (index_feature = 0; index_feature<chip->num_features; index_feature++) {
+ chipfeature = g_ptr_array_index (chip->chip_features, index_feature);
+ g_assert (chipfeature!=NULL);
+
+ if ( chipfeature->valid == TRUE && chipfeature->show == TRUE ) {
+
+ if (prependedChipName != TRUE) {
+
+ if (first == TRUE) {
+ myToolTipText = g_strdup (chip->sensorId);
+ first = FALSE;
+ }
+ else {
+ myToolTipText2 = g_strconcat (myToolTipText, " \n",
+ chip->sensorId, NULL);
+ g_free (myToolTipText);
+ myToolTipText = myToolTipText2;
+ }
+
+ prependedChipName = TRUE;
+ }
+
+ res = sensor_get_value (chip, chipfeature->address,
+ &sensorFeature);
+
+ if ( res!=0 ) {
+ /* FIXME: either print nothing, or undertake appropriate action,
+ * or pop up a message box. */
+ g_printf ( _("Xfce Hardware Sensors Plugin:\n"
+ "Seems like there was a problem reading a sensor feature "
+ "value.\nProper proceeding cannot be guaranteed.\n") );
+ break;
+ }
+ tmp = g_new (gchar, 0);
+ format_sensor_value (sensors->scale, chipfeature,
+ sensorFeature, &tmp);
+
+ myToolTipText2 = g_strconcat (myToolTipText, "\n ",
+ chipfeature->name, ": ", tmp,
+ NULL);
+ g_free (myToolTipText);
+ myToolTipText = myToolTipText2;
+
+ g_free (chipfeature->formatted_value);
+ chipfeature->formatted_value = g_strdup (tmp);
+ chipfeature->raw_value = sensorFeature;
+
+ g_free (tmp);
+ } /* end if chipfeature->valid */
+ }
+ }
+
+ if (!tooltips)
+ tooltips = gtk_tooltips_new();
+
+ /* #if GTK_VERSION < 2.11 */
+ gtk_tooltips_set_tip (tooltips, GTK_WIDGET(sensors->eventbox),
+ myToolTipText, NULL);
+ g_free (myToolTipText);
+
+ TRACE ("leaves sensors_create_tooltip");
+
+ return TRUE;
+}
+
+
+static gboolean
+sensors_show_panel (gpointer data)
+{
+ t_sensors *sensors;
+ gboolean result;
+
+ TRACE ("enters sensors_show_panel");
+
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ sensors = (t_sensors *) data;
+
+ sensors_create_tooltip ((gpointer) sensors);
+
+ if (sensors->display_values_graphically == FALSE)
+ result = sensors_show_text_display (sensors);
+ else
+ result = sensors_show_graphical_display (sensors);
+
+ TRACE ("leaves sensors_show_panel\n");
+ return result;
+}
+
+
+static void
+sensors_set_orientation (XfcePanelPlugin *plugin, GtkOrientation orientation,
+ t_sensors *sensors)
+{
+ GtkWidget *newBox;
+ int i, feature;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ t_barpanel *panel;
+
+ TRACE ("enters sensors_set_orientation");
+
+ if (orientation == sensors->orientation || !sensors->display_values_graphically)
+ return;
+
+ sensors->orientation = orientation; /* now assign the new orientation */
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ newBox = gtk_hbox_new(FALSE, 0);
+ else
+ newBox = gtk_vbox_new(FALSE, 0);
+
+ gtk_widget_show (newBox);
+
+ gtk_widget_reparent (sensors->panel_label_text, newBox);
+ gtk_widget_reparent (sensors->panel_label_data, newBox);
+
+ for (i=0; i < sensors->num_sensorchips; i++) {
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, i);
+ g_assert (chip!=NULL);
+
+ for (feature = 0; feature<chip->num_features; feature++) {
+ chipfeature = g_ptr_array_index (chip->chip_features, feature);
+ g_assert (chipfeature!=NULL);
+
+ if (chipfeature->show == TRUE) {
+ panel = (t_barpanel*) sensors->panels[i][feature];
+ gtk_widget_reparent (panel->databox, newBox);
+ }
+ }
+ }
+
+ gtk_widget_destroy (sensors->widget_sensors);
+ sensors->widget_sensors = newBox;
+
+ gtk_container_add (GTK_CONTAINER (sensors->eventbox),
+ sensors->widget_sensors);
+
+ sensors_remove_graphical_panel (sensors);
+ sensors_show_panel (sensors);
+
+ TRACE ("leaves sensors_set_orientation");
+}
+
+
+/* initialize box and label to pack them together */
+static void
+create_panel_widget (t_sensors * sensors)
+{
+ gchar *myLabelText;
+ TRACE ("enters create_panel_widget");
+
+ /* initialize a new vbox widget */
+ if (sensors->orientation == GTK_ORIENTATION_HORIZONTAL)
+ sensors->widget_sensors = gtk_hbox_new (FALSE, 0);
+ else
+ sensors->widget_sensors = gtk_vbox_new (FALSE, 0);
+
+ gtk_widget_show (sensors->widget_sensors);
+
+ /* initialize value label widget */
+ sensors->panel_label_text = gtk_label_new (NULL);
+ gtk_misc_set_padding (GTK_MISC(sensors->panel_label_text), INNER_BORDER, 0);
+ gtk_misc_set_alignment(GTK_MISC(sensors->panel_label_text), 0.0, 0.5);
+
+ myLabelText = g_strdup (_("<span foreground=\"#000000\"><b>Sensors"
+ "</b></span>"));
+ gtk_label_set_markup(GTK_LABEL(sensors->panel_label_text), myLabelText);
+ gtk_widget_show (sensors->panel_label_text);
+ g_free(myLabelText);
+
+ sensors->panel_label_data = gtk_label_new (NULL);
+ gtk_widget_show (sensors->panel_label_data);
+
+ /* create 'valued' label */
+ sensors_show_panel (sensors);
+
+ /* add newly created label to box */
+ gtk_box_pack_start (GTK_BOX (sensors->widget_sensors),
+ sensors->panel_label_text, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (sensors->widget_sensors),
+ sensors->panel_label_data, TRUE, TRUE, 0);
+
+
+ TRACE ("leaves create_panel_widget");
+}
+
+
+/* double-click improvement */
+static gboolean
+execute_command (GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ t_sensors *sensors;
+
+ TRACE ("enters execute_command");
+
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ if (event->type == GDK_2BUTTON_PRESS) {
+
+ sensors = (t_sensors *) data;
+
+ g_return_val_if_fail ( sensors->exec_command, FALSE);
+
+ xfce_exec (sensors->command_name, FALSE, FALSE, NULL);
+
+ TRACE ("leaves execute_command with TRUE");
+
+ return TRUE;
+ }
+ else {
+ TRACE ("leaves execute_command with FALSE");
+ return FALSE;
+ }
+}
+
+
+static void
+sensors_init_default_values (t_sensors *sensors, XfcePanelPlugin *plugin)
+{
+ TRACE ("enters sensors_init_default_values");
+
+ sensors->show_title = TRUE;
+ sensors->show_labels = TRUE;
+ sensors->display_values_graphically = FALSE;
+ sensors->bars_created = FALSE;
+ sensors->font_size = "medium";
+ sensors->font_size_numerical = 2;
+ if (plugin!=NULL)
+ sensors->panel_size = xfce_panel_plugin_get_size (plugin);
+ sensors->show_colored_bars = TRUE;
+ sensors->sensors_refresh_time = 60;
+ sensors->scale = CELSIUS;
+
+ sensors->plugin = plugin; // we prefer storing NULL in here in case it is NULL.
+ if (plugin!=NULL)
+ sensors->orientation = xfce_panel_plugin_get_orientation (plugin);
+
+ /* double-click improvement */
+ sensors->exec_command = TRUE;
+ sensors->command_name = g_strdup("xsensors");
+ sensors->doubleclick_id = 0;
+
+ /* show units */
+ sensors->show_units = TRUE;
+
+ sensors->suppressmessage = FALSE;
+
+ sensors->show_smallspacings = FALSE;
+
+ TRACE ("leaves sensors_init_default_values");
+}
+
+
+/* #if GTK_VERSION >= 2.11
+ * static gboolean
+handle_tooltip_query (GtkWidget *widget,
+ gint x, gint y,
+ GtkTooltip *tooltip,
+ gpointer data)
+{
+ t_sensors *sensors;
+ gchar *buffer;
+
+ g_assert (data!=NULL);
+
+ sensors = (t_sensors *) data;
+
+ buffer = g_strdup("Tooltip placeholder");
+
+ gtk_tooltip_set_markup (tooltip, buffer);
+
+ return TRUE;
+} */
+
+
+
+
+static void
+sensors_free (XfcePanelPlugin *plugin, t_sensors *sensors)
+{
+ TRACE ("enters sensors_free");
+
+ g_return_if_fail (sensors != NULL);
+
+ /* stop association to libsensors and others*/
+ sensor_interface_cleanup();
+
+ /* remove timeout functions */
+ if (sensors->timeout_id)
+ g_source_remove (sensors->timeout_id);
+
+ /* double-click improvement */
+ g_source_remove (sensors->doubleclick_id);
+
+ /* free structures and arrays */
+ g_ptr_array_foreach (sensors->chips, free_chip, NULL);
+ g_ptr_array_free (sensors->chips, TRUE);
+
+ g_free (sensors);
+
+ TRACE ("leaves sensors_free");
+}
+
+
+static void
+sensors_set_size (XfcePanelPlugin *plugin, int size, t_sensors *sensors)
+{
+ TRACE ("enters sensors_set_size");
+
+ sensors->panel_size = (gint) size;
+
+ /* update the panel widget */
+ sensors_show_panel ((gpointer) sensors);
+
+ TRACE ("leaves sensors_set_size");
+}
+
+
+static void
+show_title_toggled (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters show_title_toggled");
+
+ sd->sensors->show_title = gtk_toggle_button_get_active
+ ( GTK_TOGGLE_BUTTON(widget) );
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel(sd->sensors);
+ }
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves show_title_toggled");
+}
+
+
+static void
+show_labels_toggled (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters show_labels_toggled");
+
+ sd->sensors->show_labels = gtk_toggle_button_get_active
+ ( GTK_TOGGLE_BUTTON(widget) );
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel(sd->sensors);
+ }
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves show_labels_toggled");
+}
+
+static void
+show_colored_bars_toggled (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters show_colored_bars_toggled");
+
+ sd->sensors->show_colored_bars = gtk_toggle_button_get_active
+ ( GTK_TOGGLE_BUTTON(widget) );
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel(sd->sensors);
+ }
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves show_colored_bars_toggled");
+}
+
+static void
+display_style_changed (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters display_style_changed");
+
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel(sd->sensors);
+ gtk_widget_hide(sd->labels_Box);
+ gtk_widget_hide(sd->coloredBars_Box);
+ gtk_widget_show(sd->font_Box);
+ gtk_widget_show (sd->unit_checkbox);
+ gtk_widget_show (sd->smallspacing_checkbox);
+ }
+ else {
+ gtk_widget_show(sd->labels_Box);
+ gtk_widget_show(sd->coloredBars_Box);
+ gtk_widget_hide(sd->font_Box);
+ gtk_widget_hide (sd->unit_checkbox);
+ gtk_widget_hide (sd->smallspacing_checkbox);
+ }
+
+ sd->sensors->display_values_graphically = gtk_toggle_button_get_active
+ ( GTK_TOGGLE_BUTTON(widget) );
+
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves display_style_changed");
+}
+
+
+static void
+sensor_entry_changed (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ gint gtk_combo_box_active;
+ t_chip *chip;
+
+ TRACE ("enters sensor_entry_changed");
+
+ gtk_combo_box_active = gtk_combo_box_get_active(GTK_COMBO_BOX (widget));
+
+ chip = (t_chip *) g_ptr_array_index (sd->sensors->chips,
+ gtk_combo_box_active);
+ gtk_label_set_label (GTK_LABEL(sd->mySensorLabel), chip->description);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (sd->myTreeView),
+ GTK_TREE_MODEL ( sd->myListStore[gtk_combo_box_active] ) );
+
+ TRACE ("leaves sensor_entry_changed");
+}
+
+
+static void
+font_size_change (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters font_size_change");
+
+ switch ( gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) ) {
+
+ case 0: sd->sensors->font_size = "x-small"; break;
+ case 1: sd->sensors->font_size = "small"; break;
+ case 3: sd->sensors->font_size = "large"; break;
+ case 4: sd->sensors->font_size = "x-large"; break;
+ default: sd->sensors->font_size = "medium";
+ }
+
+ sd->sensors->font_size_numerical =
+ gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+
+ /* refresh the panel content */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves font_size_change");
+}
+
+
+static void
+fill_gtkTreeStore (GtkTreeStore *model, t_chip *chip, t_tempscale scale)
+{
+ int featureindex, res;
+ double sensorFeature;
+ t_chipfeature *chipfeature;
+ GtkTreeIter *iter;
+
+ TRACE ("enters fill_gtkTreeStore");
+
+ for (featureindex=0; featureindex < chip->num_features; featureindex++)
+ {
+ chipfeature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, featureindex);
+ g_assert (chipfeature!=NULL);
+
+ iter = g_new0 (GtkTreeIter, 1);
+
+ if ( chipfeature->valid == TRUE ) {
+ res = sensor_get_value
+ (chip, chipfeature->address, &sensorFeature);
+ if ( res!=0) {
+ DBG ( _("Xfce Hardware Sensors Plugin:\n"
+ "Seems like there was a problem reading a sensor "
+ "feature value.\nProper proceeding cannot be "
+ "guaranteed.\n") );
+ /* FIXME: Better popup a window or DBG message or quit plugin. */
+ break;
+ }
+ g_free (chipfeature->formatted_value);
+ chipfeature->formatted_value = g_new (gchar, 0);
+ format_sensor_value (scale, chipfeature, sensorFeature,
+ &(chipfeature->formatted_value));
+ chipfeature->raw_value = sensorFeature;
+ gtk_tree_store_append (model, iter, NULL);
+ gtk_tree_store_set ( model, iter,
+ 0, chipfeature->name,
+ 1, chipfeature->formatted_value,
+ 2, chipfeature->show,
+ 3, chipfeature->color,
+ 4, chipfeature->min_value,
+ 5, chipfeature->max_value,
+ -1);
+ } /* end if sensors-valid */
+ /* g_free(iter); ??? */
+ }
+
+ TRACE ("leaves fill_gtkTreeStore");
+}
+
+
+static void
+reload_listbox (t_sensors_dialog *sd)
+{
+ int chipindex;
+ t_chip *chip;
+ GtkTreeStore *model;
+ t_sensors *sensors;
+
+ TRACE ("enters reload_listbox");
+
+ sensors = sd->sensors;
+
+ for (chipindex=0; chipindex < sensors->num_sensorchips; chipindex++) {
+ chip = (t_chip *) g_ptr_array_index (sensors->chips, chipindex);
+
+ model = sd->myListStore[chipindex];
+ gtk_tree_store_clear (model);
+
+ fill_gtkTreeStore (model, chip, sensors->scale);
+
+ }
+ TRACE ("leaves reload_listbox");
+}
+
+
+static void
+temperature_unit_change (GtkWidget *widget, t_sensors_dialog *sd)
+{
+ TRACE ("enters temperature_unit_change ");
+
+ /* toggle celsius-fahrenheit by use of mathematics ;) */
+ sd->sensors->scale = 1 - sd->sensors->scale;
+
+ /* refresh the panel content */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ reload_listbox (sd);
+
+ TRACE ("laeves temperature_unit_change ");
+}
+
+
+static void
+adjustment_value_changed (GtkWidget *widget, t_sensors_dialog* sd)
+{
+ TRACE ("enters adjustment_value_changed ");
+
+ sd->sensors->sensors_refresh_time =
+ (gint) gtk_adjustment_get_value ( GTK_ADJUSTMENT (widget) );
+
+ /* stop the timeout functions ... */
+ g_source_remove (sd->sensors->timeout_id);
+ /* ... and start them again */
+ sd->sensors->timeout_id = g_timeout_add (
+ sd->sensors->sensors_refresh_time * 1000,
+ (GtkFunction) sensors_show_panel, (gpointer) sd->sensors);
+
+ TRACE ("leaves adjustment_value_changed ");
+}
+
+
+static void
+draw_units_changed (GtkWidget *widget, t_sensors_dialog* sd)
+{
+ TRACE ("enters draw_units_changed");
+
+ sd->sensors->show_units = ! sd->sensors->show_units;
+
+ sensors_show_text_display (sd->sensors);
+
+ TRACE ("leaves draw_units_changed");
+}
+
+
+static void
+draw_smallspacings_changed (GtkWidget *widget, t_sensors_dialog* sd)
+{
+ TRACE ("enters draw_smallspacings_changed");
+
+ sd->sensors->show_smallspacings = ! sd->sensors->show_smallspacings;
+
+ sensors_show_text_display (sd->sensors);
+
+ TRACE ("leaves draw_smallspacings_changed");
+}
+
+
+static void
+suppressmessage_changed (GtkWidget *widget, t_sensors_dialog* sd)
+{
+ TRACE ("enters suppressmessage_changed");
+
+ sd->sensors->suppressmessage = ! sd->sensors->suppressmessage;
+
+ TRACE ("leaves suppressmessage_changed");
+}
+
+
+/* double-click improvement */
+static void
+execCommand_toggled (GtkWidget *widget, t_sensors_dialog* sd)
+{
+ TRACE ("enters execCommand_toggled");
+
+ sd->sensors->exec_command =
+ gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (widget) );
+
+ if ( sd->sensors->exec_command )
+ g_signal_handler_unblock (sd->sensors->eventbox,
+ sd->sensors->doubleclick_id);
+ else
+ g_signal_handler_block (sd->sensors->eventbox,
+ sd->sensors->doubleclick_id );
+
+ TRACE ("leaves execCommand_toggled");
+}
+
+
+static void
+minimum_changed (GtkCellRendererText *cellrenderertext, gchar *path_str,
+ gchar *new_value, t_sensors_dialog *sd)
+{
+ gint gtk_combo_box_active;
+ float value;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters minimum_changed");
+
+ value = atof (new_value);
+
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX (sd->myComboBox));
+
+ /* get model and path */
+ model = (GtkTreeModel *) sd->myListStore
+ [gtk_combo_box_active];
+ path = gtk_tree_path_new_from_string (path_str);
+
+ /* get model iterator */
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 4, value, -1);
+ chip = (t_chip *) g_ptr_array_index(sd->sensors->chips, gtk_combo_box_active);
+
+ chipfeature = (t_chipfeature *) g_ptr_array_index(chip->chip_features, atoi(path_str));
+ chipfeature->min_value = value;
+
+ /* clean up */
+ gtk_tree_path_free (path);
+
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel (sd->sensors);
+ }
+
+ /* update panel */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves minimum_changed");
+}
+
+
+static void
+maximum_changed (GtkCellRendererText *cellrenderertext, gchar *path_str,
+ gchar *new_value, t_sensors_dialog *sd)
+{
+ gint gtk_combo_box_active;
+ float value;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters maximum_changed");
+
+ value = atof (new_value);
+
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX (sd->myComboBox));
+
+ /* get model and path */
+ model = (GtkTreeModel *) sd->myListStore
+ [gtk_combo_box_active];
+ path = gtk_tree_path_new_from_string (path_str);
+
+ /* get model iterator */
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 5, value, -1);
+ chip = (t_chip *) g_ptr_array_index(sd->sensors->chips, gtk_combo_box_active);
+
+ chipfeature = (t_chipfeature *) g_ptr_array_index(chip->chip_features, atoi(path_str));
+ chipfeature->max_value = value;
+
+ /* clean up */
+ gtk_tree_path_free (path);
+
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel (sd->sensors);
+ }
+
+ /* update panel */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves maximum_changed");
+}
+
+
+static void
+list_cell_color_edited (GtkCellRendererText *cellrenderertext, gchar *path_str,
+ gchar *new_color, t_sensors_dialog *sd)
+{
+ gint gtk_combo_box_active;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gboolean hexColor;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters list_cell_color_edited");
+
+ /* store new color in appropriate array */
+ hexColor = g_str_has_prefix (new_color, "#");
+
+ if (hexColor && strlen(new_color) == 7) {
+ int i;
+ for (i=1; i<7; i++) {
+ /* only save hex numbers! */
+ if ( ! g_ascii_isxdigit (new_color[i]) )
+ return;
+ }
+
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX (sd->myComboBox));
+
+ /* get model and path */
+ model = (GtkTreeModel *) sd->myListStore
+ [gtk_combo_box_active];
+ path = gtk_tree_path_new_from_string (path_str);
+
+ /* get model iterator */
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 3, new_color, -1);
+ chip = (t_chip *) g_ptr_array_index(sd->sensors->chips, gtk_combo_box_active);
+
+ chipfeature = (t_chipfeature *) g_ptr_array_index(chip->chip_features, atoi(path_str));
+ g_free (chipfeature->color);
+ chipfeature->color = g_strdup(new_color);
+
+ /* clean up */
+ gtk_tree_path_free (path);
+
+ /* update panel */
+ sensors_show_panel ((gpointer) sd->sensors);
+ }
+
+ TRACE ("leaves list_cell_color_edited");
+}
+
+
+static void
+list_cell_text_edited (GtkCellRendererText *cellrenderertext,
+ gchar *path_str, gchar *new_text, t_sensors_dialog *sd)
+{
+ gint gtk_combo_box_active;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters list_cell_text_edited");
+
+ if (sd->sensors->display_values_graphically == TRUE) {
+ DBG("removing graphical panel");
+ sensors_remove_graphical_panel(sd->sensors);
+ DBG("done removing grap. panel");
+ }
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX (sd->myComboBox));
+
+ model =
+ (GtkTreeModel *) sd->myListStore [gtk_combo_box_active];
+ path = gtk_tree_path_new_from_string (path_str);
+
+ /* get model iterator */
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, new_text, -1);
+ chip = (t_chip *) g_ptr_array_index(sd->sensors->chips, gtk_combo_box_active);
+
+ /* if (chip->type!=ACPI) { */ /* No Bug. The cryptic filesystem names are
+ needed for the update in ACPI and hddtemp. */
+ chipfeature = (t_chipfeature *) g_ptr_array_index (chip->chip_features,
+ atoi(path_str));
+ g_free(chipfeature->name);
+ chipfeature->name = g_strdup (new_text);
+ /* } */
+
+ /* clean up */
+ gtk_tree_path_free (path);
+
+ /* update panel */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves list_cell_text_edited");
+}
+
+
+static void
+list_cell_toggle (GtkCellRendererToggle *cell, gchar *path_str,
+ t_sensors_dialog *sd)
+{
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+ gint gtk_combo_box_active;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gboolean toggle_item;
+
+ TRACE ("enters list_cell_toggle");
+
+ if (sd->sensors->display_values_graphically == TRUE) {
+ sensors_remove_graphical_panel(sd->sensors);
+ }
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX (sd->myComboBox));
+
+ model = (GtkTreeModel *) sd->myListStore[gtk_combo_box_active];
+ path = gtk_tree_path_new_from_string (path_str);
+
+ /* get toggled iter */
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, 2, &toggle_item, -1);
+
+ /* do something with the value */
+ toggle_item ^= 1;
+
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 2, toggle_item, -1);
+ chip = (t_chip *) g_ptr_array_index(sd->sensors->chips, gtk_combo_box_active);
+
+ chipfeature = (t_chipfeature *) g_ptr_array_index(chip->chip_features, atoi(path_str));
+
+ /* help = chip->sensorAddress [ gtk_combo_box_active ] [atoi(path_str)];
+ chipfeature = (t_chipfeature *) g_ptr_array_index(chip->chip_features, help); */
+
+ chipfeature->show = toggle_item;
+
+ /* clean up */
+ gtk_tree_path_free (path);
+
+ /* update tooltip and panel widget */
+ sensors_show_panel ((gpointer) sd->sensors);
+
+ TRACE ("leaves list_cell_toggle");
+}
+
+
+
+
+
+static void
+add_ui_style_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *hbox, *label, *radioText, *radioBars; /* *checkButton, */
+
+ TRACE ("enters add_ui_style_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+
+ label = gtk_label_new (_("UI style:"));
+ radioText = gtk_radio_button_new_with_mnemonic(NULL, _("_text"));
+ radioBars = gtk_radio_button_new_with_mnemonic(
+ gtk_radio_button_group(GTK_RADIO_BUTTON(radioText)), _("g_raphical"));
+
+ gtk_widget_show(radioText);
+ gtk_widget_show(radioBars);
+ gtk_widget_show(label);
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radioText),
+ sd->sensors->display_values_graphically == FALSE);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radioBars),
+ sd->sensors->display_values_graphically == TRUE);
+
+ gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX (hbox), radioText, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX (hbox), radioBars, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+
+ g_signal_connect (G_OBJECT (radioBars), "toggled",
+ G_CALLBACK (display_style_changed), sd );
+
+ TRACE ("leaves add_ui_style_box");
+}
+
+
+static void
+add_labels_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *hbox, *checkButton;
+
+ TRACE ("enters add_labels_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+ sd->labels_Box = hbox;
+ /* gtk_widget_set_sensitive(hbox, sd->sensors->display_values_graphically); */
+
+ checkButton = gtk_check_button_new_with_mnemonic (
+ _("Show _labels in graphical UI"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkButton),
+ sd->sensors->show_labels);
+ gtk_widget_show (checkButton);
+
+ gtk_box_pack_start (GTK_BOX (hbox), checkButton, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+
+ if (sd->sensors->display_values_graphically==FALSE)
+ gtk_widget_hide(sd->labels_Box);
+
+ g_signal_connect (G_OBJECT (checkButton), "toggled",
+ G_CALLBACK (show_labels_toggled), sd );
+
+ TRACE ("leaves add_labels_box");
+}
+
+static void
+add_colored_bars_box (GtkWidget *vbox, t_sensors_dialog *sd)
+{
+ GtkWidget *hbox, *checkButton;
+
+ TRACE ("enters add_colored_bars_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+
+ gtk_widget_show (hbox);
+ sd->coloredBars_Box = hbox;
+
+ checkButton = gtk_check_button_new_with_mnemonic (
+ _("Show colored _bars"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkButton),
+ sd->sensors->show_colored_bars);
+
+ gtk_widget_show (checkButton);
+
+ gtk_box_pack_start (GTK_BOX (hbox), checkButton, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+
+ if (sd->sensors->display_values_graphically==FALSE)
+ gtk_widget_hide(sd->coloredBars_Box);
+
+ g_signal_connect (G_OBJECT (checkButton), "toggled",
+ G_CALLBACK (show_colored_bars_toggled), sd );
+
+ TRACE ("leaves add_colored_bars_box");
+}
+
+static void
+add_title_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *hbox, *checkButton;
+
+ TRACE ("enters add_title_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+
+ checkButton = gtk_check_button_new_with_mnemonic (_("_Show title"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkButton),
+ sd->sensors->show_title);
+ gtk_widget_show (checkButton);
+
+ gtk_box_pack_start (GTK_BOX (hbox), checkButton, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+
+ g_signal_connect (G_OBJECT (checkButton), "toggled",
+ G_CALLBACK (show_title_toggled), sd );
+
+ TRACE ("leaves add_title_box");
+}
+
+
+static void
+add_type_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *hbox, *label;
+ t_chip *chip;
+ gint gtk_combo_box_active;
+
+ TRACE ("enters add_type_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("Sensors t_ype:"));
+ gtk_widget_show (label);
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ gtk_widget_show (sd->myComboBox);
+ gtk_box_pack_start (GTK_BOX (hbox), sd->myComboBox, FALSE, FALSE, 0);
+
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), sd->myComboBox);
+
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX(sd->myComboBox));
+
+ chip = g_ptr_array_index (sd->sensors->chips, gtk_combo_box_active);
+
+ /* if (sd->sensors->num_sensorchips > 0)
+ sd->mySensorLabel = gtk_label_new
+ ( sensors_get_adapter_name_wrapper
+ ( chip->chip_name->bus) );
+ else */
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("Description:"));
+ gtk_widget_show (label);
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ sd->mySensorLabel =
+ gtk_label_new (chip->description);
+
+ gtk_widget_show (sd->mySensorLabel);
+ gtk_box_pack_start (GTK_BOX (hbox), sd->mySensorLabel, FALSE, FALSE, 0);
+
+ g_signal_connect (G_OBJECT (sd->myComboBox), "changed",
+ G_CALLBACK (sensor_entry_changed), sd );
+
+ TRACE ("leaves add_type_box");
+}
+
+
+static void
+add_sensor_settings_box ( GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkTreeViewColumn *aTreeViewColumn;
+ GtkCellRenderer *myCellRendererText, *myCellRendererToggle;
+ GtkWidget *myScrolledWindow;
+ gint gtk_combo_box_active;
+
+ TRACE ("enters add_sensor_settings_box");
+
+ gtk_combo_box_active =
+ gtk_combo_box_get_active(GTK_COMBO_BOX(sd->myComboBox));
+
+ sd->myTreeView = gtk_tree_view_new_with_model
+ ( GTK_TREE_MODEL ( sd->myListStore[ gtk_combo_box_active ] ) );
+
+ myCellRendererText = gtk_cell_renderer_text_new ();
+ g_object_set ( (gpointer*) myCellRendererText, "editable", TRUE, NULL );
+
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes (_("Name"),
+ myCellRendererText, "text", 0, NULL);
+ g_signal_connect (G_OBJECT (myCellRendererText), "edited",
+ G_CALLBACK (list_cell_text_edited), sd);
+ gtk_tree_view_column_set_expand (aTreeViewColumn, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN (aTreeViewColumn));
+
+ myCellRendererText = gtk_cell_renderer_text_new ();
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes (_("Value"),
+ myCellRendererText, "text", 1, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN (aTreeViewColumn));
+
+ myCellRendererToggle = gtk_cell_renderer_toggle_new();
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes (_("Show"),
+ myCellRendererToggle, "active", 2, NULL);
+ g_signal_connect (G_OBJECT (myCellRendererToggle), "toggled",
+ G_CALLBACK (list_cell_toggle), sd );
+ gtk_tree_view_append_column (GTK_TREE_VIEW (sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN (aTreeViewColumn));
+
+ myCellRendererText = gtk_cell_renderer_text_new ();
+ g_object_set ( (gpointer*) myCellRendererText, "editable", TRUE, NULL );
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes (_("Color"),
+ myCellRendererText, "text", 3, NULL);
+ g_signal_connect (G_OBJECT (myCellRendererText), "edited",
+ G_CALLBACK (list_cell_color_edited), sd);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN (aTreeViewColumn));
+
+ myCellRendererText = gtk_cell_renderer_text_new ();
+ g_object_set ( (gpointer*) myCellRendererText, "editable", TRUE, NULL );
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes
+ (_("Min"), myCellRendererText, "text", 4, NULL);
+ g_signal_connect(G_OBJECT(myCellRendererText), "edited",
+ G_CALLBACK(minimum_changed), sd);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN(aTreeViewColumn));
+
+ myCellRendererText = gtk_cell_renderer_text_new ();
+ g_object_set ( (gpointer*) myCellRendererText, "editable", TRUE, NULL );
+ aTreeViewColumn = gtk_tree_view_column_new_with_attributes
+ (_("Max"), myCellRendererText, "text", 5, NULL);
+ g_signal_connect(G_OBJECT(myCellRendererText), "edited",
+ G_CALLBACK(maximum_changed), sd);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(sd->myTreeView),
+ GTK_TREE_VIEW_COLUMN(aTreeViewColumn));
+
+ myScrolledWindow = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (
+ GTK_SCROLLED_WINDOW (myScrolledWindow), GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_set_border_width (GTK_CONTAINER (myScrolledWindow), 0);
+ /* gtk_scrolled_window_add_with_viewport (
+ GTK_SCROLLED_WINDOW (myScrolledWindow), sd->myTreeView); */
+ gtk_container_add (GTK_CONTAINER (myScrolledWindow), sd->myTreeView);
+
+ gtk_box_pack_start (GTK_BOX (vbox), myScrolledWindow, TRUE, TRUE, BORDER);
+
+ gtk_widget_show (sd->myTreeView);
+ gtk_widget_show (myScrolledWindow);
+
+ TRACE ("leaves add_sensor_settings_box");
+}
+
+
+static void
+add_font_size_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *myFontLabel;
+ GtkWidget *myFontBox;
+ GtkWidget *myFontSizeComboBox;
+
+ TRACE ("enters add_font_size_box");
+
+ myFontLabel = gtk_label_new_with_mnemonic (_("F_ont size:"));
+ myFontBox = gtk_hbox_new(FALSE, BORDER);
+ myFontSizeComboBox = gtk_combo_box_new_text();
+
+ sd->font_Box = myFontBox;
+ /* gtk_widget_set_sensitive(myFontBox, !sd->sensors->display_values_graphically); */
+
+ gtk_combo_box_append_text (GTK_COMBO_BOX(myFontSizeComboBox), _("x-small"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX(myFontSizeComboBox), _("small") );
+ gtk_combo_box_append_text (GTK_COMBO_BOX(myFontSizeComboBox), _("medium") );
+ gtk_combo_box_append_text (GTK_COMBO_BOX(myFontSizeComboBox), _("large") );
+ gtk_combo_box_append_text (GTK_COMBO_BOX(myFontSizeComboBox), _("x-large"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX(myFontSizeComboBox),
+ sd->sensors->font_size_numerical);
+
+ gtk_box_pack_start (GTK_BOX (myFontBox), myFontLabel, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (myFontBox), myFontSizeComboBox, FALSE, FALSE,
+ 0);
+ gtk_box_pack_start (GTK_BOX (vbox), myFontBox, FALSE, FALSE, 0);
+
+ gtk_widget_show (myFontLabel);
+ gtk_widget_show (myFontSizeComboBox);
+ gtk_widget_show (myFontBox);
+
+ if (sd->sensors->display_values_graphically==TRUE)
+ gtk_widget_hide(sd->font_Box);
+
+ g_signal_connect (G_OBJECT (myFontSizeComboBox), "changed",
+ G_CALLBACK (font_size_change), sd );
+
+ TRACE ("leaves add_font_size_box");
+}
+
+static void
+add_temperature_unit_box (GtkWidget *vbox, t_sensors_dialog *sd)
+{
+ GtkWidget *hbox, *label, *radioCelsius, *radioFahrenheit;
+
+ TRACE ("enters add_temperature_unit_box");
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_widget_show (hbox);
+
+ label = gtk_label_new ( _("Temperature scale:"));
+ radioCelsius = gtk_radio_button_new_with_mnemonic (NULL,
+ _("_Celsius"));
+ radioFahrenheit = gtk_radio_button_new_with_mnemonic(
+ gtk_radio_button_get_group(GTK_RADIO_BUTTON(radioCelsius)), _("_Fahrenheit"));
+
+ gtk_widget_show(radioCelsius);
+ gtk_widget_show(radioFahrenheit);
+ gtk_widget_show(label);
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radioCelsius),
+ sd->sensors->scale == CELSIUS);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radioFahrenheit),
+ sd->sensors->scale == FAHRENHEIT);
+
+ gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX (hbox), radioCelsius, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX (hbox), radioFahrenheit, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+
+ g_signal_connect (G_OBJECT (radioCelsius), "toggled",
+ G_CALLBACK (temperature_unit_change), sd );
+
+ TRACE ("leaves add_temperature_unit_box");
+}
+
+
+static void
+add_units_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ TRACE ("enters add_units_box");
+
+ sd->unit_checkbox = gtk_check_button_new_with_mnemonic(_("Show _Units"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sd->unit_checkbox), sd->sensors->show_units);
+
+ gtk_widget_show (sd->unit_checkbox);
+
+ gtk_box_pack_start (GTK_BOX (vbox), sd->unit_checkbox, FALSE, TRUE, 0);
+
+ if (sd->sensors->display_values_graphically==TRUE)
+ gtk_widget_hide(sd->unit_checkbox);
+
+ g_signal_connect (G_OBJECT (sd->unit_checkbox), "toggled",
+ G_CALLBACK (draw_units_changed), sd );
+
+ TRACE ("leaves add_units_box");
+}
+
+static void
+add_smallspacings_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ TRACE ("enters add_smallspacings_box");
+
+ sd->smallspacing_checkbox = gtk_check_button_new_with_mnemonic(_("Small horizontal s_pacing"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sd->smallspacing_checkbox), sd->sensors->show_smallspacings);
+
+ gtk_widget_show (sd->smallspacing_checkbox);
+
+ gtk_box_pack_start (GTK_BOX (vbox), sd->smallspacing_checkbox, FALSE, TRUE, 0);
+
+ if (sd->sensors->display_values_graphically==TRUE)
+ gtk_widget_hide(sd->smallspacing_checkbox);
+
+ g_signal_connect (G_OBJECT (sd->smallspacing_checkbox), "toggled",
+ G_CALLBACK (draw_smallspacings_changed), sd );
+
+ TRACE ("leaves add_smallspacings_box");
+}
+
+
+static void
+add_suppressmessage_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ TRACE ("enters add_suppressmessage_box");
+
+ sd->suppressmessage_checkbox = gtk_check_button_new_with_mnemonic(_("Suppress messages"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sd->suppressmessage_checkbox), sd->sensors->suppressmessage);
+
+ gtk_widget_show (sd->suppressmessage_checkbox);
+
+ gtk_box_pack_start (GTK_BOX (vbox), sd->suppressmessage_checkbox, FALSE, TRUE, 0);
+
+ g_signal_connect (G_OBJECT (sd->suppressmessage_checkbox), "toggled",
+ G_CALLBACK (suppressmessage_changed), sd );
+
+ TRACE ("leaves add_suppressmessage_box");
+}
+
+
+static void
+add_update_time_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *spinner, *myLabel, *myBox;
+ GtkAdjustment *spinner_adj;
+
+ TRACE ("enters add_update_time_box");
+
+ spinner_adj = (GtkAdjustment *) gtk_adjustment_new (
+/* TODO: restore original */
+ sd->sensors->sensors_refresh_time, 1.0, 990.0, 1.0, 60.0, 60.0);
+
+ /* creates the spinner, with no decimal places */
+ spinner = gtk_spin_button_new (spinner_adj, 10.0, 0);
+
+ myLabel = gtk_label_new_with_mnemonic ( _("U_pdate interval (seconds):"));
+ gtk_label_set_mnemonic_widget (GTK_LABEL(myLabel), spinner);
+
+ myBox = gtk_hbox_new(FALSE, BORDER);
+
+ gtk_box_pack_start (GTK_BOX (myBox), myLabel, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (myBox), spinner, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), myBox, FALSE, FALSE, 0);
+
+ gtk_widget_show (myLabel);
+ gtk_widget_show (spinner);
+ gtk_widget_show (myBox);
+
+ g_signal_connect (G_OBJECT (spinner_adj), "value_changed",
+ G_CALLBACK (adjustment_value_changed), sd );
+
+ TRACE ("leaves add_update_time_box");
+}
+
+/* double-click improvement */
+static void
+add_command_box (GtkWidget * vbox, t_sensors_dialog * sd)
+{
+ GtkWidget *myBox;
+
+ TRACE ("enters add_command_box");
+
+ myBox = gtk_hbox_new(FALSE, BORDER);
+
+ sd->myExecCommand_CheckBox = gtk_check_button_new_with_mnemonic
+ (_("E_xecute on double click:"));
+ gtk_toggle_button_set_active
+ ( GTK_TOGGLE_BUTTON (sd->myExecCommand_CheckBox),
+ sd->sensors->exec_command );
+
+ sd->myCommandName_Entry = gtk_entry_new ();
+ gtk_widget_set_size_request (sd->myCommandName_Entry, 160, 25);
+
+
+ gtk_entry_set_text( GTK_ENTRY(sd->myCommandName_Entry),
+ sd->sensors->command_name );
+
+ gtk_box_pack_start (GTK_BOX (myBox), sd->myExecCommand_CheckBox, FALSE,
+ FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (myBox), sd->myCommandName_Entry, FALSE,
+ FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), myBox, FALSE, FALSE, 0);
+
+ gtk_widget_show (sd->myExecCommand_CheckBox);
+ gtk_widget_show (sd->myCommandName_Entry);
+ gtk_widget_show (myBox);
+
+ g_signal_connect (G_OBJECT (sd->myExecCommand_CheckBox), "toggled",
+ G_CALLBACK (execCommand_toggled), sd );
+
+ /* g_signal_connect (G_OBJECT (sd->myCommandNameEntry), "focus-out-event",
+ G_CALLBACK (execCommandName_activate), sd ); */
+
+ TRACE ("leaves add_command_box");
+}
+
+
+static void
+add_view_frame (GtkWidget * notebook, t_sensors_dialog * sd)
+{
+ GtkWidget *_vbox, *_label;
+
+ TRACE ("enters add_view_frame");
+
+ _vbox = gtk_vbox_new (FALSE, 4);
+ gtk_container_set_border_width (GTK_CONTAINER(_vbox), 4);
+ gtk_widget_show (_vbox);
+
+ _label = gtk_label_new_with_mnemonic(_("_View"));
+ gtk_widget_show (_label);
+
+ gtk_container_set_border_width (GTK_CONTAINER (_vbox), BORDER<<1);
+
+ gtk_notebook_append_page (GTK_NOTEBOOK(notebook), _vbox, _label);
+
+ add_title_box (_vbox, sd);
+
+ add_ui_style_box (_vbox, sd);
+ add_labels_box (_vbox, sd);
+ add_colored_bars_box (_vbox, sd);
+ add_font_size_box (_vbox, sd);
+ add_units_box (_vbox, sd);
+ add_smallspacings_box(_vbox, sd);
+
+ TRACE ("leaves add_view_frame");
+}
+
+
+
+static void
+add_miscellaneous_frame (GtkWidget * notebook, t_sensors_dialog * sd)
+{
+ GtkWidget *_vbox, *_label;
+
+ TRACE ("enters add_miscellaneous_frame");
+
+ _vbox = gtk_vbox_new (FALSE, 4);
+ gtk_container_set_border_width (GTK_CONTAINER(_vbox), 4);
+ gtk_widget_show (_vbox);
+
+ _label = gtk_label_new_with_mnemonic (_("_Miscellaneous"));
+ gtk_widget_show (_label);
+
+ gtk_container_set_border_width (GTK_CONTAINER (_vbox), BORDER<<1);
+
+ gtk_notebook_append_page (GTK_NOTEBOOK(notebook), _vbox, _label);
+
+ add_update_time_box (_vbox, sd);
+
+ add_suppressmessage_box(_vbox, sd);
+
+ add_command_box (_vbox, sd);
+
+ TRACE ("leaves add_miscellaneous_frame");
+}
+
+
+static void
+on_optionsDialog_response (GtkWidget *dlg, int response, t_sensors_dialog *sd)
+{
+ TRACE ("enters on_optionsDialog_response");
+
+ if (response==GTK_RESPONSE_OK) {
+ /* FIXME: save most of the content in this function,
+ remove those toggle functions where possible. NYI */
+ /* sensors_apply_options (sd); */
+ g_free(sd->sensors->command_name);
+ sd->sensors->command_name =
+ g_strdup ( gtk_entry_get_text(GTK_ENTRY(sd->myCommandName_Entry)) );
+ sensors_write_config (sd->sensors->plugin, sd->sensors);
+ }
+ gtk_widget_destroy (sd->dialog);
+
+ xfce_panel_plugin_unblock_menu (sd->sensors->plugin);
+
+ /* g_free(sd->coloredBars_Box);
+ g_free(sd->font_Box);
+ g_free(sd->labels_Box);
+ g_free(sd->myComboBox);
+ g_free(sd->myCommandName_Entry);
+ g_free(sd->myExecCommand_CheckBox);
+ g_free(sd->mySensorLabel);
+ g_free(sd->smallspacing_checkbox);
+ g_free(sd->suppressmessage_checkbox);
+ g_free(sd->temperature_radio_group);
+ g_free(sd->unit_checkbox); */
+
+ g_free(sd);
+
+ TRACE ("leaves on_optionsDialog_response");
+}
+
+
+/* create sensor options box */
+static void
+sensors_create_options (XfcePanelPlugin *plugin, t_sensors *sensors)
+{
+ GtkWidget *dlg, *header, *vbox, *notebook;
+ t_sensors_dialog *sd;
+
+ TRACE ("enters sensors_create_options");
+
+ xfce_panel_plugin_block_menu (plugin);
+
+ dlg = gtk_dialog_new_with_buttons (_("Edit Properties"),
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL);
+
+ gtk_container_set_border_width (GTK_CONTAINER (dlg), 2);
+
+ header = xfce_create_header (NULL, _("Sensors Plugin"));
+ gtk_widget_set_size_request (GTK_BIN (header)->child, -1, 32);
+ gtk_container_set_border_width (GTK_CONTAINER (header), BORDER-2);
+ gtk_widget_show (header);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), header,
+ FALSE, TRUE, 0);
+
+ vbox = GTK_DIALOG (dlg)->vbox;
+
+ sd = g_new0 (t_sensors_dialog, 1);
+
+ sd->sensors = sensors;
+ sd->dialog = dlg;
+
+ sd->myComboBox = gtk_combo_box_new_text();
+
+ init_widgets (sd);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX(sd->myComboBox), 0);
+
+ notebook = gtk_notebook_new ();
+
+ gtk_box_pack_start (GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
+ gtk_widget_show(notebook);
+
+ add_sensors_frame (notebook, sd);
+ add_view_frame (notebook, sd);
+ add_miscellaneous_frame (notebook, sd);
+
+ gtk_widget_set_size_request (vbox, 400, 400);
+
+ g_signal_connect (dlg, "response",
+ G_CALLBACK(on_optionsDialog_response), sd);
+
+ gtk_widget_show (dlg);
+
+ TRACE ("leaves sensors_create_options");
+}
+
+
+/**
+ * Add event box to sensors panel
+ * @param sensors Pointer to t_sensors structure
+ */
+static void
+add_event_box (t_sensors *sensors)
+{
+ /* create eventbox to catch events on widget */
+ sensors->eventbox = gtk_event_box_new ();
+ gtk_widget_set_name (sensors->eventbox, "xfce_sensors");
+ gtk_widget_show (sensors->eventbox);
+
+ /* double-click improvement */
+ sensors->doubleclick_id = g_signal_connect (G_OBJECT(sensors->eventbox),
+ "button-press-event",
+ G_CALLBACK (execute_command),
+ (gpointer) sensors);
+}
+
+
+/**
+ * Create sensors panel control
+ * @param plugin Panel plugin proxy to create sensors plugin in
+ */
+static t_sensors *
+create_sensors_control (XfcePanelPlugin *plugin)
+{
+ t_sensors *sensors;
+
+ TRACE ("enters create_sensors_control");
+
+ sensors = sensors_new (plugin);
+
+ add_event_box (sensors);
+
+ /* sensors_set_size (control, settings.size); */
+
+ TRACE ("leaves create_sensors_control");
+
+ return sensors;
+}
+
+
+static void
+sensors_plugin_construct (XfcePanelPlugin *plugin)
+{
+ t_sensors *sensors;
+
+ TRACE ("enters sensors_plugin_construct");
+
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+ sensors = create_sensors_control (plugin);
+
+ sensors_read_config (plugin, sensors);
+
+ /* Try to resize the sensors to fit the user settings.
+ Do also modify the tooltip text. */
+ sensors_show_panel ((gpointer) sensors);
+
+ sensors->timeout_id = g_timeout_add (sensors->sensors_refresh_time * 1000,
+ (GtkFunction) sensors_show_panel,
+ (gpointer) sensors);
+
+ g_signal_connect (plugin, "free-data", G_CALLBACK (sensors_free), sensors);
+
+ g_signal_connect (plugin, "save", G_CALLBACK (sensors_write_config),
+ sensors);
+
+ xfce_panel_plugin_menu_show_configure (plugin);
+
+ g_signal_connect (plugin, "configure-plugin",
+ G_CALLBACK (sensors_create_options), sensors);
+
+ g_signal_connect (plugin, "size-changed", G_CALLBACK (sensors_set_size),
+ sensors);
+
+ g_signal_connect (plugin, "orientation-changed",
+ G_CALLBACK (sensors_set_orientation), sensors);
+
+ gtk_container_add (GTK_CONTAINER(plugin), sensors->eventbox);
+
+ xfce_panel_plugin_add_action_widget (plugin, sensors->eventbox);
+
+ TRACE ("leaves sensors_plugin_construct");
+}
+
+XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (sensors_plugin_construct);
Property changes on: xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c
___________________________________________________________________
Name: svn:keywords
+ author date id revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.h (from rev 5493, xfce4-sensors-plugin/trunk/panel-plugin/sensors.h)
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.h (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,47 @@
+/* Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#ifndef XFCE4_SENSORS_SENSORS_H
+#define XFCE4_SENSORS_SENSORS_H
+
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+/* #endif */
+
+#include <glib/garray.h>
+#include <glib/gprintf.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+
+#include <string.h>
+
+#include <middlelayer.h>
+#include <sensors-interface-common.h>
+/* #include <types.h> */
+
+#define APP_NAME N_("Sensors Plugin")
+
+
+
+
+
+#endif /* XFCE4_SENSORS_SENSORS_H */
Property changes on: xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.h
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/sensors.c
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/sensors.h
Deleted: xfce4-sensors-plugin/trunk/panel-plugin/types.h
Modified: xfce4-sensors-plugin/trunk/src/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/src/Makefile.am 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/Makefile.am 2008-10-05 17:32:34 UTC (rev 5516)
@@ -1,9 +1,16 @@
# $Id$
-INCLUDES = -I../panel-plugin/
-
bin_PROGRAMS = xfce4-sensors
+
+INCLUDES = \
+ -I$(top_builddir)/include \
+ -I$(top_builddir)/lib
+
+# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
+# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+
+
# LIBS = @LIBS@ @SOLLIBS@
# CFLAGS = @CFLAGS@
@@ -11,30 +18,35 @@
main.c \
interface.c \
callbacks.c \
- actions.c \
- ../panel-plugin/middlelayer.c \
- ../panel-plugin/acpi.c \
- ../panel-plugin/hddtemp.c \
- ../panel-plugin/lmsensors.c
+ actions.c
xfce4_sensors_CFLAGS = \
- @GTK_CFLAGS@ \
- @PLATFORM_CFLAGS@ \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ @GTK_CFLAGS@ \
+ @GLIB_CFLAGS@ \
+ @PLATFORM_CFLAGS@ \
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ @LIBSENSORS_CFLAGS@ \
@LIBXFCE4UTIL_CFLAGS@ \
- @LIBSENSORS_CFLAGS@
+ @LIBXFCEGUI4_CFLAGS@
+
# @LIBXFCE4PANEL_CFLAGS@
-xfce4_sensors_LDFLAGS = \
- @GTK_LIBS@ \
+#xfce4_sensors_LDFLAGS = \
+# $(top_builddir)/lib/libxfce4sensors.la
+
+xfce4_sensors_LDADD = \
+ @GTK_LIBS@ \
+ @GLIB_LIBS@ \
@SOLLIBS@ \
- @LIBSENSORS_LDFLAGS@ \
- @LIBXFCE4UTIL_LIBS@
+ @LIBSENSORS_LDFLAGS@ \
+ @LIBXFCE4UTIL_LIBS@ \
+ @LIBXFCEGUI4_LIBS@
+
+#-L/usr/local/lib/xfce4/modules/ -L$(top_builddir)/lib -lxfce4sensors
# @LIBXFCE4PANEL_LIBS@
-# INCLUDES = \
-# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
-# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+#xfce4_sensors_DEPENDENCIES = \
+# $(top_builddir)/lib/libxfce4sensors.la
# .desktop file
#
@@ -53,6 +65,5 @@
EXTRA_DIST = \
$(desktop_in_in_files)
-
DISTCLEANFILES = \
$(desktop_DATA) $(desktop_in_files)
Modified: xfce4-sensors-plugin/trunk/src/actions.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/actions.c 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/actions.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/actions.h
===================================================================
--- xfce4-sensors-plugin/trunk/src/actions.h 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/actions.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/callbacks.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/callbacks.c 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/callbacks.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/callbacks.h
===================================================================
--- xfce4-sensors-plugin/trunk/src/callbacks.h 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/callbacks.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/interface.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/interface.c 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/interface.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/interface.h
===================================================================
--- xfce4-sensors-plugin/trunk/src/interface.h 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/interface.h 2008-10-05 17:32:34 UTC (rev 5516)
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
+ *
+ * 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 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.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
Modified: xfce4-sensors-plugin/trunk/src/main.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/main.c 2008-10-05 16:01:03 UTC (rev 5515)
+++ xfce4-sensors-plugin/trunk/src/main.c 2008-10-05 17:32:34 UTC (rev 5516)
@@ -27,27 +27,81 @@
#include <string.h>
+/* #ifdef HAVE_CONFIG_H */
+ #include <config.h>
+/* #endif */
+
+#include <sensors-interface-common.h>
+#include <sensors-interface.h>
+#include <types.h>
+
void
print_usage ()
{
- printf (_("Xfce4 Sensors -- \n"
+ printf (_("Xfce4 Sensors %s\n"
"Displays information about your sensors and ACPI.\n"
"Synopsis: \n"
" xfce4-sensors options\n"
"where options are one or more of the following:\n"
" -h, --help Print this help dialog.\n"
"\n"
- "This program is published under the GPL v2.\n")
+ "This program is published under the GPL v2.\n"), PACKAGE_VERSION
);
}
int
main (int argc, char **argv)
{
+ t_sensors_dialog *sd;
+ GtkWidget *dlg, *header, *vbox, *notebook;
+ t_sensors *sensors;
+
if ( argc > 1 && (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-h")==0) )
{
print_usage ();
return 0;
}
+ /* initialize */
+ sensors = sensors_new (NULL);
+ sd->sensors = sensors;
+
+ sd = g_new0 (t_sensors_dialog, 1);
+
+ /* start and populate */
+ dlg = (GtkWidget *) gtk_dialog_new_with_buttons (_("Xfce 4 Sensors Viewer"),
+ NULL, // anciently: GTK_WINDOW(gtk_get_toplevel(plugin));
+ GTK_DIALOG_NO_SEPARATOR, // anciently: | GTK_DIALOG_DESTROY_WITH_PARENT
+ GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL);
+
+ gtk_container_set_border_width (GTK_CONTAINER (dlg), 2);
+
+ header = (GtkWidget *) xfce_create_header (NULL, _("View sensor values"));
+ gtk_widget_set_size_request (GTK_BIN (header)->child, -1, 32);
+ gtk_container_set_border_width (GTK_CONTAINER (header), BORDER-2);
+ gtk_widget_show (header);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), header,
+ FALSE, TRUE, 0);
+
+ vbox = GTK_DIALOG (dlg)->vbox;
+
+ sd->dialog = dlg;
+
+ sd->myComboBox = gtk_combo_box_new_text();
+
+ init_widgets (sd);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX(sd->myComboBox), 0);
+
+ notebook = gtk_notebook_new ();
+
+ gtk_box_pack_start (GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
+ gtk_widget_show(notebook);
+
+ add_sensors_frame (notebook, sd);
+
+ /* show window and run forever */
+ gtk_main();
+
+ return 0;
}
More information about the Goodies-commits
mailing list