1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgRepoList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
24 #include <qdatetime.h>
26 #define y2log_component "qt-pkg"
27 #include <ycp/y2log.h>
28 #include <zypp/RepoManager.h>
31 #include "YQPkgRepoList.h"
41 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
42 : QY2ListView( parent )
44 y2debug( "Creating repository list" );
51 // Column headers for repository list
52 addColumn( _( "Name" ) ); _nameCol = numCol++;
53 addColumn( _( "URL" ) ); _urlCol = numCol++;
55 setAllColumnsShowFocus( true );
56 setSelectionMode( Q3ListView::Extended ); // allow multi-selection with Ctrl-mouse
58 connect( this, SIGNAL( currentItemChanged() ),
59 this, SLOT ( filterIfVisible()) );
65 y2debug( "Creating repository list done" );
69 YQPkgRepoList::~YQPkgRepoList()
76 YQPkgRepoList::fillList()
79 y2debug( "Filling repository list" );
81 for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
82 it != ZyppRepositoriesEnd();
88 y2debug( "Inst repository filled" );
93 YQPkgRepoList::countEnabledRepositories()
95 return zyppPool().knownRepositoriesSize();
100 YQPkgRepoList::filterIfVisible()
108 YQPkgRepoList::filter()
113 y2milestone( "Collecting packages in selected repositories..." );
119 // Collect all packages on this repository
122 set<ZyppSel> exactMatches;
123 set<ZyppSel> nearMatches;
125 Q3ListViewItem * item = firstChild(); // take multi selection into account
129 if ( item->isSelected() )
131 YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
135 ZyppRepo currentRepo = repoItem->zyppRepo();
137 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
138 sel_it != zyppPkgEnd();
141 if ( (*sel_it)->candidateObj() &&
142 (*sel_it)->candidateObj()->repository() == currentRepo )
144 exactMatches.insert( *sel_it );
148 zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
150 while ( pkg_it != (*sel_it)->availableEnd() )
152 if ( (*pkg_it)->repository() == currentRepo )
153 nearMatches.insert( *sel_it );
163 item = item->nextSibling();
168 // Send all exact matches to the list
169 // (emit a filterMatch signal for each one)
172 set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
174 while ( sel_it != exactMatches.end() )
176 emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
177 nearMatches.erase( *sel_it );
183 // Send all near matches to the list
184 // (emit a filterNearMatch signal for each one)
187 sel_it = nearMatches.begin();
189 while ( sel_it != nearMatches.end() )
191 emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
195 y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
197 emit filterFinished();
203 YQPkgRepoList::addRepo( ZyppRepo repo )
205 new YQPkgRepoListItem( this, repo );
210 YQPkgRepoList::selection() const
213 Q3ListViewItem * item = selectedItem();
218 return dynamic_cast<YQPkgRepoListItem *> (item);
229 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList * repoList,
231 : QY2ListViewItem( repoList )
232 , _repoList( repoList )
235 if ( nameCol() >= 0 )
237 string name = repo.info().name();
239 #if SHOW_SINGLE_PRODUCT
240 ZyppProduct product = singleProduct( _zyppRepo );
242 if ( product ) // only if the repository provides exactly one product
243 { // (which is the most common case)
244 name = product->summary();
248 if ( ! name.empty() )
249 setText( nameCol(), fromUTF8( name ));
256 if ( ! repo.info().baseUrlsEmpty() )
257 repoUrl = *repo.info().baseUrlsBegin();
259 setText( urlCol(), repoUrl.asString().c_str() );
265 YQPkgRepoListItem::~YQPkgRepoListItem()
272 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
276 zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
279 // Find the first product on this repository
282 while ( it != zyppRepo.resolvables().end() && ! product )
284 product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
289 // Check if there is another product on this repository
292 while ( it != zyppRepo.resolvables().end() )
294 if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
296 y2milestone( "Multiple products in repository %s",
297 zyppRepo.info().alias().c_str() );
306 y2milestone( "No product in repository %s",
307 zyppRepo.info().alias().c_str() );
314 #include "YQPkgRepoList.moc"