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