libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YPartitionSplitter.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YPartitionSplitter.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YPartitionSplitter_h
00026 #define YPartitionSplitter_h
00027 
00028 #include "YWidget.h"
00029 
00030 
00031 class YPartitionSplitterPrivate;
00032 
00033 
00034 /**
00035  * PartitionSplitter: A (very custom) widget for easily splitting one existing
00036  * partition into two.
00037  *
00038  * Layout:
00039  *
00040  *     +--------------------+---------------+--------------------------+
00041  *     | Old Partition      | Old Partition | New Partition            |
00042  *     | used               | free          |                          |
00043  *     +--------------------+---------------+--------------------------+
00044  *
00045  *     Old Partition free                                  New Partition
00046  *     [ 123 ] ================O================================ [ 123 ]
00047  *
00048  *
00049  * At the top, there is a BarGraph that dynamicylla displays the sizes in
00050  * graphical form. Below are an IntField to the left and an IntField to the
00051  * right, each with its respective label. Between the two IntFields there is a
00052  * Slider.
00053  *
00054  * The user can enter a value in either IntField or drag the slider. The other
00055  * sub-widgets (including the BarGraph) will automatically be
00056  * adjusted. Visually (in the BarGraph), the border between "old partition
00057  * free" and "new partition" will move left and right. The border between "old
00058  * partition used" and "old partition free" is static.
00059  *
00060  * There are built-in (configurable) limits for the minimum sizes of "old
00061  * partition free" and "new partition".
00062  **/
00063 class YPartitionSplitter : public YWidget
00064 {
00065 protected:
00066     /**
00067      * Constructor.
00068      *
00069      * usedSize:        Used size of the old partition (constant)
00070      *
00071      * totalFreeSize:   Total free size of the old partition before the split:
00072      *                  OldPartitionFree + NewPartition
00073      *
00074      * newPartSize':    Initial size of the new partition
00075      *
00076      * minNewPartSize:  Miminum size of the new partition
00077      *
00078      * minFreeSize:     Minimum free size of the old partition
00079      *
00080      * usedLabel:       BarGraph label for the used part of the old partition
00081      *
00082      * freeLabel:       BarGraph label for the free part of the old partition
00083      *
00084      * newPartLabel:    BarGraph label for the new partition
00085      *
00086      * freeFieldLabel:  IntField label for the free part of the old partition
00087      *
00088      * newPartFieldLabel: IntField label for the size of the new partition
00089      **/
00090     YPartitionSplitter( YWidget *               parent,
00091                         int                     usedSize,
00092                         int                     totalFreeSize,
00093                         int                     newPartSize,
00094                         int                     minNewPartSize,
00095                         int                     minFreeSize,
00096                         const std::string &     usedLabel,
00097                         const std::string &     freeLabel,
00098                         const std::string &     newPartLabel,
00099                         const std::string &     freeFieldLabel,
00100                         const std::string &     newPartFieldLabel );
00101 
00102 public:
00103 
00104     /**
00105      * Destructor.
00106      **/
00107     virtual ~YPartitionSplitter();
00108 
00109     /**
00110      * Returns a descriptive name of this widget class for logging,
00111      * debugging etc.
00112      **/
00113     virtual const char * widgetClass() const { return "YPartitionSplitter"; }
00114 
00115     /**
00116      * The value of this PartitionSplitter: The size of the new partition.
00117      *
00118      * Derived classes are required to implement this.
00119      **/
00120     virtual int value() = 0;
00121 
00122     /**
00123      * Set the value (the size of the new partition).
00124      *
00125      * Derived classes are required to implement this.
00126      **/
00127     virtual void setValue( int newValue ) = 0;
00128 
00129 
00130     // Access methods
00131 
00132     int         usedSize()              const;
00133     int         totalFreeSize()         const;
00134     int         minFreeSize()           const;
00135     int         maxFreeSize()           const   { return totalFreeSize() - minNewPartSize(); }
00136     int         freeSize()                      { return totalFreeSize() - newPartSize(); }
00137     int         newPartSize()                   { return value(); }
00138     int         minNewPartSize()        const;
00139     int         maxNewPartSize()        const   { return totalFreeSize() - minFreeSize(); }
00140 
00141     std::string usedLabel()             const;
00142     std::string freeLabel()             const;
00143     std::string newPartLabel()          const;
00144     std::string freeFieldLabel()        const;
00145     std::string newPartFieldLabel()     const;
00146 
00147     /**
00148      * Set a property.
00149      * Reimplemented from YWidget.
00150      *
00151      * This function may throw YUIPropertyExceptions.
00152      *
00153      * This function returns 'true' if the value was successfully set and
00154      * 'false' if that value requires special handling (not in error cases:
00155      * those are covered by exceptions).
00156      **/
00157     virtual bool setProperty( const std::string & propertyName,
00158                               const YPropertyValue & val );
00159 
00160     /**
00161      * Get a property.
00162      * Reimplemented from YWidget.
00163      *
00164      * This method may throw YUIPropertyExceptions.
00165      **/
00166     virtual YPropertyValue getProperty( const std::string & propertyName );
00167 
00168     /**
00169      * Return this class's property set.
00170      * This also initializes the property upon the first call.
00171      *
00172      * Reimplemented from YWidget.
00173      **/
00174     virtual const YPropertySet & propertySet();
00175 
00176 
00177     /**
00178      * The name of the widget property that will return user input.
00179      * Inherited from YWidget.
00180      **/
00181     const char * userInputProperty() { return YUIProperty_Value; }
00182 
00183 
00184 private:
00185 
00186     ImplPtr<YPartitionSplitterPrivate> priv;
00187 };
00188 
00189 
00190 #endif // YPartitionSplitter_h
 All Classes Functions Variables Enumerations Friends