1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgRpmGroupTagsFilterView.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 "YQPkgRpmGroupTagsFilterView.h"
31 YRpmGroupsTree * YQPkgRpmGroupTagsFilterView::_rpmGroupsTree = 0;
34 YQPkgRpmGroupTagsFilterView::YQPkgRpmGroupTagsFilterView( QWidget * parent )
35 : Q3ListView( parent )
37 addColumn( _( "Package Groups" ) );
38 setRootIsDecorated( true );
39 cloneTree( rpmGroupsTree()->root(), 0 );
41 new YQPkgRpmGroupTag( this, _( "zzz All" ), 0 );
43 connect( this, SIGNAL( selectionChanged ( Q3ListViewItem * ) ),
44 this, SLOT ( slotSelectionChanged ( Q3ListViewItem * ) ) );
50 YQPkgRpmGroupTagsFilterView::~YQPkgRpmGroupTagsFilterView()
56 YQPkgRpmGroupTagsFilterView::rpmGroupsTree()
58 if ( ! _rpmGroupsTree )
60 _rpmGroupsTree = new YRpmGroupsTree();
61 Q_CHECK_PTR( _rpmGroupsTree );
66 return _rpmGroupsTree;
71 YQPkgRpmGroupTagsFilterView::fillRpmGroupsTree()
73 y2debug( "Filling RPM groups tree" );
75 for ( ZyppPoolIterator it = zyppPkgBegin();
79 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
82 rpmGroupsTree()->addRpmGroup( zyppPkg->group() );
85 y2debug( "Filling RPM groups tree done" );
90 YQPkgRpmGroupTagsFilterView::cloneTree( YStringTreeItem * parentRpmGroup,
91 YQPkgRpmGroupTag * parentClone )
93 YStringTreeItem * child = parentRpmGroup->firstChild();
94 YQPkgRpmGroupTag * clone;
99 clone = new YQPkgRpmGroupTag( this, parentClone, child );
101 clone = new YQPkgRpmGroupTag( this, child );
103 Q_CHECK_PTR( clone );
104 clone->setOpen( clone->depth() < 1 );
106 cloneTree( child, clone );
107 child = child->next();
113 YQPkgRpmGroupTagsFilterView::selectSomething()
115 Q3ListViewItem * item = firstChild();
118 setSelected( item, true );
123 YQPkgRpmGroupTagsFilterView::filterIfVisible()
131 YQPkgRpmGroupTagsFilterView::filter()
134 // y2debug( "Filtering packages for RPM group \"%s\"", selectedRpmGroup().c_str() );
138 for ( ZyppPoolIterator it = zyppPkgBegin();
142 ZyppSel selectable = *it;
144 // Multiple instances of this package may or may not be in the same
145 // RPM group, so let's check both the installed version (if there
146 // is any) and the candidate version.
148 // Make sure we emit only one filterMatch() signal if both exist
149 // and both are in the same RPM group. We don't want multiple list
150 // entries for the same package!
153 check( selectable, tryCastToZyppPkg( selectable->candidateObj() ) ) ||
154 check( selectable, tryCastToZyppPkg( selectable->installedObj() ) );
156 // If there is neither an installed nor a candidate package, check
157 // any other instance.
160 ! selectable->candidateObj() &&
161 ! selectable->installedObj() )
162 check( selectable, tryCastToZyppPkg( selectable->theObj() ) );
166 emit filterFinished();
171 YQPkgRpmGroupTagsFilterView::slotSelectionChanged( Q3ListViewItem * newSelection )
173 YQPkgRpmGroupTag * sel = dynamic_cast<YQPkgRpmGroupTag *>( newSelection );
177 if ( sel->rpmGroup() )
178 _selectedRpmGroup = rpmGroupsTree()->rpmGroup( sel->rpmGroup() );
180 _selectedRpmGroup = "*"; // "zzz_All"
184 _selectedRpmGroup = "";
192 YQPkgRpmGroupTagsFilterView::check( ZyppSel selectable,
195 if ( ! pkg || ! selection() )
198 if ( selection()->rpmGroup() == 0 ) // Special case: All packages
200 emit filterMatch( selectable, pkg );
204 if ( selectedRpmGroup().empty() )
207 if ( pkg->group() == selectedRpmGroup() || // full match?
208 pkg->group().find( selectedRpmGroup() + "/" ) == 0 ) // starts with selected?
210 emit filterMatch( selectable, pkg );
219 YQPkgRpmGroupTagsFilterView::selection() const
221 Q3ListViewItem * item = selectedItem();
226 return dynamic_cast<YQPkgRpmGroupTag *> ( selectedItem() );
234 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
235 YStringTreeItem * rpmGroup )
236 : Q3ListViewItem( parentFilterView )
237 , _filterView( parentFilterView )
238 , _rpmGroup( rpmGroup )
240 setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
244 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
245 YQPkgRpmGroupTag * parentGroupTag,
246 YStringTreeItem * rpmGroup )
247 : Q3ListViewItem( parentGroupTag )
248 , _filterView( parentFilterView )
249 , _rpmGroup( rpmGroup )
251 setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
255 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
256 const QString & rpmGroupName,
257 YStringTreeItem * rpmGroup )
258 : Q3ListViewItem( parentFilterView )
259 , _filterView( parentFilterView )
260 , _rpmGroup( rpmGroup )
262 setText( 0, rpmGroupName );
266 YQPkgRpmGroupTag::~YQPkgRpmGroupTag()
273 #include "YQPkgRpmGroupTagsFilterView.moc"