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