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