[Goodies-commits] r1761 - in xfce4-genmon-plugin/trunk: . panel-plugin scripts

Julien Devemy jujucece at xfce.org
Thu Jul 13 10:50:27 CEST 2006


Author: jujucece
Date: 2006-07-13 08:50:25 +0000 (Thu, 13 Jul 2006)
New Revision: 1761

Added:
   xfce4-genmon-plugin/trunk/scripts/monBat
   xfce4-genmon-plugin/trunk/scripts/monCPU
   xfce4-genmon-plugin/trunk/scripts/monTime
   xfce4-genmon-plugin/trunk/scripts/monUSB
   xfce4-genmon-plugin/trunk/scripts/monWIFI
Modified:
   xfce4-genmon-plugin/trunk/AUTHORS
   xfce4-genmon-plugin/trunk/README
   xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.c
   xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.h
   xfce4-genmon-plugin/trunk/panel-plugin/main.c
Log:
New version of genmon which can display icon, text, tooltip, bar
and a button, if the command returns a special XML string.


Modified: xfce4-genmon-plugin/trunk/AUTHORS
===================================================================
--- xfce4-genmon-plugin/trunk/AUTHORS	2006-07-12 22:02:00 UTC (rev 1760)
+++ xfce4-genmon-plugin/trunk/AUTHORS	2006-07-13 08:50:25 UTC (rev 1761)
@@ -1 +1,2 @@
 Roger Seguin <roger_seguin at msn.com>
+Julien Devemy <jujucece at gmail.com>

Modified: xfce4-genmon-plugin/trunk/README
===================================================================
--- xfce4-genmon-plugin/trunk/README	2006-07-12 22:02:00 UTC (rev 1760)
+++ xfce4-genmon-plugin/trunk/README	2006-07-13 08:50:25 UTC (rev 1761)
@@ -17,17 +17,21 @@
 	- make install  (as root)
 	
 You should then end up with:
-        libgenmon.a   libgenmon.la  libgenmon.so
-installed in <XFce4InstallationDir>/lib/xfce4/panel-plugins/
+        xfce4-genmon-plugin
+installed in <XFce4InstallationDir>/libexec/xfce4/panel-plugins/
+and
+        genmon.desktop
+installed in <XFce4InstallationDir>/share/xfce4/panel-plugins/
 
-
 3 -	Testing
+	-------
 
 Use GenMon for invoking the provided "datetime" shell script.
 Then the current date/time should be continuously updated in your panel.
 
 
 4 -	Extra
+	-----
 
 A simple Perl script, disktemp, that retrieves the temperature of a disk
 using the smartmontools is provided.
@@ -42,8 +46,50 @@
 If this works, you should be able to use GenMon for continually monitoring
 your disk temperature.
 
+5 -	New Features
+	-----------
 
-5 -	Bugs
+The new version of genmon plugin can also display an icon (which can be a
+clickable icon), a tooltip, a text and a bar.
+
+To display these items, the script called by genmon should return a simple
+XML string.
+
+The XML tags which can be used are :
+<txt>Text to display</txt>
+<img>Path to the image to display</img>
+<tool>Tooltip text</tool>
+<bar>Pourcentage to display in the bar</img>
+<click>The command to be executed by clicking on the image</click>
+
+If None of the tags are detected in the result of the command, the plugin
+returns to its original behaviour (displaying the result of the command).
+
+No tag is mandatory: for instance, you can display a tooltip without and image...
+
+Here's a simple example of a plugin displaying the Temp of the CPU in the panel
+(with an icon) and the Freq in a Tooltip:
+
+#!/bin/bash
+echo "<img>/usr/share/icons/Bluecurve/16x16/apps/gnome-monitor.png</img>"
+
+declare -i cpuFreq
+cpuFreq=$(cat /proc/cpuinfo | grep "cpu MHz" | sed 's/\ \ */ /g' | cut -f3 -d" " | cut -f1 -d".")
+
+if [ $cpuFreq -ge 1000 ]
+then
+  cpu=$(echo $cpuFreq | cut -c1).$(echo $cpuFreq | cut -c2)GHz
+else
+  cpu=${cpuFreq}MHz
+fi
+echo "<txt>"$(cat /proc/acpi/thermal_zone/THM/temperature | sed 's/\ \ */ /g' | cut -f2 -d" ")" C</txt>"
+echo "<tool>Freq: "$cpu"</tool>"
+
+PS: Depending on your configuration, you should change the image path.
+
+You can find more scripts in scripts/mon*. 
+
+6 -	Bugs
 	----
 If you find a bug, fix it, then tell me how you did it :-)
 
