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