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()) );
63 y2debug( "Creating repository list done" );
67 YQPkgRepoList::~YQPkgRepoList()
74 YQPkgRepoList::fillList()
77 y2debug( "Filling repository list" );
79 for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
80 it != ZyppRepositoriesEnd();
86 y2debug( "Inst repository filled" );
91 YQPkgRepoList::countEnabledRepositories()
93 return zyppPool().knownRepositoriesSize();
98 YQPkgRepoList::filterIfVisible()
106 YQPkgRepoList::filter()
110 y2milestone( "Collecting packages in selected repositories..." );
116 // Collect all packages on this repository
119 set<ZyppSel> exactMatches;
120 set<ZyppSel> nearMatches;
122 Q3ListViewItem * item = firstChild(); // take multi selection into account
126 if ( item->isSelected() )
128 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
132 ZyppRepo currentRepo = repoItem->zyppRepo();
134 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
135 sel_it != zyppPkgEnd();
138 if ( (*sel_it)->candidateObj() &&
139 (*sel_it)->candidateObj()->repository() == currentRepo )
141 exactMatches.insert( *sel_it );
145 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
147 while ( pkg_it != (*sel_it)->availableEnd() )
149 if ( (*pkg_it)->repository() == currentRepo )
150 nearMatches.insert( *sel_it );
160 item = item->nextSibling();
165 // Send all exact matches to the list
166 // (emit a filterMatch signal for each one)
169 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
171 while ( sel_it != exactMatches.end() )
173 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
174 nearMatches.erase( *sel_it );
180 // Send all near matches to the list
181 // (emit a filterNearMatch signal for each one)
184 sel_it = nearMatches.begin();
186 while ( sel_it != nearMatches.end() )
188 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
192 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
194 emit filterFinished();
199 YQPkgRepoList::addRepo( ZyppRepo repo )
201 new YQPkgRepoListItem( this, repo );
206 YQPkgRepoList::selection() const
208 Q3ListViewItem * item = selectedItem();
213 return dynamic_cast<YQPkgRepoListItem *> (item);
221 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
223 : QY2ListViewItem( repoList )
224 , _repoList( repoList )
227 if ( nameCol() >= 0 )
229 string name = repo.info().name();
231 #if SHOW_SINGLE_PRODUCT
232 ZyppProduct product = singleProduct( _zyppRepo );
234 if ( product ) // only if the repository provides exactly one product
235 { // (which is the most common case)
236 name = product->summary();
240 if ( ! name.empty() )
241 setText( nameCol(), fromUTF8( name ));
248 if ( ! repo.info().baseUrlsEmpty() )
249 repoUrl = *repo.info().baseUrlsBegin();
251 setText( urlCol(), repoUrl.asString().c_str() );
257 YQPkgRepoListItem::~YQPkgRepoListItem()
264 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
268 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
271 // Find the first product on this repository
274 while ( it != zyppRepo.resolvables().end() && ! product )
276 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
281 // Check if there is another product on this repository
284 while ( it != zyppRepo.resolvables().end() )
286 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
288 y2milestone( "Multiple products in repository %s",
289 zyppRepo.info().alias().c_str() );
298 y2milestone( "No product in repository %s",
299 zyppRepo.info().alias().c_str() );
306 #include "YQPkgRepoList.moc"