libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
NCPkgPopupTable.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: NCPkgPopupTable.cc
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "YMenuButton.h"
45 #include "YDialog.h"
46 
47 #include "NCLayoutBox.h"
48 #include "NCSpacing.h"
49 #include "NCPkgStrings.h"
50 #include "NCPackageSelector.h"
51 #include "NCLabel.h"
52 #include "NCPushButton.h"
53 #include "NCPkgTable.h"
54 
55 #include "NCZypp.h"
56 #include "NCi18n.h"
57 
58 #include <zypp/ui/Selectable.h>
59 #include <zypp/ui/UserWantedPackages.h>
60 
61 #include "NCPkgPopupTable.h"
62 
63 using std::endl;
64 
65 /*
66  Textdomain "ncurses-pkg"
67 */
68 
69 ///////////////////////////////////////////////////////////////////
70 //
71 //
72 // METHOD NAME : NCPkgPopupTable::NCPkgPopupTable
73 // METHOD TYPE : Constructor
74 //
75 // DESCRIPTION :
76 //
77 NCPkgPopupTable::NCPkgPopupTable( const wpos at, NCPackageSelector * pkger )
78  : NCPopup( at, false )
79  , pkgTable( 0 )
80  , okButton( 0 )
81  , cancelButton( 0 )
82  , packager( pkger )
83 {
84  createLayout( );
85 }
86 
87 ///////////////////////////////////////////////////////////////////
88 //
89 //
90 // METHOD NAME : NCPkgPopupTable::~NCPkgPopupTable
91 // METHOD TYPE : Destructor
92 //
93 // DESCRIPTION :
94 //
95 NCPkgPopupTable::~NCPkgPopupTable()
96 {
97 }
98 
99 ///////////////////////////////////////////////////////////////////
100 //
101 //
102 // METHOD NAME : NCPkgPopupTable::createLayout
103 // METHOD TYPE : void
104 //
105 // DESCRIPTION :
106 //
107 void NCPkgPopupTable::createLayout( )
108 {
109  // the vertical split is the (only) child of the dialog
110  NCLayoutBox * split = new NCLayoutBox( this, YD_VERT );
111 
112  new NCSpacing( split, YD_VERT, false, 0.6 ); // stretchable = false
113 
114  // the headline of the popup containing a list with packages with status changes
115  new NCLabel( split, _( "Automatic Changes" ), true, false ); // isHeading = true
116 
117  new NCSpacing( split, YD_VERT, false, 0.6 );
118 
119  // text part1 of popup with automatic changes (it's a label; text continous)
120  new NCLabel( split, _( "In addition to your manual selections, the following" ), false, false );
121 
122  // text part2 of popup with automatic changes
123  new NCLabel( split, _( "packages have been changed to resolve dependencies:" ), false, false );
124 
125  YTableHeader * tableHeader = new YTableHeader();
126  // add the package table (use default type T_Packages)
127  pkgTable = new NCPkgTable( split, tableHeader );
128  pkgTable->setPackager( packager );
129  pkgTable->fillHeader();
130 
131  // HBox for the buttons
132  NCLayoutBox * hSplit = new NCLayoutBox( split, YD_HORIZ );
133  new NCSpacing( hSplit, YD_HORIZ, true, 0.2 ); // stretchable = true
134 
135  // add the OK button
136  okButton = new NCPushButton( hSplit, NCPkgStrings::OKLabel() );
137  okButton->setFunctionKey( 10 );
138  okButton->setKeyboardFocus();
139 
140  new NCSpacing( hSplit, YD_HORIZ, true, 0.4 );
141 
142  // add the Cancel button
143  cancelButton = new NCPushButton( hSplit, NCPkgStrings::CancelLabel() );
144  cancelButton->setFunctionKey( 9 );
145 
146  new NCSpacing( hSplit, YD_HORIZ, true, 0.2 );
147 
148  new NCSpacing( split, YD_VERT, false, 0.6 );
149 }
150 
151 
152 ///////////////////////////////////////////////////////////////////
153 //
154 //
155 // METHOD NAME : NCPkgPopupTable::fillAutoChanges
156 // METHOD TYPE : bool
157 //
158 // DESCRIPTION :
159 //
160 bool NCPkgPopupTable::fillAutoChanges( NCPkgTable * pkgTable )
161 {
162  if ( !pkgTable )
163  return false;
164 
165  pkgTable->itemsCleared(); // clear the table
166 
167  std::set<std::string> ignoredNames;
168  std::set<std::string> userWantedNames = zypp::ui::userWantedPackageNames();
169  //these are the packages already selected for autoinstallation in previous 'verify system' run
170  std::set<std::string> verifiedNames = packager->getVerifiedPkgs();
171 
172  //initialize storage for the new set
173  std::insert_iterator< std::set<std::string> > result (ignoredNames, ignoredNames.begin());
174 
175  if(!verifiedNames.empty())
176  {
177  //if we have some leftovers from previous run, do the union of the sets
178  set_union(userWantedNames.begin(), userWantedNames.end(),
179  verifiedNames.begin(), verifiedNames.end(), result );
180  }
181  else
182  //else just take userWanted stuff
183  ignoredNames = userWantedNames;
184 
185  for ( std::set<std::string>::iterator it = ignoredNames.begin(); it != ignoredNames.end(); ++it )
186  yuiMilestone() << "Ignoring: " << *it << endl;
187 
188  ZyppPoolIterator
189  b = zyppPkgBegin(),
190  e = zyppPkgEnd(),
191  it;
192 
193  for (it = b; it != e; ++it)
194  {
195  ZyppSel slb = *it;
196 
197  // show all packages which are automatically selected for installation
198  if ( slb->toModify() && slb->modifiedBy () != zypp::ResStatus::USER )
199  {
200  if ( ! inContainer( ignoredNames, slb->name() ) )
201  {
202  ZyppPkg pkgPtr = tryCastToZyppPkg (slb->theObj());
203  if ( pkgPtr )
204  {
205  yuiMilestone() << "The status of " << pkgPtr->name() << " has automatically changed" << endl;
206  pkgTable->createListEntry( pkgPtr, slb );
207  //also add to 'already verified' set
208  packager->insertVerifiedPkg( pkgPtr->name() );
209  }
210  }
211  }
212  }
213 
214  pkgTable->drawList();
215 
216  if ( pkgTable->getNumLines() > 0 )
217  {
218  return true;
219  }
220  else
221  {
222  return false;
223  }
224 }
225 
226 ///////////////////////////////////////////////////////////////////
227 //
228 //
229 // METHOD NAME : NCPkgPopupTable::showInfoPopup
230 // METHOD TYPE : NCursesEvent event
231 //
232 // DESCRIPTION :
233 //
234 NCursesEvent NCPkgPopupTable::showInfoPopup( )
235 {
236  postevent = NCursesEvent();
237 
238  if ( !fillAutoChanges( pkgTable ) )
239  {
240  postevent = NCursesEvent::button;
241  return postevent;
242  }
243 
244  do {
245  // show the popup
246  popupDialog( );
247  } while ( postAgain() );
248 
249  popdownDialog();
250 
251  return postevent;
252 }
253 
254 ///////////////////////////////////////////////////////////////////
255 //
256 //
257 // METHOD NAME : NCPkgPopupTable::preferredWidth
258 // METHOD TYPE : int
259 //
260 int NCPkgPopupTable::preferredWidth()
261 {
262  return NCurses::cols()-15;
263 }
264 
265 ///////////////////////////////////////////////////////////////////
266 //
267 //
268 // METHOD NAME : NCPkgPopupTable::preferredHeight
269 // METHOD TYPE : int
270 //
271 int NCPkgPopupTable::preferredHeight()
272 {
273  return NCurses::lines()-5;
274 }
275 
276 ///////////////////////////////////////////////////////////////////
277 //
278 //
279 // METHOD NAME : NCPopup::wHandleInput
280 // METHOD TYPE : NCursesEvent
281 //
282 // DESCRIPTION :
283 //
284 NCursesEvent NCPkgPopupTable::wHandleInput( wint_t ch )
285 {
286  if ( ch == 27 ) // ESC
287  return NCursesEvent::cancel;
288 
289  if ( ch == KEY_RETURN )
290  return NCursesEvent::button;
291 
292  return NCDialog::wHandleInput( ch );
293 }
294 
295 ///////////////////////////////////////////////////////////////////
296 //
297 //
298 // METHOD NAME : NCPkgPopupTable::postAgain
299 // METHOD TYPE : bool
300 //
301 // DESCRIPTION :
302 //
303 bool NCPkgPopupTable::postAgain()
304 {
305  if ( ! postevent.widget )
306  return false;
307 
308  if ( postevent.widget == cancelButton )
309  {
310  //user hit cancel - discard set of changes (if not empty)
311  packager->clearVerifiedPkgs();
312 
313  // close the dialog
314  postevent = NCursesEvent::cancel;
315  }
316 
317  if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
318  {
319  // return false means: close the popup dialog
320  return false;
321  }
322  return true;
323 }
324