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