[Goodies-commits] r5660 - xfce4-power-manager/trunk/src
Ali Abdallah
aliov at xfce.org
Fri Oct 17 12:42:47 CEST 2008
Author: aliov
Date: 2008-10-17 10:42:47 +0000 (Fri, 17 Oct 2008)
New Revision: 5660
Modified:
xfce4-power-manager/trunk/src/xfpm-dpms-spins.c
xfce4-power-manager/trunk/src/xfpm-dpms.c
xfce4-power-manager/trunk/src/xfpm-spin-button.c
xfce4-power-manager/trunk/src/xfpm-spin-button.h
Log:
Improve DPMS control to allow 0 values and separate dpms on-ac and on-battery settings
Modified: xfce4-power-manager/trunk/src/xfpm-dpms-spins.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-dpms-spins.c 2008-10-17 09:05:40 UTC (rev 5659)
+++ xfce4-power-manager/trunk/src/xfpm-dpms-spins.c 2008-10-17 10:42:47 UTC (rev 5660)
@@ -62,8 +62,13 @@
struct XfpmDpmsSpinsPrivate
{
GtkWidget *spin_1;
+ gint spin_value_1;
+
GtkWidget *spin_2;
+ gint spin_value_2;
+
GtkWidget *spin_3;
+ gint spin_value_3;
};
@@ -117,7 +122,7 @@
label = gtk_label_new(_("Standby after"));
gtk_widget_show(label);
gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,0,1);
- priv->spin_1 = xfpm_spin_button_new_with_range(1,238,1);
+ priv->spin_1 = xfpm_spin_button_new_with_range(0,298,1);
xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),_(" min"));
gtk_widget_show(priv->spin_1);
gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_1,1,2,0,1,GTK_SHRINK,GTK_SHRINK,0,0);
@@ -125,7 +130,7 @@
label = gtk_label_new(_("Suspend after"));
gtk_widget_show(label);
gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,1,2);
- priv->spin_2 = xfpm_spin_button_new_with_range(1,239,1);
+ priv->spin_2 = xfpm_spin_button_new_with_range(0,299,1);
xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),_(" min"));
gtk_widget_show(priv->spin_2);
gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_2,1,2,1,2,GTK_SHRINK,GTK_SHRINK,0,0);
@@ -133,7 +138,7 @@
label = gtk_label_new(_("Turn off after"));
gtk_widget_show(label);
gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,2,3);
- priv->spin_3 = xfpm_spin_button_new_with_range(1,300,1);
+ priv->spin_3 = xfpm_spin_button_new_with_range(0,300,1);
xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),_(" min"));
gtk_widget_show(priv->spin_3);
gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_3,1,2,2,3,GTK_SHRINK,GTK_SHRINK,0,0);
@@ -162,11 +167,24 @@
gint value1,value2,value3;
value1 = gtk_spin_button_get_value(spin_1);
-
value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2));
+ value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3));
- value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3));
-
+ if ( value1 == 0 )
+ {
+ priv->spin_value_1 = 0;
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),_(" disabled"));
+ g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,
+ value1,value2,value3);
+ return;
+ }
+ if ( priv->spin_value_1 == 0 )
+ {
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),_(" min"));
+ if ( priv->spin_value_2 == 0 )
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),value1+1);
+ }
+
if ( value2 <= value1 )
{
value2 = value1 + 1;
@@ -203,6 +221,21 @@
value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3));
+ if ( value2 == 0 )
+ {
+ priv->spin_value_2 = 0;
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),_(" disabled"));
+ g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
+
+ return;
+ }
+ if ( priv->spin_value_2 == 0 )
+ {
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),_(" min"));
+ if ( priv->spin_value_3 == 0 )
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value2+1);
+ }
+
if ( value2 <= value1 )
{
value2 = value1 + 1;
@@ -236,6 +269,20 @@
value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2));
+ if ( value3 == 0 )
+ {
+ priv->spin_value_3 = 0;
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),_(" disabled"));
+ g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3);
+
+ return;
+ }
+
+ if ( priv->spin_value_3 == 0 )
+ {
+ xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),_(" min"));
+ }
+
if ( value3 <= value2 )
{
value3 = value2 + 1;
@@ -261,9 +308,13 @@
{
XfpmDpmsSpinsPrivate *priv;
priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins);
+ if ( spin_1 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),_(" disabled"));
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_1),spin_1);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_1),spin_1);
+ if ( spin_2 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),_(" disabled"));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),spin_2);
+
+ if ( spin_3 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),_(" disabled"));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),spin_3);
}
Modified: xfce4-power-manager/trunk/src/xfpm-dpms.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-dpms.c 2008-10-17 09:05:40 UTC (rev 5659)
+++ xfce4-power-manager/trunk/src/xfpm-dpms.c 2008-10-17 10:42:47 UTC (rev 5660)
@@ -362,7 +362,7 @@
if ( dpms->dpms_enabled )
{
- xfpm_dpms_set_timeouts(dpms);
+ xfpm_dpms_set_timeouts(dpms);
}
}
Modified: xfce4-power-manager/trunk/src/xfpm-spin-button.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-spin-button.c 2008-10-17 09:05:40 UTC (rev 5659)
+++ xfce4-power-manager/trunk/src/xfpm-spin-button.c 2008-10-17 10:42:47 UTC (rev 5660)
@@ -132,7 +132,6 @@
iface->delete_text = xfpm_spin_button_delete_text;
}
-
static void
_spin_button_update(XfpmSpinButton *spin)
{
@@ -144,8 +143,24 @@
{
gtk_widget_queue_resize_no_redraw(widget);
}
+}
+
+
+static void
+xfpm_spin_button_delete_all_text(GtkEditable *editable)
+{
+ GtkEditableClass *spin_iface = g_type_interface_peek (xfpm_spin_button_parent_class,
+ GTK_TYPE_EDITABLE);
+ GtkEditableClass *entry_iface = g_type_interface_peek_parent(spin_iface);
+ gint start,end;
+ const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable));
+ start = 0;
+ end = strlen(text);
+
+ entry_iface->delete_text(editable,start,end);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(editable),gtk_spin_button_get_value(GTK_SPIN_BUTTON(editable)));
}
static void
@@ -164,6 +179,7 @@
gint text_length = strlen(text);
gint length;
+
if ( spin->suffix )
{
length = text_length - spin->suffix_length ;
@@ -232,7 +248,7 @@
}
/* Constructor for the xfpm-spin button is the same as
- * gtk_spin_button_new_with_range.
+ * gtk_spin_button_new_with_range but slightly modified
*
* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
@@ -268,7 +284,7 @@
gtk_spin_button_configure (GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT (adj), step, digits);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON(spin), TRUE);
-
+
return GTK_WIDGET(spin);
}
@@ -278,9 +294,18 @@
{
g_return_if_fail(XFPM_IS_SPIN_BUTTON(spin));
g_return_if_fail(suffix != NULL);
-
+
+ xfpm_spin_button_delete_all_text(GTK_EDITABLE(spin));
+
+ if ( spin->suffix ) g_free(spin->suffix);
+
spin->suffix = g_strdup(suffix);
spin->suffix_length = strlen(spin->suffix);
-
- gtk_entry_append_text(GTK_ENTRY(spin),spin->suffix);
+
+ gint spin_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
+ gint digits_num = 1 ;
+ if ( spin_value != 0 )
+ digits_num = abs ((gint) floor (log10 (fabs (spin_value)))) + 1;
+
+ xfpm_spin_button_insert_text(GTK_EDITABLE(spin),spin->suffix,spin->suffix_length,&(digits_num));
}
Modified: xfce4-power-manager/trunk/src/xfpm-spin-button.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-spin-button.h 2008-10-17 09:05:40 UTC (rev 5659)
+++ xfce4-power-manager/trunk/src/xfpm-spin-button.h 2008-10-17 10:42:47 UTC (rev 5660)
@@ -40,6 +40,7 @@
gchar *suffix;
gint suffix_length;
gint suffix_position;
+ gint digits_num;
} XfpmSpinButton;
More information about the Goodies-commits
mailing list