]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgPatchList.h
YQPkgChangesDialog QT3_SUPPORT
[duncan/yast2-qt4.git] / src / pkg / YQPkgPatchList.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgPatchList.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgPatchList_h
21 #define YQPkgPatchList_h
22
23 #include <string>
24 #include "YQPkgObjList.h"
25 #include "YQPkgSelMapper.h"
26 //Added by qt3to4:
27 #include <QTreeWidgetItem>
28 #include <QEvent>
29 #include <QMenu>
30
31 #define ENABLE_DELETING_PATCHES 1
32
33 using std::string;
34
35 class YQPkgPatchListItem;
36
37
38 enum YQPkgPatchCategory // This is also the sort order
39 {
40     YQPkgYaSTPatch,
41     YQPkgSecurityPatch,
42     YQPkgRecommendedPatch,
43     YQPkgOptionalPatch,
44     YQPkgDocumentPatch,
45
46     YQPkgUnknownPatchCategory = 9999
47 };
48
49
50
51 /**
52  * @short Display a list of zypp::Patch objects.
53  **/
54 class YQPkgPatchList : public YQPkgObjList
55 {
56     Q_OBJECT
57
58 public:
59
60     /**
61      * Constructor
62      **/
63     YQPkgPatchList( QWidget * parent );
64
65     /**
66      * Destructor
67      **/
68     virtual ~YQPkgPatchList();
69
70
71     enum FilterCriteria
72     {
73         RelevantPatches,                // needed + broken
74         RelevantAndInstalledPatches,    // needed + broken + installed
75         AllPatches                      // all
76     };
77
78
79 public slots:
80
81     /**
82      * Filter according to the view's rules and current selection.
83      * Emits those signals:
84      *    filterStart()
85      *    filterMatch() for each pkg that matches the filter
86      *    filterFinished()
87      **/
88     void filter();
89
90     /**
91      * Same as filter(), but only if this widget is currently visible.
92      **/
93     void filterIfVisible();
94
95     /**
96      * Add a patch to the list. Connect a filter's filterMatch() signal to
97      * this slot. Remember to connect filterStart() to clear() (inherited from
98      * QListView).
99      **/
100     void addPatchItem( ZyppSel   selectable,
101                        ZyppPatch zyppPatch );
102
103     /**
104      * Fill the patch list according to filterCriteria().
105      **/
106     void fillList();
107
108     /**
109      * Display a one-line message in the list.
110      * Reimplemented from YQPkgObjList.
111      **/
112     virtual void message( const QString & text );
113
114
115 public:
116
117     /**
118      * Set the filter criteria for fillList().
119      **/
120     void setFilterCriteria( FilterCriteria filterCriteria );
121
122     /**
123      * Returns the current filter criteria.
124      **/
125     FilterCriteria filterCriteria() const { return _filterCriteria; }
126
127     /**
128      * Returns the currently selected item or 0 if there is none.
129      **/
130     YQPkgPatchListItem * selection() const;
131
132     /**
133      * Returns the column for the patch category
134      **/
135     int categoryCol() const { return _categoryCol; }
136
137     /**
138      * Add a submenu "All in this list..." to 'menu'.
139      * Returns the newly created submenu.
140      *
141      * Reimplemented from YQPkgObjList.
142      **/
143     virtual QMenu * addAllInListSubMenu( QMenu * menu );
144
145     /**
146      * Delayed initialization after the dialog is fully created.
147      *
148      * Reimplemented from QWidget.
149      **/
150     virtual void polish();
151
152
153 signals:
154
155     /**
156      * Emitted when the filtering starts. Use this to clear package lists
157      * etc. prior to adding new entries.
158      **/
159     void filterStart();
160
161     /**
162      * Emitted during filtering for each pkg that matches the filter.
163      **/
164     void filterMatch( ZyppSel   selectable,
165                       ZyppPkg   pkg );
166
167     /**
168      * Emitted during filtering for non-pkg items:
169      * pre-script, post-script, files
170      **/
171     void filterMatch( const QString &   name,
172                       const QString &   summary,
173                       FSize             size );
174
175     /**
176      * Emitted when filtering is finished.
177      **/
178     void filterFinished();
179
180
181 protected:
182
183     /**
184      * Create the context menu for items that are not installed.
185      *
186      * Reimplemented from YQPkgObjList.
187      **/
188     virtual void createNotInstalledContextMenu();
189
190     /**
191      * Create the context menu for installed items.
192      *
193      * Reimplemented from YQPkgObjList.
194      **/
195     virtual void createInstalledContextMenu();
196
197     /**
198      * Event handler for keyboard input.
199      * Only very special keys are processed here.
200      *
201      * Reimplemented from YQPkgObjList / QWidget.
202      **/
203     virtual void keyPressEvent( QKeyEvent * ev );
204
205
206     // Data members
207
208     int                 _categoryCol;
209     YQPkgSelMapper      _selMapper;
210     FilterCriteria      _filterCriteria;
211 };
212
213
214
215 class YQPkgPatchListItem: public YQPkgObjListItem
216 {
217 public:
218
219     /**
220      * Constructor. Creates a YQPkgPatchList item that corresponds to
221      * zyppPatch.
222      **/
223     YQPkgPatchListItem( YQPkgPatchList *        patchList,
224                            ZyppSel              selectable,
225                            ZyppPatch            zyppPatch );
226
227     /**
228      * Destructor
229      **/
230     virtual ~YQPkgPatchListItem();
231
232     /**
233      * Returns the original zyppPatch object.
234      **/
235     ZyppPatch zyppPatch() const { return _zyppPatch; }
236
237     /**
238      * Maps a string patch category to the corresponding enum.
239      **/
240     static YQPkgPatchCategory patchCategory( QString category );
241     static YQPkgPatchCategory patchCategory( const string & category );
242
243     /**
244      * Converts a patch category to a user-readable (translated) string.
245      **/
246     static QString asString( YQPkgPatchCategory category );
247
248     /**
249      * Returns the category of this patch (security, recommended, ...).
250      **/
251     YQPkgPatchCategory patchCategory() const { return _patchCategory; }
252
253     /**
254      * Cycle the package status to the next valid value.
255      * Reimplemented from YQPkgObjList.
256      **/
257     virtual void cycleStatus();
258
259     /**
260      * Returns a tool tip text for a specific column of this item.
261      * 'column' is -1 if the mouse pointer is in the tree indentation area.
262      *
263      * Reimplemented from YQPkgObjList.
264      **/
265     virtual QString toolTip( int column );
266
267     /**
268      * Comparison function used for sorting the list.
269      * Returns:
270      * -1 if this <  other
271      *  0 if this == other
272      * +1 if this >  other
273      *
274      * Reimplemented from QListViewItem.
275      **/
276     virtual int compare( QTreeWidgetItem *      other,
277                          int                    col,
278                          bool                   ascending ) const;
279
280     // Columns
281
282     int statusCol()     const   { return _patchList->statusCol();       }
283     int summaryCol()    const   { return _patchList->summaryCol();      }
284     int categoryCol()   const   { return _patchList->categoryCol();     }
285
286
287 protected:
288
289     /**
290      * Propagate status changes in this list to other lists:
291      * Have the solver transact all patches.
292      *
293      * Reimplemented from YQPkgObjListItem.
294      **/
295     virtual void applyChanges();
296
297
298     // Data members
299
300     YQPkgPatchList *    _patchList;
301     ZyppPatch           _zyppPatch;
302     YQPkgPatchCategory  _patchCategory;
303 };
304
305
306 #endif // ifndef YQPkgPatchList_h