[yast-commit] r39123 - in /branches/tmp/sh/mod-ui/core/libyui/src: YCPPropertyHandler.cc YCPPropertyHandler.h YProperty.cc YProperty.h YRadioButtonGroup.cc YUI_builtins.cc
Author: sh-sh-sh Date: Mon Jul 2 18:02:01 2007 New Revision: 39123 URL: http://svn.opensuse.org/viewcvs/yast?rev=39123&view=rev Log: got rid of widgetPtrProperty kludge Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Mon Jul 2 18:02:01 2007 @@ -29,42 +29,50 @@ #include <ycp/y2log.h> #include "YCPPropertyHandler.h" +#include "YCPDialogParser.h" #include "YCPItemParser.h" +#include "YCPValueWidgetID.h" #include "YCheckBox.h" #include "YSelectionBox.h" #include "YComboBox.h" +#include "YRadioButtonGroup.h" +#include "YRadioButton.h" #include "YCPItem.h" #include "YUISymbols.h" -void +bool YCPPropertyHandler::setComplexProperty( YWidget * widget, const string & propertyName, const YCPValue & val ) { // y2debug( "%s::%s", widget->widgetClass(), propertyName.c_str() ); - + if ( propertyName == YUIProperty_Value ) { - if ( trySetCheckBoxValue ( widget, val ) ) return; - if ( trySetSelectionBoxValue ( widget, val ) ) return; - if ( trySetComboBoxValue ( widget, val ) ) return; + if ( trySetCheckBoxValue ( widget, val ) ) return true; + if ( trySetSelectionBoxValue ( widget, val ) ) return true; + if ( trySetComboBoxValue ( widget, val ) ) return true; } - - if ( propertyName == YUIProperty_CurrentItem ) + else if ( propertyName == YUIProperty_CurrentItem ) { - if ( trySetSelectionBoxValue ( widget, val ) ) return; + if ( trySetSelectionBoxValue ( widget, val ) ) return true; } - - if ( propertyName == YUIProperty_Items ) + else if ( propertyName == YUIProperty_Items ) + { + if ( trySetSelectionWidgetItems( widget, val ) ) return true; + } + else if ( propertyName == YUIProperty_CurrentButton ) { - if ( trySetSelectionWidgetItems( widget, val ) ) return; + if ( trySetRadioButtonGroupCurrentButton( widget, val ) ) return true; } y2error( "Can't handle property %s::%s - not changing anything", widget->widgetClass(), propertyName.c_str() ); + + return false; } @@ -72,30 +80,32 @@ YCPPropertyHandler::getComplexProperty( YWidget * widget, const string & propertyName ) { YCPValue val = YCPNull(); - + if ( propertyName == YUIProperty_Value ) { val = tryGetCheckBoxValue ( widget ); if ( ! val.isNull() ) return val; val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val; val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val; } - - if ( propertyName == YUIProperty_CurrentItem ) + else if ( propertyName == YUIProperty_CurrentItem ) { val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val; val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val; // tryGetMultiSelectionBoxCurrentItem } + else if ( propertyName == YUIProperty_CurrentButton ) + { + val = tryGetRadioButtonGroupCurrentButton( widget ); if ( ! val.isNull() ) return val; + } + - // FIXME: TO DO: // FIXME: TO DO: // FIXME: TO DO: - + // tryGetMultiSelectionBoxSelectedItems // tryGetSelectionWidgetItems - // tryGetRadioButtonGroupCurrentButton y2error( "Can't handle property %s::%s - returning 'nil'", widget->widgetClass(), propertyName.c_str() ); @@ -115,7 +125,7 @@ if ( ! checkBox ) return false; - + if ( val->isBoolean() ) { checkBox->setChecked( val->asBoolean()->value() ); @@ -155,7 +165,7 @@ widget->debugLabel().c_str(), val->toString().c_str() ); } - + return true; } @@ -190,7 +200,7 @@ widget->debugLabel().c_str(), val->toString().c_str() ); } - + return true; } @@ -240,6 +250,37 @@ } +bool +YCPPropertyHandler::trySetRadioButtonGroupCurrentButton( YWidget * widget, const YCPValue & val ) +{ + YRadioButtonGroup * radioButtonGroup = dynamic_cast<YRadioButtonGroup *> (widget); + + if ( ! radioButtonGroup ) + return false; + + YWidget * refWidget = YCPDialogParser::findWidgetWithId( radioButtonGroup, val ); + // This will throw an exception if no widget with that ID found + + YRadioButton * newCurrentButton = dynamic_cast<YRadioButton *> (refWidget); + + if ( newCurrentButton ) + { + y2debug( "Setting new current radio button: %s", newCurrentButton->debugLabel().c_str() ); + newCurrentButton->setValue( true ); + } + else + { + string msg = string( "Expected a YRadioButton, not a " ) + widget->widgetClass(); + YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_CurrentButton, + YOtherProperty ), + widget, msg ) ); + } + + return true; +} + + + @@ -253,7 +294,7 @@ if ( ! checkBox ) return YCPNull(); - + switch ( checkBox->value() ) { case YCheckBox_on: return YCPBoolean( true ); @@ -274,7 +315,7 @@ if ( ! comboBox ) return YCPNull(); - + YItem * selectedItem = comboBox->selectedItem(); if ( selectedItem ) @@ -296,7 +337,7 @@ if ( ! selBox ) return YCPNull(); - + YItem * selectedItem = selBox->selectedItem(); if ( selectedItem ) @@ -312,3 +353,33 @@ return YCPVoid(); } + +YCPValue +YCPPropertyHandler::tryGetRadioButtonGroupCurrentButton( YWidget * widget ) +{ + YRadioButtonGroup * radioButtonGroup = dynamic_cast<YRadioButtonGroup *> (widget); + + if ( ! radioButtonGroup ) + return YCPNull(); + + YRadioButton * currentButton = radioButtonGroup->currentButton(); + + if ( ! currentButton ) + return YCPVoid(); + + y2debug( "Current radio button: %s", currentButton->debugLabel().c_str() ); + + if ( currentButton->hasId() ) + { + YCPValueWidgetID * id = dynamic_cast<YCPValueWidgetID *> ( currentButton->id() ); + + if ( id ) + return id->value(); + } + + y2warning( "%s \"%s\" has no ID", + currentButton->widgetClass(), + currentButton->debugLabel().c_str() ); + + return YCPVoid(); +} Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Mon Jul 2 18:02:01 2007 @@ -48,14 +48,18 @@ public: /** * Set a complex property. + * + * Return 'true' on success, 'false' on failure. **/ - static void setComplexProperty( YWidget * widget, + static bool setComplexProperty( YWidget * widget, const string & propertyName, const YCPValue & val ); /** * Get a complex property. + * + * Return YCPNull upon failure, a non-null YCPValue (the result) upon success. **/ static YCPValue getComplexProperty( YWidget * widget, const string & propertyName ); @@ -77,10 +81,11 @@ * * They all return 'true' upon success and 'false' upon failure. **/ - static bool trySetCheckBoxValue ( YWidget * widget, const YCPValue & val ); - static bool trySetSelectionBoxValue ( YWidget * widget, const YCPValue & val ); - static bool trySetComboBoxValue ( YWidget * widget, const YCPValue & val ); - static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val ); + static bool trySetCheckBoxValue ( YWidget * widget, const YCPValue & val ); + static bool trySetSelectionBoxValue ( YWidget * widget, const YCPValue & val ); + static bool trySetComboBoxValue ( YWidget * widget, const YCPValue & val ); + static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val ); + static bool trySetRadioButtonGroupCurrentButton ( YWidget * widget, const YCPValue & val ); /** * All trySet..() functions try to dynamic_cast 'widget' to the expected @@ -88,9 +93,10 @@ * * They all return YCPNull upon failure and a non-null YCPValue upon success. **/ - static YCPValue tryGetCheckBoxValue ( YWidget * widget ); - static YCPValue tryGetComboBoxValue ( YWidget * widget ); - static YCPValue tryGetSelectionBoxValue ( YWidget * widget ); + static YCPValue tryGetCheckBoxValue ( YWidget * widget ); + static YCPValue tryGetComboBoxValue ( YWidget * widget ); + static YCPValue tryGetSelectionBoxValue ( YWidget * widget ); + static YCPValue tryGetRadioButtonGroupCurrentButton ( YWidget * widget ); }; Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc Mon Jul 2 18:02:01 2007 @@ -33,7 +33,6 @@ case YStringProperty: return "String"; case YBoolProperty: return "Bool"; case YIntegerProperty: return "Integer"; - case YWidgetPtrProperty: return "YWidget *"; // Intentionally omitting default branch // so the compiler catches unhandled enum values @@ -105,18 +104,7 @@ it->type() == YOtherProperty ) // "Other" could be anything return true; - YUIPropertyTypeMismatchException exception( *it, type ); - - if ( it->type() == YWidgetPtrProperty ) - { - // Kludge for YWidget * properties: Those typically throw an - // exception (and the caller tries again with the correct - // type), so let's at least not appear it in the log file. - - throw exception; // silent throw (doesn't appear in log file) - } - else - YUI_THROW( exception ); // verbose throw (appears in log file) + YUI_THROW( YUIPropertyTypeMismatchException( *it, type ) ); } } 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/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h Mon Jul 2 18:02:01 2007 @@ -32,8 +32,7 @@ YOtherProperty, // requires futher checking YStringProperty, // const string & YBoolProperty, // bool - YIntegerProperty, // YCP Integer == C++ long long - YWidgetPtrProperty // YWidget * + YIntegerProperty // YCP Integer == C++ long long }; class YWidget; @@ -126,12 +125,6 @@ explicit YPropertyValue( int num ): _type( YIntegerProperty ), _integerVal( num ) {} - /** - * Constructor for YWidget * properties. - **/ - YPropertyValue( YWidget * widget ): - _type( YWidgetPtrProperty ), _widgetPtrVal( widget ) {} - explicit YPropertyValue( YPropertyType type ) : _type( type ) {} 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/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc Mon Jul 2 18:02:01 2007 @@ -131,8 +131,8 @@ * @property any CurrentButton widget ID of the currently selected RadioButton of this group * @property any Value Alias for CurrentButton */ - propSet.add( YProperty( YUIProperty_Value, YWidgetPtrProperty ) ); - propSet.add( YProperty( YUIProperty_CurrentButton, YWidgetPtrProperty ) ); + propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_CurrentButton, YOtherProperty ) ); propSet.add( YWidget::propertySet() ); } @@ -146,33 +146,7 @@ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch if ( propertyName == YUIProperty_CurrentButton || - propertyName == YUIProperty_Value ) - { - YWidget * widget = val.widgetPtrVal(); - - if ( widget ) - { - YRadioButton * newCurrentButton = dynamic_cast<YRadioButton *> (widget); - - if ( newCurrentButton ) - { - newCurrentButton->setValue( true ); - return true; // success -- no special processing necessary - } - } - - // widget == 0 or not a YRadioButton - throw exception - - string msg; - - if ( widget ) - msg = string( "Expected a YRadioButton, not a " ) + widget->widgetClass(); - else - msg = "Null widget"; - - YUI_THROW( YUIBadPropertyArgException( YProperty( propertyName, YWidgetPtrProperty ), - this, msg ) ); - } + propertyName == YUIProperty_Value ) return false; // Needs special handling else { YWidget::setProperty( propertyName, val ); @@ -188,7 +162,7 @@ propertySet().check( propertyName ); // throws exceptions if not found if ( propertyName == YUIProperty_CurrentButton || - propertyName == YUIProperty_Value ) return YPropertyValue( currentButton() ); + propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty ); else { return YWidget::getProperty( propertyName ); 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/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Mon Jul 2 18:02:01 2007 @@ -894,46 +894,20 @@ if ( newValue->isString() ) val = YPropertyValue( newValue->asString()->value() ); else if ( newValue->isInteger() ) val = YPropertyValue( newValue->asInteger()->value() ); else if ( newValue->isBoolean() ) val = YPropertyValue( newValue->asBoolean()->value() ); - else if ( newValue->isVoid() || - newValue->isSymbol() ) YCPPropertyHandler::setComplexProperty( widget, propertyName, newValue ); else - { - y2error( "Unknown type for property %s::%s: %s", - widget->widgetClass(), sym->symbol().c_str(), newValue->toString().c_str() ); - - unblockEvents(); - return YCPBoolean( false ); - } + val = YPropertyValue( false ); // Dummy value, will be rejected anyway try { bool success = widget->setProperty( propertyName, val ); if ( ! success ) - YCPPropertyHandler::setComplexProperty( widget, propertyName, newValue ); - - ret = YCPBoolean( true ); - } - catch ( YUIPropertyTypeMismatchException & typeMismatchException ) - { - if ( typeMismatchException.property().type() == YWidgetPtrProperty ) { - try - { - // This is not particularly elegant, but it's the only way with widget IDs that are - // YCPStrings or YCPIntegers (which is legal): It's not at all clear if that kind of - // YCPValue should be passed as a YCPString or as a widget ID. So now that YCPString - // failed, let's try again with a widget. - - YWidget * refWidget = YCPDialogParser::findWidgetWithId( newValue ); - widget->setProperty( sym->symbol(), YPropertyValue( refWidget ) ); - ret = YCPBoolean( true ); - } - catch( YUIPropertyException & exception ) - { - y2error( "Caught property exception" ); - } + // Try again with the known special cases + success = YCPPropertyHandler::setComplexProperty( widget, propertyName, newValue ); } + + ret = YCPBoolean( success ); } catch( YUIPropertyException & exception ) { @@ -1022,24 +996,6 @@ case YBoolProperty: return YCPBoolean( val.boolVal() ); case YIntegerProperty: return YCPInteger( val.integerVal() ); case YOtherProperty: return YCPPropertyHandler::getComplexProperty( widget, propertyName ); - case YWidgetPtrProperty: - { - YWidget * widget = val.widgetPtrVal(); - - if ( widget->hasId() ) - { - YCPValueWidgetID * id = dynamic_cast<YCPValueWidgetID *> ( widget->id() ); - - if ( id ) - return id->value(); - } - - y2warning( "%s \"%s\" has no ID", - widget->widgetClass(), - widget->debugLabel().c_str() ); - - return YCPVoid(); - } default: y2error( "Unknown result for setProperty( %s )", sym->symbol().c_str() ); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org