libyui-ncurses-pkg  2.48.2
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 
69 NCPkgFilterClassification::NCPkgFilterClassification( YWidget *parent, NCPackageSelector *pkg )
70  :NCSelectionBox( parent, "" )
71  ,packager(pkg)
72 {
73  // fill seclection box
74  recommended = new YItem( _("Recommended") );
75  addItem( recommended );
76 
77  suggested = new YItem( _("Suggested") );
78  addItem( suggested );
79 
80  orphaned = new YItem( _("Orphaned") );
81  addItem( orphaned );
82 
83  unneeded = new YItem( _("Unneeded" ) );
84  addItem( unneeded );
85 
86  showPackages();
87  showDescription();
88 }
89 
91 {
92  int index = getCurrentItem();
93 
94  return itemAt( index );
95 
96 }
97 
99 {
100  NCPkgTable * packageList = packager->PackageList();
101 
102  YItem * group = getCurrentGroup();
103 
104  if ( !group )
105  return false;
106 
107  if ( !packageList )
108  {
109  yuiError() << "No valid NCPkgTable widget" << endl;
110  return false;
111  }
112 
113  // clear the package table
114  packageList->itemsCleared ();
115 
116  for ( ZyppPoolIterator it = zyppPkgBegin();
117  it != zyppPkgEnd();
118  ++it )
119  {
120  ZyppSel selectable = *it;
121  bool match = false;
122 
123  // If there is an installed obj, check this first. The bits are set for the installed
124  // obj only and the installed obj is not contained in the pick list if there in an
125  // identical candidate available from a repo.
126  if ( selectable->installedObj() )
127  {
128  match = check( selectable, tryCastToZyppPkg( selectable->installedObj() ), group );
129  }
130  // And then check the pick list which contain all availables and all objects for multi
131  // version packages and the installed obj if there isn't same version in a repo.
132  if ( !match )
133  {
134  zypp::ui::Selectable::picklist_iterator it = selectable->picklistBegin();
135  while ( it != selectable->picklistEnd() && !match )
136  {
137  check( selectable, tryCastToZyppPkg( *it ), group );
138  ++it;
139  }
140  }
141  }
142 
143  // show the package list
144  packageList->setCurrentItem( 0 );
145  packageList->drawList();
146  packageList->showInformation();
147 
148  yuiMilestone() << "Filling package list \"" << group->label() << "\"" << endl;
149 
150  return true;
151 }
152 
153 bool NCPkgFilterClassification::check( ZyppSel selectable, ZyppPkg pkg, YItem * group )
154 {
155  NCPkgTable * packageList = packager->PackageList();
156 
157  // log solver bits, e.g. I__s_ou(668)libcogl11-1.12.0-1.2.i586(@System)
158  yuiDebug() << zypp::PoolItem(pkg) << endl;
159 
160  if ( !packageList || !selectable || !pkg )
161  {
162  yuiError() << "No valid data" << endl;
163  return false;
164  }
165 
166  if ( group == recommended &&
167  zypp::PoolItem(pkg).status().isRecommended() )
168  {
169  packageList->createListEntry( pkg, selectable );
170  return true;
171  }
172  if ( group == suggested &&
173  zypp::PoolItem(pkg).status().isSuggested() )
174  {
175  packageList->createListEntry( pkg, selectable );
176  return true;
177  }
178  if ( group == orphaned &&
179  zypp::PoolItem(pkg).status().isOrphaned() )
180  {
181  packageList->createListEntry( pkg, selectable );
182  return true;
183  }
184  if ( group == unneeded &&
185  zypp::PoolItem(pkg).status().isUnneeded() )
186  {
187  packageList->createListEntry( pkg, selectable );
188  return true;
189  }
190 
191  return false;
192 }
193 
194 
195 void NCPkgFilterClassification::showDescription( )
196 {
197  std::string description;
198 
199  YItem * group = getCurrentGroup();
200 
201  if ( group == recommended )
202  {
203  description = _("This is a list of useful packages. They will be additionally installed if recommeded by a newly installed package.");
204  }
205  else if ( group == suggested )
206  {
207  description = _("It's suggested to install these packages because they fit to already installed packages. The decision to install it is by the user.");
208  }
209  else if ( group == orphaned )
210  {
211  description = _("The solver has detected that these packages are without a repository, i.e. updates aren't possible.");
212  }
213  else if ( group == unneeded )
214  {
215  description = _("These packages might be unneeded because former dependencies don't apply any longer.");
216  }
217  packager->FilterDescription()->setText ( description );
218 }
219 
220 ///////////////////////////////////////////////////////////////////
221 //
222 //
223 // METHOD NAME : NCPkgFilterRepo::wHandleInput
224 // METHOD TYPE : NCursesEvent
225 //
226 // DESCRIPTION : show packages for selected group
227 //
228 
229 NCursesEvent NCPkgFilterClassification::wHandleInput( wint_t ch )
230 {
231  NCursesEvent ret = NCursesEvent::none;
232  handleInput( ch );
233 
234  switch ( ch )
235  {
236  case KEY_UP:
237  case KEY_DOWN:
238  case KEY_NPAGE:
239  case KEY_PPAGE:
240  case KEY_END:
241  case KEY_HOME: {
242  ret = NCursesEvent::handled;
243  showPackages();
244  showDescription();
245  break;
246  }
247 
248  default:
249  ret = NCSelectionBox::wHandleInput( ch ) ;
250  }
251 
252  return ret;
253 }
254 
bool showPackages()
Fill package list.
bool showInformation()
Show the corresponding information (e.g.
Definition: NCPkgTable.cc:762
The package table class.
Definition: NCPkgTable.h:175
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:550
YItem * getCurrentGroup()
Get currently selected package group item.
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:184
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:263