1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatternList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
24 #include <zypp/ZYppFactory.h>
25 #include <zypp/Resolver.h>
27 #include <QHeaderView>
28 #include <zypp/ui/PatternContents.h>
32 #include "YQPkgPatternList.h"
33 #include "YQIconPool.h"
34 #include "YQApplication.h"
38 #define CATEGORY_BACKGROUND QColor( 0xFF, 0xC0, 0x50 )
41 YQPkgPatternList::YQPkgPatternList( QWidget * parent, bool autoFill, bool autoFilter )
42 : YQPkgObjList( parent )
44 y2debug( "Creating pattern list" );
48 headers << ""; _statusCol = numCol++;
50 // Translators: "Pattern" refers to so-called "installation patterns",
51 // i.e., specific task-oriented groups of packages, like "everything that
52 // is needed to run a web server". The idea of patterns is that they also
53 // include the configuration workflow needed for that task, such of
54 // configuring the web server. For the scope of the package selector, this
55 // is only of little relevance, though.
57 headers << _( "Pattern" ); _summaryCol = numCol++;
59 setHeaderLabels(headers);
60 // Can use the same colum for "broken" and "satisfied":
61 // Both states are mutually exclusive
63 _satisfiedIconCol = _summaryCol;
64 _brokenIconCol = _summaryCol;
66 // header()->setStretchEnabled( _statusCol , false );
67 // header()->setStretchEnabled( _summaryCol, true );
69 setAllColumnsShowFocus( true );
70 //setTreeStepSize( 0 );
74 connect( this, SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * ) ),
75 this, SLOT ( filter() ) );
83 y2debug( "Creating pattern list done" );
87 YQPkgPatternList::~YQPkgPatternList()
94 YQPkgPatternList::fillList()
97 y2debug( "Filling pattern list" );
100 for ( ZyppPoolIterator it = zyppPatternsBegin();
101 it != zyppPatternsEnd();
104 ZyppPattern zyppPattern = tryCastToZyppPattern( (*it)->theObj() );
108 if ( zyppPattern->userVisible() )
110 addPatternItem( *it, zyppPattern );
113 y2debug( "Pattern %s is not user-visible", zyppPattern->name().c_str() );
117 y2error( "Found non-Pattern selectable" );
121 y2debug( "Pattern list filled" );
125 YQPkgPatternCategoryItem *
126 YQPkgPatternList::category( const QString & categoryName )
128 if ( categoryName.isEmpty() )
131 YQPkgPatternCategoryItem * cat = _categories[ categoryName ];
135 y2debug( "New pattern category \"%s\"", qPrintable(categoryName) );
137 cat = new YQPkgPatternCategoryItem( this, categoryName );
139 _categories.insert( categoryName, cat );
148 YQPkgPatternList::filterIfVisible()
156 YQPkgPatternList::filter()
160 if ( selection() ) // The seleted QListViewItem
162 ZyppPattern zyppPattern = selection()->zyppPattern();
166 zypp::ui::PatternContents patternContents( zyppPattern );
167 set<string> wanted = patternContents.install_packages();
169 for ( ZyppPoolIterator it = zyppPkgBegin();
173 string name = (*it)->theObj()->name();
175 if ( contains( wanted, name ) )
177 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
181 emit filterMatch( *it, zyppPkg );
188 emit filterFinished();
193 YQPkgPatternList::addPatternItem( ZyppSel selectable,
194 ZyppPattern zyppPattern )
198 y2error( "NULL ZyppSelectable!" );
202 YQPkgPatternCategoryItem * cat = category( fromUTF8( zyppPattern->category() ) );
203 YQPkgPatternListItem * item = 0;
206 item = new YQPkgPatternListItem( this, cat, selectable, zyppPattern );
208 item = new YQPkgPatternListItem( this, selectable, zyppPattern );
210 addTopLevelItem(item);
211 applyExcludeRules( item );
215 YQPkgPatternListItem *
216 YQPkgPatternList::selection() const
218 QTreeWidgetItem * item = currentItem();
223 return dynamic_cast<YQPkgPatternListItem *> (item);
228 YQPkgPatternList::pkgObjClicked( int button,
229 QTreeWidgetItem * listViewItem,
233 YQPkgPatternCategoryItem * categoryItem
234 = dynamic_cast<YQPkgPatternCategoryItem *> (listViewItem);
238 if ( button == Qt::LeftButton )
240 if ( col == statusCol() )
242 categoryItem->setExpanded( ! categoryItem->isExpanded() );
248 YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
254 YQPkgPatternList::selectSomething()
257 QTreeWidgetItemIterator it( this );
261 QY2ListViewItem * item = dynamic_cast<QY2ListViewItem *> (*it);
262 YQPkgPatternCategoryItem * categoryItem =
263 dynamic_cast<YQPkgPatternCategoryItem *> (*it);
265 if ( item && item->isSelectable() && ! categoryItem )
267 setSelected( item, true ); // emits signal, too
276 void YQPkgPatternList::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
278 painter->setFont( YQUI::yqApp()->headingFont() );
279 QTreeWidget::drawRow ( painter, option, index );
282 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
284 ZyppPattern zyppPattern )
285 : YQPkgObjListItem( patternList, selectable, zyppPattern )
286 , _patternList( patternList )
287 , _zyppPattern( zyppPattern )
293 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
294 YQPkgPatternCategoryItem * parentCategory,
296 ZyppPattern zyppPattern )
297 : YQPkgObjListItem( patternList, parentCategory, selectable, zyppPattern )
298 , _patternList( patternList )
299 , _zyppPattern( zyppPattern )
302 parentCategory->addPattern( _zyppPattern );
307 YQPkgPatternListItem::init()
309 if ( ! _zyppPattern )
310 _zyppPattern = tryCastToZyppPattern( selectable()->theObj() );
317 YQPkgPatternListItem::~YQPkgPatternListItem()
324 YQPkgPatternListItem::applyChanges()
326 solveResolvableCollections();
330 bool YQPkgPatternListItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
332 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
334 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->zyppPattern() )
335 return _zyppPattern->order().compare( otherPatternListitem->zyppPattern()->order() );
337 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
339 if ( otherCategoryItem ) // Patterns without category should always be sorted
340 return true; // before any category
342 return QTreeWidgetItem::operator<( otherListViewItem );
350 YQPkgPatternCategoryItem::YQPkgPatternCategoryItem( YQPkgPatternList * patternList,
351 const QString & category )
352 : QY2ListViewItem( patternList )
353 , _patternList( patternList )
355 setText( _patternList->summaryCol(), category );
356 setBackgroundColor( CATEGORY_BACKGROUND );
362 YQPkgPatternCategoryItem::~YQPkgPatternCategoryItem()
368 YQPkgPatternCategoryItem::addPattern( ZyppPattern pattern )
370 if ( ! _firstPattern )
372 _firstPattern = pattern;
376 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
377 _firstPattern = pattern;
383 YQPkgPatternCategoryItem::setExpanded( bool open )
385 QTreeWidgetItem::setExpanded( open );
391 YQPkgPatternCategoryItem::setTreeIcon()
393 setData( _patternList->statusCol(), Qt::DecorationRole,
395 YQIconPool::treeMinus() :
396 YQIconPool::treePlus() );
401 bool YQPkgPatternCategoryItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
403 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
405 if ( _firstPattern && otherCategoryItem && otherCategoryItem->firstPattern() )
406 return _firstPattern->order().compare( otherCategoryItem->firstPattern()->order() );
409 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
411 if ( otherPatternListitem ) // Patterns without category should always be sorted
412 return true; // before any category
414 return QTreeWidgetItem::operator<( otherListViewItem );
419 #include "YQPkgPatternList.moc"