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 : QTreeWidget( parent )
37 setHeaderLabels( QStringList(_( "Package Groups" )) );
38 setRootIsDecorated( true );
39 cloneTree( rpmGroupsTree()->root(), 0 );
41 new YQPkgRpmGroupTag( this, _( "zzz All" ), 0 );
43 connect( this, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
44 this, SLOT ( slotSelectionChanged ( QTreeWidgetItem * ) ) );
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 //FIXME clone->setExpanded( clone->depth() < 1 );
105 clone->setExpanded( true );
106 cloneTree( child, clone );
107 child = child->next();
113 YQPkgRpmGroupTagsFilterView::selectSomething()
116 // QTreeWidgetItem * item = children().first();
119 // setCurrentItem(item);
124 YQPkgRpmGroupTagsFilterView::filterIfVisible()
132 YQPkgRpmGroupTagsFilterView::filter()
135 // y2debug( "Filtering packages for RPM group \"%s\"", selectedRpmGroup().c_str() );
139 for ( ZyppPoolIterator it = zyppPkgBegin();
143 ZyppSel selectable = *it;
145 // Multiple instances of this package may or may not be in the same
146 // RPM group, so let's check both the installed version (if there
147 // is any) and the candidate version.
149 // Make sure we emit only one filterMatch() signal if both exist
150 // and both are in the same RPM group. We don't want multiple list
151 // entries for the same package!
154 check( selectable, tryCastToZyppPkg( selectable->candidateObj() ) ) ||
155 check( selectable, tryCastToZyppPkg( selectable->installedObj() ) );
157 // If there is neither an installed nor a candidate package, check
158 // any other instance.
161 ! selectable->candidateObj() &&
162 ! selectable->installedObj() )
163 check( selectable, tryCastToZyppPkg( selectable->theObj() ) );
167 emit filterFinished();
172 YQPkgRpmGroupTagsFilterView::slotSelectionChanged( QTreeWidgetItem * newSelection )
174 YQPkgRpmGroupTag * sel = dynamic_cast<YQPkgRpmGroupTag *>( newSelection );
178 if ( sel->rpmGroup() )
179 _selectedRpmGroup = rpmGroupsTree()->rpmGroup( sel->rpmGroup() );
181 _selectedRpmGroup = "*"; // "zzz_All"
185 _selectedRpmGroup = "";
193 YQPkgRpmGroupTagsFilterView::check( ZyppSel selectable,
196 if ( ! pkg || ! selection() )
199 if ( selection()->rpmGroup() == 0 ) // Special case: All packages
201 emit filterMatch( selectable, pkg );
205 if ( selectedRpmGroup().empty() )
208 if ( pkg->group() == selectedRpmGroup() || // full match?
209 pkg->group().find( selectedRpmGroup() + "/" ) == 0 ) // starts with selected?
211 emit filterMatch( selectable, pkg );
220 YQPkgRpmGroupTagsFilterView::selection() const
222 QTreeWidgetItem * item = currentItem();
227 return dynamic_cast<YQPkgRpmGroupTag *> ( item );
235 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
236 YStringTreeItem * rpmGroup )
237 : QTreeWidgetItem( parentFilterView )
238 , _filterView( parentFilterView )
239 , _rpmGroup( rpmGroup )
241 setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
245 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
246 YQPkgRpmGroupTag * parentGroupTag,
247 YStringTreeItem * rpmGroup )
248 : QTreeWidgetItem( parentGroupTag )
249 , _filterView( parentFilterView )
250 , _rpmGroup( rpmGroup )
252 setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
256 YQPkgRpmGroupTag::YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView * parentFilterView,
257 const QString & rpmGroupName,
258 YStringTreeItem * rpmGroup )
259 : QTreeWidgetItem( parentFilterView )
260 , _filterView( parentFilterView )
261 , _rpmGroup( rpmGroup )
263 setText( 0, rpmGroupName );
267 YQPkgRpmGroupTag::~YQPkgRpmGroupTag()
274 #include "YQPkgRpmGroupTagsFilterView.moc"