libyui  3.10.0
YBusyIndicator.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YBusyIndicator.cc
20 
21  Author: Thomas Goettlicher <tgoettlicher@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YBusyIndicator.h"
31 
32 using std::string;
33 
34 
36 {
37  YBusyIndicatorPrivate( const string & label,
38  int timeout ,
39  bool alive )
40  : label( label )
41  , timeout( timeout )
42  , alive (true)
43  {
44  }
45 
46  string label;
47  int timeout;
48  bool alive;
49 };
50 
51 
52 
53 
55  const string & label,
56  int timeout,
57  bool alive )
58  : YWidget( parent )
59  , priv( new YBusyIndicatorPrivate( label, timeout, alive ) )
60 {
61  YUI_CHECK_NEW( priv );
62 
63  setDefaultStretchable( YD_HORIZ, true );
64  setStretchable( YD_VERT, false );
65 }
66 
67 
69 {
70  // NOP
71 }
72 
73 
75 {
76  return priv->label;
77 }
78 
79 
80 void YBusyIndicator::setLabel( const string & label )
81 {
82  priv->label = label;
83 }
84 
85 
87 {
88  return priv->timeout;
89 }
90 
91 
92 void YBusyIndicator::setTimeout( int newTimeout )
93 {
94  if ( newTimeout < 1 )
95  newTimeout = 1;
96 
97  priv->timeout = newTimeout;
98 }
99 
100 
101 void YBusyIndicator::setAlive( bool alive )
102 {
103  priv->alive = alive;
104 }
105 
107 {
108  return priv->alive;
109 }
110 
111 const YPropertySet &
113 {
114  static YPropertySet propSet;
115 
116  if ( propSet.isEmpty() )
117  {
118  /*
119  * @property integer Timeout timeout in ms until busy indicator changes to stalled state
120  * @property bool Alive busy indicator is in alive or stalled state
121  * @property string Label caption above the busy indicator
122  */
123  propSet.add( YProperty( YUIProperty_Timeout, YIntegerProperty ) );
124  propSet.add( YProperty( YUIProperty_Alive, YBoolProperty ) );
125  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
126  propSet.add( YWidget::propertySet() );
127  }
128 
129  return propSet;
130 }
131 
132 
133 bool
134 YBusyIndicator::setProperty( const string & propertyName, const YPropertyValue & val )
135 {
136  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
137 
138  if ( propertyName == YUIProperty_Timeout ) setTimeout( val.integerVal() );
139  else if ( propertyName == YUIProperty_Alive ) setAlive( val.boolVal() );
140  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
141  else
142  {
143  return YWidget::setProperty( propertyName, val );
144  }
145 
146  return true; // success -- no special processing necessary
147 }
148 
149 
151 YBusyIndicator::getProperty( const string & propertyName )
152 {
153  propertySet().check( propertyName ); // throws exceptions if not found
154 
155  if ( propertyName == YUIProperty_Timeout ) return YPropertyValue( timeout() );
156  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
157  else if ( propertyName == YUIProperty_Alive ) return YPropertyValue( alive() );
158  else
159  {
160  return YWidget::getProperty( propertyName );
161  }
162 }
std::string label()
Get the label (the caption above the progress bar).
virtual ~YBusyIndicator()
Destructor.
YBusyIndicator(YWidget *parent, const std::string &label, int timeout=1000, bool alive=true)
Constructor.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
int timeout() const
Return the current timeout in milliseconds.
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
bool alive() const
Return whether busy indicator is alive or in stalled stated.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual void setAlive(bool newAlive)
Send a keep alive message to prevent BusyIndicator from changing to 'stalled' state.
virtual void setTimeout(int newTimeout)
Set the timeout in milliseconds after that the widget shows 'stalled' when no new tick is received.
virtual const YPropertySet & propertySet()
Return this class's property set.
A set of properties to check names and types against.
Definition: YProperty.h:198
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:88
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:146
Transport class for the value of simple properties.
Definition: YProperty.h:105
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
Class for widget properties.
Definition: YProperty.h:52
Abstract base class of all UI widgets.
Definition: YWidget.h:55
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:395
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:566
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457
void setStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
Definition: YWidget.cc:560