1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgRepoList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
24 #define y2log_component "qt-pkg"
25 #include <ycp/y2log.h>
26 #include <zypp/RepoManager.h>
28 #include <QTreeWidget>
29 #include "YQPkgRepoList.h"
39 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
40 : QY2ListView( parent )
42 y2debug( "Creating repository list" );
51 // Column headers for repository list
52 headers << _( "Name"); _nameCol = numCol++;
53 headers << _( "URL"); _urlCol = numCol++;
55 setHeaderLabels(headers);
57 //setAllColumnsShowFocus( true );
58 //setSelectionMode( Q3ListView::Extended ); // allow multi-selection with Ctrl-mouse
60 connect( this, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *) ),
61 this, SLOT ( filterIfVisible()) );
66 y2debug( "Creating repository list done" );
70 YQPkgRepoList::~YQPkgRepoList()
77 YQPkgRepoList::fillList()
80 y2debug( "Filling repository list" );
82 for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
83 it != ZyppRepositoriesEnd();
89 y2debug( "Inst repository filled" );
94 YQPkgRepoList::countEnabledRepositories()
96 return zyppPool().knownRepositoriesSize();
101 YQPkgRepoList::filterIfVisible()
109 YQPkgRepoList::filter()
113 y2milestone( "Collecting packages in selected repositories..." );
119 // Collect all packages on this repository
122 set<ZyppSel> exactMatches;
123 set<ZyppSel> nearMatches;
127 QTreeWidgetItem * item;
129 QList<QTreeWidgetItem *> items = selectedItems();
130 QListIterator<QTreeWidgetItem *> it(items);
132 while ( it.hasNext() )
135 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
139 ZyppRepo currentRepo = repoItem->zyppRepo();
141 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
142 sel_it != zyppPkgEnd();
145 if ( (*sel_it)->candidateObj() &&
146 (*sel_it)->candidateObj()->repository() == currentRepo )
148 exactMatches.insert( *sel_it );
152 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
154 while ( pkg_it != (*sel_it)->availableEnd() )
156 if ( (*pkg_it)->repository() == currentRepo )
157 nearMatches.insert( *sel_it );
169 // Send all exact matches to the list
170 // (emit a filterMatch signal for each one)
173 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
175 while ( sel_it != exactMatches.end() )
177 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
178 nearMatches.erase( *sel_it );
184 // Send all near matches to the list
185 // (emit a filterNearMatch signal for each one)
188 sel_it = nearMatches.begin();
190 while ( sel_it != nearMatches.end() )
192 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
196 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
198 emit filterFinished();
203 YQPkgRepoList::addRepo( ZyppRepo repo )
205 new YQPkgRepoListItem( this, repo );
210 YQPkgRepoList::selection() const
212 QTreeWidgetItem * item = currentItem();
217 return dynamic_cast<YQPkgRepoListItem *> (item);
225 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
227 : QY2ListViewItem( repoList )
228 , _repoList( repoList )
231 if ( nameCol() >= 0 )
233 string name = repo.info().name();
235 #if SHOW_SINGLE_PRODUCT
236 ZyppProduct product = singleProduct( _zyppRepo );
238 if ( product ) // only if the repository provides exactly one product
239 { // (which is the most common case)
240 name = product->summary();
244 if ( ! name.empty() )
245 setText( nameCol(), fromUTF8( name ));
252 if ( ! repo.info().baseUrlsEmpty() )
253 repoUrl = *repo.info().baseUrlsBegin();
255 setText( urlCol(), repoUrl.asString().c_str() );
261 YQPkgRepoListItem::~YQPkgRepoListItem()
268 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
272 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
275 // Find the first product on this repository
278 while ( it != zyppRepo.resolvables().end() && ! product )
280 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
285 // Check if there is another product on this repository
288 while ( it != zyppRepo.resolvables().end() )
290 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
292 y2milestone( "Multiple products in repository %s",
293 zyppRepo.info().alias().c_str() );
302 y2milestone( "No product in repository %s",
303 zyppRepo.info().alias().c_str() );
310 #include "YQPkgRepoList.moc"