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