Author: sh-sh-sh
Date: Fri Jun 1 17:16:19 2007
New Revision: 38252
URL: http://svn.opensuse.org/viewcvs/yast?rev=38252&view=rev
Log:
- Ported YTextEntry
- Removed obsolete changeWidget/queryWidget code in proted widgets
- Interim solution for shortcut management
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc
branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h
branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc
branches/tmp/sh/mod-ui/core/libyui/src/YShortcut.cc
branches/tmp/sh/mod-ui/core/libyui/src/YShortcutManager.cc
branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.cc
branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
branches/tmp/sh/mod-ui/core/libyui/src/YWidgetOpt.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Fri Jun 1 17:16:19 2007
@@ -7,6 +7,20 @@
This had cluttered the API for a long time.
+* Got rid of all YCP data types in all widget classes:
+
+ * YCPString -> std::string
+ * YCPInteger -> int
+ * YCPBoolean -> bool
+
+* In function parameters, std::string is generally passed as const std::string & .
+
+* All widgets: No longer implementing changeWidget() / queryWidget() directly,
+ now using setProperty() / getProperty().
+ Reason: No more YCP depencency in YWidget derived classes.
+ See YRadioButton or YTextEntry for examples.
+
+
* YRadioButton:
* Made all memeber variables private.
@@ -21,4 +35,22 @@
* virtual void setValue( YCPBoolean ) -> virtual void setValue( bool )
+* YTextEntry:
+
+ * Made all memeber variables private.
+ Access via access functions only from now on.
+
+ * label is now std::string , no longer YCPString
+ * passwordMode is now passed directly in the constructor, not only via YWidgetOpt
+ * passwordMode is now a member, no longer avaliable only from YWidgetOpt
+
+ * Renamed getText() -> value(),
+ * Renamed setText() -> setValue()
+ * virtual YCPString getText() -> virtual std::string value()
+ * virtual void setText( YCPString ) -> virtual void setValue( std::string )
+ * getLabel() -> label()
+ * virtual setValidChars( YCPStrng ) -> virtual setValidChars( std::string )
+ * virtual setInputMaxLength( YCPInteger ) -> virtual setInputMaxLength( int )
+ * overloaded virtual setInputMaxLength( int ) is now required to call
+ YTextEntry::setInputMaxLength() at its end
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h Fri Jun 1 17:16:19 2007
@@ -119,6 +119,18 @@
_type( YIntegerProperty ), _integerVal( num ) {}
/**
+ * Constructor for numerical (YCP integer) properties.
+ **/
+ YPropertyValue( int num ):
+ _type( YIntegerProperty ), _integerVal( num ) {}
+
+ /**
+ * Default constructor
+ **/
+ YPropertyValue():
+ _type( YUnknownPropertyType ) {}
+
+ /**
* Returns the type of this property value.
* Use this to determine which xyVal() method to use.
**/
@@ -218,6 +230,11 @@
bool isEmpty() const { return _properties.empty(); }
/**
+ * Returns the number of properties in this set.
+ **/
+ int size() const { return (int) _properties.size(); }
+
+ /**
* Add a property to this property set.
**/
void add( const YProperty & prop );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc Fri Jun 1 17:16:19 2007
@@ -44,14 +44,14 @@
YRadioButtonPrivate( std::string label )
: label( label )
, radioButtonGroup( 0 )
- {};
+ {}
};
YRadioButton::YRadioButton( const YWidgetOpt & opt,
- const YCPString & label )
+ const std::string & label )
: YWidget( opt )
- , priv( new YRadioButtonPrivate( label->value() ) )
+ , priv( new YRadioButtonPrivate( label ) )
{
YUI_CHECK_NEW( priv );
}
@@ -83,6 +83,11 @@
if ( propSet.isEmpty() )
{
+ /*
+ * @property boolean Value the on/off state of the RadioButton
+ * @property string Label the text on the RadioButton
+ */
+
propSet.add( YProperty( YUIProperty_Value, YBoolProperty ) );
propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
propSet.add( YWidget::propertySet() );
@@ -111,8 +116,8 @@
{
propertySet().check( propertyName ); // throws exceptions if not found
- if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
- if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
+ else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
else
{
return YWidget::getProperty( propertyName );
@@ -120,58 +125,6 @@
}
-YCPValue YRadioButton::changeWidget( const YCPSymbol & property, const YCPValue & newvalue )
-{
- string s = property->symbol();
- /*
- * @property boolean Value the state of the RadioButton ( on or off )
- */
- if ( s == YUIProperty_Value )
- {
- if ( newvalue->isBoolean() )
- {
- setValue( newvalue->asBoolean()->value() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "RadioButton: Invalid parameter %s for property `Value. Must be boolean",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
-
- /*
- * @property string Label the RadioButton's text
- */
- else if ( s == YUIProperty_Label )
- {
- if ( newvalue->isString() )
- {
- setLabel( newvalue->asString()->value() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "RadioButton: Invalid parameter %s for property `Label. Must be string",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- else return YWidget::changeWidget( property, newvalue );
-}
-
-
-
-YCPValue YRadioButton::queryWidget( const YCPSymbol & property )
-{
- string s = property->symbol();
- if ( s == YUIProperty_Value ) return YCPBoolean( value() );
- else if ( s == YUIProperty_Label ) return YCPString( label() );
- else return YWidget::queryWidget( property );
-}
-
-
void YRadioButton::buttonGroupIsDead()
{
priv->radioButtonGroup = 0;
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h Fri Jun 1 17:16:19 2007
@@ -22,7 +22,6 @@
#include "ImplPtr.h"
#include "YWidget.h"
-#include
class YRadioButtonGroup;
class YMacroRecorder;
@@ -54,7 +53,7 @@
* Creates a new RadioButton with user-visible text 'label'.
* 'label' can and should contain a keyboard shortcut (designated with '&').
*/
- YRadioButton( const YWidgetOpt & opt, const YCPString & label );
+ YRadioButton( const YWidgetOpt & opt, const std::string & label );
/**
* Destructor: Removes the button from the radio button group.
@@ -62,6 +61,39 @@
virtual ~YRadioButton();
/**
+ * Set the radio button to a new value - check or uncheck it
+ */
+ virtual void setValue( bool checked ) = 0;
+
+ /**
+ * Returns the current value of the radio button:
+ * 'true' if checked, 'false' if unchecked.
+ */
+ virtual bool value() = 0;
+
+ /**
+ * Returns the user-visible label (the text on the RadioButton).
+ **/
+ std::string label() const;
+
+ /**
+ * Change the label. Overload this, but call
+ * YRadioButton::setLabel at the end of your own function.
+ */
+ virtual void setLabel( const std::string & label );
+
+ /**
+ * Get a pointer to the radio button group this button belongs to.
+ */
+ YRadioButtonGroup *buttonGroup();
+
+ /**
+ * This function is called from YRadioButtonGroup::~YRadioButtonGroup to
+ * notify this widget that the radio button group is no longer valid.
+ */
+ void buttonGroupIsDead();
+
+ /**
* Returns a descriptive name of this widget class for logging,
* debugging etc.
*/
@@ -91,58 +123,25 @@
/**
* Return this class's property set.
* This also initializes the property upon the first call.
+ *
* Reimplemented from YWidget.
**/
virtual const YPropertySet & propertySet();
-
- /**
- * Returns the user-visible label (the text on the RadioButton).
- **/
- std::string label() const;
-
- /**
- * Change the label. Overload this, but call
- * YRadioButton::setLabel at the end of your own function.
- */
- virtual void setLabel( const std::string & label );
/**
- * Implements the ui command changeWidget.
- */
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
-
- /**
- * Implements the ui command queryWidget
- */
- YCPValue queryWidget( const YCPSymbol & property );
-
- /**
- * Set the radio button to a new value - check or uncheck it
- */
- virtual void setValue( bool checked ) = 0;
-
- /**
- * Returns the current value of the radio button:
- * 'true' if checked, 'false' if unchecked.
- */
- virtual bool value() = 0;
-
- /**
- * This function is called from @ref YRadioButtonGroup#~YRadioButtonGroup and
- * tells that the pointer to the radiobuttongroup is not longer valid.
- */
- void buttonGroupIsDead();
-
- /**
- * Get a pointer to the radio button group this button belongs to.
- */
- YRadioButtonGroup *buttonGroup();
+ * Get the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual std::string shortcutString() { return label(); }
/**
- * The name of the widget property that holds the keyboard shortcut.
- * Inherited from YWidget.
- */
- const char *shortcutProperty() { return YUIProperty_Label; }
+ * Set the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setShortcutString( const std::string & str )
+ { setLabel( str ); }
/**
* The name of the widget property that will return user input.
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc Fri Jun 1 17:16:19 2007
@@ -59,6 +59,8 @@
* please tell me.
*/
+ // FIXME: There must be a better way to do this.
+
for ( unsigned i=0; ibuttonGroupIsDead();
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YShortcut.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YShortcut.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YShortcut.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YShortcut.cc Fri Jun 1 17:16:19 2007
@@ -152,9 +152,22 @@
string( 1, shortcutMarker() ) ); // equivalent to 'string( "& " )'
}
- YCPSymbol propertyName( widget()->shortcutProperty() );
- YCPValue propertyValue = YCPString( str );
- widget()->changeWidget( propertyName, propertyValue );
+ if ( widget()->shortcutProperty() )
+ {
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ YCPSymbol propertyName( widget()->shortcutProperty() );
+ YCPValue propertyValue = YCPString( str );
+ widget()->changeWidget( propertyName, propertyValue );
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ }
+ else
+ {
+ widget()->setShortcutString( str );
+ }
_shortcut_string_chached = false;
_clean_shortcut_string_chached = false;
@@ -214,12 +227,6 @@
string
YShortcut::getShortcutString()
{
- if ( ! widget()->shortcutProperty() )
- {
- y2error( "ERROR: %s widgets can't handle shortcuts!", widgetClass() );
- return string( "" );
- }
-
return getShortcutString( widget() );
}
@@ -227,14 +234,27 @@
string
YShortcut::getShortcutString( YWidget * widget )
{
- if ( ! widget || ! widget->shortcutProperty() )
+ if ( ! widget )
return string( "" );
- YCPSymbol propertyName( widget->shortcutProperty() );
- YCPValue propertyValue = widget->queryWidget( propertyName );
-
- return propertyValue.isNull() || ! propertyValue->isString() ?
- string( "" ) : propertyValue->asString()->value();
+ if ( widget->shortcutProperty() )
+ {
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ YCPSymbol propertyName( widget->shortcutProperty() );
+ YCPValue propertyValue = widget->queryWidget( propertyName );
+
+ return propertyValue.isNull() || ! propertyValue->isString() ?
+ string( "" ) : propertyValue->asString()->value();
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ }
+ else
+ {
+ return widget->shortcutString();
+ }
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YShortcutManager.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YShortcutManager.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YShortcutManager.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YShortcutManager.cc Fri Jun 1 17:16:19 2007
@@ -359,7 +359,8 @@
for ( YWidgetListIterator it = widgetList.begin(); it != widgetList.end(); ++it )
{
- if ( ( *it )->shortcutProperty() )
+ if ( ( *it )->shortcutProperty() ||
+ ! (*it)->shortcutString().empty() )
{
YShortcut * shortcut = new YShortcut( *it );
_shortcutList.push_back( shortcut );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.cc Fri Jun 1 17:16:19 2007
@@ -1,16 +1,16 @@
/*---------------------------------------------------------------------\
-| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
-| \ V / _` \___ \ | | __) | |
-| | | (_| |___) || | / __/ |
-| |_|\__,_|____/ |_| |_____| |
-| |
-| core system |
-| (C) SuSE GmbH |
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
\----------------------------------------------------------------------/
- File: YTextEntry.cc
+ File: YTextEntry.cc
Author: Mathias Kettner
Maintainer: Stefan Hundhammer
@@ -29,126 +29,138 @@
#include "YTextEntry.h"
-YTextEntry::YTextEntry( const YWidgetOpt & opt, const YCPString & label )
+struct YTextEntryPrivate
+{
+ std::string label;
+ bool passwordMode;
+ std::string validChars;
+ int inputMaxLength;
+
+ /**
+ * Constructor
+ **/
+
+ YTextEntryPrivate( std::string label, bool passwordMode )
+ : label( label )
+ , passwordMode( passwordMode )
+ , validChars( "" )
+ , inputMaxLength( -1 )
+ {}
+};
+
+
+
+YTextEntry::YTextEntry( const YWidgetOpt & opt, const std::string & label, bool passwordMode )
: YWidget( opt )
- , label( label )
- , validChars( "" )
+ , priv( new YTextEntryPrivate( label, passwordMode ) )
{
- _passwordMode = opt.passwordMode.value();
+ YUI_CHECK_NEW( priv );
+
setDefaultStretchable( YD_HORIZ, true );
setDefaultStretchable( YD_VERT, false );
}
-void YTextEntry::setLabel( const YCPString & label )
+YTextEntry::~YTextEntry()
{
- this->label = label;
+ // NOP
}
-YCPString YTextEntry::getLabel()
+std::string YTextEntry::label()
{
- return label;
+ return priv->label;
}
-void YTextEntry::setValidChars( const YCPString & newValidChars )
+void YTextEntry::setLabel( const std::string & label )
{
- this->validChars= newValidChars;
+ priv->label = label;
}
-YCPString YTextEntry::getValidChars()
+std::string YTextEntry::validChars()
{
- return validChars;
+ return priv->validChars;
}
-YCPValue YTextEntry::changeWidget( const YCPSymbol & property, const YCPValue & newvalue )
+void YTextEntry::setValidChars( const std::string & newValidChars )
{
- string s = property->symbol();
- /**
- * @property string Value the field's contents ( the user input )
- */
- if ( s == YUIProperty_Value )
- {
- if ( newvalue->isString() )
- {
- setText( newvalue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "TextEntry: Invalid parameter %s for Value property. Must be string.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- /**
- * @property string Label label above the field
- */
- else if ( s == YUIProperty_Label )
- {
- if ( newvalue->isString() )
- {
- setLabel( newvalue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "TextEntry: Invalid parameter %s for Label property. Must be string.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- /**
- * @property string ValidChars valid input characters
- */
- else if ( s == YUIProperty_ValidChars )
- {
- if ( newvalue->isString() )
- {
- setValidChars( newvalue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "TextEntry: Invalid parameter %s for ValidChars property. Must be string.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- /**
- * @property interger InputMaxLength limit the amount of characters
- */
- else if ( s == YUIProperty_InputMaxLength )
+ priv->validChars= newValidChars;
+}
+
+
+bool YTextEntry::passwordMode() const
+{
+ return priv->passwordMode;
+}
+
+
+int YTextEntry::inputMaxLength() const
+{
+ return priv->inputMaxLength;
+}
+
+void YTextEntry::setInputMaxLength( int len )
+{
+ priv->inputMaxLength = len;
+}
+
+
+const YPropertySet &
+YTextEntry::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
{
- if ( newvalue->isInteger() )
- {
- setInputMaxLength( newvalue->asInteger()->value() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "TextEntry: Invalid parameter %s for InputMaxLength. Must be integer.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
+ /*
+ * @property string Value the field's contents (the user input)
+ * @property string Label caption above the field
+ * @property string ValidChars set of valid input characters
+ * @property integer InputMaxLength maximum number of input characters
+ */
+ propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_ValidChars, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_InputMaxLength, YIntegerProperty ) );
+ propSet.add( YWidget::propertySet() );
}
- else return YWidget::changeWidget( property, newvalue );
+
+ return propSet;
}
-void YTextEntry::setInputMaxLength( const YCPInteger & numberOfChars )
+
+void
+YTextEntry::setProperty( const std::string & propertyName, const YPropertyValue & val )
{
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
+
+ if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() );
+ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
+ else if ( propertyName == YUIProperty_ValidChars ) setValidChars( val.stringVal() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() );
+ else
+ {
+ YWidget::setProperty( propertyName, val );
+ }
}
-YCPValue YTextEntry::queryWidget( const YCPSymbol & property )
+
+YPropertyValue
+YTextEntry::getProperty( const std::string & propertyName )
{
- string s = property->symbol();
- if ( s == YUIProperty_Value ) return getText();
- else if ( s == YUIProperty_Label ) return getLabel();
- else if ( s == YUIProperty_ValidChars ) return getValidChars();
- else return YWidget::queryWidget( property );
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
+ else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ else if ( propertyName == YUIProperty_ValidChars ) return YPropertyValue( validChars() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) return YPropertyValue( inputMaxLength() );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
}
@@ -165,7 +177,7 @@
text += ", \"<not recording password in plain text>\" );\t// ";
text += widgetClass();
text += " \"" + debugLabel() + "\"";
-
+
macroRecorder->recordComment( text );
}
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h Fri Jun 1 17:16:19 2007
@@ -12,128 +12,160 @@
File: YTextEntry.h
- Author: Mathias Kettner
- Maintainer: Stefan Hundhammer
+ Author: Stefan Hundhammer
/-*/
#ifndef YTextEntry_h
#define YTextEntry_h
+#include <string>
+#include "ImplPtr.h"
#include "YWidget.h"
-#include
class YMacroRecorder;
+class YTextEntryPrivate;
+
-/**
- * @short Implementation of the TextEntry and Password widgets
- * Notice: Derived classes need to check opt.passwordMode!
- */
class YTextEntry : public YWidget
{
public:
/**
- * Creates a new text entry with a label and an initial text.
+ * Constructor.
+ *
+ * Creates an input field with 'label' as the caption.
+ * If 'passwordMode' is set, the input will be not be echoed as clear text.
*/
- YTextEntry( const YWidgetOpt & opt, const YCPString & label );
+ YTextEntry( const YWidgetOpt & opt,
+ const std::string & label,
+ bool passwordMode = false );
/**
- * Returns a descriptive name of this widget class for logging,
- * debugging etc.
- */
- virtual char *widgetClass() { return "YTextEntry"; }
-
+ * Destructor.
+ **/
+ virtual ~YTextEntry();
/**
- * Implements the ui command changeWidget for the widget specific
- * properties.
+ * Get the current value (the text entered by the user or set from the
+ * outside) of this input field.
+ *
+ * Derived classes need to implement this.
*/
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
+ virtual std::string value() = 0;
/**
- * Implements the ui command changeWidget for the widget specific properties.
+ * Set the current value (the text entered by the user or set from the
+ * outside) of this input field.
+ *
+ * Derived classes need to implement this.
*/
- YCPValue queryWidget( const YCPSymbol & property );
+ virtual void setValue( const std::string & text ) = 0;
/**
- * Set the text in the entry to a new value
- */
- virtual void setText( const YCPString & text ) = 0;
+ * Get the label (the caption above the input field).
+ **/
+ std::string label();
/**
- * get the text currently entered in the text entry
- */
- virtual YCPString getText() = 0;
+ * Set the label (the caption above the input field).
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method (YTextEntry::setLabel() at the end of the overloaded
+ * function.
+ **/
+ virtual void setLabel( const std::string & label );
/**
- * change the label of the text entry. Overload this, but call
- * YTextEntry::setLabel at the end of your own function.
- */
- virtual void setLabel( const YCPString & label );
+ * Returns 'true' if this input field is in password mode, i.e. if there should
+ * be no on-screen echo or only a '*' for each character typed.
+ *
+ * Notice that this can only be set in the constructor.
+ **/
+ bool passwordMode() const;
/**
- * Get the current label of the text entry. This method cannot be
- * overidden. The value of the label cannot be changed other than by
- * calling setLabel, i.e. not by the ui. Therefore setLabel stores the
- * current label in #label.
- */
- YCPString getLabel();
+ * Get the valid input characters. No input validation is performed (i.e.,
+ * the user can enter anything) if this is empty.
+ **/
+ std::string validChars();
/**
- * Change the valid input characters.
+ * Set the valid input characters. No input validation is performed (i.e.,
+ * the user can enter anything) if this is empty.
*
- * Overload this, but call YTextEntry::setValidChars at the end of your own
- * method.
- */
- virtual void setValidChars( const YCPString & validChars );
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
+ **/
+ virtual void setValidChars( const std::string & validChars );
/**
- * Specify the amount of characters which can be inserted.
- *
- * Overload this to limit the input.
- */
- virtual void setInputMaxLength( const YCPInteger & numberOfChars );
+ * Gthe maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ **/
+ int inputMaxLength() const;
/**
- * Get the valid input characters.
- */
- YCPString getValidChars();
+ * Set the maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
+ **/
+ virtual void setInputMaxLength( int numberOfChars );
+
/**
- * The name of the widget property that holds the keyboard shortcut.
- * Inherited from YWidget.
+ * Returns a descriptive name of this widget class for logging,
+ * debugging etc.
*/
- const char *shortcutProperty() { return YUIProperty_Label; }
-
+ virtual char *widgetClass() { return "YTextEntry"; }
+
+
/**
- * The name of the widget property that will return user input.
- * Inherited from YWidget.
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
**/
- const char *userInputProperty() { return YUIProperty_Value; }
+ virtual void setProperty( const std::string & propertyName,
+ const YPropertyValue & val );
/**
- * Returns 'true' if this text entry is in password mode, i.e. there should
- * be no on-screen echo or only a '*' for each character typed
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
**/
- bool passwordMode() const { return _passwordMode; }
-
-
-protected:
+ virtual YPropertyValue getProperty( const std::string & propertyName );
/**
- * The text entry label
- */
- YCPString label;
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual const YPropertySet & propertySet();
+
+ /**
+ * Get the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual std::string shortcutString() { return label(); }
/**
- * Valid input characters
- */
- YCPString validChars;
+ * Set the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setShortcutString( const std::string & str )
+ { setLabel( str ); }
/**
- * Flag: password mode (-> true) or plain text entry?
+ * The name of the widget property that will return user input.
+ * Inherited from YWidget.
**/
- bool _passwordMode;
+ const char *userInputProperty() { return YUIProperty_Value; }
private:
@@ -142,8 +174,10 @@
* Save the widget's user input to a macro recorder.
* Intentionally declared as "private" so all macro recording internals are
* handled by the abstract libyui level, not by a specific UI.
- */
+ **/
virtual void saveUserInput( YMacroRecorder *macroRecorder );
+
+ ImplPtr<YTextEntryPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Fri Jun 1 17:16:19 2007
@@ -558,7 +558,7 @@
* @param rbg the radio button group the new button will belong to
*/
virtual YWidget *createRadioButton( YWidget *parent, YWidgetOpt & opt, YRadioButtonGroup *rbg,
- const YCPString & label, bool checked ) = 0;
+ const std::string & label, bool checked ) = 0;
/**
* Creates a check box
@@ -570,7 +570,7 @@
/**
* Creates a text entry or password entry field.
*/
- virtual YWidget *createTextEntry( YWidget *parent, YWidgetOpt & opt, const YCPString & label, const YCPString & text ) = 0;
+ virtual YWidget *createTextEntry( YWidget *parent, YWidgetOpt & opt, const std::string & label, bool passwordMode ) = 0;
/**
* Creates a MultiLineEdit widget.
@@ -1263,11 +1263,11 @@
* Helper function of createWidgetTree.
* Creates one of TextEntry, Password
*
- * @param password true if this should be password entry field
+ * 'passwordMode' true if this should be a password input field
*/
YWidget *createTextEntry( YWidget *parent, YWidgetOpt & opt,
const YCPTerm & term, const YCPList & optList, int argnr,
- bool password );
+ bool passwordMode );
/**
* Helper function of createWidgetTree.
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Fri Jun 1 17:16:19 2007
@@ -45,6 +45,7 @@
#include "YUI.h"
#include "YEvent.h"
+#include "YUIException.h"
#include "YUISymbols.h"
#include "YDialog.h"
#include "YWidget.h"
@@ -235,7 +236,7 @@
* @description
* Use this builtin if you want to run external program from ncurses UI
* as a separate process. It saves current window layout to the stack and
- * runs the external program in the same terminal. When done, it restores
+ * runs the external program in the same terminal. When done, it restores
* the original window layout and returns exit code of the external program
* (an integer value returned by system() call). When called from Qt UI,
* an error message is printed to the log.
@@ -246,17 +247,17 @@
*/
YCPInteger YUI::evaluateRunInTerminal(const YCPString & module )
-{
- int ret = runInTerminal( module );
+{
+ int ret = runInTerminal( module );
return YCPInteger ( ret );
}
-int YUI::runInTerminal ( const YCPString & module )
+int YUI::runInTerminal ( const YCPString & module )
{
- y2error("Not in text-mode: Cannot run external program in terminal.");
-
+ y2error("Not in text-mode: Cannot run external program in terminal.");
+
return -1;
}
@@ -860,7 +861,52 @@
{
blockEvents(); // We don't want self-generated events from UI::ChangeWidget().
YCPSymbol sym = property->asSymbol();
- YCPValue ret = widget->changeWidget( sym, new_value );
+ YCPValue ret = YCPVoid();
+
+ YPropertySet propSet = widget->propertySet();
+
+ if ( propSet.size() == 6 ) // unchanged from YWidget, no properties supported
+ {
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ y2debug( "Old style UI::ChangeWidget() for %s::%s",
+ widget->widgetClass(), sym->symbol().c_str() );
+ ret = widget->changeWidget( sym, new_value );
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ }
+ else
+ {
+ y2milestone( "New style UI::ChangeWidget() for %s::%s",
+ widget->widgetClass(), sym->symbol().c_str() );
+
+ YPropertyValue val;
+
+ if ( new_value->isString() ) val = YPropertyValue( new_value->asString()->value() );
+ else if ( new_value->isInteger() ) val = YPropertyValue( new_value->asInteger()->value() );
+ else if ( new_value->isBoolean() ) val = YPropertyValue( new_value->asBoolean()->value() );
+ else
+ {
+ y2error( "Unknown type for property %s::%s: %s",
+ widget->widgetClass(), sym->symbol().c_str(), new_value->toString().c_str() );
+
+ unblockEvents();
+ return YCPBoolean( false );
+ }
+
+ try
+ {
+ widget->setProperty( sym->symbol(), val );
+ ret = YCPBoolean( true );
+ }
+ catch( YUIPropertyException & exception )
+ {
+ y2error( "Caught property exception" );
+ }
+ }
+
if ( widget->shortcutProperty() // The widget has a shortcut property
&& sym->symbol() == widget->shortcutProperty() // and this is what should be changed
@@ -918,7 +964,50 @@
return YCPVoid();
if ( property->isSymbol() )
- return widget->queryWidget( property->asSymbol() );
+ {
+ YPropertySet propSet = widget->propertySet();
+ YCPSymbol sym = property->asSymbol();
+
+ if ( propSet.size() == 6 ) // unchanged from YWidget, no properties supported
+ {
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ y2debug( "Old style UI::QueryWidget() for %s::%s",
+ widget->widgetClass(), sym->symbol().c_str() );
+ return widget->queryWidget( property->asSymbol() );
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ }
+ else
+ {
+ y2debug( "New style UI::QueryWidget() for %s::%s",
+ widget->widgetClass(), sym->symbol().c_str() );
+
+ try
+ {
+ YPropertyValue val = widget->getProperty( sym->symbol() );
+
+ switch ( val.type() )
+ {
+ case YStringProperty: return YCPString ( val.stringVal() );
+ case YBoolProperty: return YCPBoolean( val.boolVal() );
+ case YIntegerProperty: return YCPInteger( val.integerVal() );
+
+ default:
+ y2error( "Unknown result for setProperty( %s )", sym->symbol().c_str() );
+ return YCPVoid();
+ }
+ }
+ catch( YUIPropertyException & exception )
+ {
+ y2error( "Caught property exception" );
+ return YCPVoid();
+ }
+ }
+
+ }
else
return widget->queryWidgetTerm( property->asTerm() );
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc Fri Jun 1 17:16:19 2007
@@ -41,15 +41,16 @@
#include "YUI_util.h"
#include "YAlignment.h"
-#include "YComboBox.h"
#include "YCheckBoxFrame.h"
+#include "YComboBox.h"
#include "YMenuButton.h"
+#include "YMultiSelectionBox.h"
+#include "YPushButton.h"
#include "YRadioButton.h"
#include "YRadioButtonGroup.h"
#include "YSelectionBox.h"
-#include "YMultiSelectionBox.h"
-#include "YPushButton.h"
#include "YTable.h"
+#include "YTextEntry.h"
#include "YTree.h"
using std::string;
@@ -1627,7 +1628,8 @@
return 0;
}
- YRadioButton *radioButton = dynamic_cast ( createRadioButton( parent, opt, rbg, term->value( argnr )->asString(), checked->value() ) );
+ YRadioButton *radioButton =
+ dynamic_cast ( createRadioButton( parent, opt, rbg, term->value( argnr )->asString()->value(), checked->value() ) );
assert( radioButton );
// Add to radiobutton group. This can _not_ be done in the
@@ -1731,8 +1733,10 @@
term->toString().c_str() );
return 0;
}
- YCPString initial_text( "" );
- if ( term->size() >= argnr + 2 ) initial_text = term->value( argnr+1 )->asString();
+
+ std::string initialValue;
+ if ( term->size() >= argnr + 2 )
+ initialValue = term->value( argnr+1 )->asString()->value();
for ( int o=0; o < optList->size(); o++ )
{
@@ -1740,9 +1744,13 @@
else logUnknownOption( term, optList->value(o) );
}
- if ( passwordMode ) opt.passwordMode.setValue( true );
+ YTextEntry * textEntry = dynamic_cast
+ ( createTextEntry( parent, opt, term->value( argnr )->asString()->value(), passwordMode ) );
+
+ if ( textEntry && ! initialValue.empty() )
+ textEntry->setValue( initialValue );
- return createTextEntry( parent, opt, term->value( argnr )->asString(), initial_text );
+ return textEntry;
}
@@ -1751,7 +1759,7 @@
* @short multiple line text edit field
* @class YMultiLineEdit
* @arg string label label above the field
- * @optarg string initialText the initial contents of the field
+ * @optarg string initialValue the initial contents of the field
* @usage `MultiLineEdit( `id( `descr ), "Enter problem & description:", "No problem here." )
*
* @examples MultiLineEdit1.ycp MultiLineEdit2.ycp MultiLineEdit3.ycp MultiLineEdit-setInputMaxLength.ycp
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc Fri Jun 1 17:16:19 2007
@@ -40,7 +40,6 @@
#define MAX_DEBUG_LABEL_LEN 50
-
int YWidget::next_internal_widget_id = 0;
@@ -305,6 +304,12 @@
}
+void YWidget::setShortcutString( const std::string & str )
+{
+ y2error( "Default setShortcutString() method called - "
+ "should be reimplemented in %s", widgetClass() );
+}
+
void YWidget::setNotify( bool notify )
{
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Fri Jun 1 17:16:19 2007
@@ -26,6 +26,7 @@
#include "YProperty.h"
#include "YWidgetOpt.h"
#include "YUISymbols.h"
+#include "YUIException.h"
#define YWIDGET_MAGIC 42 // what else? ;- )
@@ -392,10 +393,29 @@
/**
* The name of the widget property that holds the keyboard shortcut, if any.
* Overwrite this for widgets that can have keyboard shortcuts.
- */
+ **/
+ // FIXME: Obsolete
+ // FIXME: Obsolete
+ // FIXME: Obsolete
virtual const char *shortcutProperty() { return (const char *) 0; }
/**
+ * Get the string of this widget that holds the keyboard shortcut, if any.
+ * Most widgets will return label().
+ *
+ * Overwrite this for widgets that can have keyboard shortcuts.
+ **/
+ virtual std::string shortcutString() { return std::string( "" ); }
+
+ /**
+ * Set the string of this widget that holds the keyboard shortcut, if any.
+ * Most widgets will call setLabel().
+ *
+ * Overwrite this for widgets that can have keyboard shortcuts.
+ **/
+ virtual void setShortcutString( const std::string & str );
+
+ /**
* The name of the widget property that will return user input, if there is
* any. Widgets that do have user input (such as TextEntry, ComboBox,
* SelBox) should overwrite this methods. Widgets that are purely passive
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidgetOpt.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidgetOpt.h?rev=38252&r1=38251&r2=38252&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidgetOpt.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidgetOpt.h Fri Jun 1 17:16:19 2007
@@ -144,7 +144,6 @@
YBoolOpt isHeading; // YLabel
YBoolOpt autoScrollDown; // YRichText
YBoolOpt plainTextMode; // YRichText
- YBoolOpt passwordMode; // YTextEntry
YBoolOpt isShrinkable; // YTextEntry
YBoolOpt isEditable; // YComboBox
YBoolOpt immediateMode; // YTable
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org