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>
24 #include <QHeaderView>
32 #include "YQPkgObjList.h"
33 #include "YQPkgTextDialog.h"
35 #include "YQIconPool.h"
42 #define VERBOSE_EXCLUDE_RULES 0
43 #define EXTRA_SOLVE_COLLECTIONS 0
46 YQPkgObjList::YQPkgObjList( QWidget * parent )
47 : QY2ListView( parent )
49 , _installedContextMenu(0)
50 , _notInstalledContextMenu(0),
51 actionSetCurrentInstall(0L),
52 actionSetCurrentDontInstall(0L),
53 actionSetCurrentKeepInstalled(0L),
54 actionSetCurrentDelete(0L),
55 actionSetCurrentUpdate(0L),
56 actionSetCurrentTaboo(0L),
57 actionSetCurrentProtected(0L),
58 actionSetListInstall(0L),
59 actionSetListDontInstall(0L),
60 actionSetListKeepInstalled(0L),
61 actionSetListDelete(0L),
62 actionSetListUpdate(0L),
63 actionSetListUpdateForce(0L),
64 actionSetListTaboo(0L),
65 actionSetListProtected(0L)
67 // This class does not add any columns. This is the main reason why this is
68 // an abstract base class: It doesn't know which columns are desired and in
74 _instVersionCol = -42;
78 _satisfiedIconCol = -42;
81 _excludedItems = new YQPkgObjList::ExcludedItems( this );
85 connect( this, SIGNAL( columnClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ),
86 this, SLOT ( pkgObjClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ) );
88 connect( this, SIGNAL( columnDoubleClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ),
89 this, SLOT ( pkgObjClicked ( int, QTreeWidgetItem *, int, const QPoint & ) ) );
91 connect( this, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
92 this, SLOT ( currentItemChangedInternal( QTreeWidgetItem * ) ) );
96 YQPkgObjList::~YQPkgObjList()
99 delete _excludedItems;
104 YQPkgObjList::addPkgObjItem( ZyppSel selectable, ZyppObj zyppObj )
108 y2error( "Null zypp::ui::Selectable!" );
112 YQPkgObjListItem * item = new YQPkgObjListItem( this, selectable, zyppObj );
113 applyExcludeRules( item );
118 YQPkgObjList::addPassiveItem( const QString & name,
119 const QString & summary,
122 QY2ListViewItem * item = new QY2ListViewItem( this, QString::null );
126 if ( nameCol() >= 0 && ! name.isEmpty() ) item->setText( nameCol(), name );
127 if ( summaryCol() >= 0 && ! summary.isEmpty() ) item->setText( summaryCol(), summary );
128 if ( sizeCol() >= 0 && size > 0L )
130 QString sizeStr = size.form().c_str();
132 item->setText( sizeCol(), sizeStr );
139 YQPkgObjList::pkgObjClicked( int button,
140 QTreeWidgetItem * listViewItem,
144 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
148 if ( button == Qt::LeftButton )
150 if ( col == statusCol() )
151 // || col == nameCol() )
153 if ( editable() && item->editable() )
157 else if ( button == Qt::RightButton )
159 if ( editable() && item->editable() )
161 updateActions( item );
163 QMenu * contextMenu =
164 item->selectable()->hasInstalledObj() ?
165 installedContextMenu() : notInstalledContextMenu();
168 contextMenu->popup( pos );
176 YQPkgObjList::currentItemChangedInternal( QTreeWidgetItem * listViewItem )
178 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
180 emit currentItemChanged( item ? item->selectable() : ZyppSel() );
185 YQPkgObjList::clear()
187 emit currentItemChanged( ZyppSel() );
189 _excludedItems->clear();
190 QY2ListView::clear();
195 YQPkgObjList::statusIcon( ZyppStatus status, bool enabled, bool bySelection )
197 QPixmap icon = YQIconPool::pkgNoInst();
203 case S_Del: icon = YQIconPool::pkgDel(); break;
204 case S_Install: icon = YQIconPool::pkgInstall(); break;
205 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled(); break;
206 case S_NoInst: icon = YQIconPool::pkgNoInst(); break;
207 case S_Protected: icon = YQIconPool::pkgProtected(); break;
208 case S_Taboo: icon = YQIconPool::pkgTaboo(); break;
209 case S_Update: icon = YQIconPool::pkgUpdate(); break;
211 case S_AutoDel: icon = bySelection ?
212 YQIconPool::pkgSelAutoDel() :
213 YQIconPool::pkgAutoDel(); break;
215 case S_AutoInstall: icon = bySelection ?
216 YQIconPool::pkgSelAutoInstall() :
217 YQIconPool::pkgAutoInstall(); break;
219 case S_AutoUpdate: icon = bySelection ?
220 YQIconPool::pkgSelAutoUpdate() :
221 YQIconPool::pkgAutoUpdate(); break;
224 // Intentionally omitting 'default' branch so the compiler can
225 // catch unhandled enum states
232 case S_Del: icon = YQIconPool::disabledPkgDel(); break;
233 case S_Install: icon = YQIconPool::disabledPkgInstall(); break;
234 case S_KeepInstalled: icon = YQIconPool::disabledPkgKeepInstalled(); break;
235 case S_NoInst: icon = YQIconPool::disabledPkgNoInst(); break;
236 case S_Protected: icon = YQIconPool::disabledPkgProtected(); break;
237 case S_Taboo: icon = YQIconPool::disabledPkgTaboo(); break;
238 case S_Update: icon = YQIconPool::disabledPkgUpdate(); break;
240 case S_AutoDel: icon = bySelection ?
241 YQIconPool::disabledPkgSelAutoDel() :
242 YQIconPool::disabledPkgAutoDel(); break;
244 case S_AutoInstall: icon = bySelection ?
245 YQIconPool::disabledPkgSelAutoInstall() :
246 YQIconPool::disabledPkgAutoInstall(); break;
248 case S_AutoUpdate: icon = bySelection ?
249 YQIconPool::disabledPkgSelAutoUpdate() :
250 YQIconPool::disabledPkgAutoUpdate(); break;
252 // Intentionally omitting 'default' branch so the compiler can
253 // catch unhandled enum states
262 YQPkgObjList::statusText( ZyppStatus status ) const
266 case S_AutoDel: return _( "Autodelete" );
267 case S_AutoInstall: return _( "Autoinstall" );
268 case S_AutoUpdate: return _( "Autoupdate" );
269 case S_Del: return _( "Delete" );
270 case S_Install: return _( "Install" );
271 case S_KeepInstalled: return _( "Keep" );
272 case S_NoInst: return _( "Do Not Install" );
273 case S_Protected: return _( "Protected -- Do Not Modify" );
274 case S_Taboo: return _( "Taboo -- Never Install" );
275 case S_Update: return _( "Update" );
278 return QString::null;
283 YQPkgObjList::setCurrentStatus( ZyppStatus newStatus, bool doSelectNextItem )
286 QTreeWidgetItem * listViewItem = selectedItem();
288 if ( ! listViewItem )
291 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
293 if ( item && item->editable() && _editable )
295 if ( newStatus != item->status() )
297 item->setStatus( newStatus );
299 if ( item->showLicenseAgreement() )
301 item->showNotifyTexts( newStatus );
303 else // License not confirmed?
305 // Status is now S_Taboo or S_Del - update status icon
306 item->setStatusIcon();
309 emit statusChanged();
313 if ( doSelectNextItem )
320 YQPkgObjList::setAllItemStatus( ZyppStatus newStatus, bool force )
325 YQUI::ui()->busyCursor();
326 QTreeWidgetItemIterator it( this );
330 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (*it);
332 if ( item && item->editable() && newStatus != item->status() )
334 if ( newStatus == S_Update )
336 if ( item->candidateIsNewer() || force )
337 item->setStatus( newStatus,
338 false ); // sendSignals
342 item->setStatus( newStatus,
343 false ); // sendSignals
350 emit updateItemStates();
351 emit updatePackages();
353 YQUI::ui()->normalCursor();
354 emit statusChanged();
359 YQPkgObjList::selectNextItem()
362 QTreeWidgetItem * item = selectedItem();
364 if ( item && item->nextSibling() )
366 item->setSelected( false ); // Doesn't emit signals
367 ensureItemVisible( item->nextSibling() ); // Scroll if necessary
368 setSelected( item->nextSibling(), true ); // Emits signals
375 YQPkgObjList::createActions()
377 actionSetCurrentInstall = createAction( S_Install, "[+]" );
378 actionSetCurrentDontInstall = createAction( S_NoInst, "[-]" );
379 actionSetCurrentKeepInstalled = createAction( S_KeepInstalled, "[<], [-]" );
380 actionSetCurrentDelete = createAction( S_Del, "[-]" );
381 actionSetCurrentUpdate = createAction( S_Update, "[>], [+]" );
382 actionSetCurrentTaboo = createAction( S_Taboo, "[!]" );
383 actionSetCurrentProtected = createAction( S_Protected, "[*]" );
385 actionSetListInstall = createAction( S_Install, "", true );
386 actionSetListDontInstall = createAction( S_NoInst, "", true );
387 actionSetListKeepInstalled = createAction( S_KeepInstalled, "", true );
388 actionSetListDelete = createAction( S_Del, "", true );
389 actionSetListProtected = createAction( S_Protected, "", true );
391 actionSetListUpdate = createAction( _( "Update if newer version available" ),
392 statusIcon( S_Update, true ),
393 statusIcon( S_Update, false ),
397 actionSetListUpdateForce = createAction( _( "Update unconditionally" ),
398 statusIcon( S_Update, true ),
399 statusIcon( S_Update, false ),
403 actionSetListTaboo = createAction( S_Taboo, "", true );
405 connect( actionSetCurrentInstall, SIGNAL( activated() ), this, SLOT( setCurrentInstall() ) );
406 connect( actionSetCurrentDontInstall, SIGNAL( activated() ), this, SLOT( setCurrentDontInstall() ) );
407 connect( actionSetCurrentKeepInstalled, SIGNAL( activated() ), this, SLOT( setCurrentKeepInstalled() ) );
408 connect( actionSetCurrentDelete, SIGNAL( activated() ), this, SLOT( setCurrentDelete() ) );
409 connect( actionSetCurrentUpdate, SIGNAL( activated() ), this, SLOT( setCurrentUpdate() ) );
410 connect( actionSetCurrentTaboo, SIGNAL( activated() ), this, SLOT( setCurrentTaboo() ) );
411 connect( actionSetCurrentProtected, SIGNAL( activated() ), this, SLOT( setCurrentProtected() ) );
413 connect( actionSetListInstall, SIGNAL( activated() ), this, SLOT( setListInstall() ) );
414 connect( actionSetListDontInstall, SIGNAL( activated() ), this, SLOT( setListDontInstall() ) );
415 connect( actionSetListKeepInstalled, SIGNAL( activated() ), this, SLOT( setListKeepInstalled() ) );
416 connect( actionSetListDelete, SIGNAL( activated() ), this, SLOT( setListDelete() ) );
417 connect( actionSetListUpdate, SIGNAL( activated() ), this, SLOT( setListUpdate() ) );
418 connect( actionSetListUpdateForce, SIGNAL( activated() ), this, SLOT( setListUpdateForce() ) );
419 connect( actionSetListTaboo, SIGNAL( activated() ), this, SLOT( setListTaboo() ) );
420 connect( actionSetListProtected, SIGNAL( activated() ), this, SLOT( setListProtected() ) );
426 YQPkgObjList::createAction( ZyppStatus status, const QString & key, bool enabled )
428 return createAction( statusText( status ),
429 statusIcon( status, true ),
430 statusIcon( status, false ),
437 YQPkgObjList::createAction( const QString & text,
438 const QPixmap & icon,
439 const QPixmap & insensitiveIcon,
443 QString label = text;
445 if ( ! key.isEmpty() )
449 QIcon iconSet ( icon );
451 if ( ! insensitiveIcon.isNull() )
453 iconSet.addPixmap( insensitiveIcon,
457 QAction * action = new QAction( label, // text
459 Q_CHECK_PTR( action );
460 action->setEnabled( enabled );
461 action->setIcon( iconSet );
468 YQPkgObjList::createNotInstalledContextMenu()
470 _notInstalledContextMenu = new QMenu( this );
471 Q_CHECK_PTR( _notInstalledContextMenu );
473 _notInstalledContextMenu->addAction(actionSetCurrentInstall);
474 _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
475 _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
477 addAllInListSubMenu( _notInstalledContextMenu );
482 YQPkgObjList::createInstalledContextMenu()
484 _installedContextMenu = new QMenu( this );
485 Q_CHECK_PTR( _installedContextMenu );
487 _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
488 _installedContextMenu->addAction(actionSetCurrentDelete);
489 _installedContextMenu->addAction(actionSetCurrentUpdate);
491 addAllInListSubMenu( _installedContextMenu );
496 YQPkgObjList::addAllInListSubMenu( QMenu * menu )
498 QMenu * submenu = new QMenu( menu );
499 Q_CHECK_PTR( submenu );
501 submenu->addAction(actionSetListInstall);
502 submenu->addAction(actionSetListDontInstall);
503 submenu->addAction(actionSetListKeepInstalled);
504 submenu->addAction(actionSetListDelete);
505 submenu->addAction(actionSetListUpdate);
506 submenu->addAction(actionSetListUpdateForce);
507 submenu->addAction(actionSetListTaboo);
509 QAction *action = menu->addMenu( submenu );
510 action->setText(_( "&All in This List" ));
517 YQPkgObjList::notInstalledContextMenu()
519 if ( ! _notInstalledContextMenu )
520 createNotInstalledContextMenu();
522 return _notInstalledContextMenu;
527 YQPkgObjList::installedContextMenu()
529 if ( ! _installedContextMenu )
530 createInstalledContextMenu();
532 return _installedContextMenu;
537 YQPkgObjList::updateActions( YQPkgObjListItem * item )
541 item = dynamic_cast<YQPkgObjListItem *> ( selectedItem() );
545 ZyppSel selectable = item->selectable();
547 if ( selectable->hasInstalledObj() )
549 actionSetCurrentInstall->setEnabled( false );
550 actionSetCurrentDontInstall->setEnabled( false );
551 actionSetCurrentTaboo->setEnabled( false );
552 actionSetCurrentProtected->setEnabled( true );
554 actionSetCurrentKeepInstalled->setEnabled( true );
555 actionSetCurrentDelete->setEnabled( true );
556 actionSetCurrentUpdate->setEnabled( selectable->hasCandidateObj() );
560 actionSetCurrentInstall->setEnabled( selectable->hasCandidateObj() );
561 actionSetCurrentDontInstall->setEnabled( true );
562 actionSetCurrentTaboo->setEnabled( true );
563 actionSetCurrentProtected->setEnabled( false );
565 actionSetCurrentKeepInstalled->setEnabled( false );
566 actionSetCurrentDelete->setEnabled( false );
567 actionSetCurrentUpdate->setEnabled( false );
572 actionSetCurrentInstall->setEnabled( false );
573 actionSetCurrentDontInstall->setEnabled( false );
574 actionSetCurrentTaboo->setEnabled( false );
576 actionSetCurrentKeepInstalled->setEnabled( false );
577 actionSetCurrentDelete->setEnabled( false );
578 actionSetCurrentUpdate->setEnabled( false );
579 actionSetCurrentProtected->setEnabled( false );
586 YQPkgObjList::keyPressEvent( QKeyEvent * event )
591 unsigned special_combo = ( Qt::ControlButton | Qt::ShiftButton | Qt::AltButton );
593 if ( ( event->state() & special_combo ) == special_combo )
595 if ( event->key() == Qt::Key_Q )
598 y2milestone( "Debug mode %s", _debug ? "on" : "off" );
602 QTreeWidgetItem * selectedListViewItem = selectedItem();
604 if ( selectedListViewItem )
606 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (selectedListViewItem);
610 bool installed = item->selectable()->hasInstalledObj();
611 ZyppStatus status = item->status();
613 switch( event->ascii() )
615 case Qt::Key_Space: // Cycle
620 case '+': // Grab everything - install or update
624 ZyppStatus newStatus = S_KeepInstalled;
626 if ( item->candidateIsNewer() )
627 newStatus = S_Update;
629 setCurrentStatus( newStatus );
632 setCurrentStatus( S_Install );
637 case '-': // Get rid of everything - don't install or delete
638 setCurrentStatus( installed ? S_Del : S_NoInst );
646 setCurrentStatus( S_Taboo );
651 case '*': // Protected
654 setCurrentStatus( S_Protected );
659 case '>': // Update what is worth to be updated
661 if ( installed && item->candidateIsNewer() )
662 setCurrentStatus( S_Update );
667 case '<': // Revert update
669 if ( status == S_Update ||
670 status == S_AutoUpdate )
672 setCurrentStatus( S_KeepInstalled );
679 case 'B': // Toggle debugIsBroken flag
683 item->toggleDebugIsBroken();
684 item->setStatusIcon();
690 case 'S': // Toggle debugIsSatisfied flag
694 item->toggleDebugIsSatisfied();
695 item->setStatusIcon();
704 QY2ListView::keyPressEvent( event );
709 YQPkgObjList::message( const QString & text )
711 QY2ListViewItem * item = new QY2ListViewItem( this );
714 item->setText( nameCol() >= 0 ? nameCol() : 0, text );
715 item->setBackgroundColor( QColor( 0xE0, 0xE0, 0xF8 ) );
720 YQPkgObjList::addExcludeRule( YQPkgObjList::ExcludeRule * rule )
722 _excludeRules.push_back( rule );
727 YQPkgObjList::applyExcludeRules()
729 // y2debug( "Applying exclude rules" );
730 QTreeWidgetItemIterator listView_it( this );
732 while ( *listView_it )
734 QTreeWidgetItem * current_item = *listView_it;
736 // Advance iterator now so it remains valid even if there are changes
737 // to the QListView, e.g., if the current item is excluded and thus
738 // removed from the QListView
741 applyExcludeRules( current_item );
744 ExcludedItems::iterator excluded_it = _excludedItems->begin();
746 while ( excluded_it != _excludedItems->end() )
748 QTreeWidgetItem * current_item = (*excluded_it).first;
750 // Advance iterator now so it remains valid even if there are changes
751 // to the excluded items, e.g., if the current item is un-excluded and thus
752 // removed from the excluded items
755 applyExcludeRules( current_item );
758 logExcludeStatistics();
763 YQPkgObjList::logExcludeStatistics()
765 if ( _excludedItems->size() > 0 )
767 y2milestone( "%d packages excluded", _excludedItems->size() );
769 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
770 rule_it != _excludeRules.end();
773 ExcludeRule * rule = *rule_it;
775 if ( rule->isEnabled() )
777 y2milestone( "Active exclude rule: \"%s\"",
778 qPrintable(rule->regexp().pattern()) );
786 YQPkgObjList::applyExcludeRules( QTreeWidgetItem * listViewItem )
788 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *>( listViewItem );
792 bool exclude = false;
793 ExcludeRule * matchingRule = 0;
795 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
796 rule_it != _excludeRules.end() && ! exclude;
799 ExcludeRule * rule = *rule_it;
801 if ( rule->match( item ) )
808 if ( exclude != item->isExcluded() ) // change exclude status?
810 this->exclude( item, exclude );
812 #if VERBOSE_EXCLUDE_RULES
815 y2debug( "Rule %s matches: Excluding %s",
816 matchingRule->regexp().pattern().ascii(),
817 item->zyppObj()->name().c_str() );
821 y2debug( "Un-excluding %s", item->zyppObj()->name().c_str() );
830 YQPkgObjList::exclude( YQPkgObjListItem * item, bool exclude )
833 if ( exclude == item->isExcluded() )
836 item->setExcluded( exclude );
840 QTreeWidgetItem * parentItem = item->parent();
843 parentItem->takeItem( item );
845 QTreeWidget::takeItem( item );
847 _excludedItems->add( item, parentItem );
851 if ( _excludedItems->contains( item ) )
853 QTreeWidgetItem * oldParent = _excludedItems->oldParentItem( item );
854 _excludedItems->remove( item );
857 oldParent->insertItem( item );
859 QTreeWidget::insertItem( item );
868 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
871 : QY2ListViewItem( pkgObjList )
872 , _pkgObjList( pkgObjList )
873 , _selectable( selectable )
874 , _zyppObj( zyppObj )
882 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
883 QY2ListViewItem * parent,
886 : QY2ListViewItem( parent )
887 , _pkgObjList( pkgObjList )
888 , _selectable( selectable )
889 , _zyppObj( zyppObj )
897 YQPkgObjListItem::~YQPkgObjListItem()
904 YQPkgObjListItem::init()
906 if ( _zyppObj == 0 && _selectable )
907 _zyppObj = _selectable->theObj();
909 _debugIsBroken = false;
910 _debugIsSatisfied = false;
911 _candidateIsNewer = false;
912 _installedIsNewer = false;
914 const ZyppObj candidate = selectable()->candidateObj();
915 const ZyppObj installed = selectable()->installedObj();
917 if ( candidate && installed )
919 if ( candidate->edition() < installed->edition() )
920 _installedIsNewer = true;
921 else if ( installed->edition() < candidate->edition() )
922 _candidateIsNewer = true;
925 if ( nameCol() >= 0 ) setText( nameCol(), zyppObj()->name() );
926 if ( summaryCol() >= 0 ) setText( summaryCol(), zyppObj()->summary() );
928 if ( sizeCol() >= 0 )
930 zypp::ByteCount size = zyppObj()->size();
933 setText( sizeCol(), size.asString() + " " );
936 if ( instVersionCol() >= 0 )
938 if ( selectable()->hasInstalledObj() )
939 setText( instVersionCol(), installed->edition() );
941 if ( zyppObj() != selectable()->installedObj() &&
942 zyppObj() != selectable()->candidateObj() )
944 setText( versionCol(), zyppObj()->edition() );
946 else if ( selectable()->hasCandidateObj() )
948 setText( versionCol(), candidate->edition() );
953 setText( versionCol(), zyppObj()->edition() );
961 YQPkgObjListItem::updateData()
968 YQPkgObjListItem::setText( int column, const string text )
970 QTreeWidgetItem::setText( column, fromUTF8( text.c_str() ) );
975 YQPkgObjListItem::setText( int column, const zypp::Edition & edition )
977 setText( column, edition.asString() );
982 YQPkgObjListItem::status() const
984 if ( ! selectable() )
986 y2error( "No selectable" );
990 return selectable()->status();
995 YQPkgObjListItem::bySelection() const
997 zypp::ResStatus::TransactByValue modifiedBy = selectable()->modifiedBy();
999 return ( modifiedBy == zypp::ResStatus::APPL_LOW ||
1000 modifiedBy == zypp::ResStatus::APPL_HIGH );
1005 YQPkgObjListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
1007 ZyppStatus oldStatus = selectable()->status();
1008 selectable()->set_status( newStatus );
1010 if ( oldStatus != selectable()->status() )
1016 _pkgObjList->updateItemStates();
1017 _pkgObjList->sendUpdatePackages();
1026 YQPkgObjListItem::solveResolvableCollections()
1028 #if EXTRA_SOLVE_COLLECTIONS
1029 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
1031 resolver->transactReset( zypp::ResStatus::APPL_LOW );
1033 resolver->transactResKind( zypp::ResTraits<zypp::Product >::kind );
1034 resolver->transactResKind( zypp::ResTraits<zypp::Selection>::kind );
1035 resolver->transactResKind( zypp::ResTraits<zypp::Pattern >::kind );
1036 resolver->transactResKind( zypp::ResTraits<zypp::Language >::kind );
1037 resolver->transactResKind( zypp::ResTraits<zypp::Patch >::kind );
1038 resolver->transactResKind( zypp::ResTraits<zypp::Atom >::kind );
1045 YQPkgObjListItem::updateStatus()
1052 YQPkgObjListItem::setStatusIcon()
1055 if ( statusCol() >= 0 )
1057 bool enabled = editable() && _pkgObjList->editable();
1058 setPixmap( statusCol(), _pkgObjList->statusIcon( status(), enabled, bySelection() ) );
1062 if ( brokenIconCol() >= 0 )
1064 // Reset this icon now - it might be the same column as satisfiedIconCol()
1065 setPixmap( brokenIconCol(), QPixmap() );
1068 if ( satisfiedIconCol() >= 0 )
1070 // Set special icon for zyppObjs that are not marked as installed,
1071 // but satisfied anyway (e.g. for patches or patterns where the user
1072 // selected all required packages manually)
1074 setPixmap( satisfiedIconCol(), isSatisfied() ? YQIconPool::pkgSatisfied() : QPixmap() );
1077 if ( brokenIconCol() >= 0 )
1079 // Set special icon for zyppObjs that are installed, but broken
1080 // (dependencies no longer satisfied, e.g. for patches or patterns)
1084 setPixmap( brokenIconCol(), YQIconPool::warningSign() );
1086 y2warning( "Broken object: %s - %s",
1087 _selectable->theObj()->name().c_str(),
1088 _selectable->theObj()->summary().c_str() );
1096 YQPkgObjListItem::isSatisfied() const
1098 if ( _debugIsSatisfied )
1101 if ( _selectable->hasInstalledObj() )
1104 return _selectable->candidatePoolItem().status().isSatisfied();
1108 bool YQPkgObjListItem::isBroken() const
1110 if ( _debugIsBroken )
1113 if ( ! _selectable->hasInstalledObj() )
1114 return false; // can't be broken if not installed
1118 case S_KeepInstalled:
1121 return _selectable->installedPoolItem().status().isIncomplete();
1123 case S_Update: // will be fixed by updating
1125 case S_Del: // will no longer be relevant after deleting
1130 case S_NoInst: // should not happen - no installed obj
1135 y2error( "Expected uninstalled zyppObj" );
1139 y2error( "Should never get here" );
1145 YQPkgObjListItem::cycleStatus()
1147 if ( ! _editable || ! _pkgObjList->editable() )
1150 ZyppStatus oldStatus = status();
1151 ZyppStatus newStatus = oldStatus;
1153 if ( selectable()->hasInstalledObj() )
1155 switch ( oldStatus )
1158 newStatus = selectable()->hasCandidateObj() ?
1159 S_KeepInstalled: S_NoInst;
1162 case S_KeepInstalled:
1163 newStatus = selectable()->hasCandidateObj() ?
1172 newStatus = S_KeepInstalled;
1176 newStatus = S_KeepInstalled;
1180 else // Pkg not installed
1182 switch ( oldStatus )
1185 if ( selectable()->hasCandidateObj() )
1187 newStatus = S_Install;
1191 y2warning( "No candidate for %s", selectable()->theObj()->name().c_str() );
1192 newStatus = S_NoInst;
1197 newStatus = S_Taboo;
1201 newStatus = S_NoInst;
1206 if ( oldStatus != newStatus )
1208 setStatus( newStatus );
1210 if ( showLicenseAgreement() )
1212 showNotifyTexts( newStatus );
1214 else // License not confirmed?
1216 // Status is now S_Taboo or S_Del - update status icon
1220 _pkgObjList->sendStatusChanged();
1226 YQPkgObjListItem::showNotifyTexts( ZyppStatus status )
1233 if ( selectable()->hasCandidateObj() )
1234 text = selectable()->candidateObj()->insnotify();
1240 if ( selectable()->hasCandidateObj() )
1241 text = selectable()->candidateObj()->delnotify();
1247 if ( ! text.empty() )
1249 y2debug( "Showing notify text" );
1250 YQPkgTextDialog::showText( _pkgObjList, selectable(), text );
1256 YQPkgObjListItem::showLicenseAgreement()
1258 return showLicenseAgreement( selectable() );
1263 YQPkgObjListItem::showLicenseAgreement( ZyppSel sel )
1267 switch ( sel->status() )
1274 if ( sel->hasLicenceConfirmed() )
1277 if ( sel->candidateObj() )
1278 licenseText = sel->candidateObj()->licenseToConfirm();
1281 default: return true;
1284 if ( licenseText.empty() )
1287 y2debug( "Showing license agreement for %s", sel->name().c_str() );
1288 bool confirmed = YQPkgTextDialog::confirmText( 0, sel, licenseText );
1292 y2milestone( "User confirmed license agreement for %s", sel->name().c_str() );
1293 sel->setLicenceConfirmed( true );
1297 // The user rejected the license agreement -
1298 // make sure the package gets unselected.
1300 switch ( sel->status() )
1305 y2warning( "User rejected license agreement for %s - setting to TABOO",
1306 sel->name().c_str() );
1308 sel->set_status( S_Taboo );
1315 y2warning( "User rejected license agreement for %s - setting to PROTECTED",
1316 sel->name().c_str() );
1318 sel->set_status( S_Protected );
1319 // S_Keep wouldn't be good enough: The next solver run might
1320 // set it to S_AutoUpdate again
1332 YQPkgObjListItem::toolTip( int col )
1334 if ( col == statusCol() )
1336 QString tip = _pkgObjList->statusText( status() );
1344 if ( bySelection() )
1345 // Translators: Additional hint what caused an auto-status
1346 tip += "\n" + _( "(by a software selection)" );
1348 tip += "\n" + _( "(by dependencies)" );
1359 if ( col == brokenIconCol() )
1362 // Translators: tool tip for patches / patterns that are installed,
1363 // but whose dependencies are broken (no longer satisfied)
1364 return _( "Dependencies broken" );
1367 // don't use "else if" here, it might be the same colum as another one!
1369 if ( col == satisfiedIconCol() )
1371 if ( isSatisfied() )
1372 // Translators: tool tip for patches / patterns that are not installed,
1373 // but whose dependencies are satisfied
1374 return _( "All dependencies satisfied" );
1377 return QString::null;
1382 * Comparison function used for sorting the list.
1384 * -1 if this < other
1385 * 0 if this == other
1386 * +1 if this > other
1389 YQPkgObjListItem::compare( QTreeWidgetItem * otherListViewItem,
1391 bool ascending ) const
1393 YQPkgObjListItem * other = dynamic_cast<YQPkgObjListItem *> (otherListViewItem);
1397 if ( col == sizeCol() )
1399 // Numeric sort by size
1401 if ( this->zyppObj()->size() < other->zyppObj()->size() ) return -1;
1402 if ( this->zyppObj()->size() > other->zyppObj()->size() ) return 1;
1405 else if ( col == statusCol() )
1407 // Sorting by status depends on the numeric value of the
1408 // ZyppStatus enum, thus it is important to insert new
1409 // package states there where they make most sense. We want to show
1410 // dangerous or noteworthy states first - e.g., "taboo" which should
1411 // seldeom occur, but when it does, it is important.
1413 if ( this->status() < other->status() ) return -1;
1414 if ( this->status() > other->status() ) return 1;
1417 else if ( col == instVersionCol() ||
1418 col == versionCol() )
1420 // Sorting by version numbers doesn't make too much sense, so let's
1421 // sort by package relation:
1422 // - Installed newer than candidate (red)
1423 // - Candidate newer than installed (blue) - worthwhile updating
1425 // - Not installed, but candidate available
1427 // Within these categories, sort versions by ASCII - OK, it's
1428 // pretty random, but predictable.
1430 int thisPoints = this->versionPoints();
1431 int otherPoints = other->versionPoints();
1433 if ( thisPoints > otherPoints ) return -1;
1434 if ( thisPoints < otherPoints ) return 1;
1435 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1439 // Fallback: Use parent class method
1440 return QY2ListViewItem::compare( otherListViewItem, col, ascending );
1445 YQPkgObjListItem::versionPoints() const
1449 if ( installedIsNewer() ) points += 1000;
1450 if ( candidateIsNewer() ) points += 100;
1451 if ( selectable()->hasInstalledObj() ) points += 10;
1452 if ( selectable()->hasCandidateObj() ) points += 1;
1459 YQPkgObjListItem::setExcluded( bool excl )
1467 YQPkgObjList::ExcludeRule::ExcludeRule( YQPkgObjList * parent,
1468 const QRegExp & regexp,
1475 _parent->addExcludeRule( this );
1480 YQPkgObjList::ExcludeRule::enable( bool enable )
1484 #if VERBOSE_EXCLUDE_RULES
1485 y2debug( "%s exclude rule %s",
1486 enable ? "Enabling" : "Disabling",
1487 _regexp.pattern().ascii() );
1493 YQPkgObjList::ExcludeRule::setRegexp( const QRegExp & regexp )
1500 YQPkgObjList::ExcludeRule::setColumn( int column )
1507 YQPkgObjList::ExcludeRule::match( QTreeWidgetItem * item )
1512 QString text = item->text( _column );
1514 if ( text.isEmpty() )
1517 return _regexp.exactMatch( text );
1525 YQPkgObjList::ExcludedItems::ExcludedItems( YQPkgObjList * parent )
1526 : _pkgObjList( parent )
1531 YQPkgObjList::ExcludedItems::~ExcludedItems()
1537 void YQPkgObjList::ExcludedItems::add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent )
1539 _excludeMap.insert( ItemPair( item, oldParent ) );
1543 void YQPkgObjList::ExcludedItems::remove( QTreeWidgetItem * item )
1545 ItemMap::iterator it = _excludeMap.find( item );
1547 if ( it != _excludeMap.end() )
1549 _excludeMap.erase( it );
1554 void YQPkgObjList::ExcludedItems::clear()
1556 for ( ItemMap::iterator it = _excludeMap.begin();
1557 it != _excludeMap.end();
1563 _excludeMap.clear();
1567 bool YQPkgObjList::ExcludedItems::contains( QTreeWidgetItem * item )
1569 return ( _excludeMap.find( item ) != _excludeMap.end() );
1573 QTreeWidgetItem * YQPkgObjList::ExcludedItems::oldParentItem( QTreeWidgetItem * item )
1575 ItemMap::iterator it = _excludeMap.find( item );
1577 if ( it == _excludeMap.end() )
1585 #include "YQPkgObjList.moc"