42 #define YUILogComponent "qt-pkg" 46 #include <QHeaderView> 49 #include <zypp/ZYppFactory.h> 52 #include "YQPkgDiskUsageList.h" 53 #include "YQPkgDiskUsageWarningDialog.h" 57 #include <boost/multiprecision/cpp_int.hpp> 70 #define MIN_FREE_MB_WARN 400 71 #define MIN_FREE_MB_PROXIMITY 700 73 #define MIN_PERCENT_WARN 90 74 #define MIN_PERCENT_PROXIMITY 80 76 #define OVERFLOW_MB_WARN 0 77 #define OVERFLOW_MB_PROXIMITY 300 80 typedef zypp::DiskUsageCounter::MountPointSet ZyppDuSet;
81 typedef zypp::DiskUsageCounter::MountPointSet::iterator ZyppDuSetIterator;
86 : QY2DiskUsageList( parent, true )
90 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
92 if ( diskUsage.empty() )
94 zypp::getZYpp()->setPartitions( zypp::DiskUsageCounter::detectMountPoints() );
95 diskUsage = zypp::getZYpp()->diskUsage();
99 for ( ZyppDuSetIterator it = diskUsage.begin();
100 it != diskUsage.end();
103 const ZyppPartitionDu & partitionDu = *it;
105 if ( ! partitionDu.readonly )
110 _items.insert( QString::fromUtf8(partitionDu.dir.c_str()), item );
114 resizeColumnToContents( nameCol() );
115 resizeColumnToContents( totalSizeCol() );
117 resizeColumnToContents( freeSizeCol() );
119 sortByColumn( percentageBarCol(), Qt::DescendingOrder );
121 header()->setSectionResizeMode( nameCol(), QHeaderView::Stretch );
122 header()->setSectionResizeMode( QHeaderView::Interactive );
132 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
134 for ( ZyppDuSetIterator it = diskUsage.begin();
135 it != diskUsage.end();
138 const ZyppPartitionDu & partitionDu = *it;
144 yuiError() <<
"No entry for mount point " << partitionDu.dir << endl;
147 resizeColumnToContents( totalSizeCol() );
167 MIN_PERCENT_WARN, _(
"&OK" ) );
182 QFontMetrics fms( font() );
183 return QSize( fms.width(
"/var/usr/home 100% 100.32GB 100.3GB" ) + 50, 100 );
186 int width = header()->headerWidth()
187 + style().pixelMetric( QStyle::PM_ScrollBarExtent, verticalScrollBar() );
189 int width = header()->sizeHint().width()
193 return QSize( width, 100 );
203 Qt::KeyboardModifiers special_combo = ( Qt::ControlModifier| Qt::ShiftModifier | Qt::AltModifier );
205 if ( ( event->modifiers() & special_combo ) == special_combo )
207 if ( event->key() == Qt::Key_Q )
210 yuiMilestone() <<
"Debug mode: " << _debug << endl;
215 if ( _debug && currentItem() )
222 int percent = item->usedPercent();
224 switch ( event->key() )
226 case Qt::Key_1: percent = 10;
break;
227 case Qt::Key_2: percent = 20;
break;
228 case Qt::Key_3: percent = 30;
break;
229 case Qt::Key_4: percent = 40;
break;
230 case Qt::Key_5: percent = 50;
break;
231 case Qt::Key_6: percent = 60;
break;
232 case Qt::Key_7: percent = 70;
break;
233 case Qt::Key_8: percent = 80;
break;
234 case Qt::Key_9: percent = 90;
break;
235 case Qt::Key_0: percent = 100;
break;
236 case Qt::Key_Plus: percent += 3;
break;
237 case Qt::Key_Minus: percent -= 3;
break;
247 100,
"&Continue anyway",
"&Cancel" );
254 ZyppPartitionDu partitionDu( item->
partitionDu() );
256 if ( percent != item->usedPercent() )
258 partitionDu.pkg_size = partitionDu.total_size / 100 * percent;
271 QY2DiskUsageList::keyPressEvent( event );
280 const ZyppPartitionDu & partitionDu )
281 : QY2DiskUsageListItem( parent )
282 , _partitionDu( partitionDu )
283 , _pkgDiskUsageList( parent )
285 yuiDebug() <<
"disk usage list entry for " <<
partitionDu.dir << endl;
293 return FSize( _partitionDu.pkg_size, FSize::Unit::K );
301 return FSize( _partitionDu.total_size, FSize::Unit::K );
308 return fromUTF8( _partitionDu.dir.c_str() );
315 _partitionDu = fromData;
324 int percent = usedPercent();
326 boost::multiprecision::cpp_int free = freeSize().in_unit(FSize::Unit::M);
328 yuiDebug() <<
"Partition " << _partitionDu.dir <<
" free percent: " <<
329 percent <<
"%, " <<
" free: " << freeSize() <<
" (" << free <<
"MiB)" << endl;
331 if ( percent > MIN_PERCENT_WARN )
336 if ( free < MIN_FREE_MB_PROXIMITY )
339 if ( free < MIN_FREE_MB_WARN )
343 if ( free < MIN_FREE_MB_PROXIMITY )
345 if ( percent > MIN_PERCENT_PROXIMITY )
349 if ( free < OVERFLOW_MB_WARN )
352 if ( free < OVERFLOW_MB_PROXIMITY )
371 _hasBeenClose = _isClose;
380 _hasBeenClose =
false;
381 _warningPosted =
false;
397 _hasBeenClose =
true;
404 _warningPosted =
true;
418 return ! _isClose && ! _hasBeenClose;
425 return _inRange && ! _warningPosted;
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.
void clear()
Clear the current values, i.e.
YQPkgWarningRangeNotifier runningOutWarning
Warning range notifier about running out of disk space warning.
static bool diskUsageWarning(const QString &message, int thresholdPercent, const QString &acceptButtonLabel, const QString &rejectButtonLabel=QString::null)
Static convenience method: Post a disk usage warning with text 'message', a list of partitions that a...
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.
List of disk usage of all attached partitions.
void updateDuData(const ZyppPartitionDu &fromData)
Update the disk usage data.