]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgList.h
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / pkg / YQPkgList.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgList.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgList_h
21 #define YQPkgList_h
22
23 #include <YQPkgObjList.h>
24 //Added by qt3to4:
25 #include <q3popupmenu.h>
26
27 class YQPkgListItem;
28
29
30 /**
31  * @short Display a list of zypp::Package objects.
32  **/
33 class YQPkgList : public YQPkgObjList
34 {
35     Q_OBJECT
36
37 public:
38
39     /**
40      * Constructor
41      **/
42     YQPkgList( QWidget * parent );
43
44     /**
45      * Destructor
46      **/
47     virtual ~YQPkgList();
48
49
50     // Column numbers
51
52     int srpmStatusCol()         const   { return _srpmStatusCol;        }
53
54     /**
55      * Save the pkg list to a file.
56      *
57      * Posts error popups if 'interactive' is 'true' ( only log entries
58      * otherwise ).
59      **/
60     void exportList( const QString filename, bool interactive ) const;
61
62     /**
63      * Add a submenu "All in this list..." to 'menu'.
64      * Returns the newly created submenu.
65      *
66      * Reimplemented from YQPkgObjList.
67      **/
68     virtual Q3PopupMenu * addAllInListSubMenu( Q3PopupMenu * menu );
69
70     /**
71      * Returns 'true' if there are any installed packages.
72      **/
73     static bool haveInstalledPkgs();
74
75     /**
76      * Set the status of all packages in the pool to a new value.
77      * This is not restricted to the current content of this package list.
78      * All selectables in the ZYPP pool are affected.
79      *
80      * 'force' indicates if it should be done even if it is not very useful,
81      * e.g., if packages should be updated even if there is no newer version.
82      *
83      * If 'countOnly' is 'true', the status is not actually changed, only the
84      * number of packages that would be affected is return.
85      *
86      * Return value: The number of status changes
87      **/
88     int globalSetPkgStatus( ZyppStatus newStatus, bool force, bool countOnly );
89
90
91 public slots:
92
93     /**
94      * Add a pkg to the list. Connect a filter's filterMatch() signal to this
95      * slot. Remember to connect filterStart() to clear() (inherited from
96      * QListView).
97      **/
98     void addPkgItem     ( ZyppSel       selectable,
99                           ZyppPkg       zyppPkg );
100
101     /**
102      * Add a pkg to the list, but display it dimmed (grey text foreground
103      * rather than normal black).
104      **/
105     void addPkgItemDimmed( ZyppSel      selectable,
106                            ZyppPkg      zyppPkg );
107
108     /**
109      * Add a pkg to the list
110      **/
111     void addPkgItem     ( ZyppSel       selectable,
112                           ZyppPkg       zyppPkg,
113                           bool          dimmed );
114
115
116     /**
117      * Dispatcher slot for mouse click: Take care of source RPM status.
118      * Let the parent class handle the normal status.
119      * Reimplemented from YQPkgObjList.
120      **/
121     virtual void pkgObjClicked( int             button,
122                                 Q3ListViewItem *        item,
123                                 int             col,
124                                 const QPoint &  pos );
125
126     /**
127      * Update the internal actions: What actions are available for 'item'?
128      *
129      * Reimplemented from YQPkgObjList
130      **/
131     virtual void updateActions( YQPkgObjListItem * item );
132
133     /**
134      * Reimplemented from QListView / QWidget:
135      * Reserve a reasonable amount of space.
136      **/
137     virtual QSize sizeHint() const;
138
139     /**
140      * Ask for a file name and save the current pkg list to file.
141      **/
142     void askExportList() const;
143
144
145     // Direct access to some states for menu actions
146
147     void setInstallCurrentSourceRpm()     { setInstallCurrentSourceRpm( true  ); }
148     void setDontInstallCurrentSourceRpm() { setInstallCurrentSourceRpm( false ); }
149
150     void setInstallListSourceRpms()       { setInstallListSourceRpms( true  ); }
151     void setDontInstallListSourceRpms()   { setInstallListSourceRpms( false ); }
152
153
154     // No separate selectionChanged( ZyppPkg ) signal:
155     // Use YQPkgObjList::selectionChanged( ZyppObj ) instead
156     // and dynamic_cast to ZyppPkg if required.
157     // This saves duplicating a lot of code.
158
159
160 protected:
161
162     /**
163      * Create ( additional ) actions for the context menus.
164      **/
165     void createActions();
166
167     /**
168      * Create the context menu for items that are not installed.
169      *
170      * Reimplemented from YQPkgObjList.
171      **/
172     virtual void createNotInstalledContextMenu();
173
174     /**
175      * Create the context menu for installed items.
176      *
177      * Reimplemented from YQPkgObjList.
178      **/
179     virtual void createInstalledContextMenu();
180
181     /**
182      * Create context menu for source RPMs.
183      **/
184     void createSourceRpmContextMenu();
185
186     /**
187      * Sets the currently selected item's source RPM status.
188      * Automatically selects the next item if 'selectNextItem' is 'true'.
189      **/
190     void setInstallCurrentSourceRpm( bool inst, bool selectNextItem = false );
191
192     /**
193      * Sets the source RPM status of all items in this list.
194      **/
195     void setInstallListSourceRpms( bool inst );
196
197
198     // Data members
199
200     int                 _srpmStatusCol;
201     Q3PopupMenu *       _sourceRpmContextMenu;
202
203
204 public:
205
206     Q3Action *          actionInstallSourceRpm;
207     Q3Action *          actionDontInstallSourceRpm;
208     Q3Action *          actionInstallListSourceRpms;
209     Q3Action *          actionDontInstallListSourceRpms;
210 };
211
212
213
214 class YQPkgListItem: public YQPkgObjListItem
215 {
216 public:
217
218     /**
219      * Constructor. Creates a YQPkgList item that corresponds to the package
220      * manager object that 'pkg' refers to.
221      **/
222     YQPkgListItem( YQPkgList *                  pkgList,
223                    ZyppSel      selectable,
224                    ZyppPkg      zyppPkg );
225
226     /**
227      * Destructor
228      **/
229     virtual ~YQPkgListItem();
230
231     /**
232      * Returns the parent package list.
233      **/
234     YQPkgList * pkgList() { return _pkgList; }
235
236     /**
237      * Returns the original object within the package manager backend.
238      **/
239     ZyppPkg zyppPkg() const { return _zyppPkg; }
240
241     /**
242      * Returns the source RPM package status:
243      * Should the source RPM be installed?
244      **/
245     bool installSourceRpm() const;
246
247     /**
248      * Set the source RPM status
249      **/
250     void setInstallSourceRpm( bool installSourceRpm );
251
252     /**
253      * Cycle the source package status to the next valid value.
254      **/
255     void toggleSourceRpmStatus();
256
257     /**
258      * Returns whether or not a source RPM is available for this package.
259      **/
260     bool hasSourceRpm() const;
261
262
263     /**
264      * Comparison function used for sorting the list.
265      * Returns:
266      * -1 if this <  other
267      *  0 if this == other
268      * +1 if this >  other
269      *
270      * Reimplemented from QListViewItem
271      **/
272     virtual int compare( Q3ListViewItem *       other,
273                          int                    col,
274                          bool                   ascending ) const;
275
276
277     /**
278      * Update this item's data completely.
279      * Triggered by QY2ListView::updateAllItemData().
280      *
281      * Reimplemented from YQPkgObjList.
282      **/
283     virtual void updateData();
284
285     /**
286      * Returns a tool tip text for a specific column of this item.
287      * 'column' is -1 if the mouse pointer is in the tree indentation area.
288      *
289      * Reimplemented from YQPkgObjList.
290      **/
291     virtual QString toolTip( int column );
292
293     /**
294      * Returns true if this package is to be displayed dimmed,
295      * i.e. with grey text foreground rather than the normal black.
296      **/
297     bool isDimmed() const { return _dimmed; }
298
299     /**
300      * Set the 'dimmed' flag.
301      **/
302     void setDimmed( bool d = true ) { _dimmed = d; }
303
304
305     // Columns
306
307     int srpmStatusCol() const { return _pkgList->srpmStatusCol(); }
308
309
310 protected:
311
312     /**
313      * Set the suitable icon for the source RPM status.
314      **/
315     void setSourceRpmIcon();
316
317     /**
318      * Paint method. Reimplemented from @ref QListViewItem so different
319      * colors can be used.
320      *
321      * Reimplemented from QListViewItem.
322      **/
323     virtual void paintCell( QPainter *          painter,
324                             const QColorGroup & colorGroup,
325                             int                 column,
326                             int                 width,
327                             int                 alignment );
328
329     // Data members
330
331     YQPkgList *                 _pkgList;
332     ZyppPkg     _zyppPkg;
333     bool                        _dimmed;
334 };
335
336
337 #endif // ifndef YQPkgList_h