libyui-qt-pkg  2.42.5
 All Classes Functions Variables Enumerations
YQPkgRepoList.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgRepoList.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #include <algorithm>
43 #include <QDateTime>
44 #include <QHeaderView>
45 
46 #define YUILogComponent "qt-pkg"
47 #include "YUILog.h"
48 #include <zypp/RepoManager.h>
49 #include <zypp/PoolQuery.h>
50 
51 #include <QTreeWidget>
52 #include "YQPkgRepoList.h"
53 #include "YQi18n.h"
54 #include "utf8.h"
55 
56 using std::string;
57 using std::list;
58 using std::endl;
59 using std::set;
60 using std::vector;
61 
62 
63 YQPkgRepoList::YQPkgRepoList( QWidget * parent )
64  : QY2ListView( parent )
65 {
66  yuiDebug() << "Creating repository list" << endl;
67 
68  _nameCol = -1;
69  _urlCol = -1;
70 
71  int numCol = 0;
72 
73  QStringList headers;
74 
75  // Column headers for repository list
76  headers << _( "Name"); _nameCol = numCol++;
77  // headers << _( "URL"); _urlCol = numCol++;
78 
79  setHeaderLabels( headers );
80  header()->setResizeMode( _nameCol, QHeaderView::Stretch );
81 
82  //setAllColumnsShowFocus( true );
83  setSelectionMode( QAbstractItemView::ExtendedSelection ); // allow multi-selection with Ctrl-mouse
84 
85  connect( this, SIGNAL( itemSelectionChanged() ),
86  this, SLOT ( filterIfVisible()) );
87  setIconSize(QSize(32,32));
88  fillList();
89  setSortingEnabled( true );
90  sortByColumn( nameCol(), Qt::AscendingOrder );
91  selectSomething();
92 
93  yuiDebug() << "Creating repository list done" << endl;
94 }
95 
96 
98 {
99  // NOP
100 }
101 
102 
103 void
105 {
106  clear();
107  yuiDebug() << "Filling repository list" << endl;
108 
109  for ( ZyppRepositoryIterator it = ZyppRepositoriesBegin();
110  it != ZyppRepositoriesEnd();
111  ++it )
112  {
113  addRepo( *it );
114  }
115 
116  yuiDebug() << "Inst repository filled" << endl;
117 }
118 
119 
120 int
122 {
123  return zyppPool().knownRepositoriesSize();
124 }
125 
126 
127 void
129 {
130  if ( isVisible() )
131  filter();
132 }
133 
134 
135 void
137 {
138  emit filterStart();
139 
140  yuiMilestone() << "Collecting packages in selected repositories..." << endl;
141  QTime stopWatch;
142  stopWatch.start();
143 
144 
145  //
146  // Collect all packages on this repository
147  //
148 
149  QTreeWidgetItem * item;
150 
151  QList<QTreeWidgetItem *> items = selectedItems();
152  QListIterator<QTreeWidgetItem *> it(items);
153 
154  while ( it.hasNext() )
155  {
156  item = it.next();
157  YQPkgRepoListItem * repoItem = dynamic_cast<YQPkgRepoListItem *> (item);
158 
159  if ( repoItem )
160  {
161  ZyppRepo currentRepo = repoItem->zyppRepo();
162 
163  zypp::PoolQuery query;
164  query.addRepo( currentRepo.info().alias() );
165  query.addKind(zypp::ResKind::package);
166 
167  for( zypp::PoolQuery::Selectable_iterator it = query.selectableBegin();
168  it != query.selectableEnd(); it++)
169  {
170  emit filterMatch( *it, tryCastToZyppPkg( (*it)->theObj() ) );
171  }
172  }
173  }
174 
175  yuiDebug() << "Packages sent to package list. Elapsed time: "
176  << stopWatch.elapsed() / 1000.0 << " sec"
177  << endl;
178 
179  emit filterFinished();
180 }
181 
182 
183 void
184 YQPkgRepoList::addRepo( ZyppRepo repo )
185 {
186  new YQPkgRepoListItem( this, repo );
187 }
188 
189 
192 {
193  QTreeWidgetItem * item = currentItem();
194 
195  if ( ! item )
196  return 0;
197 
198  return dynamic_cast<YQPkgRepoListItem *> (item);
199 }
200 
201 
202 
203 
204 
205 
207  ZyppRepo repo )
208  : QY2ListViewItem( repoList )
209  , _repoList( repoList )
210  , _zyppRepo( repo )
211 {
212  if ( nameCol() >= 0 )
213  {
214  string name = repo.info().name();
215  if ( ! name.empty() )
216  {
217  setText( nameCol(), fromUTF8( name ));
218  }
219  }
220 
221  std::string infoToolTip;
222  infoToolTip += ("<b>" + repo.info().name() + "</b>");
223 
224  ZyppProduct product = singleProduct( _zyppRepo );
225  if ( product )
226  {
227  infoToolTip += ("<p>" + product->summary() + "</p>");
228  }
229 
230  if ( ! repo.info().baseUrlsEmpty() )
231  {
232  zypp::RepoInfo::urls_const_iterator it;
233  infoToolTip += "<ul>";
234 
235  for ( it = repo.info().baseUrlsBegin();
236  it != repo.info().baseUrlsEnd();
237  ++it )
238  {
239  infoToolTip += ("<li>" + (*it).asString() + "</li>");
240  }
241  infoToolTip += "</ul>";
242  }
243  setToolTip( nameCol(), fromUTF8(infoToolTip) );
244 
245  QString iconPath;
246  QString iconName = "yast-sw_source";
247 
248  if ( ! repo.info().baseUrlsEmpty() )
249  {
250  zypp::Url repoUrl = *repo.info().baseUrlsBegin();
251 
252  if ( urlCol() >= 0 )
253  {
254  setText( urlCol(), repoUrl.asString().c_str() );
255  }
256 
257  if (QString(repoUrl.asString().c_str()).contains("KDE") )
258  iconName = "pattern-kde";
259  if (QString(repoUrl.asString().c_str()).contains("GNOME") )
260  iconName = "pattern-gnome";
261  if (QString(repoUrl.asString().c_str()).contains("KDE") )
262  iconName = "pattern-kde";
263  if (QString(repoUrl.asString().c_str()).contains("update") )
264  iconName = "yast-update";
265  if (QString(repoUrl.asString().c_str()).contains("home:") )
266  iconName = "yast-users";
267  }
268 
269  if ( repo.isSystemRepo() )
270  iconName = "yast-host";
271 
272 
273  setIcon( 0, QIcon( iconPath.sprintf("/usr/share/icons/hicolor/48x48/apps/%s.png", iconName.toUtf8().data()) ));
274 }
275 
276 
277 
279 {
280  // NOP
281 }
282 
283 
284 ZyppProduct
286 {
287  ZyppProduct product;
288 
289  zypp::ResPool::byKind_iterator it = zypp::ResPool::instance().byKindBegin( zypp::ResKind::product );
290  zypp::ResPool::byKind_iterator end = zypp::ResPool::instance().byKindEnd( zypp::ResKind::product );
291 
292  //
293  // Find the first product on this repository
294  //
295 
296  while ( it != end && ! product )
297  {
298  if ( it->resolvable()->repoInfo().alias() == zyppRepo.info().alias() )
299  product = zypp::asKind<zypp::Product>( it->resolvable() );
300  ++it;
301  }
302 
303  //
304  // Check if there is another product on this repository
305  //
306 
307  while ( it != end )
308  {
309  if ( it->resolvable()->repoInfo().alias() == zyppRepo.info().alias() )
310  {
311  yuiMilestone() << "Multiple products in repository "
312  << zyppRepo.info().alias()
313  << endl;
314  ZyppProduct null;
315  return null;
316  }
317 
318  ++it;
319  }
320 
321  if ( ! product )
322  yuiMilestone() << "No product in repository "
323  << zyppRepo.info().alias()
324  << endl;
325 
326  return product;
327 }
328 
329 bool
330 YQPkgRepoListItem::operator< ( const QTreeWidgetItem & other ) const
331 {
332  const YQPkgRepoListItem * otherItem = dynamic_cast<const YQPkgRepoListItem *>(&other);
333 
334  return zyppRepo().info().name() < otherItem->zyppRepo().info().name();
335 }
336 
337 #include "YQPkgRepoList.moc"