libyui  3.10.0
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 using std::string;
33 
34 
36 {
37  YPartitionSplitterPrivate( int usedSize,
38  int totalFreeSize,
39  int minNewPartSize,
40  int minFreeSize,
41  const string & usedLabel,
42  const string & freeLabel,
43  const string & newPartLabel,
44  const string & freeFieldLabel,
45  const string & newPartFieldLabel )
46  : usedSize ( usedSize )
47  , totalFreeSize ( totalFreeSize )
48  , minNewPartSize ( minNewPartSize )
49  , minFreeSize ( minFreeSize )
50  , usedLabel ( usedLabel )
51  , freeLabel ( freeLabel )
52  , newPartLabel ( newPartLabel )
53  , freeFieldLabel ( freeFieldLabel )
54  , newPartFieldLabel ( newPartFieldLabel )
55  {}
56 
57  int usedSize;
58  int totalFreeSize;
59  int minNewPartSize;
60  int minFreeSize;
61  string usedLabel;
62  string freeLabel;
63  string newPartLabel;
64  string freeFieldLabel;
65  string newPartFieldLabel;
66 };
67 
68 
69 
70 
72  int usedSize,
73  int totalFreeSize,
74  int newPartSize,
75  int minNewPartSize,
76  int minFreeSize,
77  const string & usedLabel,
78  const string & freeLabel,
79  const string & newPartLabel,
80  const string & freeFieldLabel,
81  const string & newPartFieldLabel )
82  : YWidget( parent )
83  , priv( new YPartitionSplitterPrivate( usedSize,
84  totalFreeSize,
85  minNewPartSize,
86  minFreeSize,
87  usedLabel,
88  freeLabel,
89  newPartLabel,
90  freeFieldLabel,
91  newPartFieldLabel )
92  )
93 {
94  YUI_CHECK_NEW( priv );
95 
96  setDefaultStretchable( YD_HORIZ, true );
97  setStretchable( YD_VERT, false );
98 }
99 
100 
102 {
103  // NOP
104 }
105 
106 
107 int YPartitionSplitter::usedSize() const
108 {
109  return priv->usedSize;
110 }
111 
112 
113 int YPartitionSplitter::totalFreeSize() const
114 {
115  return priv->totalFreeSize;
116 }
117 
118 
119 int YPartitionSplitter::minNewPartSize() const
120 {
121  return priv->minNewPartSize;
122 }
123 
124 
125 int YPartitionSplitter::minFreeSize() const
126 {
127  return priv->minFreeSize;
128 }
129 
130 
131 string YPartitionSplitter::usedLabel() const
132 {
133  return priv->usedLabel;
134 }
135 
136 
137 string YPartitionSplitter::freeLabel() const
138 {
139  return priv->freeLabel;
140 }
141 
142 
143 string YPartitionSplitter::newPartLabel() const
144 {
145  return priv->newPartLabel;
146 }
147 
148 
149 string YPartitionSplitter::freeFieldLabel() const
150 {
151  return priv->freeFieldLabel;
152 }
153 
154 
155 string YPartitionSplitter::newPartFieldLabel() const
156 {
157  return priv->newPartFieldLabel;
158 }
159 
160 
161 const YPropertySet &
163 {
164  static YPropertySet propSet;
165 
166  if ( propSet.isEmpty() )
167  {
168  /*
169  * @property string Value the value (the size of the new partition)
170  */
171  propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
172  propSet.add( YWidget::propertySet() );
173  }
174 
175  return propSet;
176 }
177 
178 
179 bool
180 YPartitionSplitter::setProperty( const string & propertyName, const YPropertyValue & val )
181 {
182  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
183 
184  if ( propertyName == YUIProperty_Value ) setValue( val.integerVal() );
185  else
186  {
187  return YWidget::setProperty( propertyName, val );
188  }
189 
190  return true; // success -- no special processing necessary
191 }
192 
193 
195 YPartitionSplitter::getProperty( const string & propertyName )
196 {
197  propertySet().check( propertyName ); // throws exceptions if not found
198 
199  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
200  else
201  {
202  return YWidget::getProperty( propertyName );
203  }
204 }
virtual const YPropertySet & propertySet()
Return this class's property set.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual int value()=0
The value of this PartitionSplitter: The size of the new partition.
virtual ~YPartitionSplitter()
Destructor.
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 void setValue(int newValue)=0
Set the value (the size of the new partition).
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
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
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