libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
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  // filter packages (like done in YQPkgPackageKitGroupsFilterView::filter())
117  for ( ZyppPoolIterator it = zyppPkgBegin();
118  it != zyppPkgEnd();
119  ++it )
120  {
121  ZyppSel selectable = *it;
122 
123  // Multiple instances of this package may or may not be in the same
124  // group, so let's check both the installed version (if there
125  // is any) and the candidate version.
126  //
127  // Make sure to add only one package entry if both exist and both are
128  // in the same group.
129  // We don't want multiple list entries for the same package!
130 
131  bool match =
132  check( selectable, tryCastToZyppPkg( selectable->candidateObj() ), group ) ||
133  check( selectable, tryCastToZyppPkg( selectable->installedObj() ), group );
134 
135  // If there is neither an installed nor a candidate package, check
136  // any other instance.
137 
138  if ( ! match &&
139  ! selectable->candidateObj() &&
140  ! selectable->installedObj() )
141  check( selectable, tryCastToZyppPkg( selectable->theObj() ), group );
142  }
143 
144  // show the package list
145  packageList->setCurrentItem( 0 );
146  packageList->drawList();
147  packageList->showInformation();
148 
149  yuiMilestone() << "Filling package list \"" << group->label() << "\"" << endl;
150 
151  return true;
152 }
153 
154 bool NCPkgFilterClassification::check( ZyppSel selectable, ZyppPkg pkg, YItem * group )
155 {
156  NCPkgTable * packageList = packager->PackageList();
157 
158  if ( !packageList )
159  {
160  yuiError() << "No valid package table widget" << endl;
161  return false;
162  }
163 
164  if ( group == recommended &&
165  zypp::PoolItem(pkg).status().isRecommended() )
166  {
167  packageList->createListEntry( pkg, selectable );
168  return true;
169  }
170  if ( group == suggested &&
171  zypp::PoolItem(pkg).status().isSuggested() )
172  {
173  packageList->createListEntry( pkg, selectable );
174  return true;
175  }
176  if ( group == orphaned &&
177  zypp::PoolItem(pkg).status().isOrphaned() )
178  {
179  packageList->createListEntry( pkg, selectable );
180  return true;
181  }
182  if ( group == unneeded &&
183  zypp::PoolItem(pkg).status().isUnneeded() )
184  {
185  packageList->createListEntry( pkg, selectable );
186  return true;
187  }
188 
189  return false;
190 }
191 
192 
193 void NCPkgFilterClassification::showDescription( )
194 {
195  std::string description;
196 
197  YItem * group = getCurrentGroup();
198 
199  if ( group == recommended )
200  {
201  description = _("This is a list of useful packages. They will be additionally installed if recommeded by a newly installed package. To get packages recommeded by already installed packages the option <b>Install Recommended Packages for Already Installed Packages</b> from <b>Dependencies</b> menu has to be set.");
202  }
203  else if ( group == suggested )
204  {
205  description = _("It's suggested to install these packages because they fit to already installed packages. The decision to install it is by the user.");
206  }
207  else if ( group == orphaned )
208  {
209  description = _("The solver has detected that these packages are without a repository, i.e. updates aren't possible.");
210  }
211  else if ( group == unneeded )
212  {
213  description = _("These packages might be unneeded because former dependencies don't apply any longer.");
214  }
215  packager->FilterDescription()->setText ( description );
216 }
217 
218 ///////////////////////////////////////////////////////////////////
219 //
220 //
221 // METHOD NAME : NCPkgFilterRepo::wHandleInput
222 // METHOD TYPE : NCursesEvent
223 //
224 // DESCRIPTION : show packages for selected group
225 //
226 
227 NCursesEvent NCPkgFilterClassification::wHandleInput( wint_t ch )
228 {
229  NCursesEvent ret = NCursesEvent::none;
230  handleInput( ch );
231 
232  switch ( ch )
233  {
234  case KEY_UP:
235  case KEY_DOWN:
236  case KEY_NPAGE:
237  case KEY_PPAGE:
238  case KEY_END:
239  case KEY_HOME: {
240  ret = NCursesEvent::handled;
241  showPackages();
242  showDescription();
243  break;
244  }
245 
246  default:
247  ret = NCSelectionBox::wHandleInput( ch ) ;
248  }
249 
250  return ret;
251 }
252