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>
29 #include "YQPkgRepoList.h"
39 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
40 : QY2ListView( parent )
42 y2debug( "Creating repository list" );
49 // Column headers for repository list
50 addColumn( _( "Name" ) ); _nameCol = numCol++;
51 addColumn( _( "URL" ) ); _urlCol = numCol++;
53 setAllColumnsShowFocus( true );
54 setSelectionMode( Q3ListView::Extended ); // allow multi-selection with Ctrl-mouse
56 connect( this, SIGNAL( selectionChanged() ),
57 this, SLOT ( filterIfVisible()) );
62 y2debug( "Creating repository list done" );
66 YQPkgRepoList::~YQPkgRepoList()
73 YQPkgRepoList::fillList()
76 y2debug( "Filling repository list" );
78 for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
79 it != ZyppRepositoriesEnd();
85 y2debug( "Inst repository filled" );
90 YQPkgRepoList::countEnabledRepositories()
92 return zyppPool().knownRepositoriesSize();
97 YQPkgRepoList::filterIfVisible()
105 YQPkgRepoList::filter()
109 y2milestone( "Collecting packages in selected repositories..." );
115 // Collect all packages on this repository
118 set<ZyppSel> exactMatches;
119 set<ZyppSel> nearMatches;
121 Q3ListViewItem * item = firstChild(); // take multi selection into account
125 if ( item->isSelected() )
127 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
131 ZyppRepo currentRepo = repoItem->zyppRepo();
133 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
134 sel_it != zyppPkgEnd();
137 if ( (*sel_it)->candidateObj() &&
138 (*sel_it)->candidateObj()->repository() == currentRepo )
140 exactMatches.insert( *sel_it );
144 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
146 while ( pkg_it != (*sel_it)->availableEnd() )
148 if ( (*pkg_it)->repository() == currentRepo )
149 nearMatches.insert( *sel_it );
159 item = item->nextSibling();
164 // Send all exact matches to the list
165 // (emit a filterMatch signal for each one)
168 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
170 while ( sel_it != exactMatches.end() )
172 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
173 nearMatches.erase( *sel_it );
179 // Send all near matches to the list
180 // (emit a filterNearMatch signal for each one)
183 sel_it = nearMatches.begin();
185 while ( sel_it != nearMatches.end() )
187 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
191 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
193 emit filterFinished();
198 YQPkgRepoList::addRepo( ZyppRepo repo )
200 new YQPkgRepoListItem( this, repo );
205 YQPkgRepoList::selection() const
207 Q3ListViewItem * item = selectedItem();
212 return dynamic_cast<YQPkgRepoListItem *> (item);
220 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
222 : QY2ListViewItem( repoList )
223 , _repoList( repoList )
226 if ( nameCol() >= 0 )
228 string name = repo.info().name();
230 #if SHOW_SINGLE_PRODUCT
231 ZyppProduct product = singleProduct( _zyppRepo );
233 if ( product ) // only if the repository provides exactly one product
234 { // (which is the most common case)
235 name = product->summary();
239 if ( ! name.empty() )
240 setText( nameCol(), fromUTF8( name ));
247 if ( ! repo.info().baseUrlsEmpty() )
248 repoUrl = *repo.info().baseUrlsBegin();
250 setText( urlCol(), repoUrl.asString().c_str() );
256 YQPkgRepoListItem::~YQPkgRepoListItem()
263 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
267 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
270 // Find the first product on this repository
273 while ( it != zyppRepo.resolvables().end() && ! product )
275 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
280 // Check if there is another product on this repository
283 while ( it != zyppRepo.resolvables().end() )
285 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
287 y2milestone( "Multiple products in repository %s",
288 zyppRepo.info().alias().c_str() );
297 y2milestone( "No product in repository %s",
298 zyppRepo.info().alias().c_str() );
305 #include "YQPkgRepoList.moc"