libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YBusyIndicator.cc 00020 00021 Author: Thomas Goettlicher <tgoettlicher@suse.de> 00022 00023 /-*/ 00024 00025 00026 #define YUILogComponent "ui" 00027 #include "YUILog.h" 00028 00029 #include "YUISymbols.h" 00030 #include "YBusyIndicator.h" 00031 00032 00033 struct YBusyIndicatorPrivate 00034 { 00035 YBusyIndicatorPrivate( const std::string & label, 00036 int timeout , 00037 bool alive ) 00038 : label( label ) 00039 , timeout( timeout ) 00040 , alive (true) 00041 { 00042 } 00043 00044 std::string label; 00045 int timeout; 00046 bool alive; 00047 }; 00048 00049 00050 00051 00052 YBusyIndicator::YBusyIndicator( YWidget * parent, 00053 const std::string & label, 00054 int timeout, 00055 bool alive ) 00056 : YWidget( parent ) 00057 , priv( new YBusyIndicatorPrivate( label, timeout, alive ) ) 00058 { 00059 YUI_CHECK_NEW( priv ); 00060 00061 setDefaultStretchable( YD_HORIZ, true ); 00062 setStretchable( YD_VERT, false ); 00063 } 00064 00065 00066 YBusyIndicator::~YBusyIndicator() 00067 { 00068 // NOP 00069 } 00070 00071 00072 std::string YBusyIndicator::label() 00073 { 00074 return priv->label; 00075 } 00076 00077 00078 void YBusyIndicator::setLabel( const std::string & label ) 00079 { 00080 priv->label = label; 00081 } 00082 00083 00084 int YBusyIndicator::timeout() const 00085 { 00086 return priv->timeout; 00087 } 00088 00089 00090 void YBusyIndicator::setTimeout( int newTimeout ) 00091 { 00092 if ( newTimeout < 1 ) 00093 newTimeout = 1; 00094 00095 priv->timeout = newTimeout; 00096 } 00097 00098 00099 void YBusyIndicator::setAlive( bool alive ) 00100 { 00101 priv->alive = alive; 00102 } 00103 00104 bool YBusyIndicator::alive() const 00105 { 00106 return priv->alive; 00107 } 00108 00109 const YPropertySet & 00110 YBusyIndicator::propertySet() 00111 { 00112 static YPropertySet propSet; 00113 00114 if ( propSet.isEmpty() ) 00115 { 00116 /* 00117 * @property integer Timeout timeout in ms until busy indicator changes to stalled state 00118 * @property bool Alive busy indicator is in alive or stalled state 00119 * @property std::string Label caption above the busy indicator 00120 */ 00121 propSet.add( YProperty( YUIProperty_Timeout, YIntegerProperty ) ); 00122 propSet.add( YProperty( YUIProperty_Alive, YBoolProperty ) ); 00123 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00124 propSet.add( YWidget::propertySet() ); 00125 } 00126 00127 return propSet; 00128 } 00129 00130 00131 bool 00132 YBusyIndicator::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00133 { 00134 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00135 00136 if ( propertyName == YUIProperty_Timeout ) setTimeout( val.integerVal() ); 00137 else if ( propertyName == YUIProperty_Alive ) setAlive( val.boolVal() ); 00138 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00139 else 00140 { 00141 return YWidget::setProperty( propertyName, val ); 00142 } 00143 00144 return true; // success -- no special processing necessary 00145 } 00146 00147 00148 YPropertyValue 00149 YBusyIndicator::getProperty( const std::string & propertyName ) 00150 { 00151 propertySet().check( propertyName ); // throws exceptions if not found 00152 00153 if ( propertyName == YUIProperty_Timeout ) return YPropertyValue( timeout() ); 00154 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00155 else if ( propertyName == YUIProperty_Alive ) return YPropertyValue( alive() ); 00156 else 00157 { 00158 return YWidget::getProperty( propertyName ); 00159 } 00160 }