1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatternList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <zypp/ZYppFactory.h>
26 #include <zypp/Resolver.h>
29 #include <zypp/ui/PatternContents.h>
33 #include "YQPkgPatternList.h"
34 #include "YQIconPool.h"
35 #include "YQApplication.h"
39 #define CATEGORY_BACKGROUND QColor( 0xFF, 0xC0, 0x50 )
42 YQPkgPatternList::YQPkgPatternList( QWidget * parent, bool autoFill, bool autoFilter )
43 : YQPkgObjList( parent )
45 y2debug( "Creating pattern list" );
48 addColumn( "" ); _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 addColumn( _( "Pattern" ) ); _summaryCol = numCol++;
59 // Can use the same colum for "broken" and "satisfied":
60 // Both states are mutually exclusive
62 _satisfiedIconCol = _summaryCol;
63 _brokenIconCol = _summaryCol;
65 header()->setStretchEnabled( _statusCol , false );
66 header()->setStretchEnabled( _summaryCol, true );
68 setAllColumnsShowFocus( true );
73 connect( this, SIGNAL( selectionChanged( QTreeWidgetItem * ) ),
74 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\"", (const char *) 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 applyExcludeRules( item );
214 YQPkgPatternListItem *
215 YQPkgPatternList::selection() const
217 QTreeWidgetItem * item = selectedItem();
222 return dynamic_cast<YQPkgPatternListItem *> (item);
227 YQPkgPatternList::pkgObjClicked( int button,
228 QTreeWidgetItem * listViewItem,
232 YQPkgPatternCategoryItem * categoryItem
233 = dynamic_cast<YQPkgPatternCategoryItem *> (listViewItem);
237 if ( button == Qt::LeftButton )
239 if ( col == statusCol() )
241 categoryItem->setOpen( ! categoryItem->isOpen() );
247 YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
253 YQPkgPatternList::selectSomething()
255 QTreeWidgetItemIterator it( this );
259 QY2ListViewItem * item = dynamic_cast<QY2ListViewItem *> (*it);
260 YQPkgPatternCategoryItem * categoryItem =
261 dynamic_cast<YQPkgPatternCategoryItem *> (*it);
263 if ( item && item->isSelectable() && ! categoryItem )
265 setSelected( item, true ); // emits signal, too
278 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
280 ZyppPattern zyppPattern )
281 : YQPkgObjListItem( patternList, selectable, zyppPattern )
282 , _patternList( patternList )
283 , _zyppPattern( zyppPattern )
289 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
290 YQPkgPatternCategoryItem * parentCategory,
292 ZyppPattern zyppPattern )
293 : YQPkgObjListItem( patternList, parentCategory, selectable, zyppPattern )
294 , _patternList( patternList )
295 , _zyppPattern( zyppPattern )
298 parentCategory->addPattern( _zyppPattern );
303 YQPkgPatternListItem::init()
305 if ( ! _zyppPattern )
306 _zyppPattern = tryCastToZyppPattern( selectable()->theObj() );
313 YQPkgPatternListItem::~YQPkgPatternListItem()
320 YQPkgPatternListItem::applyChanges()
322 solveResolvableCollections();
328 * Comparison function used for sorting the list.
335 YQPkgPatternListItem::compare( QTreeWidgetItem * otherListViewItem,
337 bool ascending ) const
339 YQPkgPatternListItem * otherPatternListitem = dynamic_cast<YQPkgPatternListItem *>(otherListViewItem);
341 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->zyppPattern() )
342 return _zyppPattern->order().compare( otherPatternListitem->zyppPattern()->order() );
344 YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<YQPkgPatternCategoryItem *>(otherListViewItem);
346 if ( otherCategoryItem ) // Patterns without category should always be sorted
347 return -1; // before any category
349 return QTreeWidgetItem::compare( otherListViewItem, col, ascending );
357 YQPkgPatternCategoryItem::YQPkgPatternCategoryItem( YQPkgPatternList * patternList,
358 const QString & category )
359 : QY2ListViewItem( patternList )
360 , _patternList( patternList )
362 setText( _patternList->summaryCol(), category );
363 setBackgroundColor( CATEGORY_BACKGROUND );
369 YQPkgPatternCategoryItem::~YQPkgPatternCategoryItem()
376 YQPkgPatternCategoryItem::paintCell( QPainter * painter,
377 const QColorGroup & colorGroup,
382 painter->setFont( YQUI::yqApp()->headingFont() );
383 QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
389 YQPkgPatternCategoryItem::addPattern( ZyppPattern pattern )
391 if ( ! _firstPattern )
393 _firstPattern = pattern;
397 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
398 _firstPattern = pattern;
404 YQPkgPatternCategoryItem::setOpen( bool open )
406 QTreeWidgetItem::setOpen( open );
412 YQPkgPatternCategoryItem::setTreeIcon()
414 setPixmap( _patternList->statusCol(),
416 YQIconPool::treeMinus() :
417 YQIconPool::treePlus() );
424 * Comparison function used for sorting the list.
431 YQPkgPatternCategoryItem::compare( QTreeWidgetItem * otherListViewItem,
433 bool ascending ) const
435 YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<YQPkgPatternCategoryItem *>(otherListViewItem);
437 if ( _firstPattern && otherCategoryItem && otherCategoryItem->firstPattern() )
438 return _firstPattern->order().compare( otherCategoryItem->firstPattern()->order() );
441 YQPkgPatternListItem * otherPatternListitem = dynamic_cast<YQPkgPatternListItem *>(otherListViewItem);
443 if ( otherPatternListitem ) // Patterns without category should always be sorted
444 return 1; // before any category
446 return QTreeWidgetItem::compare( otherListViewItem, col, ascending );
451 #include "YQPkgPatternList.moc"