1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDiskUsageList.h
15 Author: Stefan Hundhammer <sh@suse.de>
20 #ifndef YQPkgDiskUsageList_h
21 #define YQPkgDiskUsageList_h
23 #include <zypp/DiskUsageCounter.h>
24 #include <QY2DiskUsageList.h>
25 #include <q3asciidict.h>
29 typedef zypp::DiskUsageCounter::MountPoint ZyppPartitionDu;
30 class YQPkgDiskUsageListItem;
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.
38 * Example: Disk space usage:
42 * 80% [proximity range start]
44 * 90% [inner range start]
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%.
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.
56 class YQPkgWarningRangeNotifier
63 YQPkgWarningRangeNotifier();
66 * Notification that the inner range is entered.
67 * The caller has to decide the criteria for that.
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.
76 void enterProximity();
79 * Notification that a warning has been posted.
81 void warningPostedNotify();
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()'.
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.
94 bool needWarning() const;
97 * Check if the value is leaving the proximity range.
99 bool leavingProximity() const;
102 * Clear the current values, i.e. prepare for a new round of checks
107 * Clear everything, including all history values such as if a warning has
126 * @short List of disk usage of all attached partitions.
128 class YQPkgDiskUsageList : public QY2DiskUsageList
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? ).
140 YQPkgDiskUsageList( QWidget * parent, int thresholdPercent = 0 );
145 virtual ~YQPkgDiskUsageList() {}
148 * Suggest reasonable default size.
150 * Reimplemented from QListView.
152 virtual QSize sizeHint() const;
155 * Warning range notifier about running out of disk space warning.
157 YQPkgWarningRangeNotifier runningOutWarning;
160 * Warning range notifier about disk space overflow warning.
162 YQPkgWarningRangeNotifier overflowWarning;
168 * Update all statistical data in the list.
170 void updateDiskUsage();
173 * Post all pending disk space warnings based on the warning range
176 void postPendingWarnings();
182 * Event handler for keyboard input - for debugging and testing.
183 * Changes the current item's percentage on the fly.
185 * Reimplemented from QListView / QWidget.
187 virtual void keyPressEvent( QKeyEvent * ev );
192 Q3AsciiDict<YQPkgDiskUsageListItem> _items;
198 class YQPkgDiskUsageListItem: public QY2DiskUsageListItem
203 * Constructor. Creates a YQPkgDiskUsageList item that corresponds to the
204 * specified file system.
206 YQPkgDiskUsageListItem( YQPkgDiskUsageList * parent,
207 const ZyppPartitionDu & partitionDu );
212 virtual ~YQPkgDiskUsageListItem() {}
215 * Returns the corresponding disk usage data.
217 ZyppPartitionDu partitionDu() const { return _partitionDu; }
220 * Update the disk usage data.
222 void updateDuData( const ZyppPartitionDu & fromData );
225 * The currently used size of this partition.
227 * Reimplemented from QY2DiskUsageListItem.
229 virtual FSize usedSize() const;
232 * The total size of this partition.
234 * Reimplemented from QY2DiskUsageListItem.
236 virtual FSize totalSize() const;
239 * The name to display for this partition ( the mount point ).
241 * Reimplemented from QY2DiskUsageListItem.
243 virtual QString name() const;
246 * The device name of this partition.
248 * Reimplemented from QY2DiskUsageListItem.
250 virtual QString deviceName() const { return ""; }
253 * Check the remaining disk space of this partition based on percentage and
254 * absolute free MB. Notify the parent YQPkgDiskUsageList's warning ranges
257 void checkRemainingDiskSpace();
264 ZyppPartitionDu _partitionDu;
265 YQPkgDiskUsageList * _pkgDiskUsageList;
270 #endif // ifndef YQPkgDiskUsageList_h