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 <qasciidict.h>
27 typedef zypp::DiskUsageCounter::MountPoint ZyppPartitionDu;
28 class YQPkgDiskUsageListItem;
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.
36 * Example: Disk space usage:
40 * 80% [proximity range start]
42 * 90% [inner range start]
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%.
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.
54 class YQPkgWarningRangeNotifier
61 YQPkgWarningRangeNotifier();
64 * Notification that the inner range is entered.
65 * The caller has to decide the criteria for that.
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.
74 void enterProximity();
77 * Notification that a warning has been posted.
79 void warningPostedNotify();
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()'.
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.
92 bool needWarning() const;
95 * Check if the value is leaving the proximity range.
97 bool leavingProximity() const;
100 * Clear the current values, i.e. prepare for a new round of checks
105 * Clear everything, including all history values such as if a warning has
124 * @short List of disk usage of all attached partitions.
126 class YQPkgDiskUsageList : public QY2DiskUsageList
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? ).
138 YQPkgDiskUsageList( QWidget * parent, int thresholdPercent = 0 );
143 virtual ~YQPkgDiskUsageList() {}
146 * Suggest reasonable default size.
148 * Reimplemented from QListView.
150 virtual QSize sizeHint() const;
153 * Warning range notifier about running out of disk space warning.
155 YQPkgWarningRangeNotifier runningOutWarning;
158 * Warning range notifier about disk space overflow warning.
160 YQPkgWarningRangeNotifier overflowWarning;
166 * Update all statistical data in the list.
168 void updateDiskUsage();
171 * Post all pending disk space warnings based on the warning range
174 void postPendingWarnings();
180 * Event handler for keyboard input - for debugging and testing.
181 * Changes the current item's percentage on the fly.
183 * Reimplemented from QListView / QWidget.
185 virtual void keyPressEvent( QKeyEvent * ev );
190 QAsciiDict<YQPkgDiskUsageListItem> _items;
196 class YQPkgDiskUsageListItem: public QY2DiskUsageListItem
201 * Constructor. Creates a YQPkgDiskUsageList item that corresponds to the
202 * specified file system.
204 YQPkgDiskUsageListItem( YQPkgDiskUsageList * parent,
205 const ZyppPartitionDu & partitionDu );
210 virtual ~YQPkgDiskUsageListItem() {}
213 * Returns the corresponding disk usage data.
215 ZyppPartitionDu partitionDu() const { return _partitionDu; }
218 * Update the disk usage data.
220 void updateDuData( const ZyppPartitionDu & fromData );
223 * The currently used size of this partition.
225 * Reimplemented from QY2DiskUsageListItem.
227 virtual FSize usedSize() const;
230 * The total size of this partition.
232 * Reimplemented from QY2DiskUsageListItem.
234 virtual FSize totalSize() const;
237 * The name to display for this partition ( the mount point ).
239 * Reimplemented from QY2DiskUsageListItem.
241 virtual QString name() const;
244 * The device name of this partition.
246 * Reimplemented from QY2DiskUsageListItem.
248 virtual QString deviceName() const { return ""; }
251 * Check the remaining disk space of this partition based on percentage and
252 * absolute free MB. Notify the parent YQPkgDiskUsageList's warning ranges
255 void checkRemainingDiskSpace();
262 ZyppPartitionDu _partitionDu;
263 YQPkgDiskUsageList * _pkgDiskUsageList;
268 #endif // ifndef YQPkgDiskUsageList_h