@@ -51,3 +97,5 @@
 Enjoy!
 Roger Seguin
 roger_seguin at msn.com
+
+Julien Devemy <jujucece at gmail.com>

Modified: xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.c
===================================================================
--- xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.c	2006-07-12 22:02:00 UTC (rev 1760)
+++ xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.c	2006-07-13 08:50:25 UTC (rev 1761)
@@ -2,6 +2,7 @@
 // Spawn - Spawn a process and capture its output
 // Copyright (c) 2004 Roger Seguin <roger_seguin at msn.com>
 //                                      <http://rmlx.dyndns.org>
+// Copyright (c) 2006 Julien Devemy <jujucece at gmail.com>
 
 /*  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -142,7 +143,7 @@
 
 /**********************************************************************/
 int genmon_Spawn (char *const argv[], char *const p_pcOutput,
-		  const size_t p_BufferSize)
+		  const size_t p_BufferSize, const int wait)
 /**********************************************************************/
  /* Spawn a command and capture its output */
  /* Return 0 on success, otherwise copy stderr into the output string and
@@ -208,24 +209,27 @@
 	goto End;
     }
 
-    /* Read stdout/stderr pipes' read-ends */
-    for (i = 0; i < OUT_ERR; i++) {
-	aoPoll[i].fd = aaiPipe[i][RD];
-	aoPoll[i].events = POLLIN;
-	aoPoll[i].revents = 0;
+    if (wait == 1)
+    {
+      /* Read stdout/stderr pipes' read-ends */
+      for (i = 0; i < OUT_ERR; i++) {
+  	aoPoll[i].fd = aaiPipe[i][RD];
+	  aoPoll[i].events = POLLIN;
+	  aoPoll[i].revents = 0;
+      }
+      poll (aoPoll, OUT_ERR, ~0);
+      for (i = 0; i < OUT_ERR; i++)
+	  if (aoPoll[i].revents & POLLIN)
+	      break;
+      if (i < OUT_ERR)
+	  read (aaiPipe[i][RD], p_pcOutput, BufSafeSize);
+      fError = (i != OUT);
+
+      /* Remove trailing carriage return if any */
+      if (p_pcOutput[(i = strlen (p_pcOutput) - 1)] == '\n')
+  	p_pcOutput[i] = 0;
     }
-    poll (aoPoll, OUT_ERR, ~0);
-    for (i = 0; i < OUT_ERR; i++)
-	if (aoPoll[i].revents & POLLIN)
-	    break;
-    if (i < OUT_ERR)
-	read (aaiPipe[i][RD], p_pcOutput, BufSafeSize);
-    fError = (i != OUT);
 
-    /* Remove trailing carriage return if any */
-    if (p_pcOutput[(i = strlen (p_pcOutput) - 1)] == '\n')
-	p_pcOutput[i] = 0;
-
   End:
     /* Close created pipes */
     for (i = 0; i < OUT_ERR; i++)
@@ -238,7 +242,7 @@
 
 /**********************************************************************/
 int genmon_SpawnCmd (const char *const p_pcCmdLine, char *const p_pcOutput,
-		     const size_t p_BufferSize)
+		     const size_t p_BufferSize, const int wait)
 /**********************************************************************/
  /* Spawn a command and capture its output */
  /* Return 0 on success, otherwise copy stderr into the output string and
@@ -257,7 +261,7 @@
 	return (-1);
 
     /* Spawn the command and free allocated memory */
-    status = genmon_Spawn (argv, p_pcOutput, p_BufferSize);
+    status = genmon_Spawn (argv, p_pcOutput, p_BufferSize, wait);
     while (argc-- > 0)
 	free (argv[argc]);
     free (argv);

Modified: xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.h
===================================================================
--- xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.h	2006-07-12 22:02:00 UTC (rev 1760)
+++ xfce4-genmon-plugin/trunk/panel-plugin/cmdspawn.h	2006-07-13 08:50:25 UTC (rev 1761)
@@ -3,6 +3,7 @@
  *  Spawn - Spawn a process and capture its output
  *  Copyright (c) 2004 Roger Seguin <roger_seguin at msn.com>
  *  					<http://rmlx.dyndns.org>
