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