1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatternList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <zypp/ZYppFactory.h>
27 #include <zypp/Resolver.h>
29 #include <QHeaderView>
30 #include <zypp/ui/PatternContents.h>
34 #include "YQPkgPatternList.h"
35 #include "YQIconPool.h"
36 #include "YQApplication.h"
40 #define CATEGORY_BACKGROUND QColor( 0xFF, 0xC0, 0x50 )
43 YQPkgPatternList::YQPkgPatternList( QWidget * parent, bool autoFill, bool autoFilter )
44 : YQPkgObjList( parent )
46 y2debug( "Creating pattern list" );
50 headers << ""; _statusCol = numCol++;
52 // Translators: "Pattern" refers to so-called "installation patterns",
53 // i.e., specific task-oriented groups of packages, like "everything that
54 // is needed to run a web server". The idea of patterns is that they also
55 // include the configuration workflow needed for that task, such of
56 // configuring the web server. For the scope of the package selector, this
57 // is only of little relevance, though.
59 headers << _( "Pattern" ); _summaryCol = numCol++;
61 setHeaderLabels(headers);
62 // Can use the same colum for "broken" and "satisfied":
63 // Both states are mutually exclusive
65 _satisfiedIconCol = _summaryCol;
66 _brokenIconCol = _summaryCol;
68 // header()->setStretchEnabled( _statusCol , false );
69 // header()->setStretchEnabled( _summaryCol, true );
71 setAllColumnsShowFocus( true );
72 //setTreeStepSize( 0 );
76 connect( this, SIGNAL( currentItemChanged( QTreeWidgetItem * ) ),
77 this, SLOT ( filter() ) );
85 y2debug( "Creating pattern list done" );
89 YQPkgPatternList::~YQPkgPatternList()
96 YQPkgPatternList::fillList()
99 y2debug( "Filling pattern list" );
102 for ( ZyppPoolIterator it = zyppPatternsBegin();
103 it != zyppPatternsEnd();
106 ZyppPattern zyppPattern = tryCastToZyppPattern( (*it)->theObj() );
110 if ( zyppPattern->userVisible() )
112 addPatternItem( *it, zyppPattern );
115 y2debug( "Pattern %s is not user-visible", zyppPattern->name().c_str() );
119 y2error( "Found non-Pattern selectable" );
123 y2debug( "Pattern list filled" );
127 YQPkgPatternCategoryItem *
128 YQPkgPatternList::category( const QString & categoryName )
130 if ( categoryName.isEmpty() )
133 YQPkgPatternCategoryItem * cat = _categories[ categoryName ];
137 y2debug( "New pattern category \"%s\"", (const char *) categoryName );
139 cat = new YQPkgPatternCategoryItem( this, categoryName );
141 _categories.insert( categoryName, cat );
150 YQPkgPatternList::filterIfVisible()
158 YQPkgPatternList::filter()
162 if ( selection() ) // The seleted QListViewItem
164 ZyppPattern zyppPattern = selection()->zyppPattern();
168 zypp::ui::PatternContents patternContents( zyppPattern );
169 set<string> wanted = patternContents.install_packages();
171 for ( ZyppPoolIterator it = zyppPkgBegin();
175 string name = (*it)->theObj()->name();
177 if ( contains( wanted, name ) )
179 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
183 emit filterMatch( *it, zyppPkg );
190 emit filterFinished();
195 YQPkgPatternList::addPatternItem( ZyppSel selectable,
196 ZyppPattern zyppPattern )
200 y2error( "NULL ZyppSelectable!" );
204 YQPkgPatternCategoryItem * cat = category( fromUTF8( zyppPattern->category() ) );
205 YQPkgPatternListItem * item = 0;
208 item = new YQPkgPatternListItem( this, cat, selectable, zyppPattern );
210 item = new YQPkgPatternListItem( this, selectable, zyppPattern );
212 addTopLevelItem(item);
213 applyExcludeRules( item );
217 YQPkgPatternListItem *
218 YQPkgPatternList::selection() const
221 QTreeWidgetItem * item = currentItem();
226 return dynamic_cast<YQPkgPatternListItem *> (item);
234 YQPkgPatternList::pkgObjClicked( int button,
235 QTreeWidgetItem * listViewItem,
240 YQPkgPatternCategoryItem * categoryItem
241 = dynamic_cast<YQPkgPatternCategoryItem *> (listViewItem);
245 if ( button == Qt::LeftButton )
247 if ( col == statusCol() )
249 categoryItem->setOpen( ! categoryItem->isExpanded() );
255 YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
262 YQPkgPatternList::selectSomething()
265 QTreeWidgetItemIterator it( this );
269 QY2ListViewItem * item = dynamic_cast<QY2ListViewItem *> (*it);
270 YQPkgPatternCategoryItem * categoryItem =
271 dynamic_cast<YQPkgPatternCategoryItem *> (*it);
273 if ( item && item->isSelectable() && ! categoryItem )
275 setSelected( item, true ); // emits signal, too
284 void YQPkgPatternList::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
286 painter->setFont( YQUI::yqApp()->headingFont() );
287 QTreeWidget::drawRow ( painter, option, index );
290 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
292 ZyppPattern zyppPattern )
293 : YQPkgObjListItem( patternList, selectable, zyppPattern )
294 , _patternList( patternList )
295 , _zyppPattern( zyppPattern )
301 YQPkgPatternListItem::YQPkgPatternListItem( YQPkgPatternList * patternList,
302 YQPkgPatternCategoryItem * parentCategory,
304 ZyppPattern zyppPattern )
305 : YQPkgObjListItem( patternList, parentCategory, selectable, zyppPattern )
306 , _patternList( patternList )
307 , _zyppPattern( zyppPattern )
310 parentCategory->addPattern( _zyppPattern );
315 YQPkgPatternListItem::init()
317 if ( ! _zyppPattern )
318 _zyppPattern = tryCastToZyppPattern( selectable()->theObj() );
325 YQPkgPatternListItem::~YQPkgPatternListItem()
332 YQPkgPatternListItem::applyChanges()
334 solveResolvableCollections();
340 * Comparison function used for sorting the list.
347 YQPkgPatternListItem::compare( QTreeWidgetItem * otherListViewItem,
349 bool ascending ) const
351 YQPkgPatternListItem * otherPatternListitem = dynamic_cast<YQPkgPatternListItem *>(otherListViewItem);
353 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->zyppPattern() )
354 return _zyppPattern->order().compare( otherPatternListitem->zyppPattern()->order() );
356 YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<YQPkgPatternCategoryItem *>(otherListViewItem);
358 if ( otherCategoryItem ) // Patterns without category should always be sorted
359 return -1; // before any category
361 return false; //FIXME QTreeWidgetItem::compare( otherListViewItem, col, ascending );
369 YQPkgPatternCategoryItem::YQPkgPatternCategoryItem( YQPkgPatternList * patternList,
370 const QString & category )
371 : QY2ListViewItem( patternList )
372 , _patternList( patternList )
374 setText( _patternList->summaryCol(), category );
375 setBackgroundColor( CATEGORY_BACKGROUND );
381 YQPkgPatternCategoryItem::~YQPkgPatternCategoryItem()
387 YQPkgPatternCategoryItem::addPattern( ZyppPattern pattern )
389 if ( ! _firstPattern )
391 _firstPattern = pattern;
395 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
396 _firstPattern = pattern;
402 YQPkgPatternCategoryItem::setOpen( bool open )
404 //FIXME QTreeWidgetItem::setOpen( open );
410 YQPkgPatternCategoryItem::setTreeIcon()
413 setPixmap( _patternList->statusCol(),
415 YQIconPool::treeMinus() :
416 YQIconPool::treePlus() );
423 * Comparison function used for sorting the list.
430 YQPkgPatternCategoryItem::compare( QTreeWidgetItem * otherListViewItem,
432 bool ascending ) const
434 YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<YQPkgPatternCategoryItem *>(otherListViewItem);
436 if ( _firstPattern && otherCategoryItem && otherCategoryItem->firstPattern() )
437 return _firstPattern->order().compare( otherCategoryItem->firstPattern()->order() );
440 YQPkgPatternListItem * otherPatternListitem = dynamic_cast<YQPkgPatternListItem *>(otherListViewItem);
442 if ( otherPatternListitem ) // Patterns without category should always be sorted
443 return 1; // before any category
445 return false; // FIXME QTreeWidgetItem::compare( otherListViewItem, col, ascending );
450 #include "YQPkgPatternList.moc"