[Goodies-commits] r3238 - xfce4-cpugraph-plugin/trunk/panel-plugin

ludovic mercier lidiriel at xfce.org
Thu Sep 20 09:54:24 CEST 2007


Author: lidiriel
Date: 2007-09-20 07:54:24 +0000 (Thu, 20 Sep 2007)
New Revision: 3238

Modified:
   xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.c
   xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.h
Log:
Add a new advanced propertie : assoiated command
by default is "xterm top". This commadn is launched when you click on the graph.

Modified: xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.c
===================================================================
--- xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.c	2007-09-19 05:26:28 UTC (rev 3237)
+++ xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.c	2007-09-20 07:54:24 UTC (rev 3238)
@@ -78,6 +78,7 @@
 
     base->m_TimeScale = 0;
     base->m_Frame = 0;
+    base->m_AssociateCommand = "xterm top";
     base->m_ColorMode = 0;
     base->m_Mode = 0;
 
@@ -105,6 +106,10 @@
             base->m_Frame =
                 xfce_rc_read_int_entry (rc, "Frame", base->m_Frame);
 
+            if (value = xfce_rc_read_entry (rc, "AssociateCommand", base->m_AssociateCommand)) {
+              base->m_AssociateCommand = g_strdup(value);
+            }
+
             base->m_ColorMode =
                 xfce_rc_read_int_entry (rc, "ColorMode", base->m_ColorMode);
 
@@ -179,6 +184,8 @@
 
     xfce_rc_write_int_entry (rc, "Frame", base->m_Frame);
 
+    xfce_rc_write_entry (rc, "AssociateCommand", base->m_AssociateCommand ? base->m_AssociateCommand : "");
+
     xfce_rc_write_int_entry (rc, "ColorMode", base->m_ColorMode);
 
     g_snprintf (value, 8, "#%02X%02X%02X", base->m_ForeGround1.red >> 8,
@@ -221,9 +228,13 @@
     gtk_widget_show (frame);
     gtk_container_add (GTK_CONTAINER (ebox), frame);
 
+    xfce_panel_plugin_add_action_widget (plugin, ebox);
+    g_signal_connect (ebox, "button-press-event", G_CALLBACK (LaunchCommand), base);
+    
     base->m_DrawArea = gtk_drawing_area_new ();
     gtk_widget_set_app_paintable (base->m_DrawArea, TRUE);
     gtk_widget_show (base->m_DrawArea);
+        
     gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (base->m_DrawArea));
 
     xfce_panel_plugin_add_action_widget (plugin, base->m_DrawArea);
@@ -419,6 +430,7 @@
     gtk_size_group_add_widget (sg, op->m_TimeScale);
 
     /* Frame */
+
     hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER));
     gtk_widget_show (GTK_WIDGET (hbox));
     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), FALSE, FALSE, 0);
@@ -437,6 +449,23 @@
     gtk_widget_show (GTK_WIDGET (vbox2));
     gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
 
+    /* Associate Command */
+
+    hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER));
+    gtk_widget_show (GTK_WIDGET (hbox));
+   	gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), FALSE, FALSE, 0);
+    label = gtk_label_new (_("Associated command :"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+    gtk_size_group_add_widget (sg, label);
+    gtk_widget_show (label);
+    gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label), FALSE, FALSE, 0);
+    op->m_AssociateCommand = gtk_entry_new ();
+    gtk_entry_set_max_length (GTK_ENTRY(op->m_AssociateCommand), 32);
+    gtk_entry_set_text (GTK_ENTRY(op->m_AssociateCommand), base->m_AssociateCommand);
+    gtk_widget_show (op->m_AssociateCommand);
+    gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (op->m_AssociateCommand), FALSE, FALSE, 0);
+    g_signal_connect (op->m_AssociateCommand, "changed", G_CALLBACK (AssociateCommandChange), base);
+
     /* Foreground 1 */
 
     hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER));
@@ -1079,6 +1108,27 @@
 }
 
 void
+AssociateCommandChange (GtkEntry *entry, CPUGraph * base)
+{
+    base->m_AssociateCommand = g_strdup (gtk_entry_get_text (entry));
+}
+
+gboolean
+LaunchCommand(GtkWidget *w,GdkEventButton *event, CPUGraph *base)
+{
+    if(event->button == 1){
+        GString *cmd;
+        if (strlen(base->m_AssociateCommand) == 0) {
+            return;
+        }
+        cmd = g_string_new (base->m_AssociateCommand);
+        xfce_exec (cmd->str, FALSE, FALSE, NULL);
+        g_string_free (cmd, TRUE);
+    }
+    return FALSE;
+}
+
+void
 TimeScaleChange (GtkToggleButton * button, CPUGraph * base)
 {
     base->m_TimeScale = gtk_toggle_button_get_active (button);

Modified: xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.h
===================================================================
--- xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.h	2007-09-19 05:26:28 UTC (rev 3237)
+++ xfce4-cpugraph-plugin/trunk/panel-plugin/cpu.h	2007-09-20 07:54:24 UTC (rev 3238)
@@ -35,6 +35,7 @@
 	GtkWidget *m_Height;
 	GtkWidget *m_GraphFrame;
 	GtkWidget *m_TimeScale;
+	GtkWidget *m_AssociateCommand;
 
 	GtkWidget *m_FG1;
 	GtkWidget *m_FG2;
@@ -75,6 +76,7 @@
    	int m_Mode; // Eventual mode of the plugin.
 	int m_ColorMode;
 	int m_Frame;
+	gchar  * m_AssociateCommand;
 
    	GdkColor m_ForeGround1; // Inactive color.
    	GdkColor m_ForeGround2; // Active color.
@@ -122,6 +124,8 @@
 void ApplyChanges (CPUGraph *base);
 void FrameChange (GtkToggleButton *button, CPUGraph *base);
 void TimeScaleChange (GtkToggleButton *button, CPUGraph *base);
+void AssociateCommandChange(GtkEntry *entry, CPUGraph *base);
 void ColorModeChange (GtkOptionMenu *om, CPUGraph *base);
+gboolean LaunchCommand (GtkWidget *w, GdkEventButton *event, CPUGraph *base);
 
 #endif




More information about the Goodies-commits mailing list