+ *  Copyright (c) 2006 Julien Devemy <jujucece at gmail.com>
  *  
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -37,10 +38,10 @@
 #endif
     int             genmon_Spawn (char *const argv[],
 				  char *const StdOutCapture,
-				  const size_t StdOutSize);
+				  const size_t StdOutSize, const int wait);
     int             genmon_SpawnCmd (const char *const cmdline,
 				     char *const StdOutCapture,
-				     const size_t StdOutSize);
+				     const size_t StdOutSize, const int wait);
     /* Spawn the given command and capture its output (stdout) */
     /* Return 0 on success, otherwise copy stderr into the output string
        and return -1 */

Modified: xfce4-genmon-plugin/trunk/panel-plugin/main.c
===================================================================
--- xfce4-genmon-plugin/trunk/panel-plugin/main.c	2006-07-12 22:02:00 UTC (rev 1760)
+++ xfce4-genmon-plugin/trunk/panel-plugin/main.c	2006-07-13 08:50:25 UTC (rev 1761)
@@ -2,6 +2,7 @@
  *  Generic Monitor plugin for the Xfce4 panel
  *  Copyright (c) 2004 Roger Seguin <roger_seguin at msn.com>
  *  					<http://rmlx.dyndns.org>
+ *  Copyright (c) 2006 Julien Devemy <jujucece at gmail.com>
  *  
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -43,7 +44,7 @@
 
 
 #define PLUGIN_NAME	"GenMon"
-#define BORDER          8
+#define BORDER          2
 
 
 typedef GtkWidget *Widget_t;
@@ -67,8 +68,14 @@
     /* Plugin monitor */
     Widget_t        wEventBox;
     Widget_t        wBox;
+    Widget_t        wImgBox;
     Widget_t        wTitle;
     Widget_t        wValue;
+    Widget_t        wImage;
+    Widget_t        wBar;
+    Widget_t        wButton;
+    Widget_t        wImgButton;
+    char            onClickCmd[128];
 } monitor_t;
 
 typedef struct genmon_t {
@@ -77,10 +84,21 @@
     struct conf_t   oConf;
     struct monitor_t
                     oMonitor;
-    char            acValue[32];	/* Commandline resulting string */
+    char            acValue[256];	/* Commandline resulting string */
 } genmon_t;
 
+	/**************************************************************/
+static void ExecOnClickCmd (Widget_t p_wSc, void *p_pvPlugin)
+	/* Execute the onClick Command */
+{
+  struct genmon_t *poPlugin = (genmon_t *) p_pvPlugin;
+  struct monitor_t *poMonitor = &(poPlugin->oMonitor);
+  char result[256];
 
+  genmon_SpawnCmd (poMonitor->onClickCmd, result,
+      sizeof (poMonitor->onClickCmd), 0);
+}
+
 	/**************************************************************/
 
 static int DisplayCmdOutput (struct genmon_t *p_poPlugin)
@@ -93,30 +111,133 @@
     struct monitor_t *poMonitor = &(p_poPlugin->oMonitor);
     char            acToolTips[128];
     int             status;
-
+    char  *begin;
+    char  *end;
+    int   newVersion=0;
+    
     if (!s_poToolTips)
-	s_poToolTips = gtk_tooltips_new ();
+      s_poToolTips = gtk_tooltips_new ();
     status = genmon_SpawnCmd (poConf->acCmd, p_poPlugin->acValue,
-			      sizeof (p_poPlugin->acValue));
+      sizeof (p_poPlugin->acValue), 1);
     if (status == -1)
