libyui  3.3.2
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 
34 {
35  YBusyIndicatorPrivate( const std::string & label,
36  int timeout ,
37  bool alive )
38  : label( label )
39  , timeout( timeout )
40  , alive (true)
41  {
42  }
43 
44  std::string label;
45  int timeout;
46  bool alive;
47 };
48 
49 
50 
51 
53  const std::string & label,
54  int timeout,
55  bool alive )
56  : YWidget( parent )
57  , priv( new YBusyIndicatorPrivate( label, timeout, alive ) )
58 {
59  YUI_CHECK_NEW( priv );
60 
61  setDefaultStretchable( YD_HORIZ, true );
62  setStretchable( YD_VERT, false );
63 }
64 
65 
67 {
68  // NOP
69 }
70 
71 
72 std::string YBusyIndicator::label()
73 {
74  return priv->label;
75 }
76 
77 
78 void YBusyIndicator::setLabel( const std::string & label )
79 {
80  priv->label = label;
81 }
82 
83 
85 {
86  return priv->timeout;
87 }
88 
89 
90 void YBusyIndicator::setTimeout( int newTimeout )
91 {
92  if ( newTimeout < 1 )
93  newTimeout = 1;
94 
95  priv->timeout = newTimeout;
96 }
97 
98 
100 {
101  priv->alive = alive;
102 }
103 
105 {
106  return priv->alive;
107 }
108 
109 const YPropertySet &
111 {
112  static YPropertySet propSet;
113 
114  if ( propSet.isEmpty() )
115  {
116  /*
117  * @property integer Timeout timeout in ms until busy indicator changes to stalled state
118  * @property bool Alive busy indicator is in alive or stalled state
119  * @property std::string Label caption above the busy indicator
120  */
121  propSet.add( YProperty( YUIProperty_Timeout, YIntegerProperty ) );
122  propSet.add( YProperty( YUIProperty_Alive, YBoolProperty ) );
123  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
124  propSet.add( YWidget::propertySet() );
125  }
126 
127  return propSet;
128 }
129 
130 
131 bool
132 YBusyIndicator::setProperty( const std::string & propertyName, const YPropertyValue & val )
133 {
134  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
135 
136  if ( propertyName == YUIProperty_Timeout ) setTimeout( val.integerVal() );
137  else if ( propertyName == YUIProperty_Alive ) setAlive( val.boolVal() );
138  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
139  else
140  {
141  return YWidget::setProperty( propertyName, val );
142  }
143 
144  return true; // success -- no special processing necessary
145 }
146 
147 
149 YBusyIndicator::getProperty( const std::string & propertyName )
150 {
151  propertySet().check( propertyName ); // throws exceptions if not found
152 
153  if ( propertyName == YUIProperty_Timeout ) return YPropertyValue( timeout() );
154  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
155  else if ( propertyName == YUIProperty_Alive ) return YPropertyValue( alive() );
156  else
157  {
158  return YWidget::getProperty( propertyName );
159  }
160 }
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
std::string label()
Get the label (the caption above the progress bar).
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual void setAlive(bool newAlive)
Send a keep alive message to prevent BusyIndicator from changing to &#39;stalled&#39; state.
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual ~YBusyIndicator()
Destructor.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:428
A set of properties to check names and types against.
Definition: YProperty.h:197
int timeout() const
Return the current timeout in milliseconds.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
bool alive() const
Return whether busy indicator is alive or in stalled stated.
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
virtual void setTimeout(int newTimeout)
Set the timeout in milliseconds after that the widget shows &#39;stalled&#39; when no new tick is received...
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:453
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:561
Class for widget properties.
Definition: YProperty.h:51
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
void setStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
Definition: YWidget.cc:555
YBusyIndicator(YWidget *parent, const std::string &label, int timeout=1000, bool alive=true)
Constructor.
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
Abstract base class of all UI widgets.
Definition: YWidget.h:54
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169