41 #define YUILogComponent "ncurses-pkg" 44 #include <boost/format.hpp> 47 #include "NCPkgTable.h" 49 #include "NCPopupInfo.h" 50 #include "NCPkgStrings.h" 52 #include "NCPkgPopupDiskspace.h" 53 #include "NCPackageSelector.h" 54 #include <zypp/ui/Selectable.h> 57 #define SOURCE_INSTALL_SUPPORTED 0 68 NCPkgTableTag::NCPkgTableTag( ZyppObj objPtr, ZyppSel selPtr, ZyppStatus stat )
71 , dataPointer( objPtr )
72 , selPointer( selPtr )
74 setLabel( statusToString(stat) );
78 string NCPkgTableTag::statusToString( ZyppStatus stat )
const 121 NCPkgTable::NCPkgTable( YWidget * parent, YTableHeader * tableHeader )
122 : NCTable( parent, tableHeader )
125 , tableType( T_Packages )
126 , haveInstalledVersion( false )
127 , visibleInfo( I_Technical )
129 yuiDebug() <<
"NCPkgTable created" << endl;
133 NCPkgTable::~NCPkgTable()
135 delete statusStrategy;
141 const vector<string> & elements,
145 YTableItem *tabItem =
new YTableItem();
148 tabItem->addCell(
new NCPkgTableTag( objPtr, slbPtr, stat ));
150 for (
const string& s: elements )
151 tabItem->addCell( s );
154 addItem( tabItem,
true );
161 return NCTable::deleteAllItems();
167 return NCTable::cellChanged( index, colnum, newtext );
175 const ZyppSel & slbPtr,
179 if ( !packager || !slbPtr )
182 yuiMilestone() <<
"Changing status of " << slbPtr->name() << endl;
186 bool confirmed =
true;
187 ZyppPkg pkgPtr = NULL;
198 notify = objPtr->delnotify();
199 yuiMilestone() <<
"DELETE message: " << notify << endl;
200 header = NCPkgStrings::WarningLabel();
209 notify = objPtr->insnotify();
210 yuiMilestone() <<
"NOTIFY message: " << notify << endl;
211 header = NCPkgStrings::NotifyLabel();
219 if ( objPtr->isRetracted() )
223 license = objPtr->licenseToConfirm();
230 string pkgName = slbPtr->name();
232 if ( ! license.empty() )
234 if ( ! slbPtr->hasLicenceConfirmed() )
239 yuiMilestone() <<
"User confirmed license agreement for " << pkgName << endl;
240 slbPtr->setLicenceConfirmed (
true);
256 newstatus = S_Protected;
266 if ( ok && ! notify.empty() )
268 int cols = NCurses::cols();
269 int lines = NCurses::lines();
271 string html_text = packager->InfoText()->createHtmlText( notify );
272 NCPopupInfo * info =
new NCPopupInfo( wpos( (lines * 35)/100, (cols * 25)/100),
274 "<i>" + pkgName +
"</i><br><br>" + html_text );
275 info->setPreferredSize( (cols * 50)/100, (lines * 30)/100);
276 info->showInfoPopup();
278 YDialog::deleteTopmostDialog();
284 if ( ok && singleChange )
322 if ( tableType == T_Availables || tableType == T_MultiVersion )
339 unsigned int index = 0;
342 while ( index < size )
345 NCTableLine * cl = myPad()->ModifyLine( index );
354 YTableItem *it =
dynamic_cast<YTableItem*
> (cl->origItem() );
355 YTableCell *tcell = it->cell(0);
367 ZyppStatus newstatus = S_NoInst;
368 if ( slbPtr && objPtr)
370 if ( tableType == T_Availables && !slbPtr->multiversionInstall() )
372 string isCandidate =
" ";
373 if ( objPtr == slbPtr->candidateObj() )
376 cl->AddCol( 2,
new NCTableCol( isCandidate ) );
386 cc->setStatus( newstatus );
387 cellChanged( index, 0, cc->statusToString (newstatus) );
400 static bool slbHasInstalledObj (
const ZyppSel & slb)
402 return ! slb->installedEmpty();
411 vector<string> header;
418 bool haveInstalledPkgs = find_if (zyppPkgBegin(), zyppPkgEnd(),
419 slbHasInstalledObj) != zyppPkgEnd();
422 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
423 header.push_back(
"L" + NCPkgStrings::PkgName() );
424 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
426 if ( haveInstalledPkgs > 0 )
428 header.push_back(
"L" + NCPkgStrings::PkgVersionNew() );
429 header.push_back(
"L" + NCPkgStrings::PkgVersionInst() );
430 haveInstalledVersion =
true;
434 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
437 header.push_back(
"L" + NCPkgStrings::PkgSize() );
439 #if SOURCE_INSTALL_SUPPORTED 440 header.push_back(
"L" + NCPkgStrings::PkgSource() );
447 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
448 header.push_back(
"L" + NCPkgStrings::PkgName() );
449 header.push_back(
"L" + NCPkgStrings::PkgVersionNew() );
450 header.push_back(
"L" + NCPkgStrings::PkgVersionInst() );
451 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
452 header.push_back(
"L" + NCPkgStrings::PkgSize() );
458 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
459 header.push_back(
"L" + NCPkgStrings::PkgName() );
460 header.push_back(
"L" + NCPkgStrings::PatchKind() );
461 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
462 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
469 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
470 header.push_back(
"L" + NCPkgStrings::PatternsLabel() );
476 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
477 header.push_back(
"L" + NCPkgStrings::LangCode() );
478 header.push_back(
"L" + NCPkgStrings::LangName() );
484 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
485 header.push_back(
"L" + NCPkgStrings::PkgName() );
486 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
487 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
488 header.push_back(
"L" + NCPkgStrings::PkgInstSource() );
489 header.push_back(
"L" + NCPkgStrings::PkgSize() );
490 header.push_back(
"L" + NCPkgStrings::PkgArch() );
496 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
497 header.push_back(
"L" + NCPkgStrings::PkgName() );
498 header.push_back(
"L" + NCPkgStrings::PkgVersion() );
499 header.push_back(
"L" + NCPkgStrings::PkgInstSource() );
500 header.push_back(
"L" + NCPkgStrings::PkgSize() );
501 header.push_back(
"L" + NCPkgStrings::PkgArch() );
506 header.push_back(
"L" + NCPkgStrings::PkgStatus() );
507 header.push_back(
"L" + NCPkgStrings::PkgName() );
508 header.push_back(
"L" + NCPkgStrings::PkgSummary() );
518 vector<string> pkgLine;
521 if ( !pkgPtr || !slbPtr )
523 yuiError() <<
"No valid package available" << endl;
528 pkgLine.push_back( slbPtr->name() );
530 string instVersion =
"";
539 if ( ! slbPtr->installedEmpty() )
541 instVersion = slbPtr->installedObj()->edition().asString();
545 if ( slbPtr->hasCandidateObj() )
547 version = slbPtr->candidateObj()->edition().asString();
551 version = pkgPtr->edition().asString();
553 pkgLine.push_back( version );
557 pkgLine.push_back( instVersion );
559 pkgLine.push_back( pkgPtr->summary() );
561 status = slbPtr->status();
562 yuiMilestone() <<
"Status of " << slbPtr->name() <<
": " << status << endl;
563 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
564 pkgLine.push_back( size.form( 8 ) );
571 string isCandidate =
" ";
572 if ( pkgPtr == slbPtr->candidateObj() )
574 pkgLine.push_back( isCandidate );
576 version = pkgPtr->edition().asString();
578 if ( pkgPtr->isRetracted() )
581 pkgLine.push_back( version );
583 pkgLine.push_back( pkgPtr->repository().info().name() );
587 zypp::ui::Selectable::installed_iterator it = slbPtr->installedBegin();
589 while ( it != slbPtr->installedEnd() )
591 if ( pkgPtr->edition() == (*it)->edition() &&
592 pkgPtr->arch() == (*it)->arch() &&
593 pkgPtr->vendor() == (*it)->vendor() )
595 status = S_KeepInstalled;
600 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
601 pkgLine.push_back( size.form( 8 ) );
602 pkgLine.push_back( pkgPtr->arch().asString());
609 version = pkgPtr->edition().asString();
611 if ( pkgPtr->isRetracted() )
614 pkgLine.push_back( version );
616 pkgLine.push_back( pkgPtr->repository().info().name() );
618 zypp::PoolItem itemPtr( pkgPtr->satSolvable() );
619 status = slbPtr->pickStatus( itemPtr );
620 yuiMilestone() <<
"Multi version: status of " << version <<
": " << status << endl;
622 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
623 pkgLine.push_back( size.form( 8 ) );
624 pkgLine.push_back( pkgPtr->arch().asString());
631 pkgLine.push_back( pkgPtr->summary() );
633 if ( ! slbPtr->installedEmpty() )
635 instVersion = slbPtr->installedObj()->edition().version();
638 if ( slbPtr->hasCandidateObj() )
640 version = slbPtr->candidateObj()->edition().version();
645 version = pkgPtr->edition().version();
647 pkgLine.push_back( version );
649 if ( haveInstalledVersion )
651 pkgLine.push_back( instVersion );
654 status = slbPtr->status();
656 FSize size(zypp::ByteCount::SizeType(pkgPtr->installSize()));
657 pkgLine.push_back( size.form( 8 ) );
659 #if SOURCE_INSTALL_SUPPORTED 660 if ( slbPtr->source_install() )
662 pkgLine.push_back(
" x " );
667 pkgLine.push_back(
" " );
683 vector<string> pkgLine;
686 pkgLine.push_back( text );
698 vector<string> pkgLine;
701 if ( !patchPtr || !slb )
703 yuiError() <<
"No valid patch available" << endl;
707 pkgLine.push_back( slb->name() );
709 pkgLine.push_back( patchPtr->category() );
711 if ( !patchPtr->summary().empty() )
712 pkgLine.push_back( patchPtr->summary() );
714 pkgLine.push_back( slb->name() );
716 pkgLine.push_back( patchPtr->edition().asString() );
736 if ( !packager || !objPtr || !slbPtr )
739 yuiMilestone() <<
"show information for " << slbPtr->name() << endl;
746 updateInfo( objPtr, slbPtr, VisibleInfo() );
747 packager->PackageLabel()->setLabel( slbPtr->name() );
752 updateInfo( objPtr, slbPtr, VisibleInfo() );
765 NCursesEvent ret = NCursesEvent::none;
770 if ( packager->isTestMode() )
772 if ( packager->diskSpacePopup() )
773 packager->diskSpacePopup()->setDiskSpace( key );
795 NCTable::wHandleInput( key);
805 changeObjStatus( key );
811 NCDialog * currentDialog =
static_cast<NCDialog *
>(YDialog::topmostDialog());
813 currentDialog->setStatusLine();
815 return NCursesEvent::handled;
828 return cc->getStatus();
838 return cc->getDataPointer();
848 return cc->getSelPointer();
854 NCTableLine * cl = myPad()->ModifyLine( index );
859 YTableItem *it =
dynamic_cast<YTableItem*
> (cl->origItem() );
860 YTableCell *tcell = it->cell(0);
867 #if SOURCE_INSTALL_SUPPORTED 869 bool NCPkgTable::SourceInstall(
bool install )
871 int index = getCurrentItem();
877 yuiError() <<
"Invalid Pointer" << endl;
880 ZyppSel selPtr = objPtr->getSelectable();
881 NCTableLine * currentLine = myPad()->ModifyLine( index );
883 if ( !selPtr || !currentLine )
885 yuiError() <<
"Invalid Selectable" << endl;
889 NCTableCol * currentCol = currentLine->GetCol( currentLine->Cols()-1 );
891 if ( install && selPtr->providesSources() )
893 ok = selPtr->set_source_install(
true );
894 yuiMilestone() <<
"Set source install returns: " << ( ok ?
"true" :
"false" ) << endl;
896 currentCol->SetLabel( NClabel(
" x " ) );
898 else if ( !install && selPtr->source_install() )
900 ok = selPtr->set_source_install(
false );
901 yuiMilestone() <<
"ReSet source install returns: " << ( ok ?
"true" :
"false" ) << endl;
903 currentCol->SetLabel( NClabel(
" " ) );
911 bool NCPkgTable::cycleObjStatus()
919 ZyppStatus newStatus;
921 bool ok = statusStrategy->
cycleStatus( slbPtr, objPtr, newStatus );
932 bool NCPkgTable::changeObjStatus(
int key )
940 ZyppStatus newStatus;
942 bool ok = statusStrategy->
keyToStatus( key, slbPtr, objPtr, newStatus );
951 bool NCPkgTable::changeListObjStatus( NCPkgTableListAction type )
953 ZyppStatus newStatus;
955 unsigned int index = 0;
957 while ( index < size )
970 if ( slbPtr->status() == S_NoInst )
971 ok = statusStrategy->
keyToStatus(
'+', slbPtr, objPtr, newStatus );
977 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
978 ok = statusStrategy->
keyToStatus(
'-', slbPtr, objPtr, newStatus );
985 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected && slbPtr->updateCandidateObj() )
987 slbPtr->setOnSystem( slbPtr->updateCandidateObj() );
988 ok = statusStrategy->
keyToStatus(
'>', slbPtr, objPtr, newStatus );
995 if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
996 ok = statusStrategy->
keyToStatus(
'>', slbPtr, objPtr, newStatus );
1002 if ( slbPtr->status() == S_Install
1003 || slbPtr->status() == S_AutoInstall
1004 || slbPtr->status() == S_Update
1005 || slbPtr->status() == S_AutoUpdate )
1006 ok = statusStrategy->
keyToStatus(
'<', slbPtr, objPtr, newStatus );
1007 else if ( slbPtr->status() == S_Del
1008 || slbPtr->status() == S_AutoDel )
1009 ok = statusStrategy->
keyToStatus(
'+', slbPtr, objPtr, newStatus );
1014 yuiError() <<
"Unknown list action" << endl;
1039 bool NCPkgTable::fillAvailableList( ZyppSel slb )
1043 yuiError() <<
"Package pointer not valid" << endl;
1051 NCPkgTableType type;
1053 if ( slb->multiversionInstall() || slb->installedSize() > 1 )
1060 type = T_MultiVersion;
1062 yuiMilestone() <<
"Multi version package " << slb->name() << endl;
1066 type = T_Availables;
1074 zypp::ui::Selectable::picklist_iterator it = slb->picklistBegin();
1075 while ( it != slb->picklistEnd() )
1085 setCurrentItem( 0 );
1092 bool NCPkgTable::fillSummaryList( NCPkgTable::NCPkgTableListType type )
1098 std::list<ZyppSel> pkgList( zyppPkgBegin(), zyppPkgEnd() );
1099 pkgList.sort( sortByName );
1102 std::list<ZyppSel>::iterator listIt;
1115 for ( listIt = pkgList.begin(); listIt != pkgList.end(); ++listIt )
1117 ZyppSel selectable = *listIt;
1118 ZyppPkg pkg = tryCastToZyppPkg( selectable->theObj() );
1122 case NCPkgTable::L_Changes:
1123 if ( selectable->status() != S_NoInst
1124 && selectable->status() != S_KeepInstalled )
1130 case NCPkgTable::L_Installed:
1131 if ( selectable->status() == S_KeepInstalled )
1149 void NCPkgTable::updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode )
1154 if ( packager->InfoText() )
1155 packager->InfoText()->longDescription( pkgPtr );
1159 if ( packager->InfoText() )
1160 packager->InfoText()->technicalData( pkgPtr, slbPtr );
1164 if ( packager->InfoText() )
1165 packager->InfoText()->fileList( slbPtr );
1169 if ( packager->InfoText() )
1170 packager->InfoText()->dependencyList( pkgPtr, slbPtr );
1174 if ( packager->VersionsList() )
1175 packager->VersionsList()->fillAvailableList( slbPtr );
1179 if ( packager->InfoText() )
1180 packager->InfoText()->patchDescription( pkgPtr, slbPtr );
1184 if ( packager->PatchPkgs() )
1196 yuiMilestone() <<
"Retracted object " << sel->name() <<
" " << pkg->edition() << endl;
1199 string heading = _(
"Please confirm" );
1201 std::ostringstream msg;
1203 msg << boost::format( _(
"<p>Really install a retracted version of \"%s\" ?</p>" ) ) % sel->name();
1204 int width = msg.str().size() + 2;
1207 NCPopupInfo * info =
new NCPopupInfo( wpos( ( NCurses::lines() - height ) / 2,
1208 ( NCurses::cols() - width ) / 2 ),
1213 info->setPreferredSize( width, height );
1214 NCursesEvent
event = info->showInfoPopup();
1215 YDialog::deleteTopmostDialog();
1216 bool confirmed = (
event != NCursesEvent::cancel );
1218 yuiMilestone() <<
"User " << ( confirmed ?
"confirmed" :
"rejected" )
1219 <<
" retracted object " << sel->name() <<
" " << pkg->edition()
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 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.
static const std::string RetractedLabel()
Marking for package versions that are retracted.
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...
virtual bool cycleStatus(ZyppSel slbPtr, ZyppObj objPtr, ZyppStatus &newStat_ret)
Cyle the package status (e.g.
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)
static const std::string YesLabel()
The label of the Yes button.
virtual void itemsCleared()
Clears the package list.
static const std::string NoLabel()
The label of the No button.
bool confirmRetracted(ZyppObj pkg, ZyppSel sel)
Ask the user for confirmation of installing a retracted package.
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.