-	return (-1);
-    gtk_label_set_text (GTK_LABEL (poMonitor->wValue),
-			p_poPlugin->acValue);
-    sprintf (acToolTips, "%s\n"
-	     "----------------\n"
-	     "%s\n"
-	     "Period (s): %d", poConf->acTitle, poConf->acCmd,
-	     poConf->iPeriod_ms / 1000);
+      return (-1);
+    
+    /* Test if the result is an Image or a Text */
+    begin=strstr(p_poPlugin->acValue, "<img>");
+    end=strstr(p_poPlugin->acValue, "</img>");
+    if ((begin != NULL) && (end != NULL) && (begin < end))
+    {
+      char  buf[256];
+      /* Get the image path */
+      strncpy(buf, begin+5*sizeof(char), end-begin-5*sizeof(char));
+      buf[end-begin-5*sizeof(char)]='\0';
+
+      gtk_image_set_from_file (GTK_IMAGE (poMonitor->wImage), buf);
+      gtk_image_set_from_file (GTK_IMAGE (poMonitor->wImgButton), buf);
+      
+      /* Test if the result has a clickable Image (button) */
+      begin=strstr(p_poPlugin->acValue, "<click>");
+      end=strstr(p_poPlugin->acValue, "</click>");
+      if ((begin != NULL) && (end != NULL) && (begin < end))
+      {
+        char  buf[256];
+        /* Get the command path */
+        strncpy(buf, begin+7*sizeof(char), end-begin-7*sizeof(char));
+        buf[end-begin-7*sizeof(char)]='\0';
+
+        strcpy(poMonitor->onClickCmd, buf);
+        
+        gtk_widget_show (poMonitor->wButton);
+        gtk_widget_show (poMonitor->wImgButton);
+        gtk_widget_hide (poMonitor->wImage);
+      }
+      else
+      {
+        gtk_widget_hide (poMonitor->wButton);
+        gtk_widget_hide (poMonitor->wImgButton);
+        gtk_widget_show (poMonitor->wImage);
+      }
+
+      newVersion=1;
+
+    }
+    else
+      gtk_widget_hide (poMonitor->wImage);
+
+    
+    /* Test if the result is a Text */
+    begin=strstr(p_poPlugin->acValue, "<txt>");
+    end=strstr(p_poPlugin->acValue, "</txt>");
+    if ((begin != NULL) && (end != NULL) && (begin < end))
+    {
+      char  buf[256];
+      /* Get the text */
+      strncpy(buf, begin+5*sizeof(char), end-begin-5*sizeof(char));
+      buf[end-begin-5*sizeof(char)]='\0';
+      gtk_label_set_text (GTK_LABEL (poMonitor->wValue), buf);
+      gtk_widget_show (poMonitor->wValue);
+
+      newVersion=1;
+
+    }
+    else
+      gtk_widget_hide (poMonitor->wValue);
+
+    /* Test if the result is a Bar */
+    begin=strstr(p_poPlugin->acValue, "<bar>");
+    end=strstr(p_poPlugin->acValue, "</bar>");
+    if ((begin != NULL) && (end != NULL) && (begin < end))
+    {
+      char  buf[256];
+      int value;
+      /* Get the text */
+      strncpy(buf, begin+5*sizeof(char), end-begin-5*sizeof(char));
+      buf[end-begin-5*sizeof(char)]='\0';
+      value=atoi(buf);
+      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(poMonitor->wBar), (float)value/100.0);
+      gtk_widget_show (poMonitor->wBar);
+
+      newVersion=1;
+
+    }
+    else
+      gtk_widget_hide (poMonitor->wBar);
+    
+    if (newVersion == 0)
+    { 
+      gtk_widget_show (poMonitor->wValue);
+      gtk_label_set_text (GTK_LABEL (poMonitor->wValue),
+        p_poPlugin->acValue);
+    }
+    
+    /* Test if a ToolTip is given */
+    begin=strstr(p_poPlugin->acValue, "<tool>");
+    end=strstr(p_poPlugin->acValue, "</tool>");
+    if ((begin != NULL) && (end != NULL) && (begin < end))
+    {
+      strncpy(acToolTips, begin+6, end-begin-6);
+      acToolTips[end-begin-6]='\0';
+    }
+    else
+      sprintf (acToolTips, "%s\n"
+        "----------------\n"
+        "%s\n"
+        "Period (s): %d", poConf->acTitle, poConf->acCmd,
+        poConf->iPeriod_ms / 1000);
+
     gtk_tooltips_set_tip (s_poToolTips, GTK_WIDGET (poMonitor->wEventBox),
-			  acToolTips, 0);
+      acToolTips, 0);
 
     return (0);
+   
 }				/* DisplayCmdOutput() */
 
 	/**************************************************************/
 
 static gboolean SetTimer (void *p_pvPlugin)
 	/* Recurrently update the panel-docked monitor through a timer */
