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" );
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( currentItemChanged() ),
57 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()
111 y2milestone( "Collecting packages in selected repositories..." );
117 // Collect all packages on this repository
120 set<ZyppSel> exactMatches;
121 set<ZyppSel> nearMatches;
123 Q3ListViewItem * item = firstChild(); // take multi selection into account
127 if ( item->isSelected() )
129 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
133 ZyppRepo currentRepo = repoItem->zyppRepo();
135 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
136 sel_it != zyppPkgEnd();
139 if ( (*sel_it)->candidateObj() &&
140 (*sel_it)->candidateObj()->repository() == currentRepo )
142 exactMatches.insert( *sel_it );
146 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
148 while ( pkg_it != (*sel_it)->availableEnd() )
150 if ( (*pkg_it)->repository() == currentRepo )
151 nearMatches.insert( *sel_it );
161 item = item->nextSibling();
166 // Send all exact matches to the list
167 // (emit a filterMatch signal for each one)
170 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
172 while ( sel_it != exactMatches.end() )
174 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
175 nearMatches.erase( *sel_it );
181 // Send all near matches to the list
182 // (emit a filterNearMatch signal for each one)
185 sel_it = nearMatches.begin();
187 while ( sel_it != nearMatches.end() )
189 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
193 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
195 emit filterFinished();
201 YQPkgRepoList::addRepo( ZyppRepo repo )
203 new YQPkgRepoListItem( this, repo );
208 YQPkgRepoList::selection() const
211 Q3ListViewItem * item = selectedItem();
216 return dynamic_cast<YQPkgRepoListItem *> (item);
227 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
229 : QY2ListViewItem( repoList )
230 , _repoList( repoList )
233 if ( nameCol() >= 0 )
235 string name = repo.info().name();
237 #if SHOW_SINGLE_PRODUCT
238 ZyppProduct product = singleProduct( _zyppRepo );
240 if ( product ) // only if the repository provides exactly one product
241 { // (which is the most common case)
242 name = product->summary();
246 if ( ! name.empty() )
247 setText( nameCol(), fromUTF8( name ));
254 if ( ! repo.info().baseUrlsEmpty() )
255 repoUrl = *repo.info().baseUrlsBegin();
257 setText( urlCol(), repoUrl.asString().c_str() );
263 YQPkgRepoListItem::~YQPkgRepoListItem()
270 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
274 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
277 // Find the first product on this repository
280 while ( it != zyppRepo.resolvables().end() && ! product )
282 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
287 // Check if there is another product on this repository
290 while ( it != zyppRepo.resolvables().end() )
292 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
294 y2milestone( "Multiple products in repository %s",
295 zyppRepo.info().alias().c_str() );
304 y2milestone( "No product in repository %s",
305 zyppRepo.info().alias().c_str() );
312 #include "YQPkgRepoList.moc"