42 #define YUILogComponent "qt-pkg"
46 #include <QHeaderView>
50 #include <zypp/ZYppFactory.h>
53 #include "YQPkgDiskUsageList.h"
54 #include "YQPkgDiskUsageWarningDialog.h"
58 #include <boost/multiprecision/cpp_int.hpp>
71 #define MIN_FREE_MB_WARN 400
72 #define MIN_FREE_MB_PROXIMITY 700
74 #define MIN_PERCENT_WARN 90
75 #define MIN_PERCENT_PROXIMITY 80
77 #define OVERFLOW_MB_WARN 0
78 #define OVERFLOW_MB_PROXIMITY 300
81 typedef zypp::DiskUsageCounter::MountPointSet ZyppDuSet;
82 typedef zypp::DiskUsageCounter::MountPointSet::iterator ZyppDuSetIterator;
87 : QY2DiskUsageList( parent, true )
91 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
93 if ( diskUsage.empty() )
95 zypp::getZYpp()->setPartitions( zypp::DiskUsageCounter::detectMountPoints() );
96 diskUsage = zypp::getZYpp()->diskUsage();
100 for ( ZyppDuSetIterator it = diskUsage.begin();
101 it != diskUsage.end();
104 const ZyppPartitionDu & partitionDu = *it;
106 if ( ! partitionDu.readonly )
111 _items.insert( QString::fromUtf8(partitionDu.dir.c_str()), item );
115 resizeColumnToContents( nameCol() );
116 resizeColumnToContents( totalSizeCol() );
118 resizeColumnToContents( freeSizeCol() );
120 sortByColumn( percentageBarCol(), Qt::DescendingOrder );
122 header()->setSectionResizeMode( nameCol(), QHeaderView::Stretch );
123 header()->setSectionResizeMode( QHeaderView::Interactive );
133 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
135 for ( ZyppDuSetIterator it = diskUsage.begin();
136 it != diskUsage.end();
139 const ZyppPartitionDu & partitionDu = *it;
145 yuiError() <<
"No entry for mount point " << partitionDu.dir << endl;
148 resizeColumnToContents( totalSizeCol() );
168 MIN_PERCENT_WARN, _(
"&OK" ) );
183 QFontMetrics fms( font() );
184 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
185 return QSize( fms.horizontalAdvance(
"/var/usr/home 100% 100.32GB 100.3GB" ) + 50, 100 );
187 return QSize( fms.width(
"/var/usr/home 100% 100.32GB 100.3GB" ) + 50, 100 );
191 int width = header()->headerWidth()
192 + style().pixelMetric( QStyle::PM_ScrollBarExtent, verticalScrollBar() );
194 int width = header()->sizeHint().width()
198 return QSize( width, 100 );
208 Qt::KeyboardModifiers special_combo = ( Qt::ControlModifier| Qt::ShiftModifier | Qt::AltModifier );
210 if ( ( event->modifiers() & special_combo ) == special_combo )
212 if ( event->key() == Qt::Key_Q )
215 yuiMilestone() <<
"Debug mode: " << _debug << endl;
220 if ( _debug && currentItem() )
227 int percent = item->usedPercent();
229 switch ( event->key() )
231 case Qt::Key_1: percent = 10;
break;
232 case Qt::Key_2: percent = 20;
break;
233 case Qt::Key_3: percent = 30;
break;
234 case Qt::Key_4: percent = 40;
break;
235 case Qt::Key_5: percent = 50;
break;
236 case Qt::Key_6: percent = 60;
break;
237 case Qt::Key_7: percent = 70;
break;
238 case Qt::Key_8: percent = 80;
break;
239 case Qt::Key_9: percent = 90;
break;
240 case Qt::Key_0: percent = 100;
break;
241 case Qt::Key_Plus: percent += 3;
break;
242 case Qt::Key_Minus: percent -= 3;
break;
252 100,
"&Continue anyway",
"&Cancel" );
259 ZyppPartitionDu partitionDu( item->
partitionDu() );
261 if ( percent != item->usedPercent() )
263 partitionDu.pkg_size = partitionDu.total_size / 100 * percent;
276 QY2DiskUsageList::keyPressEvent( event );
285 const ZyppPartitionDu & partitionDu )
286 : QY2DiskUsageListItem( parent )
287 , _partitionDu( partitionDu )
288 , _pkgDiskUsageList( parent )
290 yuiDebug() <<
"disk usage list entry for " <<
partitionDu.dir << endl;
298 return FSize( _partitionDu.pkg_size, FSize::Unit::K );
306 return FSize( _partitionDu.total_size, FSize::Unit::K );
313 return fromUTF8( _partitionDu.dir.c_str() );
320 _partitionDu = fromData;
329 int percent = usedPercent();
331 boost::multiprecision::cpp_int free = freeSize().in_unit(FSize::Unit::M);
333 yuiDebug() <<
"Partition " << _partitionDu.dir <<
" free percent: " <<
334 percent <<
"%, " <<
" free: " << freeSize() <<
" (" << free <<
"MiB)" << endl;
336 if ( percent > MIN_PERCENT_WARN )
341 if ( free < MIN_FREE_MB_PROXIMITY )
344 if ( free < MIN_FREE_MB_WARN )
348 if ( free < MIN_FREE_MB_PROXIMITY )
350 if ( percent > MIN_PERCENT_PROXIMITY )
354 if ( free < OVERFLOW_MB_WARN )
357 if ( free < OVERFLOW_MB_PROXIMITY )
376 _hasBeenClose = _isClose;
385 _hasBeenClose =
false;
386 _warningPosted =
false;
402 _hasBeenClose =
true;
409 _warningPosted =
true;
423 return ! _isClose && ! _hasBeenClose;
430 return _inRange && ! _warningPosted;