+  /* Warning : should not be called directly (except the 1st time) */
+  /* To avoid multiple timers */
 {
     struct genmon_t *poPlugin = (genmon_t *) p_pvPlugin;
     struct param_t *poConf = &(poPlugin->oConf.oParam);
@@ -124,8 +245,12 @@
     DisplayCmdOutput (poPlugin);
 
     if (poPlugin->iTimerId == 0)
+    {
         poPlugin->iTimerId = g_timeout_add (poConf->iPeriod_ms,
 	        			    (GSourceFunc) SetTimer, poPlugin);
+        return FALSE;
+    }
+
     return TRUE;
 }				/* SetTimer() */
 
@@ -168,7 +293,7 @@
 	poMonitor->wBox = gtk_vbox_new (FALSE, 0);
     gtk_widget_show (poMonitor->wBox);
     gtk_container_set_border_width (GTK_CONTAINER
-				    (poMonitor->wBox), 4);
+				    (poMonitor->wBox), BORDER);
     gtk_container_add (GTK_CONTAINER (poMonitor->wEventBox),
 		       poMonitor->wBox);
 
@@ -178,10 +303,44 @@
     gtk_box_pack_start (GTK_BOX (poMonitor->wBox),
 			GTK_WIDGET (poMonitor->wTitle), FALSE, FALSE, 0);
 
+    /* Create a VBox to put image and text */
+    poMonitor->wImgBox = gtk_vbox_new (FALSE, 0);
+    gtk_widget_show (poMonitor->wImgBox);
+    gtk_container_set_border_width (GTK_CONTAINER
+      (poMonitor->wImgBox), 0);
+    gtk_container_add (GTK_CONTAINER (poMonitor->wBox),
+      poMonitor->wImgBox);
+ 
+    /* Add Image */   
+    poMonitor->wImage = gtk_image_new ();
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wImage), TRUE, FALSE, 0);
+
+    /* Add Button */ 
+    poMonitor->wButton = gtk_button_new ();
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wButton), TRUE, FALSE, 0);
+
+    /* Add Image Button*/   
+    poMonitor->wImgButton = gtk_image_new ();
+    gtk_container_add (GTK_CONTAINER (poMonitor->wButton), poMonitor->wImgButton);
+    gtk_container_set_border_width (GTK_CONTAINER (poMonitor->wButton), 0);
+
+    /* Add Value */
     poMonitor->wValue = gtk_label_new ("");
     gtk_widget_show (poMonitor->wValue);
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wValue), TRUE, FALSE, 0);
+
+    /* Add Bar */   
+    poMonitor->wBar = gtk_progress_bar_new();
     gtk_box_pack_start (GTK_BOX (poMonitor->wBox),
-			GTK_WIDGET (poMonitor->wValue), FALSE, FALSE, 0);
+      GTK_WIDGET (poMonitor->wBar), FALSE, FALSE, 0);
+    /*gtk_widget_show (poMonitor->wBar);*/
+    if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL)
+      gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(poMonitor->wBar), GTK_PROGRESS_BOTTOM_TO_TOP);
+    else
+      gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(poMonitor->wBar), GTK_PROGRESS_LEFT_TO_RIGHT);
 
     return poPlugin;
 }				/* genmon_create_control() */
@@ -388,7 +547,8 @@
     SetCmd (poGUI->wTF_Cmd, poPlugin);
     SetLabel (poGUI->wTF_Title, poPlugin);
     SetMonitorFont (poPlugin);
-    SetTimer (poPlugin);
+    /* Force to regenerate a timer */
+    poPlugin->iTimerId = 0;
 }				/* UpdateConf() */
 
 	/**************************************************************/
@@ -399,7 +559,8 @@
     xfce_info (_("%s %s - Generic Monitor\n"
 	       "Cyclically spawns a script/program, captures its output "
 	       "and displays the resulting string in the panel\n\n"
-	       "(c) 2004 Roger Seguin <roger_seguin at msn.com>"),
+	       "(c) 2004 Roger Seguin <roger_seguin at msn.com>\n"
+	       "(c) 2006 Julien Devemy <jujucece at gmail.com>"),
 	       PACKAGE, VERSION);
 }				/* About() */
 
@@ -440,6 +601,8 @@
     gtk_widget_destroy (dlg);
     xfce_panel_plugin_unblock_menu (genmon->plugin);
     genmon_write_config (genmon->plugin, genmon);
