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 //y2internal("CLICKED: %s", item->zyppObj()->name().c_str());
149 if ( button == Qt::LeftButton )
151 if ( col == statusCol() )
152 // || col == nameCol() )
154 if ( editable() && item->editable() )
158 else if ( button == Qt::RightButton )
160 if ( editable() && item->editable() )
162 updateActions( item );
164 QMenu * contextMenu =
165 item->selectable()->hasInstalledObj() ?
166 installedContextMenu() : notInstalledContextMenu();
169 contextMenu->popup( pos );
177 YQPkgObjList::currentItemChangedInternal( QTreeWidgetItem * listViewItem )
179 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (listViewItem);
181 emit currentItemChanged( item ? item->selectable() : ZyppSel() );
186 YQPkgObjList::clear()
188 emit currentItemChanged( ZyppSel() );
190 _excludedItems->clear();
191 QY2ListView::clear();
196 YQPkgObjList::statusIcon( ZyppStatus status, bool enabled, bool bySelection )
198 QPixmap icon = YQIconPool::pkgNoInst();
204 case S_Del: icon = YQIconPool::pkgDel(); break;
205 case S_Install: icon = YQIconPool::pkgInstall(); break;
206 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled(); break;
207 case S_NoInst: icon = YQIconPool::pkgNoInst(); break;
208 case S_Protected: icon = YQIconPool::pkgProtected(); break;
209 case S_Taboo: icon = YQIconPool::pkgTaboo(); break;
210 case S_Update: icon = YQIconPool::pkgUpdate(); break;
212 case S_AutoDel: icon = bySelection ?
213 YQIconPool::pkgSelAutoDel() :
214 YQIconPool::pkgAutoDel(); break;
216 case S_AutoInstall: icon = bySelection ?
217 YQIconPool::pkgSelAutoInstall() :
218 YQIconPool::pkgAutoInstall(); break;
220 case S_AutoUpdate: icon = bySelection ?
221 YQIconPool::pkgSelAutoUpdate() :
222 YQIconPool::pkgAutoUpdate(); break;
225 // Intentionally omitting 'default' branch so the compiler can
226 // catch unhandled enum states
233 case S_Del: icon = YQIconPool::disabledPkgDel(); break;
234 case S_Install: icon = YQIconPool::disabledPkgInstall(); break;
235 case S_KeepInstalled: icon = YQIconPool::disabledPkgKeepInstalled(); break;
236 case S_NoInst: icon = YQIconPool::disabledPkgNoInst(); break;
237 case S_Protected: icon = YQIconPool::disabledPkgProtected(); break;
238 case S_Taboo: icon = YQIconPool::disabledPkgTaboo(); break;
239 case S_Update: icon = YQIconPool::disabledPkgUpdate(); break;
241 case S_AutoDel: icon = bySelection ?
242 YQIconPool::disabledPkgSelAutoDel() :
243 YQIconPool::disabledPkgAutoDel(); break;
245 case S_AutoInstall: icon = bySelection ?
246 YQIconPool::disabledPkgSelAutoInstall() :
247 YQIconPool::disabledPkgAutoInstall(); break;
249 case S_AutoUpdate: icon = bySelection ?
250 YQIconPool::disabledPkgSelAutoUpdate() :
251 YQIconPool::disabledPkgAutoUpdate(); break;
253 // Intentionally omitting 'default' branch so the compiler can
254 // catch unhandled enum states
263 YQPkgObjList::statusText( ZyppStatus status ) const
267 case S_AutoDel: return _( "Autodelete" );
268 case S_AutoInstall: return _( "Autoinstall" );
269 case S_AutoUpdate: return _( "Autoupdate" );
270 case S_Del: return _( "Delete" );
271 case S_Install: return _( "Install" );
272 case S_KeepInstalled: return _( "Keep" );
273 case S_NoInst: return _( "Do Not Install" );
274 case S_Protected: return _( "Protected -- Do Not Modify" );
275 case S_Taboo: return _( "Taboo -- Never Install" );
276 case S_Update: return _( "Update" );
279 return QString::null;
284 YQPkgObjList::setCurrentStatus( ZyppStatus newStatus, bool doSelectNextItem )
286 QTreeWidgetItem * listViewItem = currentItem();
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 )
319 YQPkgObjList::setAllItemStatus( ZyppStatus newStatus, bool force )
324 YQUI::ui()->busyCursor();
325 QTreeWidgetItemIterator it( this );
329 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (*it);
331 if ( item && item->editable() && newStatus != item->status() )
333 if ( newStatus == S_Update )
335 if ( item->candidateIsNewer() || force )
336 item->setStatus( newStatus,
337 false ); // sendSignals
341 item->setStatus( newStatus,
342 false ); // sendSignals
349 emit updateItemStates();
350 emit updatePackages();
352 YQUI::ui()->normalCursor();
353 emit statusChanged();
358 YQPkgObjList::selectNextItem()
360 QTreeWidgetItemIterator it(this);
361 QTreeWidgetItem * item;
363 while ( (item = *it) != NULL )
366 //item->setSelected( false ); // Doesn't emit signals
367 scrollToItem( *it ); // Scroll if necessary
368 setCurrentItem( *it ); // 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 )
540 item = dynamic_cast<YQPkgObjListItem *> ( currentItem() );
544 ZyppSel selectable = item->selectable();
546 if ( selectable->hasInstalledObj() )
548 actionSetCurrentInstall->setEnabled( false );
549 actionSetCurrentDontInstall->setEnabled( false );
550 actionSetCurrentTaboo->setEnabled( false );
551 actionSetCurrentProtected->setEnabled( true );
553 actionSetCurrentKeepInstalled->setEnabled( true );
554 actionSetCurrentDelete->setEnabled( true );
555 actionSetCurrentUpdate->setEnabled( selectable->hasCandidateObj() );
559 actionSetCurrentInstall->setEnabled( selectable->hasCandidateObj() );
560 actionSetCurrentDontInstall->setEnabled( true );
561 actionSetCurrentTaboo->setEnabled( true );
562 actionSetCurrentProtected->setEnabled( false );
564 actionSetCurrentKeepInstalled->setEnabled( false );
565 actionSetCurrentDelete->setEnabled( false );
566 actionSetCurrentUpdate->setEnabled( false );
571 actionSetCurrentInstall->setEnabled( false );
572 actionSetCurrentDontInstall->setEnabled( false );
573 actionSetCurrentTaboo->setEnabled( false );
575 actionSetCurrentKeepInstalled->setEnabled( false );
576 actionSetCurrentDelete->setEnabled( false );
577 actionSetCurrentUpdate->setEnabled( false );
578 actionSetCurrentProtected->setEnabled( false );
584 YQPkgObjList::keyPressEvent( QKeyEvent * event )
588 int special_combo = ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier );
590 if ( ( event->modifiers() & special_combo ) == special_combo )
592 if ( event->key() == Qt::Key_Q )
595 y2milestone( "Debug mode %s", _debug ? "on" : "off" );
599 QTreeWidgetItem * selectedListViewItem = currentItem();
601 if ( selectedListViewItem )
603 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *> (selectedListViewItem);
607 bool installed = item->selectable()->hasInstalledObj();
608 ZyppStatus status = item->status();
610 switch( event->key() )
612 case Qt::Key_Space: // Cycle
617 case Qt::Key_Plus: // Grab everything - install or update
621 ZyppStatus newStatus = S_KeepInstalled;
623 if ( item->candidateIsNewer() )
624 newStatus = S_Update;
626 setCurrentStatus( newStatus );
629 setCurrentStatus( S_Install );
634 case Qt::Key_Minus: // Get rid of everything - don't install or delete
635 setCurrentStatus( installed ? S_Del : S_NoInst );
640 case Qt::Key_Exclam: // Taboo
643 setCurrentStatus( S_Taboo );
648 case Qt::Key_Asterisk: // Protected
651 setCurrentStatus( S_Protected );
656 case Qt::Key_Greater: // Update what is worth to be updated
658 if ( installed && item->candidateIsNewer() )
659 setCurrentStatus( S_Update );
664 case Qt::Key_Less: // Revert update
666 if ( status == S_Update ||
667 status == S_AutoUpdate )
669 setCurrentStatus( S_KeepInstalled );
675 case Qt::Key_B: // Toggle debugIsBroken flag
679 item->toggleDebugIsBroken();
680 item->setStatusIcon();
685 case Qt::Key_S: // Toggle debugIsSatisfied flag
689 item->toggleDebugIsSatisfied();
690 item->setStatusIcon();
698 QY2ListView::keyPressEvent( event );
703 YQPkgObjList::message( const QString & text )
705 QY2ListViewItem * item = new QY2ListViewItem( this );
708 item->setText( nameCol() >= 0 ? nameCol() : 0, text );
709 item->setBackgroundColor( QColor( 0xE0, 0xE0, 0xF8 ) );
714 YQPkgObjList::addExcludeRule( YQPkgObjList::ExcludeRule * rule )
716 _excludeRules.push_back( rule );
721 YQPkgObjList::applyExcludeRules()
723 // y2debug( "Applying exclude rules" );
724 QTreeWidgetItemIterator listView_it( this );
726 while ( *listView_it )
728 QTreeWidgetItem * current_item = *listView_it;
730 // Advance iterator now so it remains valid even if there are changes
731 // to the QListView, e.g., if the current item is excluded and thus
732 // removed from the QListView
735 applyExcludeRules( current_item );
738 ExcludedItems::iterator excluded_it = _excludedItems->begin();
740 while ( excluded_it != _excludedItems->end() )
742 QTreeWidgetItem * current_item = (*excluded_it).first;
744 // Advance iterator now so it remains valid even if there are changes
745 // to the excluded items, e.g., if the current item is un-excluded and thus
746 // removed from the excluded items
749 applyExcludeRules( current_item );
752 logExcludeStatistics();
757 YQPkgObjList::logExcludeStatistics()
759 if ( _excludedItems->size() > 0 )
761 y2milestone( "%d packages excluded", _excludedItems->size() );
763 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
764 rule_it != _excludeRules.end();
767 ExcludeRule * rule = *rule_it;
769 if ( rule->isEnabled() )
771 y2milestone( "Active exclude rule: \"%s\"",
772 qPrintable(rule->regexp().pattern()) );
780 YQPkgObjList::applyExcludeRules( QTreeWidgetItem * listViewItem )
782 YQPkgObjListItem * item = dynamic_cast<YQPkgObjListItem *>( listViewItem );
786 bool exclude = false;
787 ExcludeRule * matchingRule = 0;
789 for ( ExcludeRuleList::iterator rule_it = _excludeRules.begin();
790 rule_it != _excludeRules.end() && ! exclude;
793 ExcludeRule * rule = *rule_it;
795 if ( rule->match( item ) )
802 if ( exclude != item->isExcluded() ) // change exclude status?
804 this->exclude( item, exclude );
806 #if VERBOSE_EXCLUDE_RULES
809 y2debug( "Rule %s matches: Excluding %s",
810 matchingRule->regexp().pattern().ascii(),
811 item->zyppObj()->name().c_str() );
815 y2debug( "Un-excluding %s", item->zyppObj()->name().c_str() );
824 YQPkgObjList::exclude( YQPkgObjListItem * item, bool exclude )
827 if ( exclude == item->isExcluded() )
830 item->setExcluded( exclude );
834 QTreeWidgetItem * parentItem = item->parent();
837 parentItem->takeItem( item );
839 QTreeWidget::takeItem( item );
841 _excludedItems->add( item, parentItem );
845 if ( _excludedItems->contains( item ) )
847 QTreeWidgetItem * oldParent = _excludedItems->oldParentItem( item );
848 _excludedItems->remove( item );
851 oldParent->insertItem( item );
853 QTreeWidget::insertItem( item );
862 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
865 : QY2ListViewItem( pkgObjList )
866 , _pkgObjList( pkgObjList )
867 , _selectable( selectable )
868 , _zyppObj( zyppObj )
876 YQPkgObjListItem::YQPkgObjListItem( YQPkgObjList * pkgObjList,
877 QY2ListViewItem * parent,
880 : QY2ListViewItem( parent )
881 , _pkgObjList( pkgObjList )
882 , _selectable( selectable )
883 , _zyppObj( zyppObj )
891 YQPkgObjListItem::~YQPkgObjListItem()
898 YQPkgObjListItem::init()
900 if ( _zyppObj == 0 && _selectable )
901 _zyppObj = _selectable->theObj();
903 _debugIsBroken = false;
904 _debugIsSatisfied = false;
905 _candidateIsNewer = false;
906 _installedIsNewer = false;
908 const ZyppObj candidate = selectable()->candidateObj();
909 const ZyppObj installed = selectable()->installedObj();
911 if ( candidate && installed )
913 if ( candidate->edition() < installed->edition() )
914 _installedIsNewer = true;
915 else if ( installed->edition() < candidate->edition() )
916 _candidateIsNewer = true;
919 if ( nameCol() >= 0 ) setText( nameCol(), zyppObj()->name() );
920 if ( summaryCol() >= 0 ) setText( summaryCol(), zyppObj()->summary() );
922 if ( sizeCol() >= 0 )
924 zypp::ByteCount size = zyppObj()->size();
927 setText( sizeCol(), size.asString() + " " );
930 if ( instVersionCol() >= 0 )
932 if ( selectable()->hasInstalledObj() )
933 setText( instVersionCol(), installed->edition() );
935 if ( zyppObj() != selectable()->installedObj() &&
936 zyppObj() != selectable()->candidateObj() )
938 setText( versionCol(), zyppObj()->edition() );
940 else if ( selectable()->hasCandidateObj() )
942 setText( versionCol(), candidate->edition() );
947 setText( versionCol(), zyppObj()->edition() );
955 YQPkgObjListItem::updateData()
962 YQPkgObjListItem::setText( int column, const string text )
964 QTreeWidgetItem::setText( column, fromUTF8( text.c_str() ) );
969 YQPkgObjListItem::setText( int column, const zypp::Edition & edition )
971 setText( column, edition.asString() );
976 YQPkgObjListItem::status() const
978 if ( ! selectable() )
980 y2error( "No selectable" );
984 return selectable()->status();
989 YQPkgObjListItem::bySelection() const
991 zypp::ResStatus::TransactByValue modifiedBy = selectable()->modifiedBy();
993 return ( modifiedBy == zypp::ResStatus::APPL_LOW ||
994 modifiedBy == zypp::ResStatus::APPL_HIGH );
999 YQPkgObjListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
1001 ZyppStatus oldStatus = selectable()->status();
1002 selectable()->set_status( newStatus );
1004 if ( oldStatus != selectable()->status() )
1010 _pkgObjList->updateItemStates();
1011 _pkgObjList->sendUpdatePackages();
1020 YQPkgObjListItem::solveResolvableCollections()
1022 #if EXTRA_SOLVE_COLLECTIONS
1023 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
1025 resolver->transactReset( zypp::ResStatus::APPL_LOW );
1027 resolver->transactResKind( zypp::ResTraits<zypp::Product >::kind );
1028 resolver->transactResKind( zypp::ResTraits<zypp::Selection>::kind );
1029 resolver->transactResKind( zypp::ResTraits<zypp::Pattern >::kind );
1030 resolver->transactResKind( zypp::ResTraits<zypp::Language >::kind );
1031 resolver->transactResKind( zypp::ResTraits<zypp::Patch >::kind );
1032 resolver->transactResKind( zypp::ResTraits<zypp::Atom >::kind );
1039 YQPkgObjListItem::updateStatus()
1046 YQPkgObjListItem::setStatusIcon()
1048 if ( statusCol() >= 0 )
1050 bool enabled = editable() && _pkgObjList->editable();
1051 setData( statusCol(), Qt::DecorationRole, _pkgObjList->statusIcon( status(), enabled, bySelection() ) );
1055 if ( brokenIconCol() >= 0 )
1057 // Reset this icon now - it might be the same column as satisfiedIconCol()
1058 setData( brokenIconCol(), Qt::DecorationRole, QPixmap() );
1061 if ( satisfiedIconCol() >= 0 )
1063 // Set special icon for zyppObjs that are not marked as installed,
1064 // but satisfied anyway (e.g. for patches or patterns where the user
1065 // selected all required packages manually)
1067 setData( satisfiedIconCol(), Qt::DecorationRole, isSatisfied() ? YQIconPool::pkgSatisfied() : QPixmap() );
1070 if ( brokenIconCol() >= 0 )
1072 // Set special icon for zyppObjs that are installed, but broken
1073 // (dependencies no longer satisfied, e.g. for patches or patterns)
1077 setData( brokenIconCol(), Qt::DecorationRole, YQIconPool::warningSign() );
1078 y2warning( "Broken object: %s - %s",
1079 _selectable->theObj()->name().c_str(),
1080 _selectable->theObj()->summary().c_str() );
1087 YQPkgObjListItem::isSatisfied() const
1089 if ( _debugIsSatisfied )
1092 if ( _selectable->hasInstalledObj() )
1095 return _selectable->candidatePoolItem().status().isSatisfied();
1099 bool YQPkgObjListItem::isBroken() const
1101 if ( _debugIsBroken )
1104 if ( ! _selectable->hasInstalledObj() )
1105 return false; // can't be broken if not installed
1109 case S_KeepInstalled:
1112 return _selectable->installedPoolItem().status().isIncomplete();
1114 case S_Update: // will be fixed by updating
1116 case S_Del: // will no longer be relevant after deleting
1121 case S_NoInst: // should not happen - no installed obj
1126 y2error( "Expected uninstalled zyppObj" );
1130 y2error( "Should never get here" );
1136 YQPkgObjListItem::cycleStatus()
1138 if ( ! _editable || ! _pkgObjList->editable() )
1141 ZyppStatus oldStatus = status();
1142 ZyppStatus newStatus = oldStatus;
1144 if ( selectable()->hasInstalledObj() )
1146 switch ( oldStatus )
1149 newStatus = selectable()->hasCandidateObj() ?
1150 S_KeepInstalled: S_NoInst;
1153 case S_KeepInstalled:
1154 newStatus = selectable()->hasCandidateObj() ?
1163 newStatus = S_KeepInstalled;
1167 newStatus = S_KeepInstalled;
1171 else // Pkg not installed
1173 switch ( oldStatus )
1176 if ( selectable()->hasCandidateObj() )
1178 newStatus = S_Install;
1182 y2warning( "No candidate for %s", selectable()->theObj()->name().c_str() );
1183 newStatus = S_NoInst;
1188 newStatus = S_Taboo;
1192 newStatus = S_NoInst;
1197 if ( oldStatus != newStatus )
1199 setStatus( newStatus );
1201 if ( showLicenseAgreement() )
1203 showNotifyTexts( newStatus );
1205 else // License not confirmed?
1207 // Status is now S_Taboo or S_Del - update status icon
1211 _pkgObjList->sendStatusChanged();
1217 YQPkgObjListItem::showNotifyTexts( ZyppStatus status )
1224 if ( selectable()->hasCandidateObj() )
1225 text = selectable()->candidateObj()->insnotify();
1231 if ( selectable()->hasCandidateObj() )
1232 text = selectable()->candidateObj()->delnotify();
1238 if ( ! text.empty() )
1240 y2debug( "Showing notify text" );
1241 YQPkgTextDialog::showText( _pkgObjList, selectable(), text );
1247 YQPkgObjListItem::showLicenseAgreement()
1249 return showLicenseAgreement( selectable() );
1254 YQPkgObjListItem::showLicenseAgreement( ZyppSel sel )
1258 switch ( sel->status() )
1265 if ( sel->hasLicenceConfirmed() )
1268 if ( sel->candidateObj() )
1269 licenseText = sel->candidateObj()->licenseToConfirm();
1272 default: return true;
1275 if ( licenseText.empty() )
1278 y2debug( "Showing license agreement for %s", sel->name().c_str() );
1279 bool confirmed = YQPkgTextDialog::confirmText( 0, sel, licenseText );
1283 y2milestone( "User confirmed license agreement for %s", sel->name().c_str() );
1284 sel->setLicenceConfirmed( true );
1288 // The user rejected the license agreement -
1289 // make sure the package gets unselected.
1291 switch ( sel->status() )
1296 y2warning( "User rejected license agreement for %s - setting to TABOO",
1297 sel->name().c_str() );
1299 sel->set_status( S_Taboo );
1306 y2warning( "User rejected license agreement for %s - setting to PROTECTED",
1307 sel->name().c_str() );
1309 sel->set_status( S_Protected );
1310 // S_Keep wouldn't be good enough: The next solver run might
1311 // set it to S_AutoUpdate again
1323 YQPkgObjListItem::toolTip( int col )
1325 if ( col == statusCol() )
1327 QString tip = _pkgObjList->statusText( status() );
1335 if ( bySelection() )
1336 // Translators: Additional hint what caused an auto-status
1337 tip += "\n" + _( "(by a software selection)" );
1339 tip += "\n" + _( "(by dependencies)" );
1350 if ( col == brokenIconCol() )
1353 // Translators: tool tip for patches / patterns that are installed,
1354 // but whose dependencies are broken (no longer satisfied)
1355 return _( "Dependencies broken" );
1358 // don't use "else if" here, it might be the same colum as another one!
1360 if ( col == satisfiedIconCol() )
1362 if ( isSatisfied() )
1363 // Translators: tool tip for patches / patterns that are not installed,
1364 // but whose dependencies are satisfied
1365 return _( "All dependencies satisfied" );
1368 return QString::null;
1373 bool YQPkgObjListItem::operator<( const QTreeWidgetItem & otherListViewItem ) const
1375 const YQPkgObjListItem * other = dynamic_cast<const YQPkgObjListItem *> (&otherListViewItem);
1376 int col = treeWidget()->sortColumn();
1380 if ( col == sizeCol() )
1382 // Numeric sort by size
1384 return ( this->zyppObj()->size() < other->zyppObj()->size() );
1386 else if ( col == statusCol() )
1388 // Sorting by status depends on the numeric value of the
1389 // ZyppStatus enum, thus it is important to insert new
1390 // package states there where they make most sense. We want to show
1391 // dangerous or noteworthy states first - e.g., "taboo" which should
1392 // seldeom occur, but when it does, it is important.
1394 return ( this->status() < other->status() );
1396 else if ( col == instVersionCol() ||
1397 col == versionCol() )
1399 // Sorting by version numbers doesn't make too much sense, so let's
1400 // sort by package relation:
1401 // - Installed newer than candidate (red)
1402 // - Candidate newer than installed (blue) - worthwhile updating
1404 // - Not installed, but candidate available
1406 // Within these categories, sort versions by ASCII - OK, it's
1407 // pretty random, but predictable.
1409 int thisPoints = this->versionPoints();
1410 int otherPoints = other->versionPoints();
1412 return ( thisPoints < otherPoints );
1413 return QY2ListViewItem::operator<( otherListViewItem );
1417 // Fallback: Use parent class method
1418 return QY2ListViewItem::operator<( otherListViewItem );
1423 YQPkgObjListItem::versionPoints() const
1427 if ( installedIsNewer() ) points += 1000;
1428 if ( candidateIsNewer() ) points += 100;
1429 if ( selectable()->hasInstalledObj() ) points += 10;
1430 if ( selectable()->hasCandidateObj() ) points += 1;
1437 YQPkgObjListItem::setExcluded( bool excl )
1445 YQPkgObjList::ExcludeRule::ExcludeRule( YQPkgObjList * parent,
1446 const QRegExp & regexp,
1453 _parent->addExcludeRule( this );
1458 YQPkgObjList::ExcludeRule::enable( bool enable )
1462 #if VERBOSE_EXCLUDE_RULES
1463 y2debug( "%s exclude rule %s",
1464 enable ? "Enabling" : "Disabling",
1465 _regexp.pattern().ascii() );
1471 YQPkgObjList::ExcludeRule::setRegexp( const QRegExp & regexp )
1478 YQPkgObjList::ExcludeRule::setColumn( int column )
1485 YQPkgObjList::ExcludeRule::match( QTreeWidgetItem * item )
1490 QString text = item->text( _column );
1492 if ( text.isEmpty() )
1495 return _regexp.exactMatch( text );
1503 YQPkgObjList::ExcludedItems::ExcludedItems( YQPkgObjList * parent )
1504 : _pkgObjList( parent )
1509 YQPkgObjList::ExcludedItems::~ExcludedItems()
1515 void YQPkgObjList::ExcludedItems::add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent )
1517 _excludeMap.insert( ItemPair( item, oldParent ) );
1521 void YQPkgObjList::ExcludedItems::remove( QTreeWidgetItem * item )
1523 ItemMap::iterator it = _excludeMap.find( item );
1525 if ( it != _excludeMap.end() )
1527 _excludeMap.erase( it );
1532 void YQPkgObjList::ExcludedItems::clear()
1534 for ( ItemMap::iterator it = _excludeMap.begin();
1535 it != _excludeMap.end();
1541 _excludeMap.clear();
1545 bool YQPkgObjList::ExcludedItems::contains( QTreeWidgetItem * item )
1547 return ( _excludeMap.find( item ) != _excludeMap.end() );
1551 QTreeWidgetItem * YQPkgObjList::ExcludedItems::oldParentItem( QTreeWidgetItem * item )
1553 ItemMap::iterator it = _excludeMap.find( item );
1555 if ( it == _excludeMap.end() )
1563 #include "YQPkgObjList.moc"