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 )
285 QTreeWidgetItem * listViewItem = currentItem();
287 if ( ! listViewItem )
290 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
292 if ( item && item->editable() && _editable )
294 if ( newStatus != item->status() )
296 item->setStatus( newStatus );
298 if ( item->showLicenseAgreement() )
300 item->showNotifyTexts( newStatus );
302 else // License not confirmed?
304 // Status is now S_Taboo or S_Del - update status icon
305 item->setStatusIcon();
308 emit statusChanged();
312 if ( doSelectNextItem )
318 YQPkgObjList::setAllItemStatus( ZyppStatus newStatus, bool force )
323 YQUI::ui()->busyCursor();
324 QTreeWidgetItemIterator it( this );
328 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (*it);
330 if ( item && item->editable() && newStatus != item->status() )
332 if ( newStatus == S_Update )
334 if ( item->candidateIsNewer() || force )
335 item->setStatus( newStatus,
336 false ); // sendSignals
340 item->setStatus( newStatus,
341 false ); // sendSignals
348 emit updateItemStates();
349 emit updatePackages();
351 YQUI::ui()->normalCursor();
352 emit statusChanged();
357 YQPkgObjList::selectNextItem()
359 QTreeWidgetItemIterator it(this);
360 QTreeWidgetItem * item;
362 while ( (item = *it) != NULL )
365 //item->setSelected( false ); // Doesn't emit signals
366 scrollToItem( *it ); // Scroll if necessary
367 setCurrentItem( *it ); // Emits signals
374 YQPkgObjList::createActions()
376 actionSetCurrentInstall = createAction( S_Install, "[+]" );
377 actionSetCurrentDontInstall = createAction( S_NoInst, "[-]" );
378 actionSetCurrentKeepInstalled = createAction( S_KeepInstalled, "[<], [-]" );
379 actionSetCurrentDelete = createAction( S_Del, "[-]" );
380 actionSetCurrentUpdate = createAction( S_Update, "[>], [+]" );
381 actionSetCurrentTaboo = createAction( S_Taboo, "[!]" );
382 actionSetCurrentProtected = createAction( S_Protected, "[*]" );
384 actionSetListInstall = createAction( S_Install, "", true );
385 actionSetListDontInstall = createAction( S_NoInst, "", true );
386 actionSetListKeepInstalled = createAction( S_KeepInstalled, "", true );
387 actionSetListDelete = createAction( S_Del, "", true );
388 actionSetListProtected = createAction( S_Protected, "", true );
390 actionSetListUpdate = createAction( _( "Update if newer version available" ),
391 statusIcon( S_Update, true ),
392 statusIcon( S_Update, false ),
396 actionSetListUpdateForce = createAction( _( "Update unconditionally" ),
397 statusIcon( S_Update, true ),
398 statusIcon( S_Update, false ),
402 actionSetListTaboo = createAction( S_Taboo, "", true );
404 connect( actionSetCurrentInstall, SIGNAL( activated() ), this, SLOT( setCurrentInstall() ) );
405 connect( actionSetCurrentDontInstall, SIGNAL( activated() ), this, SLOT( setCurrentDontInstall() ) );
406 connect( actionSetCurrentKeepInstalled, SIGNAL( activated() ), this, SLOT( setCurrentKeepInstalled() ) );
407 connect( actionSetCurrentDelete, SIGNAL( activated() ), this, SLOT( setCurrentDelete() ) );
408 connect( actionSetCurrentUpdate, SIGNAL( activated() ), this, SLOT( setCurrentUpdate() ) );
409 connect( actionSetCurrentTaboo, SIGNAL( activated() ), this, SLOT( setCurrentTaboo() ) );
410 connect( actionSetCurrentProtected, SIGNAL( activated() ), this, SLOT( setCurrentProtected() ) );
412 connect( actionSetListInstall, SIGNAL( activated() ), this, SLOT( setListInstall() ) );
413 connect( actionSetListDontInstall, SIGNAL( activated() ), this, SLOT( setListDontInstall() ) );
414 connect( actionSetListKeepInstalled, SIGNAL( activated() ), this, SLOT( setListKeepInstalled() ) );
415 connect( actionSetListDelete, SIGNAL( activated() ), this, SLOT( setListDelete() ) );
416 connect( actionSetListUpdate, SIGNAL( activated() ), this, SLOT( setListUpdate() ) );
417 connect( actionSetListUpdateForce, SIGNAL( activated() ), this, SLOT( setListUpdateForce() ) );
418 connect( actionSetListTaboo, SIGNAL( activated() ), this, SLOT( setListTaboo() ) );
419 connect( actionSetListProtected, SIGNAL( activated() ), this, SLOT( setListProtected() ) );
425 YQPkgObjList::createAction( ZyppStatus status, const QString & key, bool enabled )
427 return createAction( statusText( status ),
428 statusIcon( status, true ),
429 statusIcon( status, false ),
436 YQPkgObjList::createAction( const QString & text,
437 const QPixmap & icon,
438 const QPixmap & insensitiveIcon,
442 QString label = text;
444 if ( ! key.isEmpty() )
448 QIcon iconSet ( icon );
450 if ( ! insensitiveIcon.isNull() )
452 iconSet.addPixmap( insensitiveIcon,
456 QAction * action = new QAction( label, // text
458 Q_CHECK_PTR( action );
459 action->setEnabled( enabled );
460 action->setIcon( iconSet );
467 YQPkgObjList::createNotInstalledContextMenu()
469 _notInstalledContextMenu = new QMenu( this );
470 Q_CHECK_PTR( _notInstalledContextMenu );
472 _notInstalledContextMenu->addAction(actionSetCurrentInstall);
473 _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
474 _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
476 addAllInListSubMenu( _notInstalledContextMenu );
481 YQPkgObjList::createInstalledContextMenu()
483 _installedContextMenu = new QMenu( this );
484 Q_CHECK_PTR( _installedContextMenu );
486 _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
487 _installedContextMenu->addAction(actionSetCurrentDelete);
488 _installedContextMenu->addAction(actionSetCurrentUpdate);
490 addAllInListSubMenu( _installedContextMenu );
495 YQPkgObjList::addAllInListSubMenu( QMenu * menu )
497 QMenu * submenu = new QMenu( menu );
498 Q_CHECK_PTR( submenu );
500 submenu->addAction(actionSetListInstall);
501 submenu->addAction(actionSetListDontInstall);
502 submenu->addAction(actionSetListKeepInstalled);
503 submenu->addAction(actionSetListDelete);
504 submenu->addAction(actionSetListUpdate);
505 submenu->addAction(actionSetListUpdateForce);
506 submenu->addAction(actionSetListTaboo);
508 QAction *action = menu->addMenu( submenu );
509 action->setText(_( "&All in This List" ));
516 YQPkgObjList::notInstalledContextMenu()
518 if ( ! _notInstalledContextMenu )
519 createNotInstalledContextMenu();
521 return _notInstalledContextMenu;
526 YQPkgObjList::installedContextMenu()
528 if ( ! _installedContextMenu )
529 createInstalledContextMenu();
531 return _installedContextMenu;
536 YQPkgObjList::updateActions( YQPkgObjListItem * item )
539 item = dynamic_cast<YQPkgObjListItem *> ( currentItem() );
543 ZyppSel selectable = item->selectable();
545 if ( selectable->hasInstalledObj() )
547 actionSetCurrentInstall->setEnabled( false );
548 actionSetCurrentDontInstall->setEnabled( false );
549 actionSetCurrentTaboo->setEnabled( false );
550 actionSetCurrentProtected->setEnabled( true );
552 actionSetCurrentKeepInstalled->setEnabled( true );
553 actionSetCurrentDelete->setEnabled( true );
554 actionSetCurrentUpdate->setEnabled( selectable->hasCandidateObj() );
558 actionSetCurrentInstall->setEnabled( selectable->hasCandidateObj() );
559 actionSetCurrentDontInstall->setEnabled( true );
560 actionSetCurrentTaboo->setEnabled( true );
561 actionSetCurrentProtected->setEnabled( false );
563 actionSetCurrentKeepInstalled->setEnabled( false );
564 actionSetCurrentDelete->setEnabled( false );
565 actionSetCurrentUpdate->setEnabled( false );
570 actionSetCurrentInstall->setEnabled( false );
571 actionSetCurrentDontInstall->setEnabled( false );
572 actionSetCurrentTaboo->setEnabled( false );
574 actionSetCurrentKeepInstalled->setEnabled( false );
575 actionSetCurrentDelete->setEnabled( false );
576 actionSetCurrentUpdate->setEnabled( false );
577 actionSetCurrentProtected->setEnabled( false );
583 YQPkgObjList::keyPressEvent( QKeyEvent * event )
587 int special_combo = ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier );
589 if ( ( event->modifiers() & special_combo ) == special_combo )
591 if ( event->key() == Qt::Key_Q )
594 y2milestone( "Debug mode %s", _debug ? "on" : "off" );
598 QTreeWidgetItem * selectedListViewItem = currentItem();
600 if ( selectedListViewItem )
602 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (selectedListViewItem);
606 bool installed = item->selectable()->hasInstalledObj();
607 ZyppStatus status = item->status();
609 switch( event->key() )
611 case Qt::Key_Space: // Cycle
616 case Qt::Key_Plus: // Grab everything - install or update
620 ZyppStatus newStatus = S_KeepInstalled;
622 if ( item->candidateIsNewer() )
623 newStatus = S_Update;
625 setCurrentStatus( newStatus );
628 setCurrentStatus( S_Install );
633 case Qt::Key_Minus: // Get rid of everything - don't install or delete
634 setCurrentStatus( installed ? S_Del : S_NoInst );
639 case Qt::Key_Exclam: // Taboo
642 setCurrentStatus( S_Taboo );
647 case Qt::Key_Asterisk: // Protected
650 setCurrentStatus( S_Protected );
655 case Qt::Key_Greater: // Update what is worth to be updated
657 if ( installed && item->candidateIsNewer() )
658 setCurrentStatus( S_Update );
663 case Qt::Key_Less: // Revert update
665 if ( status == S_Update ||
666 status == S_AutoUpdate )
668 setCurrentStatus( S_KeepInstalled );
674 case Qt::Key_B: // Toggle debugIsBroken flag
678 item->toggleDebugIsBroken();
679 item->setStatusIcon();
684 case Qt::Key_S: // Toggle debugIsSatisfied flag
688 item->toggleDebugIsSatisfied();
689 item->setStatusIcon();
697 QY2ListView::keyPressEvent( event );
702 YQPkgObjList::message( const QString & text )
704 QY2ListViewItem * item = new QY2ListViewItem( this );
707 item->setText( nameCol() >= 0 ? nameCol() : 0, text );
708 item->setBackgroundColor( QColor( 0xE0, 0xE0, 0xF8 ) );
713 YQPkgObjList::addExcludeRule( YQPkgObjList::ExcludeRule * rule )
715 _excludeRules.push_back( rule );
720 YQPkgObjList::applyExcludeRules()
722 // y2debug( "Applying exclude rules" );
723 QTreeWidgetItemIterator listView_it( this );
725 while ( *listView_it )
727 QTreeWidgetItem * current_item = *listView_it;
729 // Advance iterator now so it remains valid even if there are changes
730 // to the QListView, e.g., if the current item is excluded and thus
731 // removed from the QListView
734 applyExcludeRules( current_item );
737 ExcludedItems::iterator excluded_it = _excludedItems->begin();
739 while ( excluded_it != _excludedItems->end() )
741 QTreeWidgetItem * current_item = (*excluded_it).first;
743 // Advance iterator now so it remains valid even if there are changes
744 // to the excluded items, e.g., if the current item is un-excluded and thus
745 // removed from the excluded items
748 applyExcludeRules( current_item );
751 logExcludeStatistics();
756 YQPkgObjList::logExcludeStatistics()
758 if ( _excludedItems->size() > 0 )
760 y2milestone( "%d packages excluded", _excludedItems->size() );
762 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
763 rule_it != _excludeRules.end();
766 ExcludeRule * rule = *rule_it;
768 if ( rule->isEnabled() )
770 y2milestone( "Active exclude rule: \"%s\"",
771 qPrintable(rule->regexp().pattern()) );
779 YQPkgObjList::applyExcludeRules( QTreeWidgetItem * listViewItem )
781 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *>( listViewItem );
785 bool exclude = false;
786 ExcludeRule * matchingRule = 0;
788 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
789 rule_it != _excludeRules.end() && ! exclude;
792 ExcludeRule * rule = *rule_it;
794 if ( rule->match( item ) )
801 if ( exclude != item->isExcluded() ) // change exclude status?
803 this->exclude( item, exclude );
805 #if VERBOSE_EXCLUDE_RULES
808 y2debug( "Rule %s matches: Excluding %s",
809 matchingRule->regexp().pattern().ascii(),
810 item->zyppObj()->name().c_str() );
814 y2debug( "Un-excluding %s", item->zyppObj()->name().c_str() );
823 YQPkgObjList::exclude( YQPkgObjListItem * item, bool exclude )
826 if ( exclude == item->isExcluded() )
829 item->setExcluded( exclude );
833 QTreeWidgetItem * parentItem = item->parent();
836 parentItem->takeItem( item );
838 QTreeWidget::takeItem( item );
840 _excludedItems->add( item, parentItem );
844 if ( _excludedItems->contains( item ) )
846 QTreeWidgetItem * oldParent = _excludedItems->oldParentItem( item );
847 _excludedItems->remove( item );
850 oldParent->insertItem( item );
852 QTreeWidget::insertItem( item );
861 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
864 : QY2ListViewItem( pkgObjList )
865 , _pkgObjList( pkgObjList )
866 , _selectable( selectable )
867 , _zyppObj( zyppObj )
875 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
876 QY2ListViewItem * parent,
879 : QY2ListViewItem( parent )
880 , _pkgObjList( pkgObjList )
881 , _selectable( selectable )
882 , _zyppObj( zyppObj )
890 YQPkgObjListItem::~YQPkgObjListItem()
897 YQPkgObjListItem::init()
899 if ( _zyppObj == 0 && _selectable )
900 _zyppObj = _selectable->theObj();
902 _debugIsBroken = false;
903 _debugIsSatisfied = false;
904 _candidateIsNewer = false;
905 _installedIsNewer = false;
907 const ZyppObj candidate = selectable()->candidateObj();
908 const ZyppObj installed = selectable()->installedObj();
910 if ( candidate && installed )
912 if ( candidate->edition() < installed->edition() )
913 _installedIsNewer = true;
914 else if ( installed->edition() < candidate->edition() )
915 _candidateIsNewer = true;
918 if ( nameCol() >= 0 ) setText( nameCol(), zyppObj()->name() );
919 if ( summaryCol() >= 0 ) setText( summaryCol(), zyppObj()->summary() );
921 if ( sizeCol() >= 0 )
923 zypp::ByteCount size = zyppObj()->size();
926 setText( sizeCol(), size.asString() + " " );
929 if ( instVersionCol() >= 0 )
931 if ( selectable()->hasInstalledObj() )
932 setText( instVersionCol(), installed->edition() );
934 if ( zyppObj() != selectable()->installedObj() &&
935 zyppObj() != selectable()->candidateObj() )
937 setText( versionCol(), zyppObj()->edition() );
939 else if ( selectable()->hasCandidateObj() )
941 setText( versionCol(), candidate->edition() );
946 setText( versionCol(), zyppObj()->edition() );
954 YQPkgObjListItem::updateData()
961 YQPkgObjListItem::setText( int column, const string text )
963 QTreeWidgetItem::setText( column, fromUTF8( text.c_str() ) );
968 YQPkgObjListItem::setText( int column, const zypp::Edition & edition )
970 setText( column, edition.asString() );
975 YQPkgObjListItem::status() const
977 if ( ! selectable() )
979 y2error( "No selectable" );
983 return selectable()->status();
988 YQPkgObjListItem::bySelection() const
990 zypp::ResStatus::TransactByValue modifiedBy = selectable()->modifiedBy();
992 return ( modifiedBy == zypp::ResStatus::APPL_LOW ||
993 modifiedBy == zypp::ResStatus::APPL_HIGH );
998 YQPkgObjListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
1000 ZyppStatus oldStatus = selectable()->status();
1001 selectable()->set_status( newStatus );
1003 if ( oldStatus != selectable()->status() )
1009 _pkgObjList->updateItemStates();
1010 _pkgObjList->sendUpdatePackages();
1019 YQPkgObjListItem::solveResolvableCollections()
1021 #if EXTRA_SOLVE_COLLECTIONS
1022 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
1024 resolver->transactReset( zypp::ResStatus::APPL_LOW );
1026 resolver->transactResKind( zypp::ResTraits<zypp::Product >::kind );
1027 resolver->transactResKind( zypp::ResTraits<zypp::Selection>::kind );
1028 resolver->transactResKind( zypp::ResTraits<zypp::Pattern >::kind );
1029 resolver->transactResKind( zypp::ResTraits<zypp::Language >::kind );
1030 resolver->transactResKind( zypp::ResTraits<zypp::Patch >::kind );
1031 resolver->transactResKind( zypp::ResTraits<zypp::Atom >::kind );
1038 YQPkgObjListItem::updateStatus()
1045 YQPkgObjListItem::setStatusIcon()
1047 if ( statusCol() >= 0 )
1049 bool enabled = editable() && _pkgObjList->editable();
1050 setData( statusCol(), Qt::DecorationRole, _pkgObjList->statusIcon( status(), enabled, bySelection() ) );
1054 if ( brokenIconCol() >= 0 )
1056 // Reset this icon now - it might be the same column as satisfiedIconCol()
1057 setData( brokenIconCol(), Qt::DecorationRole, QPixmap() );
1060 if ( satisfiedIconCol() >= 0 )
1062 // Set special icon for zyppObjs that are not marked as installed,
1063 // but satisfied anyway (e.g. for patches or patterns where the user
1064 // selected all required packages manually)
1066 setData( satisfiedIconCol(), Qt::DecorationRole, isSatisfied() ? YQIconPool::pkgSatisfied() : QPixmap() );
1069 if ( brokenIconCol() >= 0 )
1071 // Set special icon for zyppObjs that are installed, but broken
1072 // (dependencies no longer satisfied, e.g. for patches or patterns)
1076 setData( brokenIconCol(), Qt::DecorationRole, YQIconPool::warningSign() );
1077 y2warning( "Broken object: %s - %s",
1078 _selectable->theObj()->name().c_str(),
1079 _selectable->theObj()->summary().c_str() );
1086 YQPkgObjListItem::isSatisfied() const
1088 if ( _debugIsSatisfied )
1091 if ( _selectable->hasInstalledObj() )
1094 return _selectable->candidatePoolItem().status().isSatisfied();
1098 bool YQPkgObjListItem::isBroken() const
1100 if ( _debugIsBroken )
1103 if ( ! _selectable->hasInstalledObj() )
1104 return false; // can't be broken if not installed
1108 case S_KeepInstalled:
1111 return _selectable->installedPoolItem().status().isIncomplete();
1113 case S_Update: // will be fixed by updating
1115 case S_Del: // will no longer be relevant after deleting
1120 case S_NoInst: // should not happen - no installed obj
1125 y2error( "Expected uninstalled zyppObj" );
1129 y2error( "Should never get here" );
1135 YQPkgObjListItem::cycleStatus()
1137 if ( ! _editable || ! _pkgObjList->editable() )
1140 ZyppStatus oldStatus = status();
1141 ZyppStatus newStatus = oldStatus;
1143 if ( selectable()->hasInstalledObj() )
1145 switch ( oldStatus )
1148 newStatus = selectable()->hasCandidateObj() ?
1149 S_KeepInstalled: S_NoInst;
1152 case S_KeepInstalled:
1153 newStatus = selectable()->hasCandidateObj() ?
1162 newStatus = S_KeepInstalled;
1166 newStatus = S_KeepInstalled;
1170 else // Pkg not installed
1172 switch ( oldStatus )
1175 if ( selectable()->hasCandidateObj() )
1177 newStatus = S_Install;
1181 y2warning( "No candidate for %s", selectable()->theObj()->name().c_str() );
1182 newStatus = S_NoInst;
1187 newStatus = S_Taboo;
1191 newStatus = S_NoInst;
1196 if ( oldStatus != newStatus )
1198 setStatus( newStatus );
1200 if ( showLicenseAgreement() )
1202 showNotifyTexts( newStatus );
1204 else // License not confirmed?
1206 // Status is now S_Taboo or S_Del - update status icon
1210 _pkgObjList->sendStatusChanged();
1216 YQPkgObjListItem::showNotifyTexts( ZyppStatus status )
1223 if ( selectable()->hasCandidateObj() )
1224 text = selectable()->candidateObj()->insnotify();
1230 if ( selectable()->hasCandidateObj() )
1231 text = selectable()->candidateObj()->delnotify();
1237 if ( ! text.empty() )
1239 y2debug( "Showing notify text" );
1240 YQPkgTextDialog::showText( _pkgObjList, selectable(), text );
1246 YQPkgObjListItem::showLicenseAgreement()
1248 return showLicenseAgreement( selectable() );
1253 YQPkgObjListItem::showLicenseAgreement( ZyppSel sel )
1257 switch ( sel->status() )
1264 if ( sel->hasLicenceConfirmed() )
1267 if ( sel->candidateObj() )
1268 licenseText = sel->candidateObj()->licenseToConfirm();
1271 default: return true;
1274 if ( licenseText.empty() )
1277 y2debug( "Showing license agreement for %s", sel->name().c_str() );
1278 bool confirmed = YQPkgTextDialog::confirmText( 0, sel, licenseText );
1282 y2milestone( "User confirmed license agreement for %s", sel->name().c_str() );
1283 sel->setLicenceConfirmed( true );
1287 // The user rejected the license agreement -
1288 // make sure the package gets unselected.
1290 switch ( sel->status() )
1295 y2warning( "User rejected license agreement for %s - setting to TABOO",
1296 sel->name().c_str() );
1298 sel->set_status( S_Taboo );
1305 y2warning( "User rejected license agreement for %s - setting to PROTECTED",
1306 sel->name().c_str() );
1308 sel->set_status( S_Protected );
1309 // S_Keep wouldn't be good enough: The next solver run might
1310 // set it to S_AutoUpdate again
1322 YQPkgObjListItem::toolTip( int col )
1324 if ( col == statusCol() )
1326 QString tip = _pkgObjList->statusText( status() );
1334 if ( bySelection() )
1335 // Translators: Additional hint what caused an auto-status
1336 tip += "\n" + _( "(by a software selection)" );
1338 tip += "\n" + _( "(by dependencies)" );
1349 if ( col == brokenIconCol() )
1352 // Translators: tool tip for patches / patterns that are installed,
1353 // but whose dependencies are broken (no longer satisfied)
1354 return _( "Dependencies broken" );
1357 // don't use "else if" here, it might be the same colum as another one!
1359 if ( col == satisfiedIconCol() )
1361 if ( isSatisfied() )
1362 // Translators: tool tip for patches / patterns that are not installed,
1363 // but whose dependencies are satisfied
1364 return _( "All dependencies satisfied" );
1367 return QString::null;
1372 bool YQPkgObjListItem::operator<( const QTreeWidgetItem & otherListViewItem ) const
1374 const YQPkgObjListItem * other = dynamic_cast<const YQPkgObjListItem *> (&otherListViewItem);
1375 int col = treeWidget()->sortColumn();
1379 if ( col == sizeCol() )
1381 // Numeric sort by size
1383 return ( this->zyppObj()->size() < other->zyppObj()->size() );
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 return ( this->status() < other->status() );
1395 else if ( col == instVersionCol() ||
1396 col == versionCol() )
1398 // Sorting by version numbers doesn't make too much sense, so let's
1399 // sort by package relation:
1400 // - Installed newer than candidate (red)
1401 // - Candidate newer than installed (blue) - worthwhile updating
1403 // - Not installed, but candidate available
1405 // Within these categories, sort versions by ASCII - OK, it's
1406 // pretty random, but predictable.
1408 int thisPoints = this->versionPoints();
1409 int otherPoints = other->versionPoints();
1411 return ( thisPoints < otherPoints );
1412 return QY2ListViewItem::operator<( otherListViewItem );
1416 // Fallback: Use parent class method
1417 return QY2ListViewItem::operator<( otherListViewItem );
1422 YQPkgObjListItem::versionPoints() const
1426 if ( installedIsNewer() ) points += 1000;
1427 if ( candidateIsNewer() ) points += 100;
1428 if ( selectable()->hasInstalledObj() ) points += 10;
1429 if ( selectable()->hasCandidateObj() ) points += 1;
1436 YQPkgObjListItem::setExcluded( bool excl )
1444 YQPkgObjList::ExcludeRule::ExcludeRule( YQPkgObjList * parent,
1445 const QRegExp & regexp,
1452 _parent->addExcludeRule( this );
1457 YQPkgObjList::ExcludeRule::enable( bool enable )
1461 #if VERBOSE_EXCLUDE_RULES
1462 y2debug( "%s exclude rule %s",
1463 enable ? "Enabling" : "Disabling",
1464 _regexp.pattern().ascii() );
1470 YQPkgObjList::ExcludeRule::setRegexp( const QRegExp & regexp )
1477 YQPkgObjList::ExcludeRule::setColumn( int column )
1484 YQPkgObjList::ExcludeRule::match( QTreeWidgetItem * item )
1489 QString text = item->text( _column );
1491 if ( text.isEmpty() )
1494 return _regexp.exactMatch( text );
1502 YQPkgObjList::ExcludedItems::ExcludedItems( YQPkgObjList * parent )
1503 : _pkgObjList( parent )
1508 YQPkgObjList::ExcludedItems::~ExcludedItems()
1514 void YQPkgObjList::ExcludedItems::add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent )
1516 _excludeMap.insert( ItemPair( item, oldParent ) );
1520 void YQPkgObjList::ExcludedItems::remove( QTreeWidgetItem * item )
1522 ItemMap::iterator it = _excludeMap.find( item );
1524 if ( it != _excludeMap.end() )
1526 _excludeMap.erase( it );
1531 void YQPkgObjList::ExcludedItems::clear()
1533 for ( ItemMap::iterator it = _excludeMap.begin();
1534 it != _excludeMap.end();
1540 _excludeMap.clear();
1544 bool YQPkgObjList::ExcludedItems::contains( QTreeWidgetItem * item )
1546 return ( _excludeMap.find( item ) != _excludeMap.end() );
1550 QTreeWidgetItem * YQPkgObjList::ExcludedItems::oldParentItem( QTreeWidgetItem * item )
1552 ItemMap::iterator it = _excludeMap.find( item );
1554 if ( it == _excludeMap.end() )
1562 #include "YQPkgObjList.moc"