[Goodies-commits] r5922 - in xfce4-sensors-plugin/trunk: . include lib panel-plugin src
Fabian Nowak
timystery at xfce.org
Sun Nov 2 20:42:26 CET 2008
Author: timystery
Date: 2008-11-02 19:42:26 +0000 (Sun, 02 Nov 2008)
New Revision: 5922
Modified:
xfce4-sensors-plugin/trunk/Makefile.am
xfce4-sensors-plugin/trunk/include/sensors-interface.h
xfce4-sensors-plugin/trunk/lib/Makefile.am
xfce4-sensors-plugin/trunk/lib/hddtemp.c
xfce4-sensors-plugin/trunk/lib/sensors-interface.c
xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c
xfce4-sensors-plugin/trunk/src/callbacks.c
xfce4-sensors-plugin/trunk/src/interface.c
xfce4-sensors-plugin/trunk/src/main.c
Log:
- lots of changes to get netcat working
- improvements in stand-alone application such as user-interface and command-line
- added new helper files and modified makefile.am accordingly
- moved functions from panel to library
Modified: xfce4-sensors-plugin/trunk/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/Makefile.am 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/Makefile.am 2008-11-02 19:42:26 UTC (rev 5922)
@@ -28,6 +28,7 @@
COPYING \
ChangeLog \
INSTALL \
+ LICENSE \
NEWS \
README \
TODO \
Modified: xfce4-sensors-plugin/trunk/include/sensors-interface.h
===================================================================
--- xfce4-sensors-plugin/trunk/include/sensors-interface.h 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/include/sensors-interface.h 2008-11-02 19:42:26 UTC (rev 5922)
@@ -26,8 +26,14 @@
/* Local includes */
#include "sensors-interface-common.h"
+/* Initializing and filling functions */
void fill_gtkTreeStore (GtkTreeStore *model, t_chip *chip, t_tempscale scale);
+void init_widgets (t_sensors_dialog *sd);
+
+void reload_listbox (t_sensors_dialog *sd);
+
+/* GUI builder functions */
void add_sensor_settings_box ( GtkWidget * vbox, t_sensors_dialog * sd);
void add_type_box (GtkWidget * vbox, t_sensors_dialog * sd);
@@ -36,7 +42,10 @@
void add_sensors_frame (GtkWidget * notebook, t_sensors_dialog * sd);
-void init_widgets (t_sensors_dialog *sd);
+/* Callbacks */
+//void temperature_unit_change (GtkWidget *widget, t_sensors_dialog *sd);
+
+
#endif /* XFCE4_SENSORS_INTERFACE_H */
Modified: xfce4-sensors-plugin/trunk/lib/Makefile.am
===================================================================
--- xfce4-sensors-plugin/trunk/lib/Makefile.am 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/lib/Makefile.am 2008-11-02 19:42:26 UTC (rev 5922)
@@ -82,6 +82,9 @@
# -DG_LOG_DOMAIN=\"xfce4-sensors-plugin\" \
# -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+EXTRA_DIST = \
+ helpers.c
+
DISTCLEANFILES =
##
Modified: xfce4-sensors-plugin/trunk/lib/hddtemp.c
===================================================================
--- xfce4-sensors-plugin/trunk/lib/hddtemp.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/lib/hddtemp.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -43,7 +43,9 @@
#include <gtk/gtkstock.h> */
/* Global includes */
+#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
+#endif
/* #include <stdio.h> */
#include <stdlib.h>
#include <string.h>
@@ -52,7 +54,31 @@
#include <unistd.h>
+#ifdef HAVE_NETCAT
+#include "helpers.c"
+# ifndef NETCAT_PATH
+# define NETCAT_PATH "/bin/netcat"
+# endif
+
+# ifndef HDDTEMP_PORT
+# define HDDTEMP_PORT "7634"
+# endif
+
+# define DOUBLE_DELIMITER "||"
+# define SINGLE_DELIMITER "|"
+#endif
+
#ifdef HAVE_LIBNOTIFY
+void
+notification_suppress_messages (NotifyNotification *n, gchar *action, gpointer *data)
+{
+ if (strcmp(action, "confirmed")!=0)
+ return;
+
+ /* FIXME: Use channels or propagate private object or use static global variable */
+}
+
+
void quick_message_notify (gchar *message)
{
NotifyNotification *nn;
@@ -66,7 +92,13 @@
if (!notify_is_initted())
notify_init(PACKAGE); /* NOTIFY_APPNAME */
- nn = notify_notification_new(summary, body, icon, NULL);
+ nn = notify_notification_new (summary, body, icon, NULL);
+ /* FIXME: Use channels or propagate private object or use static global variable */
+ //notify_notification_add_action (nn,
+ //"confirmed",
+ //_("Don't show this message again"),
+ //(NotifyActionCallback) notification_suppress_messages,
+ //NULL);
notify_notification_show(nn, &error);
}
#else
@@ -101,20 +133,7 @@
TRACE ("leaves quick_message");
}
-#endif
-
-void quick_message (gchar *message)
-{
-#ifdef HAVE_LIBNOTIFY
- quick_message_notify (message);
-#else
- quick_message_dialog (message);
-#endif
-}
-
-
-
gboolean quick_message_with_checkbox (gchar *message, gchar *checkboxtext) {
GtkWidget *dialog, *checkbox; /*, *label; */
@@ -145,9 +164,64 @@
return is_active;
}
+#endif
+void quick_message (gchar *message)
+{
+#ifdef HAVE_LIBNOTIFY
+ quick_message_notify (message);
+#else
+ quick_message_dialog (message);
+#endif
+}
+
+
+#ifdef HAVE_NETCAT
void
+read_disks_netcat (t_chip *chip)
+{
+ char *stdoutput, *stderrput, *cmdline, *tmp, *tmp2, *tmp3;
+ gboolean result;
+ gint exit_status = 0;
+ GError *error = NULL;
+
+ t_chipfeature *cf;
+
+ cmdline = g_strdup_printf ("%s localhost %s", NETCAT_PATH, HDDTEMP_PORT);
+ //g_printf("cmdline=%s\n", cmdline);
+
+ result = g_spawn_command_line_sync ( (const gchar*) cmdline,
+ &stdoutput, &stderrput, &exit_status, &error);
+
+ if (!result)
+ return;
+
+ //g_printf("stdouput=%s\n", stdoutput);
+
+ tmp = str_split (stdoutput, DOUBLE_DELIMITER);
+ do {
+ //g_printf ("Found token: %s\n", tmp);
+ cf = g_new(t_chipfeature, 1);
+
+ tmp2 = g_strdup (tmp);
+ tmp3 = strtok (tmp2, SINGLE_DELIMITER);
+ cf->devicename = g_strdup(tmp3);
+ tmp3 = strtok (NULL, SINGLE_DELIMITER);
+ cf->name = g_strdup(tmp3);
+
+ g_ptr_array_add(chip->chip_features, cf);
+ chip->num_features++;
+
+ g_free (tmp2);
+ }
+ while ( (tmp = str_split(NULL, DOUBLE_DELIMITER)) );
+
+ g_free (stdoutput);
+}
+
+#else
+void
read_disks_fallback (t_chip *chip)
{
GError *error;
@@ -213,8 +287,8 @@
TRACE ("leaves read_disks_linux26");
}
+#endif
-
void
remove_unmonitored_drives (t_chip *chip, gboolean *suppressmessage)
{
@@ -326,10 +400,14 @@
/* Note: This is actually supposed to be carried out by ifdef HAVE_LINUX
and major/minor number stuff from compile time*/
+#ifdef HAVE_NETCAT
+ read_disks_netcat (chip);
+#else
if (strcmp(p_uname->sysname, "Linux")==0 && major>=5)
read_disks_linux26 (chip);
else
read_disks_fallback (chip); /* hopefully, that's a safe variant */
+#endif
g_free(p_uname);
@@ -355,12 +433,17 @@
get_hddtemp_value (char* disk, gboolean *suppressmessage)
{
gchar *standard_output, *standard_error;
- gchar *cmd_line, *msg_text, *checktext;
+ gchar *cmd_line, *msg_text;
+#ifndef HAVE_LIBNOTIFY
+ gchar *checktext;
+#endif
gint exit_status=0;
double value;
gboolean result, nevershowagain;
GError *error;
+ gchar *tmp, *tmp2, *tmp3;
+
if (suppressmessage!=NULL)
nevershowagain = *suppressmessage;
else
@@ -368,14 +451,45 @@
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);
+#ifdef HAVE_NETCAT
+ exit_status = 1; // assume error by default
+ cmd_line = g_strdup_printf ( "%s localhost %s", NETCAT_PATH, HDDTEMP_PORT);
+ result = g_spawn_command_line_sync ( (const gchar*) cmd_line,
+ &standard_output, &standard_error, &exit_status, NULL);
+ error = g_new(GError, 1);
+ tmp3 = "-255";
+ tmp = str_split (standard_output, DOUBLE_DELIMITER);
+ do {
+ //g_printf ("Found token: %s for disk %s\n", tmp, disk);
+ tmp2 = g_strdup (tmp);
+ tmp3 = strtok (tmp2, SINGLE_DELIMITER); // device name
+ if (strcmp(tmp3, disk)==0)
+ {
+ tmp3 = strtok(NULL, SINGLE_DELIMITER); // name
+ tmp3 = strdup(strtok(NULL, SINGLE_DELIMITER)); // value
+ // tmp3 = strtok(NULL, SINGLE_DELIMITER); // temperature unit
+ exit_status = 0;
+ g_free(error);
+ error = NULL;
+ g_free (tmp2);
+ break;
+ }
+ g_free (tmp2);
+ }
+ while ( (tmp = str_split(NULL, DOUBLE_DELIMITER)) );
- msg_text = NULL;
+ g_free(standard_output);
+ standard_output = tmp3;
+#else
error = NULL;
+ cmd_line = g_strdup_printf ( "%s -n -q %s", PATH_HDDTEMP, disk);
result = g_spawn_command_line_sync ( (const gchar*) cmd_line,
&standard_output, &standard_error, &exit_status, &error);
+#endif
+ msg_text = NULL; // wonder if this is still necessary
+
DBG ("Exit code %d on %s with stdout of %s.\n", exit_status, disk, standard_output);
/* filter those with no sensors out */
@@ -398,9 +512,14 @@
"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);
+
+#ifdef HAVE_LIBNOTIFY
+ quick_message_notify (msg_text);
+ nevershowagain = FALSE;
+#else
checktext = g_strdup(_("Suppress this message in future"));
- quick_message (msg_text);
- nevershowagain = FALSE; //quick_message_with_checkbox(msg_text, checktext);
+ nevershowagain = quick_message_with_checkbox(msg_text, checktext);
+#endif
if (suppressmessage!=NULL)
*suppressmessage = nevershowagain;
@@ -424,8 +543,13 @@
if (!nevershowagain) {
msg_text = g_strdup_printf (_("An error occurred when executing"
" \"%s\":\n%s"), cmd_line, error->message);
+#ifdef HAVE_LIBNOTIFY
+ quick_message_notify (msg_text);
+ nevershowagain = FALSE;
+#else
checktext = g_strdup(_("Suppress this message in future"));
nevershowagain = quick_message_with_checkbox (msg_text, checktext);
+#endif
if (suppressmessage!=NULL)
*suppressmessage = nevershowagain;
@@ -452,6 +576,9 @@
g_free (standard_output);
g_free (standard_error);
g_free (msg_text);
+#ifndef HAVE_LIBNOTIFY
+ g_free (checktext);
+#endif
TRACE ("leaves get_hddtemp_value");
Modified: xfce4-sensors-plugin/trunk/lib/sensors-interface.c
===================================================================
--- xfce4-sensors-plugin/trunk/lib/sensors-interface.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/lib/sensors-interface.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -386,3 +386,28 @@
TRACE ("leaves init_widgets");
}
+
+
+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");
+}
Modified: xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/panel-plugin/sensors-plugin.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -1015,33 +1015,6 @@
}
-
-
-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");
-}
-
-
void
temperature_unit_change (GtkWidget *widget, t_sensors_dialog *sd)
{
Modified: xfce4-sensors-plugin/trunk/src/callbacks.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/callbacks.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/src/callbacks.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -160,5 +160,20 @@
maximum_changed (GtkCellRendererText *cellrenderertext, gchar *path_str,
gchar *new_value, t_sensors_dialog *sd) {}
+
void
-temperature_unit_change (GtkWidget *widget, t_sensors_dialog *sd) {}
+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 */
+
+ reload_listbox (sd);
+
+ TRACE ("laeves temperature_unit_change ");
+}
+
+
Modified: xfce4-sensors-plugin/trunk/src/interface.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/interface.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/src/interface.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id:$ */
/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
*
@@ -80,12 +80,16 @@
gtk_combo_box_set_active (GTK_COMBO_BOX(sd->myComboBox), 0);
- notebook = gtk_notebook_new ();
+ /* 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_sensors_frame (notebook, sd); */
+ add_type_box(vbox, sd);
+ add_sensor_settings_box(vbox, sd);
+ add_temperature_unit_box(vbox, sd);
+ gtk_widget_show_all (vbox);
g_signal_connect (dlg, "response",
G_CALLBACK(on_main_window_response), sd);
Modified: xfce4-sensors-plugin/trunk/src/main.c
===================================================================
--- xfce4-sensors-plugin/trunk/src/main.c 2008-11-02 18:20:06 UTC (rev 5921)
+++ xfce4-sensors-plugin/trunk/src/main.c 2008-11-02 19:42:26 UTC (rev 5922)
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id:$ */
/* Copyright 2008 Fabian Nowak (timystery at arcor.de)
*
@@ -41,6 +41,18 @@
#include "interface.h"
void
+print_license ()
+{
+ printf (_("Xfce4 Sensors %s\n"
+ "This program is published under the GPL v2.\n"
+ "The license text can be found inside the program's source archive "
+ "or under /usr/share/apps/LICENSES/GPL_V2 or at "
+ "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n" ), PACKAGE_VERSION
+ );
+}
+
+
+void
print_usage ()
{
printf (_("Xfce4 Sensors %s\n"
@@ -48,12 +60,21 @@
"Synopsis: \n"
" xfce4-sensors options\n"
"where options are one or more of the following:\n"
- " -h, --help Print this help dialog.\n"
+ " -h, --help Print this help dialog.\n"
+ " -l, --license Print license information.\n"
+ " -v, --version Print version information.\n"
"\n"
"This program is published under the GPL v2.\n"), PACKAGE_VERSION
);
}
+
+void
+print_version ()
+{
+ printf (_("Xfce4 Sensors %s\n"), PACKAGE_VERSION);
+}
+
int
main (int argc, char **argv)
{
@@ -68,6 +89,16 @@
print_usage ();
return 0;
}
+ else if ( argc > 1 && (strcmp(argv[1], "--license")==0 || strcmp(argv[1], "-l")==0) )
+ {
+ print_license ();
+ return 0;
+ }
+ else if ( argc > 1 && (strcmp(argv[1], "--version")==0 || strcmp(argv[1], "-v")==0) )
+ {
+ print_version ();
+ return 0;
+ }
/* start the Gtk engine */
gtk_init (&argc, &argv);
More information about the Goodies-commits
mailing list