Author: sh-sh-sh Date: Wed Jan 16 18:38:16 2008 New Revision: 43682 URL: http://svn.opensuse.org/viewcvs/yast?rev=43682&view=rev Log: Support stream logging and general I/O Modified: trunk/core/libyui/src/YWidget.cc trunk/core/libyui/src/YWidget.h trunk/core/libyui/src/YWidgetID.cc trunk/core/libyui/src/YWidgetID.h Modified: trunk/core/libyui/src/YWidget.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YWidget.cc?rev=43... ============================================================================== --- trunk/core/libyui/src/YWidget.cc (original) +++ trunk/core/libyui/src/YWidget.cc Wed Jan 16 18:38:16 2008 @@ -18,15 +18,10 @@ #include <signal.h> +#include <iostream> -#include <ycp/YCPBoolean.h> -#include <ycp/YCPInteger.h> -#include <ycp/YCPSymbol.h> -#include <ycp/YCPString.h> -#include <ycp/YCPTerm.h> -#include <ycp/YCPVoid.h> -#define y2log_component "ui" -#include <ycp/y2log.h> +#define YUILogComponent "ui" +#include "YUILog.h" #include "YUISymbols.h" #include "YShortcut.h" @@ -106,8 +101,11 @@ if ( ! _usedOperatorNew ) { - y2error( "FATAL: Widget at %p not created with operator new !", this ); - y2error( "Check core dump for a backtrace." ); + yuiError() << "FATAL: Widget at " + << hex << (void *) this << dec + << " not created with operator new !" + << endl; + yuiError() << "Check core dump for a backtrace." << endl; abort(); } @@ -129,7 +127,7 @@ { YUI_CHECK_WIDGET( this ); setBeingDestroyed(); - // y2debug( "Destructor of YWidget %p", this ); + // yuiDebug() << "Destructor of YWidget " << this << endl; deleteChildren(); @@ -168,8 +166,7 @@ #if CHECK_FOR_DUPLICATE_CHILDREN if ( child && childrenManager()->contains( child ) ) { - y2error( "%s at %p already contains %s at %p!", - widgetClass(), this, child->widgetClass(), child ); + yuiError() << this << " already contains " << child << endl; YUI_THROW( YUIInvalidChildException<YWidget>( this, child ) ); } #endif @@ -183,7 +180,7 @@ { if ( ! beingDestroyed() ) { - // y2debug( "Removing widget at %p from %s", child, widgetClass() ); + // yuiDebug() << "Removing " << child << " from " << this << endl; childrenManager()->remove( child ); } } @@ -201,7 +198,7 @@ if ( child->isValid() ) { - // y2debug( "Deleting %s at %p", child->widgetClass(), child ); + // yuiDebug() << "Deleting " << child << endl; delete child; } } @@ -211,7 +208,7 @@ string -YWidget::debugLabel() +YWidget::debugLabel() const { string label = YShortcut::cleanShortcutString( YShortcut::getShortcutString( this ) ); @@ -272,8 +269,9 @@ if ( newParent && priv->parent ) { YDialog::currentDialog()->dumpWidgetTree(); - y2warning( "%s::setParent( %p ) this: %p old parent: %p", - widgetClass(), newParent, this, priv->parent ); + yuiWarning() << "Reparenting " << this + << " from " << priv->parent + << " to " << newParent << endl; YUI_THROW( YUIException( string( widgetClass() ) + " already has a parent!" ) ); } @@ -461,8 +459,10 @@ void YWidget::setShortcutString( const std::string & str ) { - y2error( "Default setShortcutString() method called - " - "should be reimplemented in %s", widgetClass() ); + yuiError() << "Default setShortcutString() method called - " + << "this should be reimplemented in " + << widgetClass() + << endl; } @@ -533,7 +533,7 @@ bool YWidget::setKeyboardFocus() { - y2warning( "Widget %s cannot accept the keyboard focus.", id()->toString().c_str() ); + yuiWarning() << this << " cannot accept the keyboard focus." << endl; return false; } @@ -585,11 +585,11 @@ if ( child->hasChildren() ) { - // y2debug( "Recursing into %s", child->debugLabel().c_str() ); + // yuiDebug() << "Recursing into " << child << endl; child->setChildrenEnabled( enabled ); } - // y2debug( "%s %s", enabled ? "Enabling" : "Disabling", child->debugLabel().c_str() ); + // yuiDebug() << ( enabled ? "Enabling " : "Disabling " ) << child << endl; child->setEnabled( enabled ); } } @@ -627,38 +627,15 @@ void YWidget::dumpWidget( YWidget *w, int indentationLevel ) { string indentation ( indentationLevel * 4, ' ' ); - - string descr( w->debugLabel() ); - - if ( ! descr.empty() ) - descr = """ + descr + """; - - if ( w->hasId() ) - { - if ( ! descr.empty() ) - descr += " "; - - descr += "`id( " + w->id()->toString() + " )"; - } - string stretch; if ( w->stretchable( YD_HORIZ ) ) stretch += "hstretch "; if ( w->stretchable( YD_VERT ) ) stretch += "vstretch"; if ( ! stretch.empty() ) - stretch = "(" + stretch + ") "; + stretch = " (" + stretch + ") "; - if ( descr.empty() ) - { - y2milestone( "Widget tree: %s%s %sat %p (widgetRep: %p)", - indentation.c_str(), w->widgetClass(), stretch.c_str(), w, w->widgetRep() ); - } - else - { - y2milestone( "Widget tree: %s%s %s %sat %p (widgetRep: %p)", - indentation.c_str(), w->widgetClass(), descr.c_str(), stretch.c_str(), w,w->widgetRep() ); - } + yuiMilestone() << indentation << "Widget tree: " << w << stretch << endl; } @@ -687,3 +664,36 @@ } +std::ostream & operator<<( std::ostream & stream, const YWidget * w ) +{ + if ( w ) + { + stream << w->widgetClass(); + string debugLabel = w->debugLabel(); + + if ( debugLabel.empty() ) + { + if ( w->hasId() ) + stream << " ID: "" << w->id() << """; + } + else // Has debugLabel + { + stream << " "" << debugLabel << """; + } + + stream << " at " << hex << (void *) w << dec; + + if ( w->widgetRep() ) + { + stream << " (widgetRep: " + << hex << w->widgetRep() << dec + << ")"; + } + } + else + { + stream << "<NULL widget>"; + } + + return stream; +} Modified: trunk/core/libyui/src/YWidget.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YWidget.h?rev=436... ============================================================================== --- trunk/core/libyui/src/YWidget.h (original) +++ trunk/core/libyui/src/YWidget.h Wed Jan 16 18:38:16 2008 @@ -20,6 +20,7 @@ #define YWidget_h #include <string> +#include <iosfwd> #include <ycp/YCPValue.h> #include "YTypes.h" @@ -79,7 +80,7 @@ * Note: This is usually translated to the user's target language. * This makes this useful for debugging only. **/ - virtual string debugLabel(); + virtual string debugLabel() const; // @@ -494,7 +495,7 @@ * * Overwrite this for widgets that can have keyboard shortcuts. **/ - virtual string shortcutString() { return string( "" ); } + virtual string shortcutString() const { return string( "" ); } /** * Set the string of this widget that holds the keyboard shortcut, if any. @@ -640,4 +641,7 @@ }; +std::ostream & operator<<( std::ostream & stream, const YWidget * widget ); + + #endif // YWidget_h Modified: trunk/core/libyui/src/YWidgetID.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YWidgetID.cc?rev=... ============================================================================== --- trunk/core/libyui/src/YWidgetID.cc (original) +++ trunk/core/libyui/src/YWidgetID.cc Wed Jan 16 18:38:16 2008 @@ -16,8 +16,12 @@ /-*/ + +#include <iostream> #include "YWidgetID.h" +using std::endl; + YStringWidgetID::YStringWidgetID( const string & val ) : _value( val ) @@ -65,3 +69,13 @@ return _value; } + +std::ostream & operator<<( std::ostream & stream, const YWidgetID * id ) +{ + if ( id ) + stream << id->toString(); + else + stream << "<NULL YWidgetID>"; + + return stream; +} Modified: trunk/core/libyui/src/YWidgetID.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YWidgetID.h?rev=4... ============================================================================== --- trunk/core/libyui/src/YWidgetID.h (original) +++ trunk/core/libyui/src/YWidgetID.h Wed Jan 16 18:38:16 2008 @@ -20,6 +20,7 @@ #define YWidgetID_h #include <string> +#include <iosfwd> using std::string; @@ -106,5 +107,7 @@ string _value; }; +std::ostream & operator<<( std::ostream & stream, const YWidgetID * id ); + #endif // YWidgetID_h -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org