41 #define YUILogComponent "ncurses-pkg" 46 #include "NCPkgTable.h" 48 #include "NCPopupInfo.h" 49 #include "NCPkgStrings.h" 51 #include "NCPkgPopupDiskspace.h" 52 #include "NCPackageSelector.h" 53 #include <zypp/ui/Selectable.h> 70 NCPkgTableTag::NCPkgTableTag( ZyppObj objPtr, ZyppSel selPtr,
74 , dataPointer( objPtr )
75 , selPointer( selPtr )
77 setLabel( statusToString(stat) );
80 std::string NCPkgTableTag::statusToString( ZyppStatus stat )
const 120 NCPkgTable::NCPkgTable( YWidget * parent, YTableHeader * tableHeader )
121 : NCTable( parent, tableHeader )
124 , tableType ( T_Packages )
125 , haveInstalledVersion ( false )
126 , visibleInfo( I_Technical )
128 yuiDebug() <<
"NCPkgTable created" << endl;
140 NCPkgTable::~NCPkgTable()
142 delete statusStrategy;
157 const std::vector<std::string> & elements,
161 YTableItem *tabItem =
new YTableItem();
164 tabItem->addCell(
new NCPkgTableTag( objPtr, slbPtr, stat ));
167 for(
const std::string& s: elements) {
172 addItem(tabItem,
true);
186 return NCTable::deleteAllItems();
200 return NCTable::cellChanged( index, colnum, newtext );
213 const ZyppSel & slbPtr,
218 if ( !packager || !slbPtr )
223 bool license_confirmed =
true;
224 ZyppPkg pkgPtr = NULL;
227 int cols = NCurses::cols();
228 int lines = NCurses::lines();
237 notify = objPtr->delnotify();
238 yuiMilestone() <<
"DELETE message: " << notify << endl;
239 header = NCPkgStrings::WarningLabel();
247 notify = objPtr->insnotify();
248 yuiMilestone() <<
"NOTIFY message: " << notify << endl;
249 header = NCPkgStrings::NotifyLabel();
257 license = objPtr->licenseToConfirm();
258 license_confirmed = slbPtr->hasLicenceConfirmed();
265 std::string pkgName = slbPtr->name();
267 if ( !license.empty() )
269 if ( !license_confirmed )
274 if ( !license_confirmed )
286 newstatus = S_Protected;
295 yuiMilestone() <<
"User confirmed license agreement for " << pkgName << endl;
296 slbPtr->setLicenceConfirmed (
true);
300 if ( ok && !notify.empty() )
302 std::string html_text = packager->InfoText()->createHtmlText( notify );
303 NCPopupInfo * info =
new NCPopupInfo( wpos( (lines * 35)/100, (cols * 25)/100),
305 "<i>" + pkgName +
"</i><br><br>" + html_text
307 info->setPreferredSize( (NCurses::cols() * 50)/100, (NCurses::lines() * 30)/100);
308 info->showInfoPopup( );
310 YDialog::deleteTopmostDialog();
316 if ( ok && singleChange )
351 if ( tableType == T_Availables || tableType == T_MultiVersion )
372 unsigned int index = 0;
375 while ( index < size )
378 NCTableLine * cl = myPad()->ModifyLine( index );
386 YTableItem *it =
dynamic_cast<YTableItem*
> (cl->origItem() );
387 YTableCell *tcell = it->cell(0);
399 ZyppStatus newstatus = S_NoInst;
400 if ( slbPtr && objPtr)
402 if ( tableType == T_Availables && !slbPtr->multiversionInstall() )
404 std::string isCandidate =
" ";
405 if ( objPtr == slbPtr->candidateObj() )
408 cl->AddCol( 2,
new NCTableCol( isCandidate ) );
418 cc->setStatus( newstatus );
419 cellChanged( index, 0, cc->statusToString (newstatus) );
437 static bool slbHasInstalledObj (
const ZyppSel & slb)
439 return ! slb->installedEmpty ();
450 std::vector<std::string> header;
456 bool haveInstalledPkgs = find_if (zyppPkgBegin (), zyppPkgEnd (),
457 slbHasInstalledObj) != zyppPkgEnd ();
460 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
461 header.push_back(
"L" + NCPkgStrings::PkgName() );
462 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
463 if ( haveInstalledPkgs > 0 )
465 header.push_back(
"L" + NCPkgStrings::PkgVersionNew() );
466 header.push_back(
"L" + NCPkgStrings::PkgVersionInst() );
467 haveInstalledVersion =
true;
471 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
473 header.push_back(
"L" + NCPkgStrings::PkgSize() );
476 header.push_back(
"L" + NCPkgStrings::PkgSource() );
482 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
483 header.push_back(
"L" + NCPkgStrings::PkgName() );
484 header.push_back(
"L" + NCPkgStrings::PkgVersionNew() );
485 header.push_back(
"L" + NCPkgStrings::PkgVersionInst() );
486 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
487 header.push_back(
"L" + NCPkgStrings::PkgSize() );
492 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
493 header.push_back(
"L" + NCPkgStrings::PkgName() );
494 header.push_back(
"L" + NCPkgStrings::PatchKind() );
495 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
496 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
502 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
503 header.push_back(
"L" + NCPkgStrings::PatternsLabel() );
508 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
509 header.push_back(
"L" + NCPkgStrings::LangCode() );
510 header.push_back(
"L" + NCPkgStrings::LangName() );
515 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
516 header.push_back(
"L" + NCPkgStrings::PkgName() );
517 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
518 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
519 header.push_back(
"L" + NCPkgStrings::PkgInstSource() );
520 header.push_back(
"L" + NCPkgStrings::PkgSize() );
521 header.push_back(
"L" + NCPkgStrings::PkgArch() );
524 case T_MultiVersion: {
526 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
527 header.push_back(
"L" + NCPkgStrings::PkgName() );
528 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
529 header.push_back(
"L" + NCPkgStrings::PkgInstSource() );
530 header.push_back(
"L" + NCPkgStrings::PkgSize() );
531 header.push_back(
"L" + NCPkgStrings::PkgArch() );
536 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
537 header.push_back(
"L" + NCPkgStrings::PkgName() );
538 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
552 std::vector<std::string> pkgLine;
555 if ( !pkgPtr || !slbPtr )
557 yuiError() <<
"No valid package available" << endl;
562 pkgLine.push_back( slbPtr->name() );
564 std::string instVersion =
"";
565 std::string version =
"";
572 if ( ! slbPtr->installedEmpty() )
574 instVersion = slbPtr->installedObj()->edition().asString();
577 if ( slbPtr->hasCandidateObj() )
579 version = slbPtr->candidateObj()->edition().asString();
583 version = pkgPtr->edition().asString();
585 pkgLine.push_back( version );
589 pkgLine.push_back( instVersion );
591 pkgLine.push_back( pkgPtr->summary() );
593 status = slbPtr->status();
594 yuiMilestone() <<
"Status of " << slbPtr->name() <<
": " << status << endl;
595 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
596 pkgLine.push_back( size.form( 8 ) );
601 std::string isCandidate =
" ";
602 if ( pkgPtr == slbPtr->candidateObj() )
604 pkgLine.push_back( isCandidate );
606 version = pkgPtr->edition().asString();
607 pkgLine.push_back( version );
609 pkgLine.push_back( pkgPtr->repository().info().name() );
613 zypp::ui::Selectable::installed_iterator it = slbPtr->installedBegin();
615 while ( it != slbPtr->installedEnd() )
617 if ( pkgPtr->edition() == (*it)->edition() &&
618 pkgPtr->arch() == (*it)->arch() &&
619 pkgPtr->vendor() == (*it)->vendor() )
621 status = S_KeepInstalled;
626 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
627 pkgLine.push_back( size.form( 8 ) );
628 pkgLine.push_back( pkgPtr->arch().asString());
632 case T_MultiVersion: {
633 version = pkgPtr->edition().asString();
634 pkgLine.push_back( version );
636 pkgLine.push_back( pkgPtr->repository().info().name() );
638 zypp::PoolItem itemPtr( pkgPtr->satSolvable() );
639 status = slbPtr->pickStatus( itemPtr );
640 yuiMilestone() <<
"Multi version: status of " << version <<
": " << status << endl;
642 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
643 pkgLine.push_back( size.form( 8 ) );
644 pkgLine.push_back( pkgPtr->arch().asString());
649 pkgLine.push_back( pkgPtr->summary() );
650 if ( ! slbPtr->installedEmpty() )
652 instVersion = slbPtr->installedObj()->edition().version();
655 if ( slbPtr->hasCandidateObj() )
657 version = slbPtr->candidateObj()->edition().version();
662 version = pkgPtr->edition().version();
664 pkgLine.push_back( version );
666 if ( haveInstalledVersion )
668 pkgLine.push_back( instVersion );
671 status = slbPtr->status();
673 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
674 pkgLine.push_back( size.form( 8 ) );
678 if ( slbPtr->source_install() )
680 pkgLine.push_back(
" x " );
685 pkgLine.push_back(
" " );
706 std::vector<std::string> pkgLine;
709 pkgLine.push_back( text );
725 std::vector<std::string> pkgLine;
728 if ( !patchPtr || !slb )
730 yuiError() <<
"No valid patch available" << endl;
734 pkgLine.push_back( slb->name() );
736 pkgLine.push_back( patchPtr->category() );
738 if ( !patchPtr->summary().empty() )
739 pkgLine.push_back( patchPtr->summary() );
741 pkgLine.push_back( slb->name() );
743 pkgLine.push_back( patchPtr->edition().asString() );
767 if ( !packager || !objPtr || !slbPtr )
770 yuiMilestone() <<
"show information for " << slbPtr->name() << endl;
777 updateInfo( objPtr, slbPtr, VisibleInfo() );
778 packager->PackageLabel()->setLabel( slbPtr->name() );
782 updateInfo( objPtr, slbPtr, VisibleInfo() );
802 NCursesEvent ret = NCursesEvent::none;
807 if ( packager->isTestMode() )
809 if ( packager->diskSpacePopup() )
810 packager->diskSpacePopup()->setDiskSpace( key );
834 NCTable::wHandleInput( key);
844 changeObjStatus( key );
851 NCDialog * currentDialog =
static_cast<NCDialog *
>(YDialog::topmostDialog());
853 currentDialog->setStatusLine();
855 return NCursesEvent::handled;
871 return cc->getStatus();
881 return cc->getDataPointer();
891 return cc->getSelPointer();
897 NCTableLine * cl = myPad()->ModifyLine( index );
902 YTableItem *it =
dynamic_cast<YTableItem*
> (cl->origItem() );
903 YTableCell *tcell = it->cell(0);
915 bool NCPkgTable::SourceInstall(
bool install )
917 int index = getCurrentItem();
923 yuiError() <<
"Invalid Pointer" << endl;
926 ZyppSel selPtr = objPtr->getSelectable();
927 NCTableLine * currentLine = myPad()->ModifyLine( index );
929 if ( !selPtr || !currentLine )
931 yuiError() <<
"Invalid Selectable" << endl;
935 NCTableCol * currentCol = currentLine->GetCol( currentLine->Cols()-1 );
937 if ( install && selPtr->providesSources() )
939 ok = selPtr->set_source_install(
true );
940 yuiMilestone() <<
"Set source install returns: " << (ok?
"true":
"false") << endl;
942 currentCol->SetLabel( NClabel(
" x " ) );
944 else if ( !install && selPtr->source_install() )
946 ok = selPtr->set_source_install(
false );
947 yuiMilestone() <<
"ReSet source install returns: " << (ok?
"true":
"false") << endl;
949 currentCol->SetLabel( NClabel(
" " ) );
961 bool NCPkgTable::toggleObjStatus( )
969 ZyppStatus newStatus;
971 bool ok = statusStrategy->
toggleStatus( slbPtr, objPtr, newStatus );
986 bool NCPkgTable::changeObjStatus(
int key )
995 ZyppStatus newStatus;
997 bool ok = statusStrategy->
keyToStatus( key, slbPtr, objPtr, newStatus );
1011 bool NCPkgTable::changeListObjStatus( NCPkgTableListAction type )
1013 ZyppStatus newStatus;
1015 unsigned int index = 0;
1017 while ( index < size )
1028 if ( slbPtr->status() == S_NoInst )
1029 ok = statusStrategy->
keyToStatus(
'+', slbPtr, objPtr, newStatus );
1033 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
1034 ok = statusStrategy->
keyToStatus(
'-', slbPtr, objPtr, newStatus );
1037 case A_UpdateNewer: {
1039 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected && slbPtr->updateCandidateObj() )
1041 slbPtr->setOnSystem( slbPtr->updateCandidateObj() );
1042 ok = statusStrategy->
keyToStatus(
'>', slbPtr, objPtr, newStatus );
1047 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
1048 ok = statusStrategy->
keyToStatus(
'>', slbPtr, objPtr, newStatus );
1052 if ( slbPtr->status() == S_Install
1053 || slbPtr->status() == S_AutoInstall
1054 || slbPtr->status() == S_Update
1055 || slbPtr->status() == S_AutoUpdate )
1056 ok = statusStrategy->
keyToStatus(
'<', slbPtr, objPtr, newStatus );
1057 else if ( slbPtr->status() == S_Del
1058 || slbPtr->status() == S_AutoDel )
1059 ok = statusStrategy->
keyToStatus(
'+', slbPtr, objPtr, newStatus );
1063 yuiError() <<
"Unknown list action" << endl;
1087 bool NCPkgTable::fillAvailableList ( ZyppSel slb )
1091 yuiError() <<
"Package pointer not valid" << endl;
1099 NCPkgTableType type;
1101 if ( slb->multiversionInstall() || slb->installedSize() > 1 )
1108 type = T_MultiVersion;
1110 yuiMilestone() <<
"Multi version package " << slb->name() << endl;
1114 type = T_Availables;
1122 zypp::ui::Selectable::picklist_iterator it = slb->picklistBegin();
1123 while ( it != slb->picklistEnd() )
1132 zypp::ui::Selectable::installed_iterator it = slb->installedBegin();
1133 while ( it != slb->installedEnd() )
1141 zypp::ui::Selectable::available_iterator it = slb->availableBegin();
1142 while ( it != slb->availableEnd() )
1155 setCurrentItem( 0 );
1161 bool NCPkgTable::fillSummaryList( NCPkgTable::NCPkgTableListType type )
1167 std::list<ZyppSel> pkgList( zyppPkgBegin (), zyppPkgEnd () );
1168 pkgList.sort( sortByName );
1171 std::list<ZyppSel>::iterator listIt;
1183 for ( listIt = pkgList.begin(); listIt != pkgList.end(); ++listIt )
1185 ZyppSel selectable = *listIt;
1186 ZyppPkg pkg = tryCastToZyppPkg (selectable->theObj ());
1190 case NCPkgTable::L_Changes: {
1191 if ( selectable->status() != S_NoInst
1192 && selectable->status() != S_KeepInstalled )
1198 case NCPkgTable::L_Installed: {
1199 if ( selectable->status() == S_KeepInstalled )
1216 void NCPkgTable::updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode )
1221 if ( packager->InfoText() )
1222 packager->InfoText()->longDescription( pkgPtr );
1225 if ( packager->InfoText() )
1226 packager->InfoText()->technicalData( pkgPtr, slbPtr );
1229 if ( packager->InfoText() )
1230 packager->InfoText()->fileList( slbPtr );
1233 if ( packager->InfoText() )
1234 packager->InfoText()->dependencyList( pkgPtr, slbPtr );
1237 if ( packager->VersionsList() )
1238 packager->VersionsList()->fillAvailableList( slbPtr );
1241 if ( packager->InfoText() )
1242 packager->InfoText()->patchDescription( pkgPtr, slbPtr );
1245 if ( packager->PatchPkgs() )
virtual NCursesEvent wHandleInput(wint_t key)
Handles the events concerning the package table (e.g.
bool showInformation()
Show the corresponding information (e.g.
virtual bool keyToStatus(const int &key, ZyppSel slbPtr, ZyppObj objPtr, ZyppStatus &newStat)
Returns the new status to the given key (respecting the old status of th eobject).
bool createPatchEntry(ZyppPatch pkgPtr, ZyppSel slbPtr)
Creates a line in the YOU patch table.
void showDiskSpace()
Calls the package mananager (updateDu()) and shows the required disk space.
void showSelectionDependencies()
Checks and shows the selectiondependencies.
virtual bool toggleStatus(ZyppSel slbPtr, ZyppObj objPtr, ZyppStatus &newStat)
Toggles the package status (e.g.
virtual void cellChanged(int index, int colnum, const std::string &newtext)
Changes the contents of a certain cell in table.
virtual void addLine(ZyppStatus status, const std::vector< std::string > &elements, ZyppObj objPtr, ZyppSel slbPtr)
This method is called to add a line to the package list.
virtual bool setObjectStatus(ZyppStatus newstatus, ZyppSel slbPtr, ZyppObj objPtr)
Informs the package manager about the new status.
ZyppObj getDataPointer(int index)
Gets the data pointer of a certain package.
void showDownloadSize()
Shows the total download size.
void updatePackageList()
Updates the status in list of packages.
void fillHeader()
Fills the header of the table.
bool fillPatchPackages(NCPkgTable *pkgTable, ZyppObj youPatch)
Fills the list of packages belonging to the youPatch.
bool showLicensePopup(std::string pkgName, std::string license)
Shows 'End User License Agreement' popup with license text.
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
This class is used for the first column of the package table which contains the status information of...
bool createInfoEntry(std::string text)
Creates a line in the table shwing an info text.
ZyppStatus getStatus(int index)
Gets the currently displayed package status.
ZyppSel getSelPointer(int index)
Gets the selectable pointer of a certain package.
bool updateTable()
Set the status information if status has changed.
bool setTableType(NCPkgTableType type, NCPkgStatusStrategy *strategy)
Sets the type of the table and the status strategy (which means call particular methods to set/get th...
unsigned int getNumLines()
Returns the number of lines in the table (the table size)
virtual void itemsCleared()
Clears the package list.
virtual ZyppStatus getPackageStatus(ZyppSel slbPtr, ZyppObj objPtr)
Gets the status information from the package manager.
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
bool changeStatus(ZyppStatus newstat, const ZyppSel &slbPtr, ZyppObj objPtr, bool singleChange)
Informs the package manager about the status change of the currently selected package and updates the...
bool showPackageDependencies(bool doit)
Checks and shows the dependencies.