+    /* Do not wait the next timer to update display */
+    DisplayCmdOutput (genmon);
 }
 
 static void genmon_create_options (XfcePanelPlugin *plugin,
@@ -538,7 +701,7 @@
 	poMonitor->wBox = gtk_vbox_new (FALSE, 0);
     gtk_widget_show (poMonitor->wBox);
     gtk_container_set_border_width (GTK_CONTAINER
-				    (poMonitor->wBox), 4);
+				    (poMonitor->wBox), BORDER);
     gtk_container_add (GTK_CONTAINER (poMonitor->wEventBox),
 		       poMonitor->wBox);
 
@@ -548,18 +711,76 @@
     gtk_box_pack_start (GTK_BOX (poMonitor->wBox),
 			GTK_WIDGET (poMonitor->wTitle), FALSE, FALSE, 0);
 
+    /* Create a VBox to put image and text */
+    poMonitor->wImgBox = gtk_vbox_new (FALSE, 0);
+    gtk_widget_show (poMonitor->wImgBox);
+    gtk_container_set_border_width (GTK_CONTAINER
+      (poMonitor->wImgBox), 0);
+    gtk_container_add (GTK_CONTAINER (poMonitor->wBox),
+      poMonitor->wImgBox);
+ 
+    /* Add Image */   
+    poMonitor->wImage = gtk_image_new ();
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wImage), TRUE, FALSE, 0);
+
+    /* Add Button */   
+    poMonitor->wButton = gtk_button_new ();
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wButton), TRUE, FALSE, 0);
+
+    /* Add Image Button*/   
+    poMonitor->wImgButton = gtk_image_new ();
+    gtk_container_add (GTK_CONTAINER (poMonitor->wButton), poMonitor->wImgButton);
+    gtk_container_set_border_width (GTK_CONTAINER (poMonitor->wButton), 0);
+
+     /* Add Value */
     poMonitor->wValue = gtk_label_new ("");
     gtk_widget_show (poMonitor->wValue);
+    gtk_box_pack_start (GTK_BOX (poMonitor->wImgBox),
+      GTK_WIDGET (poMonitor->wValue), TRUE, FALSE, 0);
+
+    /* Add Bar */   
+    poMonitor->wBar = gtk_progress_bar_new();
     gtk_box_pack_start (GTK_BOX (poMonitor->wBox),
-			GTK_WIDGET (poMonitor->wValue), FALSE, FALSE, 0);
-
+      GTK_WIDGET (poMonitor->wBar), FALSE, FALSE, 0);
+    /*gtk_widget_show (poMonitor->wBar);*/
+    if (p_iOrientation == GTK_ORIENTATION_HORIZONTAL)
+      gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(poMonitor->wBar), GTK_PROGRESS_BOTTOM_TO_TOP);
+    else
+      gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(poMonitor->wBar), GTK_PROGRESS_LEFT_TO_RIGHT);
+    
     SetMonitorFont (poPlugin);
 
-    SetTimer (poPlugin);
 }				/* genmon_set_orientation() */
 
 	/**************************************************************/
+static gboolean genmon_set_size (XfcePanelPlugin *plugin, int size, genmon_t *poPlugin)
+      /* Plugin API */
+      /* Set the size of the panel-docked monitor */
+{
 
+  struct monitor_t *poMonitor = &(poPlugin->oMonitor);
+
+  if (xfce_panel_plugin_get_orientation (plugin) ==
+    GTK_ORIENTATION_HORIZONTAL)
+  {
+    if (size>BORDER)
+      gtk_widget_set_size_request(GTK_WIDGET(poMonitor->wBar),
+        8, size-BORDER*2);
+  }
+  else
+  {
+    if (size>BORDER)
+      gtk_widget_set_size_request(GTK_WIDGET(poMonitor->wBar),
+        size-BORDER*2, 8);
+  }
+
+  return TRUE;
+}                       /* genmon_set_size() */
+
+  /**************************************************************/
+
 static void genmon_construct (XfcePanelPlugin *plugin)
 {
     genmon_t *genmon;
@@ -582,12 +803,17 @@
     g_signal_connect (plugin, "orientation-changed", 
                       G_CALLBACK (genmon_set_orientation), genmon);
 
+    g_signal_connect (plugin, "size-changed", G_CALLBACK (genmon_set_size), genmon);
+  
     xfce_panel_plugin_menu_show_about (plugin);
     g_signal_connect (plugin, "about", G_CALLBACK (About), genmon);
 
     xfce_panel_plugin_menu_show_configure (plugin);
     g_signal_connect (plugin, "configure-plugin", 
                       G_CALLBACK (genmon_create_options), genmon);
+
+    g_signal_connect (G_OBJECT (genmon->oMonitor.wButton), "clicked",
+		      G_CALLBACK (ExecOnClickCmd), genmon);
 }
 
 XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (genmon_construct)

