libyui-ncurses-pkg  2.48.2
NCPkgPopupDiskspace.h
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgPopupDiskspace.h
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #ifndef NCPkgPopupDiskspace_h
42 #define NCPkgPopupDiskspace_h
43 
44 #include <iosfwd>
45 
46 #include <vector>
47 #include <string>
48 
49 #include <FSize.h>
50 #include "NCPopup.h"
51 #include "NCLabel.h"
52 
53 #include "NCZypp.h"
54 
55 typedef zypp::DiskUsageCounter::MountPoint ZyppPartitionDu;
56 typedef zypp::DiskUsageCounter::MountPointSet ZyppDuSet;
57 typedef zypp::DiskUsageCounter::MountPointSet::iterator ZyppDuSetIterator;
58 
59 class NCTable;
60 class NCPushButton;
61 
62 ///////////////////////////////////////////////////////////////////////////////
63 //
64 // CLASS NAME : NCPkgWarningRangeNotifier
65 //
66 // Class YQPkgWarningRangeNotifier from YQPkgDiskUsageList.h
67 //
68 
69 /**
70  * Helper class to manage warnings that are to be issued when a value enters a
71  * predefined range, but repeated only when that value leaves a (wider)
72  * "proximity" range and then re-enters the (narrower) "inner" range.
73  *
74  * Example: Disk space usage:
75  *
76  * 70%
77  * 75%
78  * 80% [proximity range start]
79  * 85%
80  * 90% [inner range start]
81  * 95%
82  * 100%
83  *
84  * A warning is to be posted when there is only 90% disk space left. After the
85  * warning is displayed, there shall be no more warning until disk usage decreases
86  * below 80% (the proximity range) and then later increases again to 90%.
87  *
88  * The net effect of all that is to avoid posting the warning over and over
89  * again while the value changes back and forth around the boundary of the
90  * ( inner ) warning range.
91  **/
93 {
94 public:
95 
96  /**
97  * Constructor.
98  **/
100 
101  /**
102  * Notification that the inner range is entered.
103  * The caller has to decide the criteria for that.
104  **/
105  void enterRange();
106 
107  /**
108  * Notification that the proximity range is entered, i.e. that the value is
109  * getting near the inner range.
110  * 'enterRange()' automatically includes this, too.
111  **/
112  void enterProximity();
113 
114  /**
115  * Notification that a warning has been posted.
116  **/
117  void warningPostedNotify();
118 
119  /**
120  * Check if the value is in range, i.e. if anybody from the outside has
121  * called 'enterRange()' since the last call to 'clear()'.
122  **/
123  bool inRange() const;
124 
125  /**
126  * Check if a warning should be posted, i.e. if the value is currently in
127  * range ( see 'inRange() ) and there has been no notification yet that a
128  * warning has already been posted.
129  **/
130  bool needWarning() const;
131 
132  /**
133  * Check if the value is leaving the proximity range.
134  **/
135  bool leavingProximity() const;
136 
137  /*
138  * Log settings to y2log
139  */
140  void logSettings() const;
141 
142  /**
143  * Clear the current values, i.e. prepare for a new round of checks
144  **/
145  void clear();
146 
147  /**
148  * Clear everything, including all history values such as if a warning has
149  * been posted.
150  **/
151  void clearHistory();
152 
153 
154 protected:
155 
156  bool _inRange;
157  bool _isClose;
158  bool _hasBeenClose;
159  bool _warningPosted;
160 };
161 
162 class NCPkgPopupDiskspace : public NCPopup {
163 
164 private:
165  NCTable * partitions;
166  NCPushButton * okButton;
167  NCLabel * head;
168 
169 protected:
170 
171  virtual bool postAgain();
172 
173  virtual NCursesEvent wHandleInput( wint_t ch );
174 
175 public:
176  NCPkgPopupDiskspace( const wpos at, std::string headline );
177 
178  virtual ~NCPkgPopupDiskspace();
179 
180  void createLayout( std::string headline );
181  void doit();
182 
183  NCTable *Partitions() { return partitions; }
184 
185  virtual int preferredWidth();
186  virtual int preferredHeight();
187 
188 };
189 
190 ///////////////////////////////////////////////////////////////////
191 //
192 // CLASS NAME : NCPkgPopupDiskspace
193 //
194 // DESCRIPTION :
195 //
197 
198  NCPkgDiskspace & operator=( const NCPkgDiskspace & );
199  NCPkgDiskspace ( const NCPkgDiskspace & );
200 
201 private:
202 
203  bool testmode;
204  NCPkgPopupDiskspace *popupWin;
205  ZyppDuSet testDiskUsage;
206 
207  std::string usedPercent( FSize used, FSize total );
208 
209  /**
210  * Warning range notifier about running out of disk space warning.
211  **/
212  NCPkgWarningRangeNotifier runningOutWarning;
213 
214  /**
215  * Warning range notifier about disk space overflow warning.
216  **/
217  NCPkgWarningRangeNotifier overflowWarning;
218 
219 
220 public:
221 
222  NCPkgDiskspace( bool testSpaceMode );
223 
224  virtual ~NCPkgDiskspace();
225 
226 
227  void fillPartitionTable();
228 
229  std::string checkDiskSpace();
230 
231  void setDiskSpace( wint_t key ); // used for testing
232 
233  void checkDiskSpaceRange( );
234 
235  void showInfoPopup( std::string headline );
236 
237  void checkRemainingDiskSpace( const ZyppPartitionDu & partition );
238 
239  zypp::ByteCount calculateDiff();
240 };
241 
242 
243 ///////////////////////////////////////////////////////////////////
244 
245 
246 #endif // NCPkgPopupDiskspace_h
void warningPostedNotify()
Notification that a warning has been posted.
void clearHistory()
Clear everything, including all history values such as if a warning has been posted.
Helper class to manage warnings that are to be issued when a value enters a predefined range...
bool inRange() const
Check if the value is in range, i.e.
void clear()
Clear the current values, i.e.
bool leavingProximity() const
Check if the value is leaving the proximity range.
NCPkgWarningRangeNotifier()
Constructor.
bool needWarning() const
Check if a warning should be posted, i.e.
void enterProximity()
Notification that the proximity range is entered, i.e.
void enterRange()
Notification that the inner range is entered.