libyui  3.4.2
YPartitionSplitter.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: YPartitionSplitter.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YPartitionSplitter.h"
31 
32 
34 {
35  YPartitionSplitterPrivate( int usedSize,
36  int totalFreeSize,
37  int minNewPartSize,
38  int minFreeSize,
39  const std::string & usedLabel,
40  const std::string & freeLabel,
41  const std::string & newPartLabel,
42  const std::string & freeFieldLabel,
43  const std::string & newPartFieldLabel )
44  : usedSize ( usedSize )
45  , totalFreeSize ( totalFreeSize )
46  , minNewPartSize ( minNewPartSize )
47  , minFreeSize ( minFreeSize )
48  , usedLabel ( usedLabel )
49  , freeLabel ( freeLabel )
50  , newPartLabel ( newPartLabel )
51  , freeFieldLabel ( freeFieldLabel )
52  , newPartFieldLabel ( newPartFieldLabel )
53  {}
54 
55  int usedSize;
56  int totalFreeSize;
57  int minNewPartSize;
58  int minFreeSize;
59  std::string usedLabel;
60  std::string freeLabel;
61  std::string newPartLabel;
62  std::string freeFieldLabel;
63  std::string newPartFieldLabel;
64 };
65 
66 
67 
68 
70  int usedSize,
71  int totalFreeSize,
72  int newPartSize,
73  int minNewPartSize,
74  int minFreeSize,
75  const std::string & usedLabel,
76  const std::string & freeLabel,
77  const std::string & newPartLabel,
78  const std::string & freeFieldLabel,
79  const std::string & newPartFieldLabel )
80  : YWidget( parent )
81  , priv( new YPartitionSplitterPrivate( usedSize,
82  totalFreeSize,
83  minNewPartSize,
84  minFreeSize,
85  usedLabel,
86  freeLabel,
87  newPartLabel,
88  freeFieldLabel,
89  newPartFieldLabel )
90  )
91 {
92  YUI_CHECK_NEW( priv );
93 
94  setDefaultStretchable( YD_HORIZ, true );
95  setStretchable( YD_VERT, false );
96 }
97 
98 
100 {
101  // NOP
102 }
103 
104 
105 int YPartitionSplitter::usedSize() const
106 {
107  return priv->usedSize;
108 }
109 
110 
111 int YPartitionSplitter::totalFreeSize() const
112 {
113  return priv->totalFreeSize;
114 }
115 
116 
117 int YPartitionSplitter::minNewPartSize() const
118 {
119  return priv->minNewPartSize;
120 }
121 
122 
123 int YPartitionSplitter::minFreeSize() const
124 {
125  return priv->minFreeSize;
126 }
127 
128 
129 std::string YPartitionSplitter::usedLabel() const
130 {
131  return priv->usedLabel;
132 }
133 
134 
135 std::string YPartitionSplitter::freeLabel() const
136 {
137  return priv->freeLabel;
138 }
139 
140 
141 std::string YPartitionSplitter::newPartLabel() const
142 {
143  return priv->newPartLabel;
144 }
145 
146 
147 std::string YPartitionSplitter::freeFieldLabel() const
148 {
149  return priv->freeFieldLabel;
150 }
151 
152 
153 std::string YPartitionSplitter::newPartFieldLabel() const
154 {
155  return priv->newPartFieldLabel;
156 }
157 
158 
159 const YPropertySet &
161 {
162  static YPropertySet propSet;
163 
164  if ( propSet.isEmpty() )
165  {
166  /*
167  * @property std::string Value the value (the size of the new partition)
168  */
169  propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
170  propSet.add( YWidget::propertySet() );
171  }
172 
173  return propSet;
174 }
175 
176 
177 bool
178 YPartitionSplitter::setProperty( const std::string & propertyName, const YPropertyValue & val )
179 {
180  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
181 
182  if ( propertyName == YUIProperty_Value ) setValue( val.integerVal() );
183  else
184  {
185  return YWidget::setProperty( propertyName, val );
186  }
187 
188  return true; // success -- no special processing necessary
189 }
190 
191 
193 YPartitionSplitter::getProperty( const std::string & propertyName )
194 {
195  propertySet().check( propertyName ); // throws exceptions if not found
196 
197  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
198  else
199  {
200  return YWidget::getProperty( propertyName );
201  }
202 }
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:430
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
A set of properties to check names and types against.
Definition: YProperty.h:197
YPartitionSplitter(YWidget *parent, int usedSize, int totalFreeSize, int newPartSize, int minNewPartSize, int minFreeSize, const std::string &usedLabel, const std::string &freeLabel, const std::string &newPartLabel, const std::string &freeFieldLabel, const std::string &newPartFieldLabel)
Constructor.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:455
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:564
Class for widget properties.
Definition: YProperty.h:51
virtual void setValue(int newValue)=0
Set the value (the size of the new partition).
void setStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
Definition: YWidget.cc:558
virtual int value()=0
The value of this PartitionSplitter: The size of the new partition.
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
virtual ~YPartitionSplitter()
Destructor.