libyui  2.42.5
 All Classes Functions Variables Enumerations Friends
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 
99 void YBusyIndicator::setAlive( bool alive )
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 }