libyui-ncurses-pkg  2.50.7
NCPkgFilterClassification.cc
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
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
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgFilterRepo.cc
37 
38  Author: Gabriele Mohr <gs@suse.com>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "NCPkgFilterClassification.h"
45 
46 #include "YDialog.h"
47 #include "NCLayoutBox.h"
48 #include "NCSpacing.h"
49 #include "NCPackageSelector.h"
50 
51 #include "NCZypp.h"
52 
53 using std::endl;
54 
55 /*
56  Textdomain "ncurses-pkg"
57 */
58 
59 
60 ///////////////////////////////////////////////////////////////////
61 //
62 //
63 // METHOD NAME : NCPkgFilterClassification::NCPkgFilterClassification
64 // METHOD TYPE : Constructor
65 //
66 // DESCRIPTION :
67 //
68 
70  :NCSelectionBox( parent, "" )
71  , packager( pkg )
72 {
73  // fill selection box
74  suggested = new YItem( _("Suggested Packages") );
75  addItem( suggested );
76 
77  recommended = new YItem( _("Recommended Packages") );
78  addItem( recommended );
79 
80  orphaned = new YItem( _("Orphaned Packages") );
81  addItem( orphaned );
82 
83  unneeded = new YItem( _("Unneeded Packages" ) );
84  addItem( unneeded );
85 
86  multiversion = new YItem( _("Multiversion Packages" ) );
87  addItem( multiversion );
88 
89  retracted = new YItem( _("Retracted Packages" ) );
90  addItem( retracted );
91 
92  retractedInstalled = new YItem( _("Retracted Installed Packages" ) );
93  addItem( retractedInstalled );
94 
95  all = new YItem( _("All Packages" ) );
96  addItem( all );
97 
98  showPackages();
99  showDescription();
100 }
101 
102 
103 bool NCPkgFilterClassification::showPackages()
104 {
105  NCPkgTable * packageList = packager->PackageList();
106  YItem * pkgClass = currentPkgClass();
107  yuiMilestone() << "Showing pkg class: " << pkgClass->label() << endl;
108 
109  if ( !pkgClass )
110  return false;
111 
112  if ( !packageList )
113  {
114  yuiError() << "No valid NCPkgTable widget" << endl;
115  return false;
116  }
117 
118  // clear the package table
119  packageList->itemsCleared();
120 
121  for ( ZyppPoolIterator it = zyppPkgBegin();
122  it != zyppPkgEnd();
123  ++it )
124  {
125  ZyppSel selectable = *it;
126  bool match = false;
127 
128  // If there is an installed obj, check this first. The bits are set for the installed
129  // obj only and the installed obj is not contained in the pick list if there in an
130  // identical candidate available from a repo.
131  if ( selectable->installedObj() )
132  {
133  match = check( selectable, tryCastToZyppPkg( selectable->installedObj() ), pkgClass );
134  }
135  // otherwise display the candidate object (the "best" version)
136  else if ( selectable->hasCandidateObj() )
137  {
138  match = check( selectable, tryCastToZyppPkg( selectable->candidateObj() ), pkgClass );
139  }
140 
141  // And then check the pick list which contain all availables and all objects for multi
142  // version packages and the installed obj if there isn't same version in a repo.
143  if ( !match )
144  {
145  zypp::ui::Selectable::picklist_iterator it = selectable->picklistBegin();
146  while ( it != selectable->picklistEnd() && !match )
147  {
148  check( selectable, tryCastToZyppPkg( *it ), pkgClass );
149  ++it;
150  }
151  }
152  }
153 
154  // show the package list
155  packageList->setCurrentItem( 0 );
156  packageList->drawList();
157  packageList->showInformation();
158 
159  int pkgCount = packageList->getNumLines();
160 
161  if ( pkgCount == 0 )
162  packager->clearInfoArea();
163 
164  yuiMilestone() << "Filling package list \"" << pkgClass->label() << "\"" << endl;
165 
166  return true;
167 }
168 
169 
170 void NCPkgFilterClassification::showRetractedInstalled()
171 {
172  selectItem( retractedInstalled, true );
173  showPackages();
174  showDescription();
175 }
176 
177 
178 bool NCPkgFilterClassification::check( ZyppSel selectable, ZyppPkg pkg, YItem * pkgClass )
179 {
180  NCPkgTable * packageList = packager->PackageList();
181 
182  // log solver bits, e.g. I__s_ou(668)libcogl11-1.12.0-1.2.i586(@System)
183  yuiDebug() << zypp::PoolItem( pkg ) << endl;
184 
185  if ( !packageList || !selectable || !pkg )
186  {
187  yuiError() << "No valid data" << endl;
188  return false;
189  }
190 
191  bool match = false;
192 
193  if ( pkgClass == all ) match = true;
194  else if ( pkgClass == recommended ) match = zypp::PoolItem( pkg ).status().isRecommended();
195  else if ( pkgClass == suggested ) match = zypp::PoolItem( pkg ).status().isSuggested();
196  else if ( pkgClass == orphaned ) match = zypp::PoolItem( pkg ).status().isOrphaned();
197  else if ( pkgClass == unneeded ) match = zypp::PoolItem( pkg ).status().isUnneeded();
198  else if ( pkgClass == multiversion ) match = selectable->multiversionInstall();
199  else if ( pkgClass == retracted ) match = selectable->hasRetracted();
200  else if ( pkgClass == retractedInstalled ) match = selectable->hasRetractedInstalled();
201 
202  if ( match )
203  packageList->createListEntry( pkg, selectable );
204 
205  return match;
206 }
207 
208 
209 void NCPkgFilterClassification::showDescription()
210 {
211  std::string description;
212  YItem * pkgClass = currentPkgClass();
213 
214  if ( pkgClass == recommended )
215  {
216  description = _("This is a list of useful packages. They will be additionally installed if recommended by a newly installed package.");
217  }
218  else if ( pkgClass == suggested )
219  {
220  description = _("It's suggested to install these packages because they fit to already installed packages. The decision to install it is by the user.");
221  }
222  else if ( pkgClass == orphaned )
223  {
224  description = _("The solver has detected that these packages are without a repository, i.e. updates aren't possible.");
225  }
226  else if ( pkgClass == unneeded )
227  {
228  description = _("These packages might be unneeded because former dependencies don't apply any longer.");
229  }
230  else if ( pkgClass == multiversion )
231  {
232  description = _("These packages might be installed in several versions in parallel.");
233  }
234  else if ( pkgClass == retracted )
235  {
236  description = _("These packages have versions that are retracted. Using those versions is strongly discouraged.");
237  }
238  else if ( pkgClass == retractedInstalled )
239  {
240  description = _("These packages have a retracted version installed. Consider up- or downgrading them to a different version.");
241  }
242  else if ( pkgClass == all )
243  {
244  description = _("All packages known by the package manager, no filtering applied.");
245  }
246 
247  packager->FilterDescription()->setText ( description );
248 }
249 
250 
251 YItem * NCPkgFilterClassification::currentPkgClass() const
252 {
253  int index = getCurrentItem();
254 
255  return itemAt( index );
256 }
257 
258 
259 void NCPkgFilterClassification::setCurrentPkgClass( YItem * item )
260 {
261  int index = itemIndex( item );
262 
263  if ( index >= 0 )
264  setCurrentItem( index );
265 }
266 
267 
268 int NCPkgFilterClassification::itemIndex( YItem * item ) const
269 {
270  for ( int i=0; i < itemsCount(); ++i )
271  {
272  if ( itemAt( i ) == item )
273  return i;
274  }
275 
276  return -1;
277 }
278 
279 
280 NCursesEvent NCPkgFilterClassification::wHandleInput( wint_t ch )
281 {
282  NCursesEvent ret = NCursesEvent::none;
283  handleInput( ch );
284 
285  switch ( ch )
286  {
287  case KEY_UP:
288  case KEY_DOWN:
289  case KEY_NPAGE:
290  case KEY_PPAGE:
291  case KEY_END:
292  case KEY_HOME:
293  ret = NCursesEvent::handled;
294  showPackages();
295  showDescription();
296  break;
297 
298  default:
299  ret = NCSelectionBox::wHandleInput( ch );
300  break;
301  }
302 
303  return ret;
304 }
305 
bool showInformation()
Show the corresponding information (e.g.
Definition: NCPkgTable.cc:731
The package table class.
Definition: NCPkgTable.h:205
NCPkgFilterClassification(YWidget *parent, NCPackageSelector *pkg)
A helper class to hold repository data in a neat table widget.
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:516
unsigned int getNumLines()
Returns the number of lines in the table (the table size)
Definition: NCPkgTable.h:417
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:159
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:296