1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
25 #include <qpopupmenu.h>
30 #include "YQPkgObjList.h"
31 #include "YQPkgTextDialog.h"
33 #include "YQIconPool.h"
40 #define VERBOSE_EXCLUDE_RULES 0
41 #define EXTRA_SOLVE_COLLECTIONS 0
44 YQPkgObjList::YQPkgObjList( QWidget * parent )
45 : QY2ListView( parent )
47 , _installedContextMenu(0)
48 , _notInstalledContextMenu(0)
50 // This class does not add any columns. This is the main reason why this is
51 // an abstract base class: It doesn't know which columns are desired and in
57 _instVersionCol = -42;
61 _satisfiedIconCol = -42;
64 _excludedItems = new YQPkgObjList::ExcludedItems( this );
68 connect( this, SIGNAL( columnClicked ( int, QListViewItem *, int, const QPoint & ) ),
69 this, SLOT ( pkgObjClicked ( int, QListViewItem *, int, const QPoint & ) ) );
71 connect( this, SIGNAL( columnDoubleClicked ( int, QListViewItem *, int, const QPoint & ) ),
72 this, SLOT ( pkgObjClicked ( int, QListViewItem *, int, const QPoint & ) ) );
74 connect( this, SIGNAL( selectionChanged ( QListViewItem * ) ),
75 this, SLOT ( selectionChangedInternal( QListViewItem * ) ) );
79 YQPkgObjList::~YQPkgObjList()
82 delete _excludedItems;
87 YQPkgObjList::addPkgObjItem( ZyppSel selectable, ZyppObj zyppObj )
91 y2error( "Null zypp::ui::Selectable!" );
95 YQPkgObjListItem * item = new YQPkgObjListItem( this, selectable, zyppObj );
96 applyExcludeRules( item );
101 YQPkgObjList::addPassiveItem( const QString & name,
102 const QString & summary,
105 QY2ListViewItem * item = new QY2ListViewItem( this, QString::null );
109 if ( nameCol() >= 0 && ! name.isEmpty() ) item->setText( nameCol(), name );
110 if ( summaryCol() >= 0 && ! summary.isEmpty() ) item->setText( summaryCol(), summary );
111 if ( sizeCol() >= 0 && size > 0L )
113 QString sizeStr = size.form().c_str();
115 item->setText( sizeCol(), sizeStr );
122 YQPkgObjList::pkgObjClicked( int button,
123 QListViewItem * listViewItem,
127 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
131 if ( button == Qt::LeftButton )
133 if ( col == statusCol() )
134 // || col == nameCol() )
136 if ( editable() && item->editable() )
140 else if ( button == Qt::RightButton )
142 if ( editable() && item->editable() )
144 updateActions( item );
146 QPopupMenu * contextMenu =
147 item->selectable()->hasInstalledObj() ?
148 installedContextMenu() : notInstalledContextMenu();
151 contextMenu->popup( pos );
159 YQPkgObjList::selectionChangedInternal( QListViewItem * listViewItem )
161 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
163 emit selectionChanged( item ? item->selectable() : ZyppSel() );
168 YQPkgObjList::clear()
170 emit selectionChanged( ZyppSel() );
172 _excludedItems->clear();
173 QY2ListView::clear();
178 YQPkgObjList::statusIcon( ZyppStatus status, bool enabled, bool bySelection )
180 QPixmap icon = YQIconPool::pkgNoInst();
186 case S_Del: icon = YQIconPool::pkgDel(); break;
187 case S_Install: icon = YQIconPool::pkgInstall(); break;
188 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled(); break;
189 case S_NoInst: icon = YQIconPool::pkgNoInst(); break;
190 case S_Protected: icon = YQIconPool::pkgProtected(); break;
191 case S_Taboo: icon = YQIconPool::pkgTaboo(); break;
192 case S_Update: icon = YQIconPool::pkgUpdate(); break;
194 case S_AutoDel: icon = bySelection ?
195 YQIconPool::pkgSelAutoDel() :
196 YQIconPool::pkgAutoDel(); break;
198 case S_AutoInstall: icon = bySelection ?
199 YQIconPool::pkgSelAutoInstall() :
200 YQIconPool::pkgAutoInstall(); break;
202 case S_AutoUpdate: icon = bySelection ?
203 YQIconPool::pkgSelAutoUpdate() :
204 YQIconPool::pkgAutoUpdate(); break;
207 // Intentionally omitting 'default' branch so the compiler can
208 // catch unhandled enum states
215 case S_Del: icon = YQIconPool::disabledPkgDel(); break;
216 case S_Install: icon = YQIconPool::disabledPkgInstall(); break;
217 case S_KeepInstalled: icon = YQIconPool::disabledPkgKeepInstalled(); break;
218 case S_NoInst: icon = YQIconPool::disabledPkgNoInst(); break;
219 case S_Protected: icon = YQIconPool::disabledPkgProtected(); break;
220 case S_Taboo: icon = YQIconPool::disabledPkgTaboo(); break;
221 case S_Update: icon = YQIconPool::disabledPkgUpdate(); break;
223 case S_AutoDel: icon = bySelection ?
224 YQIconPool::disabledPkgSelAutoDel() :
225 YQIconPool::disabledPkgAutoDel(); break;
227 case S_AutoInstall: icon = bySelection ?
228 YQIconPool::disabledPkgSelAutoInstall() :
229 YQIconPool::disabledPkgAutoInstall(); break;
231 case S_AutoUpdate: icon = bySelection ?
232 YQIconPool::disabledPkgSelAutoUpdate() :
233 YQIconPool::disabledPkgAutoUpdate(); break;
235 // Intentionally omitting 'default' branch so the compiler can
236 // catch unhandled enum states
245 YQPkgObjList::statusText( ZyppStatus status ) const
249 case S_AutoDel: return _( "Autodelete" );
250 case S_AutoInstall: return _( "Autoinstall" );
251 case S_AutoUpdate: return _( "Autoupdate" );
252 case S_Del: return _( "Delete" );
253 case S_Install: return _( "Install" );
254 case S_KeepInstalled: return _( "Keep" );
255 case S_NoInst: return _( "Do Not Install" );
256 case S_Protected: return _( "Protected -- Do Not Modify" );
257 case S_Taboo: return _( "Taboo -- Never Install" );
258 case S_Update: return _( "Update" );
261 return QString::null;
266 YQPkgObjList::setCurrentStatus( ZyppStatus newStatus, bool doSelectNextItem )
268 QListViewItem * listViewItem = selectedItem();
270 if ( ! listViewItem )
273 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
275 if ( item && item->editable() && _editable )
277 if ( newStatus != item->status() )
279 item->setStatus( newStatus );
281 if ( item->showLicenseAgreement() )
283 item->showNotifyTexts( newStatus );
285 else // License not confirmed?
287 // Status is now S_Taboo or S_Del - update status icon
288 item->setStatusIcon();
291 emit statusChanged();
295 if ( doSelectNextItem )
301 YQPkgObjList::setAllItemStatus( ZyppStatus newStatus, bool force )
306 YQUI::ui()->busyCursor();
307 QListViewItemIterator it( this );
311 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (*it);
313 if ( item && item->editable() && newStatus != item->status() )
315 if ( newStatus == S_Update )
317 if ( item->candidateIsNewer() || force )
318 item->setStatus( newStatus,
319 false ); // sendSignals
323 item->setStatus( newStatus,
324 false ); // sendSignals
331 emit updateItemStates();
332 emit updatePackages();
334 YQUI::ui()->normalCursor();
335 emit statusChanged();
340 YQPkgObjList::selectNextItem()
342 QListViewItem * item = selectedItem();
344 if ( item && item->nextSibling() )
346 item->setSelected( false ); // Doesn't emit signals
347 ensureItemVisible( item->nextSibling() ); // Scroll if necessary
348 setSelected( item->nextSibling(), true ); // Emits signals
354 YQPkgObjList::createActions()
356 actionSetCurrentInstall = createAction( S_Install, "[+]" );
357 actionSetCurrentDontInstall = createAction( S_NoInst, "[-]" );
358 actionSetCurrentKeepInstalled = createAction( S_KeepInstalled, "[<], [-]" );
359 actionSetCurrentDelete = createAction( S_Del, "[-]" );
360 actionSetCurrentUpdate = createAction( S_Update, "[>], [+]" );
361 actionSetCurrentTaboo = createAction( S_Taboo, "[!]" );
362 actionSetCurrentProtected = createAction( S_Protected, "[*]" );
364 actionSetListInstall = createAction( S_Install, "", true );
365 actionSetListDontInstall = createAction( S_NoInst, "", true );
366 actionSetListKeepInstalled = createAction( S_KeepInstalled, "", true );
367 actionSetListDelete = createAction( S_Del, "", true );
368 actionSetListProtected = createAction( S_Protected, "", true );
370 actionSetListUpdate = createAction( _( "Update if newer version available" ),
371 statusIcon( S_Update, true ),
372 statusIcon( S_Update, false ),
376 actionSetListUpdateForce = createAction( _( "Update unconditionally" ),
377 statusIcon( S_Update, true ),
378 statusIcon( S_Update, false ),
382 actionSetListTaboo = createAction( S_Taboo, "", true );
384 connect( actionSetCurrentInstall, SIGNAL( activated() ), this, SLOT( setCurrentInstall() ) );
385 connect( actionSetCurrentDontInstall, SIGNAL( activated() ), this, SLOT( setCurrentDontInstall() ) );
386 connect( actionSetCurrentKeepInstalled, SIGNAL( activated() ), this, SLOT( setCurrentKeepInstalled() ) );
387 connect( actionSetCurrentDelete, SIGNAL( activated() ), this, SLOT( setCurrentDelete() ) );
388 connect( actionSetCurrentUpdate, SIGNAL( activated() ), this, SLOT( setCurrentUpdate() ) );
389 connect( actionSetCurrentTaboo, SIGNAL( activated() ), this, SLOT( setCurrentTaboo() ) );
390 connect( actionSetCurrentProtected, SIGNAL( activated() ), this, SLOT( setCurrentProtected() ) );
392 connect( actionSetListInstall, SIGNAL( activated() ), this, SLOT( setListInstall() ) );
393 connect( actionSetListDontInstall, SIGNAL( activated() ), this, SLOT( setListDontInstall() ) );
394 connect( actionSetListKeepInstalled, SIGNAL( activated() ), this, SLOT( setListKeepInstalled() ) );
395 connect( actionSetListDelete, SIGNAL( activated() ), this, SLOT( setListDelete() ) );
396 connect( actionSetListUpdate, SIGNAL( activated() ), this, SLOT( setListUpdate() ) );
397 connect( actionSetListUpdateForce, SIGNAL( activated() ), this, SLOT( setListUpdateForce() ) );
398 connect( actionSetListTaboo, SIGNAL( activated() ), this, SLOT( setListTaboo() ) );
399 connect( actionSetListProtected, SIGNAL( activated() ), this, SLOT( setListProtected() ) );
405 YQPkgObjList::createAction( ZyppStatus status, const QString & key, bool enabled )
407 return createAction( statusText( status ),
408 statusIcon( status, true ),
409 statusIcon( status, false ),
416 YQPkgObjList::createAction( const QString & text,
417 const QPixmap & icon,
418 const QPixmap & insensitiveIcon,
422 QString label = text;
424 if ( ! key.isEmpty() )
428 QIconSet iconSet ( icon );
430 if ( ! insensitiveIcon.isNull() )
432 iconSet.setPixmap( insensitiveIcon,
434 QIconSet::Disabled );
437 QAction * action = new QAction( label, // text
443 action->setEnabled( enabled );
450 YQPkgObjList::createNotInstalledContextMenu()
452 _notInstalledContextMenu = new QPopupMenu( this );
453 CHECK_PTR( _notInstalledContextMenu );
455 actionSetCurrentInstall->addTo( _notInstalledContextMenu );
456 actionSetCurrentDontInstall->addTo( _notInstalledContextMenu );
457 actionSetCurrentTaboo->addTo( _notInstalledContextMenu );
459 addAllInListSubMenu( _notInstalledContextMenu );
464 YQPkgObjList::createInstalledContextMenu()
466 _installedContextMenu = new QPopupMenu( this );
467 CHECK_PTR( _installedContextMenu );
469 actionSetCurrentKeepInstalled->addTo( _installedContextMenu );
470 actionSetCurrentDelete->addTo( _installedContextMenu );
471 actionSetCurrentUpdate->addTo( _installedContextMenu );
473 addAllInListSubMenu( _installedContextMenu );
478 YQPkgObjList::addAllInListSubMenu( QPopupMenu * menu )
480 QPopupMenu * submenu = new QPopupMenu( menu );
481 CHECK_PTR( submenu );
483 actionSetListInstall->addTo( submenu );
484 actionSetListDontInstall->addTo( submenu );
485 actionSetListKeepInstalled->addTo( submenu );
486 actionSetListDelete->addTo( submenu );
487 actionSetListUpdate->addTo( submenu );
488 actionSetListUpdateForce->addTo( submenu );
489 actionSetListTaboo->addTo( submenu );
491 menu->insertItem( _( "&All in This List" ), submenu );
498 YQPkgObjList::notInstalledContextMenu()
500 if ( ! _notInstalledContextMenu )
501 createNotInstalledContextMenu();
503 return _notInstalledContextMenu;
508 YQPkgObjList::installedContextMenu()
510 if ( ! _installedContextMenu )
511 createInstalledContextMenu();
513 return _installedContextMenu;
518 YQPkgObjList::updateActions()
520 updateActions( dynamic_cast<YQPkgObjListItem *> ( selectedItem() ) );
525 YQPkgObjList::updateActions( YQPkgObjListItem * item )
529 ZyppSel selectable = item->selectable();
531 if ( selectable->hasInstalledObj() )
533 actionSetCurrentInstall->setEnabled( false );
534 actionSetCurrentDontInstall->setEnabled( false );
535 actionSetCurrentTaboo->setEnabled( false );
536 actionSetCurrentProtected->setEnabled( true );
538 actionSetCurrentKeepInstalled->setEnabled( true );
539 actionSetCurrentDelete->setEnabled( true );
540 actionSetCurrentUpdate->setEnabled( selectable->hasCandidateObj() );
544 actionSetCurrentInstall->setEnabled( selectable->hasCandidateObj() );
545 actionSetCurrentDontInstall->setEnabled( true );
546 actionSetCurrentTaboo->setEnabled( true );
547 actionSetCurrentProtected->setEnabled( false );
549 actionSetCurrentKeepInstalled->setEnabled( false );
550 actionSetCurrentDelete->setEnabled( false );
551 actionSetCurrentUpdate->setEnabled( false );
556 actionSetCurrentInstall->setEnabled( false );
557 actionSetCurrentDontInstall->setEnabled( false );
558 actionSetCurrentTaboo->setEnabled( false );
560 actionSetCurrentKeepInstalled->setEnabled( false );
561 actionSetCurrentDelete->setEnabled( false );
562 actionSetCurrentUpdate->setEnabled( false );
563 actionSetCurrentProtected->setEnabled( false );
569 YQPkgObjList::keyPressEvent( QKeyEvent * event )
573 unsigned special_combo = ( Qt::ControlButton | Qt::ShiftButton | Qt::AltButton );
575 if ( ( event->state() & special_combo ) == special_combo )
577 if ( event->key() == Qt::Key_Q )
580 y2milestone( "Debug mode %s", _debug ? "on" : "off" );
585 QListViewItem * selectedListViewItem = selectedItem();
587 if ( selectedListViewItem )
589 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (selectedListViewItem);
593 bool installed = item->selectable()->hasInstalledObj();
594 ZyppStatus status = item->status();
596 switch( event->ascii() )
598 case Qt::Key_Space: // Cycle
603 case '+': // Grab everything - install or update
607 ZyppStatus newStatus = S_KeepInstalled;
609 if ( item->candidateIsNewer() )
610 newStatus = S_Update;
612 setCurrentStatus( newStatus );
615 setCurrentStatus( S_Install );
620 case '-': // Get rid of everything - don't install or delete
621 setCurrentStatus( installed ? S_Del : S_NoInst );
629 setCurrentStatus( S_Taboo );
634 case '*': // Protected
637 setCurrentStatus( S_Protected );
642 case '>': // Update what is worth to be updated
644 if ( installed && item->candidateIsNewer() )
645 setCurrentStatus( S_Update );
650 case '<': // Revert update
652 if ( status == S_Update ||
653 status == S_AutoUpdate )
655 setCurrentStatus( S_KeepInstalled );
662 case 'B': // Toggle debugIsBroken flag
666 item->toggleDebugIsBroken();
667 item->setStatusIcon();
673 case 'S': // Toggle debugIsSatisfied flag
677 item->toggleDebugIsSatisfied();
678 item->setStatusIcon();
687 QListView::keyPressEvent( event );
692 YQPkgObjList::message( const QString & text )
694 QY2ListViewItem * item = new QY2ListViewItem( this );
697 item->setText( nameCol() >= 0 ? nameCol() : 0, text );
698 item->setBackgroundColor( QColor( 0xE0, 0xE0, 0xF8 ) );
703 YQPkgObjList::addExcludeRule( YQPkgObjList::ExcludeRule * rule )
705 _excludeRules.push_back( rule );
710 YQPkgObjList::applyExcludeRules()
712 // y2debug( "Applying exclude rules" );
713 QListViewItemIterator listView_it( this );
715 while ( *listView_it )
717 QListViewItem * current_item = *listView_it;
719 // Advance iterator now so it remains valid even if there are changes
720 // to the QListView, e.g., if the current item is excluded and thus
721 // removed from the QListView
724 applyExcludeRules( current_item );
727 ExcludedItems::iterator excluded_it = _excludedItems->begin();
729 while ( excluded_it != _excludedItems->end() )
731 QListViewItem * current_item = (*excluded_it).first;
733 // Advance iterator now so it remains valid even if there are changes
734 // to the excluded items, e.g., if the current item is un-excluded and thus
735 // removed from the excluded items
738 applyExcludeRules( current_item );
741 logExcludeStatistics();
746 YQPkgObjList::logExcludeStatistics()
748 if ( _excludedItems->size() > 0 )
750 y2milestone( "%d packages excluded", _excludedItems->size() );
752 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
753 rule_it != _excludeRules.end();
756 ExcludeRule * rule = *rule_it;
758 if ( rule->isEnabled() )
760 y2milestone( "Active exclude rule: \"%s\"",
761 rule->regexp().pattern().ascii() );
769 YQPkgObjList::applyExcludeRules( QListViewItem * listViewItem )
771 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *>( listViewItem );
775 bool exclude = false;
776 ExcludeRule * matchingRule = 0;
778 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
779 rule_it != _excludeRules.end() && ! exclude;
782 ExcludeRule * rule = *rule_it;
784 if ( rule->match( item ) )
791 if ( exclude != item->isExcluded() ) // change exclude status?
793 this->exclude( item, exclude );
795 #if VERBOSE_EXCLUDE_RULES
798 y2debug( "Rule %s matches: Excluding %s",
799 matchingRule->regexp().pattern().ascii(),
800 item->zyppObj()->name().c_str() );
804 y2debug( "Un-excluding %s", item->zyppObj()->name().c_str() );
813 YQPkgObjList::exclude( YQPkgObjListItem * item, bool exclude )
815 if ( exclude == item->isExcluded() )
818 item->setExcluded( exclude );
822 QListViewItem * parentItem = item->parent();
825 parentItem->takeItem( item );
827 QListView::takeItem( item );
829 _excludedItems->add( item, parentItem );
833 if ( _excludedItems->contains( item ) )
835 QListViewItem * oldParent = _excludedItems->oldParentItem( item );
836 _excludedItems->remove( item );
839 oldParent->insertItem( item );
841 QListView::insertItem( item );
849 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
852 : QY2ListViewItem( pkgObjList )
853 , _pkgObjList( pkgObjList )
854 , _selectable( selectable )
855 , _zyppObj( zyppObj )
863 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
864 QY2ListViewItem * parent,
867 : QY2ListViewItem( parent )
868 , _pkgObjList( pkgObjList )
869 , _selectable( selectable )
870 , _zyppObj( zyppObj )
878 YQPkgObjListItem::~YQPkgObjListItem()
885 YQPkgObjListItem::init()
887 if ( _zyppObj == 0 && _selectable )
888 _zyppObj = _selectable->theObj();
890 _debugIsBroken = false;
891 _debugIsSatisfied = false;
892 _candidateIsNewer = false;
893 _installedIsNewer = false;
895 const ZyppObj candidate = selectable()->candidateObj();
896 const ZyppObj installed = selectable()->installedObj();
898 if ( candidate && installed )
900 if ( candidate->edition() < installed->edition() )
901 _installedIsNewer = true;
902 else if ( installed->edition() < candidate->edition() )
903 _candidateIsNewer = true;
906 if ( nameCol() >= 0 ) setText( nameCol(), zyppObj()->name() );
907 if ( summaryCol() >= 0 ) setText( summaryCol(), zyppObj()->summary() );
909 if ( sizeCol() >= 0 )
911 zypp::ByteCount size = zyppObj()->size();
914 setText( sizeCol(), size.asString() + " " );
917 if ( instVersionCol() >= 0 )
919 if ( selectable()->hasInstalledObj() )
920 setText( instVersionCol(), installed->edition() );
922 if ( zyppObj() != selectable()->installedObj() &&
923 zyppObj() != selectable()->candidateObj() )
925 setText( versionCol(), zyppObj()->edition() );
927 else if ( selectable()->hasCandidateObj() )
929 setText( versionCol(), candidate->edition() );
934 setText( versionCol(), zyppObj()->edition() );
942 YQPkgObjListItem::updateData()
949 YQPkgObjListItem::setText( int column, const string text )
951 QListViewItem::setText( column, fromUTF8( text.c_str() ) );
956 YQPkgObjListItem::setText( int column, const zypp::Edition & edition )
958 setText( column, edition.asString() );
963 YQPkgObjListItem::status() const
965 if ( ! selectable() )
967 y2error( "No selectable" );
971 return selectable()->status();
976 YQPkgObjListItem::bySelection() const
978 zypp::ResStatus::TransactByValue modifiedBy = selectable()->modifiedBy();
980 return ( modifiedBy == zypp::ResStatus::APPL_LOW ||
981 modifiedBy == zypp::ResStatus::APPL_HIGH );
986 YQPkgObjListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
988 ZyppStatus oldStatus = selectable()->status();
989 selectable()->set_status( newStatus );
991 if ( oldStatus != selectable()->status() )
997 _pkgObjList->updateItemStates();
998 _pkgObjList->sendUpdatePackages();
1007 YQPkgObjListItem::solveResolvableCollections()
1009 #if EXTRA_SOLVE_COLLECTIONS
1010 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
1012 resolver->transactReset( zypp::ResStatus::APPL_LOW );
1014 resolver->transactResKind( zypp::ResTraits<zypp::Product >::kind );
1015 resolver->transactResKind( zypp::ResTraits<zypp::Selection>::kind );
1016 resolver->transactResKind( zypp::ResTraits<zypp::Pattern >::kind );
1017 resolver->transactResKind( zypp::ResTraits<zypp::Language >::kind );
1018 resolver->transactResKind( zypp::ResTraits<zypp::Patch >::kind );
1019 resolver->transactResKind( zypp::ResTraits<zypp::Atom >::kind );
1026 YQPkgObjListItem::updateStatus()
1033 YQPkgObjListItem::setStatusIcon()
1035 if ( statusCol() >= 0 )
1037 bool enabled = editable() && _pkgObjList->editable();
1038 setPixmap( statusCol(), _pkgObjList->statusIcon( status(), enabled, bySelection() ) );
1042 if ( brokenIconCol() >= 0 )
1044 // Reset this icon now - it might be the same column as satisfiedIconCol()
1045 setPixmap( brokenIconCol(), QPixmap() );
1048 if ( satisfiedIconCol() >= 0 )
1050 // Set special icon for zyppObjs that are not marked as installed,
1051 // but satisfied anyway (e.g. for patches or patterns where the user
1052 // selected all required packages manually)
1054 setPixmap( satisfiedIconCol(), isSatisfied() ? YQIconPool::pkgSatisfied() : QPixmap() );
1057 if ( brokenIconCol() >= 0 )
1059 // Set special icon for zyppObjs that are installed, but broken
1060 // (dependencies no longer satisfied, e.g. for patches or patterns)
1064 setPixmap( brokenIconCol(), YQIconPool::warningSign() );
1066 y2warning( "Broken object: %s - %s",
1067 _selectable->theObj()->name().c_str(),
1068 _selectable->theObj()->summary().c_str() );
1076 YQPkgObjListItem::isSatisfied() const
1078 if ( _debugIsSatisfied )
1081 if ( _selectable->hasInstalledObj() )
1084 return _selectable->candidatePoolItem().status().isSatisfied();
1088 bool YQPkgObjListItem::isBroken() const
1090 if ( _debugIsBroken )
1093 if ( ! _selectable->hasInstalledObj() )
1094 return false; // can't be broken if not installed
1098 case S_KeepInstalled:
1101 return _selectable->installedPoolItem().status().isIncomplete();
1103 case S_Update: // will be fixed by updating
1105 case S_Del: // will no longer be relevant after deleting
1110 case S_NoInst: // should not happen - no installed obj
1115 y2error( "Expected uninstalled zyppObj" );
1119 y2error( "Should never get here" );
1125 YQPkgObjListItem::cycleStatus()
1127 if ( ! _editable || ! _pkgObjList->editable() )
1130 ZyppStatus oldStatus = status();
1131 ZyppStatus newStatus = oldStatus;
1133 if ( selectable()->hasInstalledObj() )
1135 switch ( oldStatus )
1138 newStatus = selectable()->hasCandidateObj() ?
1139 S_KeepInstalled: S_NoInst;
1142 case S_KeepInstalled:
1143 newStatus = selectable()->hasCandidateObj() ?
1152 newStatus = S_KeepInstalled;
1156 newStatus = S_KeepInstalled;
1160 else // Pkg not installed
1162 switch ( oldStatus )
1165 if ( selectable()->hasCandidateObj() )
1167 newStatus = S_Install;
1171 y2warning( "No candidate for %s", selectable()->theObj()->name().c_str() );
1172 newStatus = S_NoInst;
1177 newStatus = S_Taboo;
1181 newStatus = S_NoInst;
1186 if ( oldStatus != newStatus )
1188 setStatus( newStatus );
1190 if ( showLicenseAgreement() )
1192 showNotifyTexts( newStatus );
1194 else // License not confirmed?
1196 // Status is now S_Taboo or S_Del - update status icon
1200 _pkgObjList->sendStatusChanged();
1206 YQPkgObjListItem::showNotifyTexts( ZyppStatus status )
1213 if ( selectable()->hasCandidateObj() )
1214 text = selectable()->candidateObj()->insnotify();
1220 if ( selectable()->hasCandidateObj() )
1221 text = selectable()->candidateObj()->delnotify();
1227 if ( ! text.empty() )
1229 y2debug( "Showing notify text" );
1230 YQPkgTextDialog::showText( _pkgObjList, selectable(), text );
1236 YQPkgObjListItem::showLicenseAgreement()
1238 return showLicenseAgreement( selectable() );
1243 YQPkgObjListItem::showLicenseAgreement( ZyppSel sel )
1247 switch ( sel->status() )
1254 if ( sel->hasLicenceConfirmed() )
1257 if ( sel->candidateObj() )
1258 licenseText = sel->candidateObj()->licenseToConfirm();
1261 default: return true;
1264 if ( licenseText.empty() )
1267 y2debug( "Showing license agreement for %s", sel->name().c_str() );
1268 bool confirmed = YQPkgTextDialog::confirmText( 0, sel, licenseText );
1272 y2milestone( "User confirmed license agreement for %s", sel->name().c_str() );
1273 sel->setLicenceConfirmed( true );
1277 // The user rejected the license agreement -
1278 // make sure the package gets unselected.
1280 switch ( sel->status() )
1285 y2warning( "User rejected license agreement for %s - setting to TABOO",
1286 sel->name().c_str() );
1288 sel->set_status( S_Taboo );
1295 y2warning( "User rejected license agreement for %s - setting to PROTECTED",
1296 sel->name().c_str() );
1298 sel->set_status( S_Protected );
1299 // S_Keep wouldn't be good enough: The next solver run might
1300 // set it to S_AutoUpdate again
1312 YQPkgObjListItem::toolTip( int col )
1314 if ( col == statusCol() )
1316 QString tip = _pkgObjList->statusText( status() );
1324 if ( bySelection() )
1325 // Translators: Additional hint what caused an auto-status
1326 tip += "\n" + _( "(by a software selection)" );
1328 tip += "\n" + _( "(by dependencies)" );
1339 if ( col == brokenIconCol() )
1342 // Translators: tool tip for patches / patterns that are installed,
1343 // but whose dependencies are broken (no longer satisfied)
1344 return _( "Dependencies broken" );
1347 // don't use "else if" here, it might be the same colum as another one!
1349 if ( col == satisfiedIconCol() )
1351 if ( isSatisfied() )
1352 // Translators: tool tip for patches / patterns that are not installed,
1353 // but whose dependencies are satisfied
1354 return _( "All dependencies satisfied" );
1357 return QString::null;
1362 * Comparison function used for sorting the list.
1364 * -1 if this < other
1365 * 0 if this == other
1366 * +1 if this > other
1369 YQPkgObjListItem::compare( QListViewItem * otherListViewItem,
1371 bool ascending ) const
1373 YQPkgObjListItem * other = dynamic_cast<YQPkgObjListItem *> (otherListViewItem);
1377 if ( col == sizeCol() )
1379 // Numeric sort by size
1381 if ( this->zyppObj()->size() < other->zyppObj()->size() ) return -1;
1382 if ( this->zyppObj()->size() > other->zyppObj()->size() ) return 1;
1385 else if ( col == statusCol() )
1387 // Sorting by status depends on the numeric value of the
1388 // ZyppStatus enum, thus it is important to insert new
1389 // package states there where they make most sense. We want to show
1390 // dangerous or noteworthy states first - e.g., "taboo" which should
1391 // seldeom occur, but when it does, it is important.
1393 if ( this->status() < other->status() ) return -1;
1394 if ( this->status() > other->status() ) return 1;
1397 else if ( col == instVersionCol() ||
1398 col == versionCol() )
1400 // Sorting by version numbers doesn't make too much sense, so let's
1401 // sort by package relation:
1402 // - Installed newer than candidate (red)
1403 // - Candidate newer than installed (blue) - worthwhile updating
1405 // - Not installed, but candidate available
1407 // Within these categories, sort versions by ASCII - OK, it's
1408 // pretty random, but predictable.
1410 int thisPoints = this->versionPoints();
1411 int otherPoints = other->versionPoints();
1413 if ( thisPoints > otherPoints ) return -1;
1414 if ( thisPoints < otherPoints ) return 1;
1415 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1419 // Fallback: Use parent class method
1420 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1425 YQPkgObjListItem::versionPoints() const
1429 if ( installedIsNewer() ) points += 1000;
1430 if ( candidateIsNewer() ) points += 100;
1431 if ( selectable()->hasInstalledObj() ) points += 10;
1432 if ( selectable()->hasCandidateObj() ) points += 1;
1439 YQPkgObjListItem::setExcluded( bool excl )
1447 YQPkgObjList::ExcludeRule::ExcludeRule( YQPkgObjList * parent,
1448 const QRegExp & regexp,
1455 _parent->addExcludeRule( this );
1460 YQPkgObjList::ExcludeRule::enable( bool enable )
1464 #if VERBOSE_EXCLUDE_RULES
1465 y2debug( "%s exclude rule %s",
1466 enable ? "Enabling" : "Disabling",
1467 _regexp.pattern().ascii() );
1473 YQPkgObjList::ExcludeRule::setRegexp( const QRegExp & regexp )
1480 YQPkgObjList::ExcludeRule::setColumn( int column )
1487 YQPkgObjList::ExcludeRule::match( QListViewItem * item )
1492 QString text = item->text( _column );
1494 if ( text.isEmpty() )
1497 return _regexp.exactMatch( text );
1505 YQPkgObjList::ExcludedItems::ExcludedItems( YQPkgObjList * parent )
1506 : _pkgObjList( parent )
1511 YQPkgObjList::ExcludedItems::~ExcludedItems()
1517 void YQPkgObjList::ExcludedItems::add( QListViewItem * item, QListViewItem * oldParent )
1519 _excludeMap.insert( ItemPair( item, oldParent ) );
1523 void YQPkgObjList::ExcludedItems::remove( QListViewItem * item )
1525 ItemMap::iterator it = _excludeMap.find( item );
1527 if ( it != _excludeMap.end() )
1529 _excludeMap.erase( it );
1534 void YQPkgObjList::ExcludedItems::clear()
1536 for ( ItemMap::iterator it = _excludeMap.begin();
1537 it != _excludeMap.end();
1543 _excludeMap.clear();
1547 bool YQPkgObjList::ExcludedItems::contains( QListViewItem * item )
1549 return ( _excludeMap.find( item ) != _excludeMap.end() );
1553 QListViewItem * YQPkgObjList::ExcludedItems::oldParentItem( QListViewItem * item )
1555 ItemMap::iterator it = _excludeMap.find( item );
1557 if ( it == _excludeMap.end() )
1565 #include "YQPkgObjList.moc"