libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgPatchList.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgPatchList.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgPatchList_h
42 #define YQPkgPatchList_h
43 
44 #include <string>
45 #include "YQPkgObjList.h"
46 #include "YQPkgSelMapper.h"
47 #include <QTreeWidgetItem>
48 #include <QEvent>
49 #include <QMenu>
50 
51 #define ENABLE_DELETING_PATCHES 1
52 
53 using std::string;
54 
55 class YQPkgPatchListItem;
57 
58 enum YQPkgPatchCategory // This is also the sort order
59 {
60  YQPkgYaSTPatch,
61  YQPkgSecurityPatch,
62  YQPkgRecommendedPatch,
63  YQPkgOptionalPatch,
64  YQPkgDocumentPatch,
65 
66  YQPkgUnknownPatchCategory = 9999
67 };
68 
69 
70 
71 /**
72  * @short Display a list of zypp::Patch objects.
73  **/
75 {
76  Q_OBJECT
77 
78 public:
79 
80  /**
81  * Constructor
82  **/
83  YQPkgPatchList( QWidget * parent );
84 
85  /**
86  * Destructor
87  **/
88  virtual ~YQPkgPatchList();
89 
90 
91  enum FilterCriteria
92  {
93  RelevantPatches, // needed (or broken)
94  RelevantAndInstalledPatches, // unneeded
95  AllPatches // all
96  };
97 
98 
99 public slots:
100 
101  /**
102  * Filter according to the view's rules and current selection.
103  * Emits those signals:
104  * filterStart()
105  * filterMatch() for each pkg that matches the filter
106  * filterFinished()
107  **/
108  void filter();
109 
110  /**
111  * Same as filter(), but only if this widget is currently visible.
112  **/
113  void filterIfVisible();
114 
115  /**
116  * Add a patch to the list. Connect a filter's filterMatch() signal to
117  * this slot. Remember to connect filterStart() to clear() (inherited from
118  * QListView).
119  **/
120  void addPatchItem( ZyppSel selectable,
121  ZyppPatch zyppPatch );
122 
123  /**
124  * Fill the patch list according to filterCriteria().
125  **/
126  void fillList();
127 
128  /**
129  * Display a one-line message in the list.
130  * Reimplemented from YQPkgObjList.
131  **/
132  virtual void message( const QString & text );
133 
134 
135 public:
136 
137  /**
138  * Set the filter criteria for fillList().
139  **/
140  void setFilterCriteria( FilterCriteria filterCriteria );
141 
142  /**
143  * Returns the current filter criteria.
144  **/
145  FilterCriteria filterCriteria() const { return _filterCriteria; }
146 
147  /**
148  * Returns the currently selected item or 0 if there is none.
149  **/
150  YQPkgPatchListItem * selection() const;
151 
152  /**
153  * Returns the column for the patch category
154  **/
155  int categoryCol() const { return _categoryCol; }
156 
157  /**
158  * Add a submenu "All in this list..." to 'menu'.
159  * Returns the newly created submenu.
160  *
161  * Reimplemented from YQPkgObjList.
162  **/
163  virtual QMenu * addAllInListSubMenu( QMenu * menu );
164 
165  /**
166  * Delayed initialization after the dialog is fully created.
167  *
168  * Reimplemented from QWidget.
169  **/
170  virtual void polish();
171 
172 
173 signals:
174 
175  /**
176  * Emitted when the filtering starts. Use this to clear package lists
177  * etc. prior to adding new entries.
178  **/
179  void filterStart();
180 
181  /**
182  * Emitted during filtering for each pkg that matches the filter.
183  **/
184  void filterMatch( ZyppSel selectable,
185  ZyppPkg pkg );
186 
187  /**
188  * Emitted during filtering for non-pkg items:
189  * pre-script, post-script, files
190  **/
191  void filterMatch( const QString & name,
192  const QString & summary,
193  FSize size );
194 
195  /**
196  * Emitted when filtering is finished.
197  **/
198  void filterFinished();
199 
200 
201 protected:
202  /**
203  * returns or creates a category item for a defined category
204  */
205  YQPkgPatchCategoryItem * category( YQPkgPatchCategory category );
206 
207  /**
208  * Create the context menu for items that are not installed.
209  *
210  * Reimplemented from YQPkgObjList.
211  **/
212  virtual void createNotInstalledContextMenu();
213 
214  /**
215  * Create the context menu for installed items.
216  *
217  * Reimplemented from YQPkgObjList.
218  **/
219  virtual void createInstalledContextMenu();
220 
221  /**
222  * Event handler for keyboard input.
223  * Only very special keys are processed here.
224  *
225  * Reimplemented from YQPkgObjList / QWidget.
226  **/
227  virtual void keyPressEvent( QKeyEvent * ev );
228 
229 
230  // Data members
231 
232  int _categoryCol;
233  YQPkgSelMapper _selMapper;
234  FilterCriteria _filterCriteria;
235  QMap<YQPkgPatchCategory, YQPkgPatchCategoryItem*> _categories;
236 };
237 
238 
239 
241 {
242 public:
243 
244  /**
245  * Constructor. Creates a YQPkgPatchList item that corresponds to
246  * zyppPatch.
247  **/
248  YQPkgPatchListItem( YQPkgPatchList * patchList,
249  ZyppSel selectable,
250  ZyppPatch zyppPatch );
251 
252 
253  /**
254  * Constructor. Creates a YQPkgPatchList item that corresponds to
255  * zyppPatch.
256  **/
257  YQPkgPatchListItem( YQPkgPatchList * patchList,
258  YQPkgPatchCategoryItem * parentCategory,
259  ZyppSel selectable,
260  ZyppPatch zyppPatch );
261 
262  /**
263  * Destructor
264  **/
265  virtual ~YQPkgPatchListItem();
266 
267  /**
268  * Returns the original zyppPatch object.
269  **/
270  ZyppPatch zyppPatch() const { return _zyppPatch; }
271 
272  /**
273  * Cycle the package status to the next valid value.
274  * Reimplemented from YQPkgObjList.
275  **/
276  virtual void cycleStatus();
277 
278  /**
279  * Returns a tool tip text for a specific column of this item.
280  * 'column' is -1 if the mouse pointer is in the tree indentation area.
281  *
282  * Reimplemented from YQPkgObjList.
283  **/
284  virtual QString toolTip( int column );
285 
286  /**
287  * sorting function
288  */
289  virtual bool operator< ( const QTreeWidgetItem & other ) const;
290 
291  // Columns
292 
293  int statusCol() const { return _patchList->statusCol(); }
294  int summaryCol() const { return _patchList->summaryCol(); }
295  int categoryCol() const { return _patchList->categoryCol(); }
296 
297  /**
298  * Returns the category of this patch (security, recommended, ...).
299  **/
300  YQPkgPatchCategory patchCategory() const { return _patchCategory; }
301 
302 protected:
303  void init();
304  /**
305  * Propagate status changes in this list to other lists:
306  * Have the solver transact all patches.
307  *
308  * Reimplemented from YQPkgObjListItem.
309  **/
310  virtual void applyChanges();
311 
312 
313  // Data members
314 
315  YQPkgPatchList * _patchList;
316  ZyppPatch _zyppPatch;
317  YQPkgPatchCategory _patchCategory;
318 };
319 
320 class YQPkgPatchCategoryItem: public QY2ListViewItem
321 {
322 public:
323 
324  /**
325  * Constructor
326  **/
327  YQPkgPatchCategoryItem( YQPkgPatchCategory category, YQPkgPatchList * patternList );
328 
329  /**
330  * Destructor
331  **/
332  virtual ~YQPkgPatchCategoryItem();
333 
334  /**
335  * Returns the first pattern. This should be the first in sort order.
336  **/
337  ZyppPatch firstPatch() const { return _firstPatch; }
338 
339  /**
340  * Add a pattern to this category. This method sets firstPatch() if necessary.
341  **/
342  void addPatch( ZyppPatch patch );
343 
344  /**
345  * sorting function
346  */
347  virtual bool operator< ( const QTreeWidgetItem & other ) const;
348 
349  /*
350  * Open or close this subtree
351  *
352  * Reimplemented from QListViewItem to force categories open at all times
353  **/
354  virtual void setExpanded( bool open );
355 
356  /**
357  * Maps a string patch category to the corresponding enum.
358  **/
359  static YQPkgPatchCategory patchCategory( QString category );
360  static YQPkgPatchCategory patchCategory( const string & category );
361  /**
362  * Converts a patch category to a user-readable (translated) string.
363  **/
364  static QString asString( YQPkgPatchCategory category );
365 
366 
367  /**
368  * Category (and order ) for this item
369  */
370  YQPkgPatchCategory category() const { return _category; }
371 
372 
373 protected:
374 
375  /**
376  * Set a suitable tree open/close icon depending on this category's
377  * open/close status.
378  *
379  * The default QListView plus/minus icons would require treeStepSize() to
380  * be set >0 and rootItemDecorated( true ), but that would look very ugly
381  * in this context, so the pattern categories paint their own tree open /
382  * close icons.
383  **/
384  void setTreeIcon( void );
385  //
386  // Data members
387  //
388 
389  YQPkgPatchCategory _category;
390  YQPkgPatchList * _patchList;
391  ZyppPatch _firstPatch;
392 };
393 
394 
395 #endif // ifndef YQPkgPatchList_h
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
Definition: YQPkgObjList.h:466
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:68
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
Display a list of zypp::Patch objects.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
virtual void polish()
Delayed initialization after the dialog is fully created.
virtual void applyChanges()
Propagate status changes in this list to other lists: Have the solver transact all patches...
void filter()
Filter according to the view's rules and current selection.
virtual ~YQPkgPatchCategoryItem()
Destructor.
ZyppPatch zyppPatch() const
Returns the original zyppPatch object.
virtual ~YQPkgPatchListItem()
Destructor.
void fillList()
Fill the patch list according to filterCriteria().
YQPkgPatchListItem * selection() const
Returns the currently selected item or 0 if there is none.
virtual void keyPressEvent(QKeyEvent *ev)
Event handler for keyboard input.
virtual void cycleStatus()
Cycle the package status to the next valid value.
YQPkgPatchCategory category() const
Category (and order ) for this item.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
ZyppPatch firstPatch() const
Returns the first pattern.
YQPkgPatchList(QWidget *parent)
Constructor.
YQPkgPatchCategoryItem(YQPkgPatchCategory category, YQPkgPatchList *patternList)
Constructor.
virtual void createInstalledContextMenu()
Create the context menu for installed items.
virtual void message(const QString &text)
Display a one-line message in the list.
static QString asString(YQPkgPatchCategory category)
Converts a patch category to a user-readable (translated) string.
virtual void createNotInstalledContextMenu()
Create the context menu for items that are not installed.
void setTreeIcon(void)
Set a suitable tree open/close icon depending on this category's open/close status.
virtual ~YQPkgPatchList()
Destructor.
Mapping from ZyppPkg to the correspoinding ZyppSel.
FilterCriteria filterCriteria() const
Returns the current filter criteria.
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Add a submenu "All in this list..." to 'menu'.
void filterFinished()
Emitted when filtering is finished.
int categoryCol() const
Returns the column for the patch category.
void filterStart()
Emitted when the filtering starts.
static YQPkgPatchCategory patchCategory(QString category)
Maps a string patch category to the corresponding enum.
void addPatchItem(ZyppSel selectable, ZyppPatch zyppPatch)
Add a patch to the list.
void addPatch(ZyppPatch patch)
Add a pattern to this category.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
void setFilterCriteria(FilterCriteria filterCriteria)
Set the filter criteria for fillList().
YQPkgPatchListItem(YQPkgPatchList *patchList, ZyppSel selectable, ZyppPatch zyppPatch)
Constructor.
YQPkgPatchCategoryItem * category(YQPkgPatchCategory category)
returns or creates a category item for a defined category
YQPkgPatchCategory patchCategory() const
Returns the category of this patch (security, recommended, ...).