41 #define YUILogComponent "ncurses-pkg"
44 #include "YMenuButton.h"
48 #include "NCLayoutBox.h"
49 #include "NCSpacing.h"
50 #include "NCPkgStrings.h"
52 #include "NCPushButton.h"
57 #include "NCPkgPopupDiskspace.h"
62 #define MIN_FREE_MB_WARN 400
63 #define MIN_FREE_MB_PROXIMITY 700
65 #define MIN_PERCENT_WARN 90
66 #define MIN_PERCENT_PROXIMITY 80
68 #define OVERFLOW_MB_WARN 0
69 #define OVERFLOW_MB_PROXIMITY 300
85 NCPkgDiskspace::NCPkgDiskspace(
bool testMode )
86 : testmode( testMode )
92 yuiMilestone() <<
"TESTMODE Diskspace" << endl;
93 zypp::getZYpp()->setPartitions(zypp::DiskUsageCounter::detectMountPoints ());
94 testDiskUsage = zypp::getZYpp()->diskUsage();
106 NCPkgDiskspace::~NCPkgDiskspace()
118 void NCPkgDiskspace::fillPartitionTable()
120 NCTable * partitions = popupWin->Partitions();
121 partitions->deleteAllItems();
123 YTableItem * newItem;
126 zypp::ZYpp::Ptr z = zypp::getZYpp();
127 ZyppDuSet du = z->diskUsage ();
135 z->setPartitions(zypp::DiskUsageCounter::detectMountPoints ());
141 for (it = b; it != e; ++it)
146 zypp::ByteCount pkg_used (it->pkg_size * 1024);
148 zypp::ByteCount pkg_available ((it->total_size - it->pkg_size) * 1024);
150 zypp::ByteCount total (it->total_size * 1024);
152 newItem =
new YTableItem( it->dir,
153 pkg_used.asString (8),
154 pkg_available.asString (8),
156 usedPercent( it->pkg_size, it->total_size ) );
158 partitions->addItem( newItem );
173 std::string NCPkgDiskspace::checkDiskSpace()
175 std::string text =
"";
177 zypp::ZYpp::Ptr z = zypp::getZYpp();
178 ZyppDuSet du = z->diskUsage ();
186 z->setPartitions(zypp::DiskUsageCounter::detectMountPoints ());
192 for (it = b; it != e; ++it)
197 zypp::ByteCount pkg_available = (it->total_size - it->pkg_size) * 1024;
198 if ( pkg_available < 0 )
204 text += NCPkgStrings::MoreText();
206 std::string available = pkg_available.asString();
207 text += available.replace( 0, 1,
" " );
209 text += NCPkgStrings::MoreSpaceText();
225 void NCPkgDiskspace::checkRemainingDiskSpace(
const ZyppPartitionDu & partition )
227 FSize usedSize ( partition.pkg_size, FSize::K );
228 FSize totalSize ( partition.total_size, FSize::K );
232 if ( totalSize != 0 )
233 percent = ( 100 * usedSize ) / totalSize;
235 int free = ( totalSize - usedSize ) / FSize::MB;
237 yuiMilestone() <<
"Partition: " << partition.dir <<
" Used percent: "
238 << percent <<
" Free: " << free << endl;
240 if ( percent > MIN_PERCENT_WARN )
244 if ( free < MIN_FREE_MB_PROXIMITY )
248 if ( free < MIN_FREE_MB_WARN )
254 if ( free < MIN_FREE_MB_PROXIMITY )
256 if ( percent > MIN_PERCENT_PROXIMITY )
260 if ( free < OVERFLOW_MB_WARN )
263 if ( free < OVERFLOW_MB_PROXIMITY )
281 void NCPkgDiskspace::setDiskSpace( wint_t ch )
286 for ( ZyppDuSetIterator it = testDiskUsage.begin();
287 it != testDiskUsage.end();
290 const ZyppPartitionDu & partitionDu = *it;
292 FSize usedSize ( partitionDu.pkg_size, FSize::K );
293 FSize totalSize ( partitionDu.total_size, FSize::K );
295 if ( totalSize != 0 )
296 percent = ( 100 * usedSize ) / totalSize;
300 else if ( ch ==
'-' )
306 partitionDu.pkg_size = partitionDu.total_size * percent / 100;
308 FSize newSize ( partitionDu.pkg_size, FSize::K );
310 yuiMilestone() <<
"Used size (MB): " << newSize / FSize::MB << endl;
311 yuiMilestone() <<
"Total size (MB): " << totalSize / FSize::MB << endl;
323 void NCPkgDiskspace::checkDiskSpaceRange( )
326 runningOutWarning.
clear();
327 overflowWarning.
clear();
331 diskUsage = testDiskUsage;
333 diskUsage = zypp::getZYpp()->diskUsage();
335 for ( ZyppDuSetIterator it = diskUsage.begin();
336 it != diskUsage.end();
342 checkRemainingDiskSpace( *it );
348 showInfoPopup( _(
"Error: Out of disk space!" ) );
356 showInfoPopup( _(
"Warning: Disk space is running out!" ) );
369 yuiMilestone() <<
"Running out Warning:" << endl;
370 runningOutWarning.logSettings();
372 yuiMilestone() <<
"Overflow Warning:" << endl;
373 overflowWarning.logSettings();
377 std::string NCPkgDiskspace::usedPercent( FSize used, FSize total )
383 percent = ( 100 * used ) / total;
385 sprintf( percentStr,
"%d%%", percent );
398 void NCPkgDiskspace::showInfoPopup( std::string headline )
401 popupWin =
new NCPkgPopupDiskspace (wpos( (NCurses::lines() - 15)/2, NCurses::cols()/6 ), headline );
403 fillPartitionTable();
405 YDialog::deleteTopmostDialog();
408 zypp::ByteCount NCPkgDiskspace::calculateDiff()
410 zypp::ZYpp::Ptr z = zypp::getZYpp();
411 ZyppDuSet du = z->diskUsage ();
419 z->setPartitions(zypp::DiskUsageCounter::detectMountPoints ());
425 zypp::ByteCount diff = 0;
426 for (it = b; it != e; ++it)
428 diff += (it->pkg_size - it->used_size) * 1024;
440 NCPkgPopupDiskspace::NCPkgPopupDiskspace(
const wpos at, std::string headline )
441 : NCPopup( at, false )
446 createLayout( headline );
455 NCPkgPopupDiskspace::~NCPkgPopupDiskspace()
467 void NCPkgPopupDiskspace::createLayout( std::string headline )
470 NCLayoutBox * split =
new NCLayoutBox(
this, YD_VERT );
472 head =
new NCLabel( split,
"",
true,
false );
473 head->setLabel( headline );
475 YTableHeader * tableHeader =
new YTableHeader();
476 tableHeader->addColumn( NCPkgStrings::Partition(), YAlignBegin );
477 tableHeader->addColumn( NCPkgStrings::UsedSpace(), YAlignBegin );
478 tableHeader->addColumn( NCPkgStrings::FreeSpace(), YAlignBegin );
479 tableHeader->addColumn( NCPkgStrings::TotalSpace(), YAlignBegin );
480 tableHeader->addColumn(
"% ", YAlignBegin );
483 partitions =
new NCTable( split, tableHeader );
487 okButton->setFunctionKey( 10 );
488 okButton->setKeyboardFocus();
498 int NCPkgPopupDiskspace::preferredWidth()
500 return NCurses::cols()*2/3;
509 int NCPkgPopupDiskspace::preferredHeight()
511 if ( NCurses::lines() > 15 )
514 return NCurses::lines()-4;
517 void NCPkgPopupDiskspace::doit()
519 postevent = NCursesEvent();
523 }
while ( postAgain() );
536 NCursesEvent NCPkgPopupDiskspace::wHandleInput( wint_t ch )
539 return NCursesEvent::cancel;
541 if ( ch == KEY_RETURN )
542 return NCursesEvent::button;
544 return NCDialog::wHandleInput( ch );
555 bool NCPkgPopupDiskspace::postAgain()
557 if ( ! postevent.widget )
560 if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
581 _hasBeenClose = _isClose;
590 _hasBeenClose =
false;
591 _warningPosted =
false;
607 _hasBeenClose =
true;
614 _warningPosted =
true;
628 return ! _isClose && ! _hasBeenClose;
635 return _inRange && ! _warningPosted;
639 NCPkgWarningRangeNotifier::logSettings()
const
641 yuiMilestone() <<
"in range: " << (_inRange?
"true":
"false") << endl;
642 yuiMilestone() <<
"is close: " << (_isClose?
"true":
"false") << endl;
643 yuiMilestone() <<
"has been close: " << (_hasBeenClose?
"true":
"false") << endl;
644 yuiMilestone() <<
"warning posted: " << (_warningPosted?
"true":
"false") << endl;
void warningPostedNotify()
bool leavingProximity() const
NCPkgWarningRangeNotifier()
static const std::string OKLabel()