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