]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgRepoList.cc
YQPkgRepoList QT3_SUPPORT
[duncan/yast2-qt4.git] / src / pkg / YQPkgRepoList.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgRepoList.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <algorithm>
22 #include <QDateTime>
23
24 #define y2log_component "qt-pkg"
25 #include <ycp/y2log.h>
26 #include <zypp/RepoManager.h>
27
28 #include <QTreeWidget>
29 #include "YQPkgRepoList.h"
30 #include "YQi18n.h"
31 #include "utf8.h"
32
33 using std::list;
34 using std::set;
35 using std::vector;
36
37
38
39 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
40     : QY2ListView( parent )
41 {
42     y2debug( "Creating repository list" );
43
44     _nameCol    = -1;
45     _urlCol     = -1;
46
47     int numCol = 0;
48 #if FIXME
49     // Column headers for repository list
50     addColumn( _( "Name"        ) );    _nameCol        = numCol++;
51     addColumn( _( "URL"         ) );    _urlCol         = numCol++;
52
53     setAllColumnsShowFocus( true );
54     setSelectionMode( Q3ListView::Extended );   // allow multi-selection with Ctrl-mouse
55
56     connect( this,      SIGNAL( currentItemChanged() ),
57              this,      SLOT  ( filterIfVisible()) );
58
59     fillList();
60     selectSomething();
61 #endif
62
63     y2debug( "Creating repository list done" );
64 }
65
66
67 YQPkgRepoList::~YQPkgRepoList()
68 {
69     // NOP
70 }
71
72
73 void
74 YQPkgRepoList::fillList()
75 {
76     clear();
77     y2debug( "Filling repository list" );
78
79     for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
80           it != ZyppRepositoriesEnd();
81           ++it )
82     {
83         addRepo( *it );
84     }
85
86     y2debug( "Inst repository filled" );
87 }
88
89
90 int
91 YQPkgRepoList::countEnabledRepositories()
92 {
93     return zyppPool().knownRepositoriesSize();
94 }
95
96
97 void
98 YQPkgRepoList::filterIfVisible()
99 {
100     if ( isVisible() )
101         filter();
102 }
103
104
105 void
106 YQPkgRepoList::filter()
107 {
108 #if FIXME
109     emit filterStart();
110
111     y2milestone( "Collecting packages in selected repositories..." );
112     QTime stopWatch;
113     stopWatch.start();
114
115
116     //
117     // Collect all packages on this repository
118     //
119
120     set<ZyppSel> exactMatches;
121     set<ZyppSel> nearMatches;
122
123     Q3ListViewItem * item = firstChild();       // take multi selection into account
124
125     while ( item )
126     {
127         if ( item->isSelected() )
128         {
129             YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
130
131             if ( repoItem )
132             {
133                 ZyppRepo currentRepo = repoItem->zyppRepo();
134
135                 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
136                       sel_it != zyppPkgEnd();
137                       ++sel_it )
138                 {
139                     if ( (*sel_it)->candidateObj() &&
140                          (*sel_it)->candidateObj()->repository() == currentRepo )
141                     {
142                         exactMatches.insert( *sel_it );
143                     }
144                     else
145                     {
146                         zypp::ui::Selectable::available_iterator pkg_it = (*sel_it)->availableBegin();
147
148                         while ( pkg_it != (*sel_it)->availableEnd() )
149                         {
150                             if ( (*pkg_it)->repository() == currentRepo )
151                                 nearMatches.insert( *sel_it );
152
153                             ++pkg_it;
154                         }
155                     }
156                 }
157
158             }
159         }
160
161         item = item->nextSibling();
162     }
163
164
165     //
166     // Send all exact matches to the list
167     // (emit a filterMatch signal for each one)
168     //
169
170     set<ZyppSel>::const_iterator sel_it = exactMatches.begin();
171
172     while ( sel_it != exactMatches.end() )
173     {
174         emit filterMatch( (*sel_it), tryCastToZyppPkg( (*sel_it)->theObj() ) );
175         nearMatches.erase( *sel_it );
176         ++sel_it;
177     }
178
179
180     //
181     // Send all near matches to the list
182     // (emit a filterNearMatch signal for each one)
183     //
184
185     sel_it = nearMatches.begin();
186
187     while ( sel_it != nearMatches.end() )
188     {
189         emit filterNearMatch( *sel_it, tryCastToZyppPkg( (*sel_it)->theObj() ) );
190         ++sel_it;
191     }
192
193     y2debug( "Packages sent to package list. Elapsed time: %f sec", stopWatch.elapsed() / 1000.0 );
194
195     emit filterFinished();
196 #endif
197 }
198
199
200 void
201 YQPkgRepoList::addRepo( ZyppRepo repo )
202 {
203     new YQPkgRepoListItem( this, repo );
204 }
205
206
207 YQPkgRepoListItem *
208 YQPkgRepoList::selection() const
209 {
210 #if FIXME
211     Q3ListViewItem * item = selectedItem();
212
213     if ( ! item )
214         return 0;
215
216     return dynamic_cast<YQPkgRepoListItem *> (item);
217 #else
218     return 0;
219 #endif
220 }
221
222
223
224
225
226
227 YQPkgRepoListItem::YQPkgRepoListItem( YQPkgRepoList *   repoList,
228                                       ZyppRepo          repo    )
229     : QY2ListViewItem( repoList )
230     , _repoList( repoList )
231     , _zyppRepo( repo )
232 {
233     if ( nameCol() >= 0 )
234     {
235         string name = repo.info().name();
236
237 #if SHOW_SINGLE_PRODUCT
238         ZyppProduct product = singleProduct( _zyppRepo );
239
240         if ( product )  // only if the repository provides exactly one product
241         {               // (which is the most common case)
242             name = product->summary();
243         }
244 #endif
245
246         if ( ! name.empty() )
247             setText( nameCol(), fromUTF8( name ));
248     }
249
250     if ( urlCol() >= 0 )
251     {
252         zypp::Url repoUrl;
253
254         if ( ! repo.info().baseUrlsEmpty() )
255             repoUrl = *repo.info().baseUrlsBegin();
256
257         setText( urlCol(), repoUrl.asString().c_str() );
258     }
259 }
260
261
262
263 YQPkgRepoListItem::~YQPkgRepoListItem()
264 {
265     // NOP
266 }
267
268
269 ZyppProduct
270 YQPkgRepoListItem::singleProduct( ZyppRepo zyppRepo )
271 {
272     ZyppProduct product;
273
274     zypp::ResStore::iterator it = zyppRepo.resolvables().begin();
275
276     //
277     // Find the first product on this repository
278     //
279
280     while ( it != zyppRepo.resolvables().end() && ! product )
281     {
282         product = zypp::dynamic_pointer_cast<zypp::Product>( *it );
283         ++it;
284     }
285
286     //
287     // Check if there is another product on this repository
288     //
289
290     while ( it != zyppRepo.resolvables().end() )
291     {
292         if ( zypp::dynamic_pointer_cast<zypp::Product>( *it ) )
293         {
294             y2milestone( "Multiple products in repository %s",
295                          zyppRepo.info().alias().c_str() );
296             ZyppProduct null;
297             return null;
298         }
299
300         ++it;
301     }
302
303     if ( ! product )
304         y2milestone( "No product in repository %s",
305                      zyppRepo.info().alias().c_str() );
306
307     return product;
308 }
309
310
311
312 #include "YQPkgRepoList.moc"