libyui-ncurses-pkg  2.44.4
 All Classes Functions
NCPackageSelector.h
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: NCPackageSelector.h
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #ifndef NCPackageSelector_h
42 #define NCPackageSelector_h
43 
44 #include <iosfwd>
45 
46 #define YUILogComponent "ncurses-pkg"
47 #include <YUILog.h>
48 
49 #include "YNCursesUI.h"
50 #include "NCPkgStrings.h"
51 
52 #include <map>
53 #include <string>
54 #include <utility> // for STL std::pair
55 
56 #include <YRpmGroupsTree.h>
57 #include "YWidgetID.h"
58 
59 #include <zypp/ResObject.h>
60 #include <zypp/ui/Selectable.h>
61 #include <zypp/Patch.h>
62 
63 #include "NCPkgFilterRPMGroups.h"
64 #include "NCPkgFilterSearch.h"
65 #include "NCPkgFilterInstSummary.h"
66 #include "NCPkgTable.h"
67 #include "NCEmpty.h"
68 #include "NCPkgMenuFilter.h"
69 #include "NCPkgPackageDetails.h"
70 #include "NCPkgPopupDeps.h"
71 #include "NCPkgFilterMain.h"
72 #include "NCPkgSearchSettings.h"
73 
74 #include "NCPkgSelMapper.h"
75 
76 class NCPkgFilterPattern;
77 class NCPkgLocaleTable;
78 class NCPkgRepoTable;
79 class LangCode;
80 class NCPkgPopupDeps;
81 class NCPkgDiskspace;
83 class NCPkgFilterSearch;
86 class NCPkgPopupFile;
87 class NCPkgMenuExtras;
88 class NCPkgMenuDeps;
89 class NCPkgMenuAction;
90 class NCPkgMenuConfig;
91 class NCPkgMenuView;
92 class NCPkgMenuHelp;
95 class NCPkgFilterMain;
96 class NCPushButton;
97 class YNCursesUI;
98 class NCMenuButton;
99 class YReplacePoint;
100 
101 inline bool ic_compare ( char c1, char c2 )
102 {
103  return ( toupper( c1 ) == toupper( c2 ) );
104 }
105 
106 #define DOCTYPETAG "<!-- DT:Rich -->" // Special doctype for preformatted HTML
107 
108 ///////////////////////////////////////////////////////////////////
109 //
110 // CLASS NAME : NCPackageSelector
111 //
112 // DESCRIPTION : holds the data and handles events
113 //
115 {
116 
117  friend std::ostream & operator<<( std::ostream & STREAM, const NCPackageSelector & OBJ );
118 
119  NCPackageSelector & operator=( const NCPackageSelector & );
121 
122  private:
123 
124  // typedef for the pointer to handler member function
125  typedef bool (NCPackageSelector::* tHandlerFctPtr) ( const NCursesEvent& event );
126 
127  // typedef for the internal map: key=nameId, value=handler-fct-ptr
128  typedef std::map<std::string, tHandlerFctPtr> tHandlerMap;
129 
130  tHandlerMap eventHandlerMap; // event handler map
131 
132  NCPkgFilterRPMGroups * filterPopup; // the rpm group tags popup
133 
134  NCPkgPopupDeps * depsPopup; // the package dependeny popup
135 
136  NCPkgFilterPattern * patternPopup; // the pattern popup
137  NCPkgLocaleTable * languagePopup; // language popup
138  NCPkgRepoTable * repoPopup;
139 
140  NCPkgDiskspace * diskspacePopup; // the popup showing the disk usage
141 
142  NCPkgFilterSearch * searchPopup; // the package search popup
143  NCPkgFilterInstSummary *inst_summary;
144 
145  NCPkgFilterClassification * pkgClass; // classification of packages
146 
147  bool youMode; // YOU
148  bool updateMode; // Update
149  bool testMode; // testing
150  bool repoMgrEnabled; // Manage repositories (add menu button "Configuration")
151  bool repoMode; // Start with "Repositories" filter view
152  bool summaryMode; // Start with "Summary" filter view
153 
154  std::map <std::string, std::string> sysconfig; // sysconfig values
155 
156  bool autoCheck; // dependency check on every 'click'
157  bool verifySystem; // system verification mode
158  bool installRecommended; // option install recommended for already installed packages
159 
160  std::string actionAtExit;
161 
162  YRpmGroupsTree * _rpmGroupsTree; // rpm groups of the found packages
163 
164  // the package table
165  NCPkgTable * pkgList;
166 
167  NCPkgMenuDeps *depsMenu;
168  NCPkgMenuView *viewMenu;
169  NCPkgMenuConfig *configMenu;
170  NCPkgMenuExtras *extrasMenu;
171  NCPkgMenuHelp *helpMenu;
172  NCPkgFilterMain *filterMain;
173  NCPkgMenuAction *actionMenu;
174  NCPkgMenuFilter *filterMenu;
175  // FIXME - add update list to NCPkgFilterMain
176  YMenuItem * updatelistItem;
177 
178  // labels
179  YLabel * packageLabel;
180  YLabel * diskspaceLabel;
181  YLabel *patternLabel;
182 
183  // information about packages
184  NCPkgPackageDetails * infoText; // short/longdecsription, filelist
185  NCRichText * filter_desc;
186  NCInputField *searchField;
187  NCPkgSearchSettings *searchSet;
188  YReplacePoint * replacePoint; // replace point for info text
189  YReplacePoint * replPoint;
190  YReplacePoint * replPoint2; //tohle pak urcite prejmenuj, Bublino
191 
192  NCPkgTable * versionsList; // list of available package versions
193  // information about patches
194  NCPkgTable * patchPkgs; // pakages belonging to a patch
195  NCPkgTable * patchPkgsVersions; // versions of packages above
196 
197  NCPushButton * okButton;
198  NCPushButton * cancelButton;
199 
200  YMenuItem * visibleInfo; // current visible package info (description, file list, ...)
201 
202  // Mapping from ZyppPkg to the correspoinding ZyppSel.
203  NCPkgSelMapper selMapper;
204 
205  std::set<std::string> verified_pkgs;
206 
207  public:
208  enum FilterMode
209  {
210  Patterns,
211  Languages,
212  Repositories,
213  RPMGroups,
214  Search,
215  Summary,
216  PkgClassification
217  };
218 
219  /**
220  * The package selector class handles the events and holds the
221  * data needed for the package selection.
222  * @param ui The NCurses UI
223  * @param opt The widget options
224  */
225  NCPackageSelector( long modeFlags );
226 
227  /**
228  * Destructor
229  */
230  virtual ~NCPackageSelector();
231 
232  void setFlags( long modeFlags);
233 
234  void readSysconfig();
235  void writeSysconfig();
236 
237  /**
238  * Create layout for the PackageSelector
239  * @param parent Parent is PackageSelectorStart
240  * @param type The package table type
241  * @return void
242  */
243  void createPkgLayout( YWidget * parent, NCPkgTable::NCPkgTableType type );
244 
245  /**
246  * Create layout for the Online Update
247  * @param parent Parent is PackageSelectorStart
248  * @return void
249  */
250  void createYouLayout( YWidget * parent );
251 
252  // returns the package table widget
253  NCPkgTable * PackageList();
254  NCPkgPopupDeps *DepsPopup() { return depsPopup; }
255  NCPkgDiskspace *diskSpacePopup() { return diskspacePopup; }
256  YLabel *PackageLabel() { return packageLabel; }
257  YLabel *PatternLabel() { return patternLabel; }
258 
259  NCPkgPackageDetails *InfoText() { return infoText; }
260  void setInfoText ( NCPkgPackageDetails *itext ) { infoText = itext ;}
261 
262  NCPkgTable *VersionsList() { return versionsList; }
263  void setVersionsList ( NCPkgTable *table ) { versionsList = table; }
264 
265  NCPkgTable * PatchPkgs() { return patchPkgs; }
266  NCPkgTable * PatchPkgsVersions() { return patchPkgsVersions; }
267 
268  YReplacePoint *ReplacePoint() { return replacePoint; }
269  NCRichText *FilterDescription() { return filter_desc; }
270  NCPkgSearchSettings *SearchSettings() { return searchSet; }
271 
272  bool checkNow( bool *ok );
273  bool systemVerification( bool *ok );
274 
275 
276 
277  /**
278  * Fills the package table with YOU patches matching the filter
279  * @param filter
280  * @return bool
281  */
282  bool fillPatchList( NCPkgMenuFilter::PatchFilter filter );
283 
284  /**
285  * Fills the package table with packages with update problems
286  * @return bool
287  */
288  bool fillUpdateList( );
289 
290 
291  /**
292  * Fills the list of packages belonging to the youPatch
293  * @param pkgTable The table widget
294  * @param youPatch Show all packages belonging to the patch
295  * @return bool
296  */
297  bool fillPatchPackages ( NCPkgTable * pkgTable, ZyppObj youPatch );
298 
299  /**
300  * Fills the package table with packages matching the search expression
301  * @param expr The search expression
302  * @param ignoreCase Ignore case (true or false)
303  * @param checkName Search in package name (true or false)
304  * @param checkSummary Check the summary (true or false)
305  * @param checkProvides Check in Provides (true or false)
306  * @param checkRequires Check in Requires (true or false)
307  * @return bool
308  */
309  bool fillPatchSearchList( const std::string & expr, bool checkName, bool checkSum );
310 
311  /**
312  * Fills the default package table
313  */
314  bool fillDefaultList();
315 
316  bool isYouMode() { return youMode; }
317 
318  bool isUpdateMode() { return updateMode; }
319 
320  bool isRepoMgrEnabled() { return repoMgrEnabled; }
321 
322  bool isTestMode() { return testMode; }
323 
324  //
325  // Action at exit (means "summary", "restart" or "close") is written to
326  // /etc/sysconfig/yast2 and gets evaluated by the YaST packager workflow.
327  //
328  std::string ActionAtExit() { return actionAtExit; }
329  void setActionAtExit( std::string action ) { actionAtExit = action; }
330 
331  //
332  // The solver options 'cleanup dependencies on remove' and
333  // 'is allow vendor change' can only be set in /etc/zypp/zypp.conf.
334  //
335  bool isCleanDepsOnRemove();
336  void setCleanDepsOnRemove( bool on );
337 
338  bool isAllowVendorChange();
339  void setAllowVendorChange( bool on );
340 
341  //
342  // The solver options 'Install recommended for already installed' and
343  // 'verify system' can be changed in UI and are written to /etc/sysconfig/yast2.
344  //
345  bool isInstallAlreadyRecommended();
346  void setInstallAlreadyRecommended( bool on );
347  bool InstallRecommended() { return installRecommended; }
348 
349  bool isVerifySystem();
350  void setVerifySystem( bool on );
351  bool VerifySystem() { return verifySystem; }
352  //
353  // The 'automatic dependency check' setting is also saved in /etc/sysconfig/yast2
354  //
355  bool isAutoCheck();
356  void setAutoCheck( bool check) { autoCheck = check; }
357  bool AutoCheck() { return autoCheck; }
358 
359  /**
360  * Handle the given event. For the given event (the widget-id
361  * is contained in the event) the corresponding handler is executed.
362  * @param event The NCurses event
363  * @return bool
364  */
365  bool handleEvent( const NCursesEvent& event );
366 
367  /**
368  * Creates an NCPkgTable widget and shows all versions
369  * of all packages belonging to a patch
370  * @return void
371  */
372  void showPatchPkgVersions();
373 
374  /**
375  * Creates an NCPkgTable widget and shows all packages
376  * belonging to a patch
377  * @return void
378  */
379  void showPatchPackages();
380 
381  /**
382  * Creates an NCPkgTable widget and shows all verions
383  * a the selected package
384  * @return void
385  */
386  void showVersionsList();
387 
388  /**
389  * Creates an NCRichText widget for package (patch)
390  * information
391  * @return void
392  */
393  void showInformation();
394 
395  void clearInfoArea();
396 
397  wrect deleteReplacePoint();
398 
399  void replaceFilter ( FilterMode mode);
400  void replaceFilterDescr ( bool b );
401  /**
402  * Handler function for "OK button pressed"
403  * @param event The Ncurses event
404  * @return bool
405  */
406  bool OkButtonHandler ( const NCursesEvent& event );
407 
408  /**
409  * Handler function for "Cancel button pressed"
410  * @param event The Ncurses event
411  * @return bool
412  */
413  bool CancelHandler ( const NCursesEvent& event );
414 
415  /**
416  * Handles hyperlinks in package description
417  * @param link The link
418  * @return bool
419  */
420  bool LinkHandler ( std::string link );
421 
422  /**
423  * Checks and shows the dependencies
424  * @param doit true: do the check, false: only check if auto check is on
425  */
426  bool showPackageDependencies ( bool doit );
427 
428  /**
429  * Checks and shows the selectiondependencies
430  */
431  void showSelectionDependencies ( );
432 
433  /**
434  * Updates the status in list of packages
435  */
436  void updatePackageList();
437 
438  /**
439  * Check if 'patch' matches the selected filter.
440  * Returns true if there is a match, false otherwise or if 'patch' is 0.
441  * @return bool
442  **/
443  bool checkPatch( ZyppPatch patch,
444  ZyppSel selectable,
445  NCPkgMenuFilter::PatchFilter filter );
446 
447  /**
448  * Shows 'End User License Agreement' popup with license text
449  * @param pkgName the package name
450  * @param license the license text
451  * @return bool license confirmed?
452  */
453  bool showLicensePopup( std::string pkgName, std::string license );
454 
455  /**
456  * Calls the package mananager (updateDu()) and shows the required disk space
457  */
458  void showDiskSpace();
459 
460  /**
461  * Shows the total download size
462  */
463  void showDownloadSize();
464 
465  /**
466  * Check for changes
467  */
468  void saveState();
469  void restoreState();
470  bool diffState();
471 
472  /**
473  * Check for license
474  */
476  bool showPendingLicenseAgreements( ZyppPoolIterator begin, ZyppPoolIterator end );
477 
478  /**
479  * Show popup with license.
480  * @return bool
481  */
482  bool showLicenseAgreement( ZyppSel & slbPtr , std::string licenseText );
483 
484  /**
485  * Get list of packages already selected for automatic changes
486  * (usually via 'verify system' call)
487  * @return std::set <std::string>
488  */
489  std::set <std::string> getVerifiedPkgs()
490  {
491  return verified_pkgs;
492  }
493 
494  /**
495  * Insert package name into the list of already selected for automatic changes
496  * @param pkgname Package name
497  */
498  void insertVerifiedPkg( std::string pkgname ) {
499  verified_pkgs.insert( pkgname);
500  }
501 
502  /**
503  * Empty the std::set of packages selected for automatic changes
504  * @return void
505  */
507  if ( !verified_pkgs.empty() )
508  {
509  yuiMilestone() << "Discarding auto-dependency changes" << std::endl;
510  verified_pkgs.clear();
511  }
512  }
513 
514 };
515 
516 ///////////////////////////////////////////////////////////////////
517 
518 #endif // NCPackageSelector_h
bool checkPatch(ZyppPatch patch, ZyppSel selectable, NCPkgMenuFilter::PatchFilter filter)
bool fillPatchList(NCPkgMenuFilter::PatchFilter filter)
void createPkgLayout(YWidget *parent, NCPkgTable::NCPkgTableType type)
void insertVerifiedPkg(std::string pkgname)
bool handleEvent(const NCursesEvent &event)
std::set< std::string > getVerifiedPkgs()
bool fillPatchPackages(NCPkgTable *pkgTable, ZyppObj youPatch)
bool CancelHandler(const NCursesEvent &event)
bool showLicensePopup(std::string pkgName, std::string license)
bool fillPatchSearchList(const std::string &expr, bool checkName, bool checkSum)
bool LinkHandler(std::string link)
void createYouLayout(YWidget *parent)
bool OkButtonHandler(const NCursesEvent &event)
bool showLicenseAgreement(ZyppSel &slbPtr, std::string licenseText)
bool showPackageDependencies(bool doit)