Added: xfce4-genmon-plugin/trunk/scripts/monBat
===================================================================
--- xfce4-genmon-plugin/trunk/scripts/monBat	                        (rev 0)
+++ xfce4-genmon-plugin/trunk/scripts/monBat	2006-07-13 08:50:25 UTC (rev 1761)
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+pres0=$(cat /proc/acpi/battery/BAT0/info | grep "present" | sed 's/\ \ */ /g' | cut -f2 -d" ")
+if [ $pres0 != "no" ]
+then
+  max0=$(cat /proc/acpi/battery/BAT0/info | grep "last full capacity" | sed 's/\ \ */ /g' | cut -f4 -d" ")
+  cur0=$(cat /proc/acpi/battery/BAT0/state | grep "remaining capacity" | sed 's/\ \ */ /g' | cut -f3 -d" ")
+  pour0=$(echo "${cur0}00/${max0}" | bc)
+fi
+
+pres1=$(cat /proc/acpi/battery/BAT1/info | grep "present" | sed 's/\ \ */ /g' | cut -f2 -d" ")
+if [ $pres1 != "no" ]
+then
+  max1=$(cat /proc/acpi/battery/BAT1/info | grep "last full capacity" | sed 's/\ \ */ /g' | cut -f4 -d" ")
+  cur1=$(cat /proc/acpi/battery/BAT1/state | grep "remaining capacity" | sed 's/\ \ */ /g' | cut -f3 -d" ")
+  pour1=$(echo "${cur1}00/${max1}" | bc)
+fi
+
+if [ $pres0 == "yes" ]
+then
+  echo "<tool>Bat0:$pour0%"
+else
+  echo "<tool>Bat0:-"
+fi
+
+if [ $pres1 == "yes" ]
+then
+  echo "Bat1:$pour1%"
+else
+  echo "Bat1:-"
+fi
+
+echo "AC:$(cat /proc/acpi/ac_adapter/AC/state | grep state | sed 's/\ \ */ /g' | cut -f2 -d" ")</tool>"
+
+if [ $pres0 == "yes" ] && [ $pres1 == "yes" ]
+then
+  echo "<txt>$pour0%-$pour1%</txt>"
+  pour=$(echo "(${cur0}00+${cur1}00)/(${max0}+${max1})" | bc)
+elif [ $pres0 == "yes" ] && [ $pres1 == "no" ]
+then
+  echo "<txt>$pour0%</txt>"
+  pour=$pour0
+elif [ $pres0 == "no" ] && [ $pres1 == "yes" ]
+then
+  echo "<txt>$pour1%</txt>"
+  pour=$pour1
+else
+  echo "<txt>-%</txt>"
+  pour="0"
+fi
+#echo "<bar>$pour</bar>"
+
+if [ $pour -le 10 ]
+then
+  echo "<img>/usr/local/share/icons/Tango/16x16/status/battery-caution.png</img>"
+else
+  echo "<img>/usr/local/share/icons/Tango/16x16/devices/battery.png</img>"
+fi
+
+
+


Property changes on: xfce4-genmon-plugin/trunk/scripts/monBat
___________________________________________________________________
Name: svn:executable
   + *

Added: xfce4-genmon-plugin/trunk/scripts/monCPU
===================================================================
--- xfce4-genmon-plugin/trunk/scripts/monCPU	                        (rev 0)
+++ xfce4-genmon-plugin/trunk/scripts/monCPU	2006-07-13 08:50:25 UTC (rev 1761)
@@ -0,0 +1,14 @@
+#!/bin/bash
+echo "<img>/usr/local/share/icons/Tango/16x16/apps/utilities-system-monitor.png</img>"
+
+declare -i cpuFreq
+cpuFreq=$(cat /proc/cpuinfo | grep "cpu MHz" | sed 's/\ \ */ /g' | cut -f3 -d" " | cut -f1 -d".")
+
+if [ $cpuFreq -ge 1000 ]
+then
+  cpu=$(echo $cpuFreq | cut -c1).$(echo $cpuFreq | cut -c2)GHz
+else
+  cpu=${cpuFreq}MHz
+fi
+echo "<txt>"$(cat /proc/acpi/thermal_zone/THM/temperature | sed 's/\ \ */ /g' | cut -f2 -d" ")"°C</txt>"
+echo "<tool>Freq: "$cpu"</tool>"


