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