libyui-qt-pkg  2.45.27
YQPkgDiskUsageList.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgDiskUsageList.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgDiskUsageList_h
42 #define YQPkgDiskUsageList_h
43 
44 #include <zypp/DiskUsageCounter.h>
45 #include <QY2DiskUsageList.h>
46 #include <QKeyEvent>
47 #include <QMap>
48 #include <QByteArray>
49 
50 typedef zypp::DiskUsageCounter::MountPoint ZyppPartitionDu;
52 
53 
54 /**
55  * Helper class to manage warnings that are to be issued when a value enters a
56  * predefined range, but repeated only when that value leaves a (wider)
57  * "proximity" range and then re-enters the (narrower) "inner" range.
58  *
59  * Example: Disk space usage:
60  *
61  * 70%
62  * 75%
63  * 80% [proximity range start]
64  * 85%
65  * 90% [inner range start]
66  * 95%
67  * 100%
68  *
69  * A warning is to be posted when there is only 90% disk space left. After the
70  * warning is displayed, there shall be no more warning until disk usage decreases
71  * below 80% (the proximity range) and then later increases again to 90%.
72  *
73  * The net effect of all that is to avoid posting the warning over and over
74  * again while the value changes back and forth around the boundary of the
75  * ( inner ) warning range.
76  **/
78 {
79 public:
80 
81  /**
82  * Constructor.
83  **/
85 
86  /**
87  * Notification that the inner range is entered.
88  * The caller has to decide the criteria for that.
89  **/
90  void enterRange();
91 
92  /**
93  * Notification that the proximity range is entered, i.e. that the value is
94  * getting near the inner range.
95  * 'enterRange()' automatically includes this, too.
96  **/
97  void enterProximity();
98 
99  /**
100  * Notification that a warning has been posted.
101  **/
102  void warningPostedNotify();
103 
104  /**
105  * Check if the value is in range, i.e. if anybody from the outside has
106  * called 'enterRange()' since the last call to 'clear()'.
107  **/
108  bool inRange() const;
109 
110  /**
111  * Check if a warning should be posted, i.e. if the value is currently in
112  * range ( see 'inRange() ) and there has been no notification yet that a
113  * warning has already been posted.
114  **/
115  bool needWarning() const;
116 
117  /**
118  * Check if the value is leaving the proximity range.
119  **/
120  bool leavingProximity() const;
121 
122  /**
123  * Clear the current values, i.e. prepare for a new round of checks
124  **/
125  void clear();
126 
127  /**
128  * Clear everything, including all history values such as if a warning has
129  * been posted.
130  **/
131  void clearHistory();
132 
133 
134 protected:
135 
136  bool _inRange;
137  bool _isClose;
138  bool _hasBeenClose;
139  bool _warningPosted;
140 };
141 
142 
143 
144 
145 
146 /**
147  * @short List of disk usage of all attached partitions.
148  **/
149 class YQPkgDiskUsageList : public QY2DiskUsageList
150 {
151  Q_OBJECT
152 
153 public:
154  /**
155  * Constructor.
156  *
157  * 'thresholdPercent' can be used to include only partitions with at least
158  * this many percent used disk space in the list. This is useful for
159  * warning dialogs ( only? ).
160  **/
161  YQPkgDiskUsageList( QWidget * parent, int thresholdPercent = 0 );
162 
163  /**
164  * Destructor.
165  **/
166  virtual ~YQPkgDiskUsageList() {}
167 
168  /**
169  * Suggest reasonable default size.
170  *
171  * Reimplemented from QListView.
172  **/
173  virtual QSize sizeHint() const;
174 
175  /**
176  * Warning range notifier about running out of disk space warning.
177  **/
179 
180  /**
181  * Warning range notifier about disk space overflow warning.
182  **/
184 
185 
186 public slots:
187 
188  /**
189  * Update all statistical data in the list.
190  **/
191  void updateDiskUsage();
192 
193  /**
194  * Post all pending disk space warnings based on the warning range
195  * notifiers.
196  **/
197  void postPendingWarnings();
198 
199 
200 protected:
201 
202  /**
203  * Event handler for keyboard input - for debugging and testing.
204  * Changes the current item's percentage on the fly.
205  *
206  * Reimplemented from QListView / QWidget.
207  **/
208  virtual void keyPressEvent( QKeyEvent * ev );
209 
210 
211  // Data members
212 
213  QMap<QString, YQPkgDiskUsageListItem*> _items;
214  bool _debug;
215 };
216 
217 
218 
219 class YQPkgDiskUsageListItem: public QY2DiskUsageListItem
220 {
221 public:
222 
223  /**
224  * Constructor. Creates a YQPkgDiskUsageList item that corresponds to the
225  * specified file system.
226  **/
228  const ZyppPartitionDu & partitionDu );
229 
230  /**
231  * Destructor.
232  **/
234 
235  /**
236  * Returns the corresponding disk usage data.
237  **/
238  ZyppPartitionDu partitionDu() const { return _partitionDu; }
239 
240  /**
241  * Update the disk usage data.
242  **/
243  void updateDuData( const ZyppPartitionDu & fromData );
244 
245  /**
246  * The currently used size of this partition.
247  *
248  * Reimplemented from QY2DiskUsageListItem.
249  **/
250  virtual FSize usedSize() const;
251 
252  /**
253  * The total size of this partition.
254  *
255  * Reimplemented from QY2DiskUsageListItem.
256  **/
257  virtual FSize totalSize() const;
258 
259  /**
260  * The name to display for this partition ( the mount point ).
261  *
262  * Reimplemented from QY2DiskUsageListItem.
263  **/
264  virtual QString name() const;
265 
266  /**
267  * The device name of this partition.
268  *
269  * Reimplemented from QY2DiskUsageListItem.
270  **/
271  virtual QString deviceName() const { return ""; }
272 
273  /**
274  * Check the remaining disk space of this partition based on percentage and
275  * absolute free MB. Notify the parent YQPkgDiskUsageList's warning ranges
276  * accordingly.
277  **/
279 
280 
281 protected:
282 
283  // Data members
284 
285  ZyppPartitionDu _partitionDu;
286  YQPkgDiskUsageList * _pkgDiskUsageList;
287 };
288 
289 
290 
291 #endif // ifndef YQPkgDiskUsageList_h
YQPkgWarningRangeNotifier overflowWarning
Warning range notifier about disk space overflow warning.
YQPkgDiskUsageListItem(YQPkgDiskUsageList *parent, const ZyppPartitionDu &partitionDu)
Constructor.
YQPkgDiskUsageList(QWidget *parent, int thresholdPercent=0)
Constructor.
void postPendingWarnings()
Post all pending disk space warnings based on the warning range notifiers.
void checkRemainingDiskSpace()
Check the remaining disk space of this partition based on percentage and absolute free MB...
bool leavingProximity() const
Check if the value is leaving the proximity range.
virtual void keyPressEvent(QKeyEvent *ev)
Event handler for keyboard input - for debugging and testing.
virtual QSize sizeHint() const
Suggest reasonable default size.
void updateDiskUsage()
Update all statistical data in the list.
bool needWarning() const
Check if a warning should be posted, i.e.
virtual QString name() const
The name to display for this partition ( the mount point ).
virtual FSize totalSize() const
The total size of this partition.
bool inRange() const
Check if the value is in range, i.e.
void enterProximity()
Notification that the proximity range is entered, i.e.
YQPkgWarningRangeNotifier()
Constructor.
virtual QString deviceName() const
The device name of this partition.
virtual ~YQPkgDiskUsageList()
Destructor.
void clear()
Clear the current values, i.e.
YQPkgWarningRangeNotifier runningOutWarning
Warning range notifier about running out of disk space warning.
void enterRange()
Notification that the inner range is entered.
void clearHistory()
Clear everything, including all history values such as if a warning has been posted.
virtual FSize usedSize() const
The currently used size of this partition.
ZyppPartitionDu partitionDu() const
Returns the corresponding disk usage data.
void warningPostedNotify()
Notification that a warning has been posted.
virtual ~YQPkgDiskUsageListItem()
Destructor.
Helper class to manage warnings that are to be issued when a value enters a predefined range...
List of disk usage of all attached partitions.
void updateDuData(const ZyppPartitionDu &fromData)
Update the disk usage data.