Property changes on: xfce4-genmon-plugin/trunk/scripts/monCPU
___________________________________________________________________
Name: svn:executable
   + *

Added: xfce4-genmon-plugin/trunk/scripts/monTime
===================================================================
--- xfce4-genmon-plugin/trunk/scripts/monTime	                        (rev 0)
+++ xfce4-genmon-plugin/trunk/scripts/monTime	2006-07-13 08:50:25 UTC (rev 1761)
@@ -0,0 +1,4 @@
+#!/bin/bash
+echo "<txt>"$(date +"%a %d/%m/%Y")
+echo "          "$(date +"%H:%M")"</txt>"
+echo "<tool>"$(date +"%A %d %B %Y")"</tool>"


Property changes on: xfce4-genmon-plugin/trunk/scripts/monTime
___________________________________________________________________
Name: svn:executable
   + *

Added: xfce4-genmon-plugin/trunk/scripts/monUSB
===================================================================
--- xfce4-genmon-plugin/trunk/scripts/monUSB	                        (rev 0)
+++ xfce4-genmon-plugin/trunk/scripts/monUSB	2006-07-13 08:50:25 UTC (rev 1761)
@@ -0,0 +1,19 @@
+#!/bin/bash
+ls -l /dev/sda1 >/dev/null 2>&1
+if [ $? == 0 ]
+then
+  grep "/dev/sda1" /etc/mtab >/dev/null 2>&1
+  if [ $? == 0 ]
+  then
+    echo "<img>/usr/local/share/icons/Tango/16x16/actions/gtk-delete.png</img>"
+    echo "<click>umount /dev/sda1</click>"
+    echo "<tool>Click to unmount the USB disk</tool>"
+  else
+    echo "<img>/usr/local/share/icons/Tango/16x16/devices/gnome-dev-harddisk-usb.png</img>"
+    echo "<click>mount /dev/sda1</click>"
+    echo "<tool>Click to mount the USB disk</tool>"
+  fi
+else
+  echo "<img>/usr/local/share/icons/Tango/16x16/actions/add.png</img>"
+  echo "<tool>No USB disk detected</tool>"
+fi


Property changes on: xfce4-genmon-plugin/trunk/scripts/monUSB
___________________________________________________________________
Name: svn:executable
   + *

Added: xfce4-genmon-plugin/trunk/scripts/monWIFI
===================================================================
--- xfce4-genmon-plugin/trunk/scripts/monWIFI	                        (rev 0)
+++ xfce4-genmon-plugin/trunk/scripts/monWIFI	2006-07-13 08:50:25 UTC (rev 1761)
@@ -0,0 +1,17 @@
+#!/bin/bash
+echo "<img>/usr/local/share/icons/Tango/16x16/devices/network-wireless.png</img>"
+
+res1=$(/sbin/ifconfig eth1 | grep inet)
+res2=$(/sbin/iwconfig eth1 | grep unassociated)
+if [ -z "$res2" ] && ! [ -z "$res1" ]
+then
+  echo "<txt>"$(/sbin/iwconfig eth1 | grep "Link Quality" |cut -d "=" -f 2 |cut -d "/" -f 1)"%</txt>"
+  echo "<tool>Essid: "$(/sbin/iwconfig eth1 | grep "ESSID" |cut -d "\"" -f 2)
+  echo "Signal Level: "$(/sbin/iwconfig eth1 | grep "Signal level" |cut -d "=" -f 3)"</tool>"
+  echo "<bar>"$(/sbin/iwconfig eth1 | grep "Link Quality" |cut -d "=" -f 2 |cut -d "/" -f 1)"</bar>"
+else
+  echo "<txt>--%</txt>"
+  echo "<tool>Essid: ???"
+  echo "Signal Level: ???</tool>"
+  echo "<bar>0</bar>"
+fi


Property changes on: xfce4-genmon-plugin/trunk/scripts/monWIFI
___________________________________________________________________
Name: svn:executable
   + *




More information about the Goodies-commits mailing list