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