1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgRepoList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #include <qdatetime.h>
25 #define y2log_component "qt-pkg"
26 #include <ycp/y2log.h>
27 #include <zypp/RepoManager.h>
30 #include "YQPkgRepoList.h"
40 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
41 : QY2ListView( parent )
43 y2debug( "Creating repository list" );
50 // Column headers for repository list
51 addColumn( _( "Name" ) ); _nameCol = numCol++;
52 addColumn( _( "URL" ) ); _urlCol = numCol++;
54 setAllColumnsShowFocus( true );
55 setSelectionMode( Q3ListView::Extended ); // allow multi-selection with Ctrl-mouse
57 connect( this, SIGNAL( selectionChanged() ),
58 this, SLOT ( filterIfVisible()) );
64 y2debug( "Creating repository list done" );
68 YQPkgRepoList::~YQPkgRepoList()
75 YQPkgRepoList::fillList()
78 y2debug( "Filling repository list" );
80 for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
81 it != ZyppRepositoriesEnd();
87 y2debug( "Inst repository filled" );
92 YQPkgRepoList::countEnabledRepositories()
94 return zyppPool().knownRepositoriesSize();
99 YQPkgRepoList::filterIfVisible()
107 YQPkgRepoList::filter()
112 y2milestone( "Collecting packages in selected repositories..." );
118 // Collect all packages on this repository
121 set<ZyppSel> exactMatches;
122 set<ZyppSel> nearMatches;
124 Q3ListViewItem * item = firstChild(); // take multi selection into account
128 if ( item->isSelected() )
130 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
134 ZyppRepo currentRepo = repoItem->zyppRepo();
136 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
137 sel_it != zyppPkgEnd();
140 if ( (*sel_it)->candidateObj() &&
141 (*sel_it)->candidateObj()->repository() == currentRepo )
143 exactMatches.insert( *sel_it );
147 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
149 while ( pkg_it != (*sel_it)->availableEnd() )
151 if ( (*pkg_it)->repository() == currentRepo )
152 nearMatches.insert( *sel_it );
162 item = item->nextSibling();
167 // Send all exact matches to the list
168 // (emit a filterMatch signal for each one)
171 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
173 while ( sel_it != exactMatches.end() )
175 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
176 nearMatches.erase( *sel_it );
182 // Send all near matches to the list
183 // (emit a filterNearMatch signal for each one)
186 sel_it = nearMatches.begin();
188 while ( sel_it != nearMatches.end() )
190 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
194 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
196 emit filterFinished();
202 YQPkgRepoList::addRepo( ZyppRepo repo )
204 new YQPkgRepoListItem( this, repo );
209 YQPkgRepoList::selection() const
212 Q3ListViewItem * item = selectedItem();
217 return dynamic_cast<YQPkgRepoListItem *> (item);
228 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
230 : QY2ListViewItem( repoList )
231 , _repoList( repoList )
234 if ( nameCol() >= 0 )
236 string name = repo.info().name();
238 #if SHOW_SINGLE_PRODUCT
239 ZyppProduct product = singleProduct( _zyppRepo );
241 if ( product ) // only if the repository provides exactly one product
242 { // (which is the most common case)
243 name = product->summary();
247 if ( ! name.empty() )
248 setText( nameCol(), fromUTF8( name ));
255 if ( ! repo.info().baseUrlsEmpty() )
256 repoUrl = *repo.info().baseUrlsBegin();
258 setText( urlCol(), repoUrl.asString().c_str() );
264 YQPkgRepoListItem::~YQPkgRepoListItem()
271 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
275 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
278 // Find the first product on this repository
281 while ( it != zyppRepo.resolvables().end() && ! product )
283 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
288 // Check if there is another product on this repository
291 while ( it != zyppRepo.resolvables().end() )
293 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
295 y2milestone( "Multiple products in repository %s",
296 zyppRepo.info().alias().c_str() );
305 y2milestone( "No product in repository %s",
306 zyppRepo.info().alias().c_str() );
313 #include "YQPkgRepoList.moc"