libyui-ncurses-pkg  2.43.4.1
 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  * @param versions Show all versions of all packages belonging to the patch
296  * @return bool
297  */
298  bool fillPatchPackages ( NCPkgTable * pkgTable, ZyppObj youPatch, bool versions = false );
299 
300  /**
301  * Fills the package table with packages matching the search expression
302  * @param expr The search expression
303  * @param ignoreCase Ignore case (true or false)
304  * @param checkName Search in package name (true or false)
305  * @param checkSummary Check the summary (true or false)
306  * @param checkProvides Check in Provides (true or false)
307  * @param checkRequires Check in Requires (true or false)
308  * @return bool
309  */
310  bool fillPatchSearchList( const std::string & expr, bool checkName, bool checkSum );
311 
312  /**
313  * Fills the default package table
314  */
315  bool fillDefaultList();
316 
317  bool isYouMode() { return youMode; }
318 
319  bool isUpdateMode() { return updateMode; }
320 
321  bool isRepoMgrEnabled() { return repoMgrEnabled; }
322 
323  bool isTestMode() { return testMode; }
324 
325  //
326  // Action at exit (means "summary", "restart" or "close") is written to
327  // /etc/sysconfig/yast2 and gets evaluated by the YaST packager workflow.
328  //
329  std::string ActionAtExit() { return actionAtExit; }
330  void setActionAtExit( std::string action ) { actionAtExit = action; }
331 
332  //
333  // The solver options 'cleanup dependencies on remove' and
334  // 'is allow vendor change' can only be set in /etc/zypp/zypp.conf.
335  //
336  bool isCleanDepsOnRemove();
337  void setCleanDepsOnRemove( bool on );
338 
339  bool isAllowVendorChange();
340  void setAllowVendorChange( bool on );
341 
342  //
343  // The solver options 'Install recommended for already installed' and
344  // 'verify system' can be changed in UI and are written to /etc/sysconfig/yast2.
345  //
346  bool isInstallAlreadyRecommended();
347  void setInstallAlreadyRecommended( bool on );
348  bool InstallRecommended() { return installRecommended; }
349 
350  bool isVerifySystem();
351  void setVerifySystem( bool on );
352  bool VerifySystem() { return verifySystem; }
353  //
354  // The 'automatic dependency check' setting is also saved in /etc/sysconfig/yast2
355  //
356  bool isAutoCheck();
357  void setAutoCheck( bool check) { autoCheck = check; }
358  bool AutoCheck() { return autoCheck; }
359 
360  /**
361  * Handle the given event. For the given event (the widget-id
362  * is contained in the event) the corresponding handler is executed.
363  * @param event The NCurses event
364  * @return bool
365  */
366  bool handleEvent( const NCursesEvent& event );
367 
368  /**
369  * Creates an NCPkgTable widget and shows all versions
370  * of all packages belonging to a patch
371  * @return void
372  */
373  void showPatchPkgVersions();
374 
375  /**
376  * Creates an NCPkgTable widget and shows all packages
377  * belonging to a patch
378  * @return void
379  */
380  void showPatchPackages();
381 
382  /**
383  * Creates an NCPkgTable widget and shows all verions
384  * a the selected package
385  * @return void
386  */
387  void showVersionsList();
388 
389  /**
390  * Creates an NCRichText widget for package (patch)
391  * information
392  * @return void
393  */
394  void showInformation();
395 
396  void clearInfoArea();
397 
398  wrect deleteReplacePoint();
399 
400  void replaceFilter ( FilterMode mode);
401  void replaceFilterDescr ( bool b );
402  /**
403  * Handler function for "OK button pressed"
404  * @param event The Ncurses event
405  * @return bool
406  */
407  bool OkButtonHandler ( const NCursesEvent& event );
408 
409  /**
410  * Handler function for "Cancel button pressed"
411  * @param event The Ncurses event
412  * @return bool
413  */
414  bool CancelHandler ( const NCursesEvent& event );
415 
416  /**
417  * Handles hyperlinks in package description
418  * @param link The link
419  * @return bool
420  */
421  bool LinkHandler ( std::string link );
422 
423  /**
424  * Checks and shows the dependencies
425  * @param doit true: do the check, false: only check if auto check is on
426  */
427  bool showPackageDependencies ( bool doit );
428 
429  /**
430  * Checks and shows the selectiondependencies
431  */
432  void showSelectionDependencies ( );
433 
434  /**
435  * Updates the status in list of packages
436  */
437  void updatePackageList();
438 
439  /**
440  * Check if 'patch' matches the selected filter.
441  * Returns true if there is a match, false otherwise or if 'patch' is 0.
442  * @return bool
443  **/
444  bool checkPatch( ZyppPatch patch,
445  ZyppSel selectable,
446  NCPkgMenuFilter::PatchFilter filter );
447 
448  /**
449  * Shows 'End User License Agreement' popup with license text
450  * @param pkgName the package name
451  * @param license the license text
452  * @return bool license confirmed?
453  */
454  bool showLicensePopup( std::string pkgName, std::string license );
455 
456  /**
457  * Calls the package mananager (updateDu()) and shows the required disk space
458  */
459  void showDiskSpace();
460 
461  /**
462  * Shows the total download size
463  */
464  void showDownloadSize();
465 
466  /**
467  * Check for changes
468  */
469  void saveState();
470  void restoreState();
471  bool diffState();
472 
473  /**
474  * Check for license
475  */
477  bool showPendingLicenseAgreements( ZyppPoolIterator begin, ZyppPoolIterator end );
478 
479  /**
480  * Show popup with license.
481  * @return bool
482  */
483  bool showLicenseAgreement( ZyppSel & slbPtr , std::string licenseText );
484 
485  /**
486  * Get list of packages already selected for automatic changes
487  * (usually via 'verify system' call)
488  * @return std::set <std::string>
489  */
490  std::set <std::string> getVerifiedPkgs()
491  {
492  return verified_pkgs;
493  }
494 
495  /**
496  * Insert package name into the list of already selected for automatic changes
497  * @param pkgname Package name
498  */
499  void insertVerifiedPkg( std::string pkgname ) {
500  verified_pkgs.insert( pkgname);
501  }
502 
503  /**
504  * Empty the std::set of packages selected for automatic changes
505  * @return void
506  */
508  if ( !verified_pkgs.empty() )
509  {
510  yuiMilestone() << "Discarding auto-dependency changes" << std::endl;
511  verified_pkgs.clear();
512  }
513  }
514 
515 };
516 
517 ///////////////////////////////////////////////////////////////////
518 
519 #endif // NCPackageSelector_h