1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <QHeaderView>
34 #include "YQPkgObjList.h"
35 #include "YQPkgTextDialog.h"
37 #include "YQIconPool.h"
44 #define VERBOSE_EXCLUDE_RULES 0
45 #define EXTRA_SOLVE_COLLECTIONS 0
48 YQPkgObjList::YQPkgObjList( QWidget * parent )
49 : QY2ListView( parent )
51 , _installedContextMenu(0)
52 , _notInstalledContextMenu(0)
54 // This class does not add any columns. This is the main reason why this is
55 // an abstract base class: It doesn't know which columns are desired and in
61 _instVersionCol = -42;
65 _satisfiedIconCol = -42;
68 _excludedItems = new YQPkgObjList::ExcludedItems( this );
72 connect( this, SIGNAL( columnClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ),
73 this, SLOT ( pkgObjClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ) );
75 connect( this, SIGNAL( columnDoubleClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ),
76 this, SLOT ( pkgObjClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ) );
78 connect( this, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
79 this, SLOT ( currentItemChangedInternal( QTreeWidgetItem * ) ) );
83 YQPkgObjList::~YQPkgObjList()
86 delete _excludedItems;
91 YQPkgObjList::addPkgObjItem( ZyppSel selectable, ZyppObj zyppObj )
95 y2error( "Null zypp::ui::Selectable!" );
99 YQPkgObjListItem * item = new YQPkgObjListItem( this, selectable, zyppObj );
100 applyExcludeRules( item );
105 YQPkgObjList::addPassiveItem( const QString & name,
106 const QString & summary,
109 QY2ListViewItem * item = new QY2ListViewItem( this, QString::null );
113 if ( nameCol() >= 0 && ! name.isEmpty() ) item->setText( nameCol(), name );
114 if ( summaryCol() >= 0 && ! summary.isEmpty() ) item->setText( summaryCol(), summary );
115 if ( sizeCol() >= 0 && size > 0L )
117 QString sizeStr = size.form().c_str();
119 item->setText( sizeCol(), sizeStr );
126 YQPkgObjList::pkgObjClicked( int button,
127 QTreeWidgetItem * listViewItem,
131 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
135 if ( button == Qt::LeftButton )
137 if ( col == statusCol() )
138 // || col == nameCol() )
140 if ( editable() && item->editable() )
144 else if ( button == Qt::RightButton )
146 if ( editable() && item->editable() )
148 updateActions( item );
150 QMenu * contextMenu =
151 item->selectable()->hasInstalledObj() ?
152 installedContextMenu() : notInstalledContextMenu();
155 contextMenu->popup( pos );
163 YQPkgObjList::currentItemChangedInternal( QTreeWidgetItem * listViewItem )
165 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
167 emit currentItemChanged( item ? item->selectable() : ZyppSel() );
172 YQPkgObjList::clear()
174 emit currentItemChanged( ZyppSel() );
176 _excludedItems->clear();
177 QY2ListView::clear();
182 YQPkgObjList::statusIcon( ZyppStatus status, bool enabled, bool bySelection )
184 QPixmap icon = YQIconPool::pkgNoInst();
190 case S_Del: icon = YQIconPool::pkgDel(); break;
191 case S_Install: icon = YQIconPool::pkgInstall(); break;
192 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled(); break;
193 case S_NoInst: icon = YQIconPool::pkgNoInst(); break;
194 case S_Protected: icon = YQIconPool::pkgProtected(); break;
195 case S_Taboo: icon = YQIconPool::pkgTaboo(); break;
196 case S_Update: icon = YQIconPool::pkgUpdate(); break;
198 case S_AutoDel: icon = bySelection ?
199 YQIconPool::pkgSelAutoDel() :
200 YQIconPool::pkgAutoDel(); break;
202 case S_AutoInstall: icon = bySelection ?
203 YQIconPool::pkgSelAutoInstall() :
204 YQIconPool::pkgAutoInstall(); break;
206 case S_AutoUpdate: icon = bySelection ?
207 YQIconPool::pkgSelAutoUpdate() :
208 YQIconPool::pkgAutoUpdate(); break;
211 // Intentionally omitting 'default' branch so the compiler can
212 // catch unhandled enum states
219 case S_Del: icon = YQIconPool::disabledPkgDel(); break;
220 case S_Install: icon = YQIconPool::disabledPkgInstall(); break;
221 case S_KeepInstalled: icon = YQIconPool::disabledPkgKeepInstalled(); break;
222 case S_NoInst: icon = YQIconPool::disabledPkgNoInst(); break;
223 case S_Protected: icon = YQIconPool::disabledPkgProtected(); break;
224 case S_Taboo: icon = YQIconPool::disabledPkgTaboo(); break;
225 case S_Update: icon = YQIconPool::disabledPkgUpdate(); break;
227 case S_AutoDel: icon = bySelection ?
228 YQIconPool::disabledPkgSelAutoDel() :
229 YQIconPool::disabledPkgAutoDel(); break;
231 case S_AutoInstall: icon = bySelection ?
232 YQIconPool::disabledPkgSelAutoInstall() :
233 YQIconPool::disabledPkgAutoInstall(); break;
235 case S_AutoUpdate: icon = bySelection ?
236 YQIconPool::disabledPkgSelAutoUpdate() :
237 YQIconPool::disabledPkgAutoUpdate(); break;
239 // Intentionally omitting 'default' branch so the compiler can
240 // catch unhandled enum states
249 YQPkgObjList::statusText( ZyppStatus status ) const
253 case S_AutoDel: return _( "Autodelete" );
254 case S_AutoInstall: return _( "Autoinstall" );
255 case S_AutoUpdate: return _( "Autoupdate" );
256 case S_Del: return _( "Delete" );
257 case S_Install: return _( "Install" );
258 case S_KeepInstalled: return _( "Keep" );
259 case S_NoInst: return _( "Do Not Install" );
260 case S_Protected: return _( "Protected -- Do Not Modify" );
261 case S_Taboo: return _( "Taboo -- Never Install" );
262 case S_Update: return _( "Update" );
265 return QString::null;
270 YQPkgObjList::setCurrentStatus( ZyppStatus newStatus, bool doSelectNextItem )
273 QTreeWidgetItem * listViewItem = selectedItem();
275 if ( ! listViewItem )
278 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
280 if ( item && item->editable() && _editable )
282 if ( newStatus != item->status() )
284 item->setStatus( newStatus );
286 if ( item->showLicenseAgreement() )
288 item->showNotifyTexts( newStatus );
290 else // License not confirmed?
292 // Status is now S_Taboo or S_Del - update status icon
293 item->setStatusIcon();
296 emit statusChanged();
300 if ( doSelectNextItem )
307 YQPkgObjList::setAllItemStatus( ZyppStatus newStatus, bool force )
312 YQUI::ui()->busyCursor();
313 QTreeWidgetItemIterator it( this );
317 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (*it);
319 if ( item && item->editable() && newStatus != item->status() )
321 if ( newStatus == S_Update )
323 if ( item->candidateIsNewer() || force )
324 item->setStatus( newStatus,
325 false ); // sendSignals
329 item->setStatus( newStatus,
330 false ); // sendSignals
337 emit updateItemStates();
338 emit updatePackages();
340 YQUI::ui()->normalCursor();
341 emit statusChanged();
346 YQPkgObjList::selectNextItem()
349 QTreeWidgetItem * item = selectedItem();
351 if ( item && item->nextSibling() )
353 item->setSelected( false ); // Doesn't emit signals
354 ensureItemVisible( item->nextSibling() ); // Scroll if necessary
355 setSelected( item->nextSibling(), true ); // Emits signals
362 YQPkgObjList::createActions()
364 actionSetCurrentInstall = createAction( S_Install, "[+]" );
365 actionSetCurrentDontInstall = createAction( S_NoInst, "[-]" );
366 actionSetCurrentKeepInstalled = createAction( S_KeepInstalled, "[<], [-]" );
367 actionSetCurrentDelete = createAction( S_Del, "[-]" );
368 actionSetCurrentUpdate = createAction( S_Update, "[>], [+]" );
369 actionSetCurrentTaboo = createAction( S_Taboo, "[!]" );
370 actionSetCurrentProtected = createAction( S_Protected, "[*]" );
372 actionSetListInstall = createAction( S_Install, "", true );
373 actionSetListDontInstall = createAction( S_NoInst, "", true );
374 actionSetListKeepInstalled = createAction( S_KeepInstalled, "", true );
375 actionSetListDelete = createAction( S_Del, "", true );
376 actionSetListProtected = createAction( S_Protected, "", true );
378 actionSetListUpdate = createAction( _( "Update if newer version available" ),
379 statusIcon( S_Update, true ),
380 statusIcon( S_Update, false ),
384 actionSetListUpdateForce = createAction( _( "Update unconditionally" ),
385 statusIcon( S_Update, true ),
386 statusIcon( S_Update, false ),
390 actionSetListTaboo = createAction( S_Taboo, "", true );
392 connect( actionSetCurrentInstall, SIGNAL( activated() ), this, SLOT( setCurrentInstall() ) );
393 connect( actionSetCurrentDontInstall, SIGNAL( activated() ), this, SLOT( setCurrentDontInstall() ) );
394 connect( actionSetCurrentKeepInstalled, SIGNAL( activated() ), this, SLOT( setCurrentKeepInstalled() ) );
395 connect( actionSetCurrentDelete, SIGNAL( activated() ), this, SLOT( setCurrentDelete() ) );
396 connect( actionSetCurrentUpdate, SIGNAL( activated() ), this, SLOT( setCurrentUpdate() ) );
397 connect( actionSetCurrentTaboo, SIGNAL( activated() ), this, SLOT( setCurrentTaboo() ) );
398 connect( actionSetCurrentProtected, SIGNAL( activated() ), this, SLOT( setCurrentProtected() ) );
400 connect( actionSetListInstall, SIGNAL( activated() ), this, SLOT( setListInstall() ) );
401 connect( actionSetListDontInstall, SIGNAL( activated() ), this, SLOT( setListDontInstall() ) );
402 connect( actionSetListKeepInstalled, SIGNAL( activated() ), this, SLOT( setListKeepInstalled() ) );
403 connect( actionSetListDelete, SIGNAL( activated() ), this, SLOT( setListDelete() ) );
404 connect( actionSetListUpdate, SIGNAL( activated() ), this, SLOT( setListUpdate() ) );
405 connect( actionSetListUpdateForce, SIGNAL( activated() ), this, SLOT( setListUpdateForce() ) );
406 connect( actionSetListTaboo, SIGNAL( activated() ), this, SLOT( setListTaboo() ) );
407 connect( actionSetListProtected, SIGNAL( activated() ), this, SLOT( setListProtected() ) );
413 YQPkgObjList::createAction( ZyppStatus status, const QString & key, bool enabled )
415 return createAction( statusText( status ),
416 statusIcon( status, true ),
417 statusIcon( status, false ),
424 YQPkgObjList::createAction( const QString & text,
425 const QPixmap & icon,
426 const QPixmap & insensitiveIcon,
430 QString label = text;
432 if ( ! key.isEmpty() )
436 QIcon iconSet ( icon );
438 if ( ! insensitiveIcon.isNull() )
440 iconSet.setPixmap( insensitiveIcon,
445 QAction * action = new QAction( label, // text
447 Q_CHECK_PTR( action );
448 action->setEnabled( enabled );
449 action->setIcon( iconSet );
456 YQPkgObjList::createNotInstalledContextMenu()
458 _notInstalledContextMenu = new QMenu( this );
459 Q_CHECK_PTR( _notInstalledContextMenu );
461 actionSetCurrentInstall->addTo( _notInstalledContextMenu );
462 actionSetCurrentDontInstall->addTo( _notInstalledContextMenu );
463 actionSetCurrentTaboo->addTo( _notInstalledContextMenu );
465 addAllInListSubMenu( _notInstalledContextMenu );
470 YQPkgObjList::createInstalledContextMenu()
472 _installedContextMenu = new QMenu( this );
473 Q_CHECK_PTR( _installedContextMenu );
475 actionSetCurrentKeepInstalled->addTo( _installedContextMenu );
476 actionSetCurrentDelete->addTo( _installedContextMenu );
477 actionSetCurrentUpdate->addTo( _installedContextMenu );
479 addAllInListSubMenu( _installedContextMenu );
484 YQPkgObjList::addAllInListSubMenu( QMenu * menu )
486 QMenu * submenu = new QMenu( menu );
487 Q_CHECK_PTR( submenu );
489 actionSetListInstall->addTo( submenu );
490 actionSetListDontInstall->addTo( submenu );
491 actionSetListKeepInstalled->addTo( submenu );
492 actionSetListDelete->addTo( submenu );
493 actionSetListUpdate->addTo( submenu );
494 actionSetListUpdateForce->addTo( submenu );
495 actionSetListTaboo->addTo( submenu );
497 menu->insertItem( _( "&All in This List" ), submenu );
504 YQPkgObjList::notInstalledContextMenu()
506 if ( ! _notInstalledContextMenu )
507 createNotInstalledContextMenu();
509 return _notInstalledContextMenu;
514 YQPkgObjList::installedContextMenu()
516 if ( ! _installedContextMenu )
517 createInstalledContextMenu();
519 return _installedContextMenu;
524 YQPkgObjList::updateActions( YQPkgObjListItem * item )
528 item = dynamic_cast<YQPkgObjListItem *> ( selectedItem() );
532 ZyppSel selectable = item->selectable();
534 if ( selectable->hasInstalledObj() )
536 actionSetCurrentInstall->setEnabled( false );
537 actionSetCurrentDontInstall->setEnabled( false );
538 actionSetCurrentTaboo->setEnabled( false );
539 actionSetCurrentProtected->setEnabled( true );
541 actionSetCurrentKeepInstalled->setEnabled( true );
542 actionSetCurrentDelete->setEnabled( true );
543 actionSetCurrentUpdate->setEnabled( selectable->hasCandidateObj() );
547 actionSetCurrentInstall->setEnabled( selectable->hasCandidateObj() );
548 actionSetCurrentDontInstall->setEnabled( true );
549 actionSetCurrentTaboo->setEnabled( true );
550 actionSetCurrentProtected->setEnabled( false );
552 actionSetCurrentKeepInstalled->setEnabled( false );
553 actionSetCurrentDelete->setEnabled( false );
554 actionSetCurrentUpdate->setEnabled( false );
559 actionSetCurrentInstall->setEnabled( false );
560 actionSetCurrentDontInstall->setEnabled( false );
561 actionSetCurrentTaboo->setEnabled( false );
563 actionSetCurrentKeepInstalled->setEnabled( false );
564 actionSetCurrentDelete->setEnabled( false );
565 actionSetCurrentUpdate->setEnabled( false );
566 actionSetCurrentProtected->setEnabled( false );
573 YQPkgObjList::keyPressEvent( QKeyEvent * event )
578 unsigned special_combo = ( Qt::ControlButton | Qt::ShiftButton | Qt::AltButton );
580 if ( ( event->state() & special_combo ) == special_combo )
582 if ( event->key() == Qt::Key_Q )
585 y2milestone( "Debug mode %s", _debug ? "on" : "off" );
589 QTreeWidgetItem * selectedListViewItem = selectedItem();
591 if ( selectedListViewItem )
593 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (selectedListViewItem);
597 bool installed = item->selectable()->hasInstalledObj();
598 ZyppStatus status = item->status();
600 switch( event->ascii() )
602 case Qt::Key_Space: // Cycle
607 case '+': // Grab everything - install or update
611 ZyppStatus newStatus = S_KeepInstalled;
613 if ( item->candidateIsNewer() )
614 newStatus = S_Update;
616 setCurrentStatus( newStatus );
619 setCurrentStatus( S_Install );
624 case '-': // Get rid of everything - don't install or delete
625 setCurrentStatus( installed ? S_Del : S_NoInst );
633 setCurrentStatus( S_Taboo );
638 case '*': // Protected
641 setCurrentStatus( S_Protected );
646 case '>': // Update what is worth to be updated
648 if ( installed && item->candidateIsNewer() )
649 setCurrentStatus( S_Update );
654 case '<': // Revert update
656 if ( status == S_Update ||
657 status == S_AutoUpdate )
659 setCurrentStatus( S_KeepInstalled );
666 case 'B': // Toggle debugIsBroken flag
670 item->toggleDebugIsBroken();
671 item->setStatusIcon();
677 case 'S': // Toggle debugIsSatisfied flag
681 item->toggleDebugIsSatisfied();
682 item->setStatusIcon();
691 QY2ListView::keyPressEvent( event );
696 YQPkgObjList::message( const QString & text )
698 QY2ListViewItem * item = new QY2ListViewItem( this );
701 item->setText( nameCol() >= 0 ? nameCol() : 0, text );
702 item->setBackgroundColor( QColor( 0xE0, 0xE0, 0xF8 ) );
707 YQPkgObjList::addExcludeRule( YQPkgObjList::ExcludeRule * rule )
709 _excludeRules.push_back( rule );
714 YQPkgObjList::applyExcludeRules()
716 // y2debug( "Applying exclude rules" );
717 QTreeWidgetItemIterator listView_it( this );
719 while ( *listView_it )
721 QTreeWidgetItem * current_item = *listView_it;
723 // Advance iterator now so it remains valid even if there are changes
724 // to the QListView, e.g., if the current item is excluded and thus
725 // removed from the QListView
728 applyExcludeRules( current_item );
731 ExcludedItems::iterator excluded_it = _excludedItems->begin();
733 while ( excluded_it != _excludedItems->end() )
735 QTreeWidgetItem * current_item = (*excluded_it).first;
737 // Advance iterator now so it remains valid even if there are changes
738 // to the excluded items, e.g., if the current item is un-excluded and thus
739 // removed from the excluded items
742 applyExcludeRules( current_item );
745 logExcludeStatistics();
750 YQPkgObjList::logExcludeStatistics()
752 if ( _excludedItems->size() > 0 )
754 y2milestone( "%d packages excluded", _excludedItems->size() );
756 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
757 rule_it != _excludeRules.end();
760 ExcludeRule * rule = *rule_it;
762 if ( rule->isEnabled() )
764 y2milestone( "Active exclude rule: \"%s\"",
765 rule->regexp().pattern().ascii() );
773 YQPkgObjList::applyExcludeRules( QTreeWidgetItem * listViewItem )
775 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *>( listViewItem );
779 bool exclude = false;
780 ExcludeRule * matchingRule = 0;
782 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
783 rule_it != _excludeRules.end() && ! exclude;
786 ExcludeRule * rule = *rule_it;
788 if ( rule->match( item ) )
795 if ( exclude != item->isExcluded() ) // change exclude status?
797 this->exclude( item, exclude );
799 #if VERBOSE_EXCLUDE_RULES
802 y2debug( "Rule %s matches: Excluding %s",
803 matchingRule->regexp().pattern().ascii(),
804 item->zyppObj()->name().c_str() );
808 y2debug( "Un-excluding %s", item->zyppObj()->name().c_str() );
817 YQPkgObjList::exclude( YQPkgObjListItem * item, bool exclude )
820 if ( exclude == item->isExcluded() )
823 item->setExcluded( exclude );
827 QTreeWidgetItem * parentItem = item->parent();
830 parentItem->takeItem( item );
832 QTreeWidget::takeItem( item );
834 _excludedItems->add( item, parentItem );
838 if ( _excludedItems->contains( item ) )
840 QTreeWidgetItem * oldParent = _excludedItems->oldParentItem( item );
841 _excludedItems->remove( item );
844 oldParent->insertItem( item );
846 QTreeWidget::insertItem( item );
855 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
858 : QY2ListViewItem( pkgObjList )
859 , _pkgObjList( pkgObjList )
860 , _selectable( selectable )
861 , _zyppObj( zyppObj )
869 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
870 QY2ListViewItem * parent,
873 : QY2ListViewItem( parent )
874 , _pkgObjList( pkgObjList )
875 , _selectable( selectable )
876 , _zyppObj( zyppObj )
884 YQPkgObjListItem::~YQPkgObjListItem()
891 YQPkgObjListItem::init()
893 if ( _zyppObj == 0 && _selectable )
894 _zyppObj = _selectable->theObj();
896 _debugIsBroken = false;
897 _debugIsSatisfied = false;
898 _candidateIsNewer = false;
899 _installedIsNewer = false;
901 const ZyppObj candidate = selectable()->candidateObj();
902 const ZyppObj installed = selectable()->installedObj();
904 if ( candidate && installed )
906 if ( candidate->edition() < installed->edition() )
907 _installedIsNewer = true;
908 else if ( installed->edition() < candidate->edition() )
909 _candidateIsNewer = true;
912 if ( nameCol() >= 0 ) setText( nameCol(), zyppObj()->name() );
913 if ( summaryCol() >= 0 ) setText( summaryCol(), zyppObj()->summary() );
915 if ( sizeCol() >= 0 )
917 zypp::ByteCount size = zyppObj()->size();
920 setText( sizeCol(), size.asString() + " " );
923 if ( instVersionCol() >= 0 )
925 if ( selectable()->hasInstalledObj() )
926 setText( instVersionCol(), installed->edition() );
928 if ( zyppObj() != selectable()->installedObj() &&
929 zyppObj() != selectable()->candidateObj() )
931 setText( versionCol(), zyppObj()->edition() );
933 else if ( selectable()->hasCandidateObj() )
935 setText( versionCol(), candidate->edition() );
940 setText( versionCol(), zyppObj()->edition() );
948 YQPkgObjListItem::updateData()
955 YQPkgObjListItem::setText( int column, const string text )
957 QTreeWidgetItem::setText( column, fromUTF8( text.c_str() ) );
962 YQPkgObjListItem::setText( int column, const zypp::Edition & edition )
964 setText( column, edition.asString() );
969 YQPkgObjListItem::status() const
971 if ( ! selectable() )
973 y2error( "No selectable" );
977 return selectable()->status();
982 YQPkgObjListItem::bySelection() const
984 zypp::ResStatus::TransactByValue modifiedBy = selectable()->modifiedBy();
986 return ( modifiedBy == zypp::ResStatus::APPL_LOW ||
987 modifiedBy == zypp::ResStatus::APPL_HIGH );
992 YQPkgObjListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
994 ZyppStatus oldStatus = selectable()->status();
995 selectable()->set_status( newStatus );
997 if ( oldStatus != selectable()->status() )
1003 _pkgObjList->updateItemStates();
1004 _pkgObjList->sendUpdatePackages();
1013 YQPkgObjListItem::solveResolvableCollections()
1015 #if EXTRA_SOLVE_COLLECTIONS
1016 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
1018 resolver->transactReset( zypp::ResStatus::APPL_LOW );
1020 resolver->transactResKind( zypp::ResTraits<zypp::Product >::kind );
1021 resolver->transactResKind( zypp::ResTraits<zypp::Selection>::kind );
1022 resolver->transactResKind( zypp::ResTraits<zypp::Pattern >::kind );
1023 resolver->transactResKind( zypp::ResTraits<zypp::Language >::kind );
1024 resolver->transactResKind( zypp::ResTraits<zypp::Patch >::kind );
1025 resolver->transactResKind( zypp::ResTraits<zypp::Atom >::kind );
1032 YQPkgObjListItem::updateStatus()
1039 YQPkgObjListItem::setStatusIcon()
1042 if ( statusCol() >= 0 )
1044 bool enabled = editable() && _pkgObjList->editable();
1045 setPixmap( statusCol(), _pkgObjList->statusIcon( status(), enabled, bySelection() ) );
1049 if ( brokenIconCol() >= 0 )
1051 // Reset this icon now - it might be the same column as satisfiedIconCol()
1052 setPixmap( brokenIconCol(), QPixmap() );
1055 if ( satisfiedIconCol() >= 0 )
1057 // Set special icon for zyppObjs that are not marked as installed,
1058 // but satisfied anyway (e.g. for patches or patterns where the user
1059 // selected all required packages manually)
1061 setPixmap( satisfiedIconCol(), isSatisfied() ? YQIconPool::pkgSatisfied() : QPixmap() );
1064 if ( brokenIconCol() >= 0 )
1066 // Set special icon for zyppObjs that are installed, but broken
1067 // (dependencies no longer satisfied, e.g. for patches or patterns)
1071 setPixmap( brokenIconCol(), YQIconPool::warningSign() );
1073 y2warning( "Broken object: %s - %s",
1074 _selectable->theObj()->name().c_str(),
1075 _selectable->theObj()->summary().c_str() );
1083 YQPkgObjListItem::isSatisfied() const
1085 if ( _debugIsSatisfied )
1088 if ( _selectable->hasInstalledObj() )
1091 return _selectable->candidatePoolItem().status().isSatisfied();
1095 bool YQPkgObjListItem::isBroken() const
1097 if ( _debugIsBroken )
1100 if ( ! _selectable->hasInstalledObj() )
1101 return false; // can't be broken if not installed
1105 case S_KeepInstalled:
1108 return _selectable->installedPoolItem().status().isIncomplete();
1110 case S_Update: // will be fixed by updating
1112 case S_Del: // will no longer be relevant after deleting
1117 case S_NoInst: // should not happen - no installed obj
1122 y2error( "Expected uninstalled zyppObj" );
1126 y2error( "Should never get here" );
1132 YQPkgObjListItem::cycleStatus()
1134 if ( ! _editable || ! _pkgObjList->editable() )
1137 ZyppStatus oldStatus = status();
1138 ZyppStatus newStatus = oldStatus;
1140 if ( selectable()->hasInstalledObj() )
1142 switch ( oldStatus )
1145 newStatus = selectable()->hasCandidateObj() ?
1146 S_KeepInstalled: S_NoInst;
1149 case S_KeepInstalled:
1150 newStatus = selectable()->hasCandidateObj() ?
1159 newStatus = S_KeepInstalled;
1163 newStatus = S_KeepInstalled;
1167 else // Pkg not installed
1169 switch ( oldStatus )
1172 if ( selectable()->hasCandidateObj() )
1174 newStatus = S_Install;
1178 y2warning( "No candidate for %s", selectable()->theObj()->name().c_str() );
1179 newStatus = S_NoInst;
1184 newStatus = S_Taboo;
1188 newStatus = S_NoInst;
1193 if ( oldStatus != newStatus )
1195 setStatus( newStatus );
1197 if ( showLicenseAgreement() )
1199 showNotifyTexts( newStatus );
1201 else // License not confirmed?
1203 // Status is now S_Taboo or S_Del - update status icon
1207 _pkgObjList->sendStatusChanged();
1213 YQPkgObjListItem::showNotifyTexts( ZyppStatus status )
1220 if ( selectable()->hasCandidateObj() )
1221 text = selectable()->candidateObj()->insnotify();
1227 if ( selectable()->hasCandidateObj() )
1228 text = selectable()->candidateObj()->delnotify();
1234 if ( ! text.empty() )
1236 y2debug( "Showing notify text" );
1237 YQPkgTextDialog::showText( _pkgObjList, selectable(), text );
1243 YQPkgObjListItem::showLicenseAgreement()
1245 return showLicenseAgreement( selectable() );
1250 YQPkgObjListItem::showLicenseAgreement( ZyppSel sel )
1254 switch ( sel->status() )
1261 if ( sel->hasLicenceConfirmed() )
1264 if ( sel->candidateObj() )
1265 licenseText = sel->candidateObj()->licenseToConfirm();
1268 default: return true;
1271 if ( licenseText.empty() )
1274 y2debug( "Showing license agreement for %s", sel->name().c_str() );
1275 bool confirmed = YQPkgTextDialog::confirmText( 0, sel, licenseText );
1279 y2milestone( "User confirmed license agreement for %s", sel->name().c_str() );
1280 sel->setLicenceConfirmed( true );
1284 // The user rejected the license agreement -
1285 // make sure the package gets unselected.
1287 switch ( sel->status() )
1292 y2warning( "User rejected license agreement for %s - setting to TABOO",
1293 sel->name().c_str() );
1295 sel->set_status( S_Taboo );
1302 y2warning( "User rejected license agreement for %s - setting to PROTECTED",
1303 sel->name().c_str() );
1305 sel->set_status( S_Protected );
1306 // S_Keep wouldn't be good enough: The next solver run might
1307 // set it to S_AutoUpdate again
1319 YQPkgObjListItem::toolTip( int col )
1321 if ( col == statusCol() )
1323 QString tip = _pkgObjList->statusText( status() );
1331 if ( bySelection() )
1332 // Translators: Additional hint what caused an auto-status
1333 tip += "\n" + _( "(by a software selection)" );
1335 tip += "\n" + _( "(by dependencies)" );
1346 if ( col == brokenIconCol() )
1349 // Translators: tool tip for patches / patterns that are installed,
1350 // but whose dependencies are broken (no longer satisfied)
1351 return _( "Dependencies broken" );
1354 // don't use "else if" here, it might be the same colum as another one!
1356 if ( col == satisfiedIconCol() )
1358 if ( isSatisfied() )
1359 // Translators: tool tip for patches / patterns that are not installed,
1360 // but whose dependencies are satisfied
1361 return _( "All dependencies satisfied" );
1364 return QString::null;
1369 * Comparison function used for sorting the list.
1371 * -1 if this < other
1372 * 0 if this == other
1373 * +1 if this > other
1376 YQPkgObjListItem::compare( QTreeWidgetItem * otherListViewItem,
1378 bool ascending ) const
1380 YQPkgObjListItem * other = dynamic_cast<YQPkgObjListItem *> (otherListViewItem);
1384 if ( col == sizeCol() )
1386 // Numeric sort by size
1388 if ( this->zyppObj()->size() < other->zyppObj()->size() ) return -1;
1389 if ( this->zyppObj()->size() > other->zyppObj()->size() ) return 1;
1392 else if ( col == statusCol() )
1394 // Sorting by status depends on the numeric value of the
1395 // ZyppStatus enum, thus it is important to insert new
1396 // package states there where they make most sense. We want to show
1397 // dangerous or noteworthy states first - e.g., "taboo" which should
1398 // seldeom occur, but when it does, it is important.
1400 if ( this->status() < other->status() ) return -1;
1401 if ( this->status() > other->status() ) return 1;
1404 else if ( col == instVersionCol() ||
1405 col == versionCol() )
1407 // Sorting by version numbers doesn't make too much sense, so let's
1408 // sort by package relation:
1409 // - Installed newer than candidate (red)
1410 // - Candidate newer than installed (blue) - worthwhile updating
1412 // - Not installed, but candidate available
1414 // Within these categories, sort versions by ASCII - OK, it's
1415 // pretty random, but predictable.
1417 int thisPoints = this->versionPoints();
1418 int otherPoints = other->versionPoints();
1420 if ( thisPoints > otherPoints ) return -1;
1421 if ( thisPoints < otherPoints ) return 1;
1422 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1426 // Fallback: Use parent class method
1427 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1432 YQPkgObjListItem::versionPoints() const
1436 if ( installedIsNewer() ) points += 1000;
1437 if ( candidateIsNewer() ) points += 100;
1438 if ( selectable()->hasInstalledObj() ) points += 10;
1439 if ( selectable()->hasCandidateObj() ) points += 1;
1446 YQPkgObjListItem::setExcluded( bool excl )
1454 YQPkgObjList::ExcludeRule::ExcludeRule( YQPkgObjList * parent,
1455 const QRegExp & regexp,
1462 _parent->addExcludeRule( this );
1467 YQPkgObjList::ExcludeRule::enable( bool enable )
1471 #if VERBOSE_EXCLUDE_RULES
1472 y2debug( "%s exclude rule %s",
1473 enable ? "Enabling" : "Disabling",
1474 _regexp.pattern().ascii() );
1480 YQPkgObjList::ExcludeRule::setRegexp( const QRegExp & regexp )
1487 YQPkgObjList::ExcludeRule::setColumn( int column )
1494 YQPkgObjList::ExcludeRule::match( QTreeWidgetItem * item )
1499 QString text = item->text( _column );
1501 if ( text.isEmpty() )
1504 return _regexp.exactMatch( text );
1512 YQPkgObjList::ExcludedItems::ExcludedItems( YQPkgObjList * parent )
1513 : _pkgObjList( parent )
1518 YQPkgObjList::ExcludedItems::~ExcludedItems()
1524 void YQPkgObjList::ExcludedItems::add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent )
1526 _excludeMap.insert( ItemPair( item, oldParent ) );
1530 void YQPkgObjList::ExcludedItems::remove( QTreeWidgetItem * item )
1532 ItemMap::iterator it = _excludeMap.find( item );
1534 if ( it != _excludeMap.end() )
1536 _excludeMap.erase( it );
1541 void YQPkgObjList::ExcludedItems::clear()
1543 for ( ItemMap::iterator it = _excludeMap.begin();
1544 it != _excludeMap.end();
1550 _excludeMap.clear();
1554 bool YQPkgObjList::ExcludedItems::contains( QTreeWidgetItem * item )
1556 return ( _excludeMap.find( item ) != _excludeMap.end() );
1560 QTreeWidgetItem * YQPkgObjList::ExcludedItems::oldParentItem( QTreeWidgetItem * item )
1562 ItemMap::iterator it = _excludeMap.find( item );
1564 if ( it == _excludeMap.end() )
1572 #include "YQPkgObjList.moc"