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
219 QTreeWidgetItem * item = currentItem();
224 return dynamic_cast<YQPkgPatternListItem *> (item);
232 YQPkgPatternList::pkgObjClicked( int button,
233 QTreeWidgetItem * listViewItem,
238 YQPkgPatternCategoryItem * categoryItem
239 = dynamic_cast<YQPkgPatternCategoryItem *> (listViewItem);
243 if ( button == Qt::LeftButton )
245 if ( col == statusCol() )
247 categoryItem->setOpen( ! categoryItem->isExpanded() );
253 YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
260 YQPkgPatternList::selectSomething()
263 QTreeWidgetItemIterator it( this );
267 QY2ListViewItem * item = dynamic_cast<QY2ListViewItem *> (*it);
268 YQPkgPatternCategoryItem * categoryItem =
269 dynamic_cast<YQPkgPatternCategoryItem *> (*it);
271 if ( item && item->isSelectable() && ! categoryItem )
273 setSelected( item, true ); // emits signal, too
282 void YQPkgPatternList::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
284 painter->setFont( YQUI::yqApp()->headingFont() );
285 QTreeWidget::drawRow ( painter, option, index );
288 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
290 ZyppPattern zyppPattern )
291 : YQPkgObjListItem( patternList, selectable, zyppPattern )
292 , _patternList( patternList )
293 , _zyppPattern( zyppPattern )
299 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
300 YQPkgPatternCategoryItem * parentCategory,
302 ZyppPattern zyppPattern )
303 : YQPkgObjListItem( patternList, parentCategory, selectable, zyppPattern )
304 , _patternList( patternList )
305 , _zyppPattern( zyppPattern )
308 parentCategory->addPattern( _zyppPattern );
313 YQPkgPatternListItem::init()
315 if ( ! _zyppPattern )
316 _zyppPattern = tryCastToZyppPattern( selectable()->theObj() );
323 YQPkgPatternListItem::~YQPkgPatternListItem()
330 YQPkgPatternListItem::applyChanges()
332 solveResolvableCollections();
336 bool YQPkgPatternListItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
338 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
340 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->zyppPattern() )
341 return _zyppPattern->order().compare( otherPatternListitem->zyppPattern()->order() );
343 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
345 if ( otherCategoryItem ) // Patterns without category should always be sorted
346 return true; // before any category
348 return QTreeWidgetItem::operator<( otherListViewItem );
356 YQPkgPatternCategoryItem::YQPkgPatternCategoryItem( YQPkgPatternList * patternList,
357 const QString & category )
358 : QY2ListViewItem( patternList )
359 , _patternList( patternList )
361 setText( _patternList->summaryCol(), category );
362 setBackgroundColor( CATEGORY_BACKGROUND );
368 YQPkgPatternCategoryItem::~YQPkgPatternCategoryItem()
374 YQPkgPatternCategoryItem::addPattern( ZyppPattern pattern )
376 if ( ! _firstPattern )
378 _firstPattern = pattern;
382 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
383 _firstPattern = pattern;
389 YQPkgPatternCategoryItem::setOpen( bool open )
391 //FIXME QTreeWidgetItem::setOpen( open );
397 YQPkgPatternCategoryItem::setTreeIcon()
400 setPixmap( _patternList->statusCol(),
402 YQIconPool::treeMinus() :
403 YQIconPool::treePlus() );
408 bool YQPkgPatternCategoryItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
410 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
412 if ( _firstPattern && otherCategoryItem && otherCategoryItem->firstPattern() )
413 return _firstPattern->order().compare( otherCategoryItem->firstPattern()->order() );
416 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
418 if ( otherPatternListitem ) // Patterns without category should always be sorted
419 return true; // before any category
421 QTreeWidgetItem::operator<( otherListViewItem );
426 #include "YQPkgPatternList.moc"