libyui-qt-pkg  2.45.6
YQPkgList.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: YQPkgList.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgList_h
42 #define YQPkgList_h
43 
44 #include <YQPkgObjList.h>
45 #include <QMenu>
46 #include <QResizeEvent>
47 
48 class YQPkgListItem;
49 
50 
51 /**
52  * @short Display a list of zypp::Package objects.
53  **/
54 class YQPkgList : public YQPkgObjList
55 {
56  Q_OBJECT
57 
58 public:
59 
60  /**
61  * Constructor
62  **/
63  YQPkgList( QWidget * parent );
64 
65  /**
66  * Destructor
67  **/
68  virtual ~YQPkgList();
69 
70 
71  // Column numbers
72 
73  int srpmStatusCol() const { return _srpmStatusCol; }
74 
75  /**
76  * Save the pkg list to a file.
77  *
78  * Posts error popups if 'interactive' is 'true' ( only log entries
79  * otherwise ).
80  **/
81  void exportList( const QString filename, bool interactive ) const;
82 
83  /**
84  * Add a submenu "All in this list..." to 'menu'.
85  * Returns the newly created submenu.
86  *
87  * Reimplemented from YQPkgObjList.
88  **/
89  virtual QMenu * addAllInListSubMenu( QMenu * menu );
90 
91  /**
92  * Returns 'true' if there are any installed packages.
93  **/
94  static bool haveInstalledPkgs();
95 
96  /**
97  * Set the status of all packages in the pool to a new value.
98  * This is not restricted to the current content of this package list.
99  * All selectables in the ZYPP pool are affected.
100  *
101  * 'force' indicates if it should be done even if it is not very useful,
102  * e.g., if packages should be updated even if there is no newer version.
103  *
104  * If 'countOnly' is 'true', the status is not actually changed, only the
105  * number of packages that would be affected is return.
106  *
107  * Return value: The number of status changes
108  **/
109  int globalSetPkgStatus( ZyppStatus newStatus, bool force, bool countOnly );
110 
111 
112 public slots:
113 
114  /**
115  * Add a pkg to the list. Connect a filter's filterMatch() signal to this
116  * slot. Remember to connect filterStart() to clear() (inherited from
117  * QListView).
118  **/
119  void addPkgItem ( ZyppSel selectable,
120  ZyppPkg zyppPkg );
121 
122  /**
123  * Add a pkg to the list, but display it dimmed (grey text foreground
124  * rather than normal black).
125  **/
126  void addPkgItemDimmed( ZyppSel selectable,
127  ZyppPkg zyppPkg );
128 
129  /**
130  * Add a pkg to the list
131  **/
132  void addPkgItem ( ZyppSel selectable,
133  ZyppPkg zyppPkg,
134  bool dimmed );
135 
136 
137  /**
138  * Dispatcher slot for mouse click: Take care of source RPM status.
139  * Let the parent class handle the normal status.
140  * Reimplemented from YQPkgObjList.
141  **/
142  virtual void pkgObjClicked( int button,
143  QTreeWidgetItem * item,
144  int col,
145  const QPoint & pos );
146 
147  /**
148  * Update the internal actions: What actions are available for 'item'?
149  *
150  * Reimplemented from YQPkgObjList
151  **/
152  virtual void updateActions( YQPkgObjListItem * item );
153 
154  /**
155  * Reimplemented from QListView / QWidget:
156  * Reserve a reasonable amount of space.
157  **/
158  virtual QSize sizeHint() const;
159 
160  /**
161  * Ask for a file name and save the current pkg list to file.
162  **/
163  void askExportList() const;
164 
165 
166  // Direct access to some states for menu actions
167 
168  void setInstallCurrentSourceRpm() { setInstallCurrentSourceRpm( true ); }
169  void setDontInstallCurrentSourceRpm() { setInstallCurrentSourceRpm( false ); }
170 
171  void setInstallListSourceRpms() { setInstallListSourceRpms( true ); }
172  void setDontInstallListSourceRpms() { setInstallListSourceRpms( false ); }
173 
174 
175  // No separate currentItemChanged( ZyppPkg ) signal:
176  // Use YQPkgObjList::currentItemChanged( ZyppObj ) instead
177  // and dynamic_cast to ZyppPkg if required.
178  // This saves duplicating a lot of code.
179 
180  /**
181  * Clears the tree-widgets content, resets the optimal column width values
182  *
183  * Reimplemented from QPkgObjList, calls QPkgObjList::reset()
184  **/
185  void clear();
186 
187  /**
188  * Sort the tree widget again according to the column selected and
189  * its current sort order.
190  **/
191  void resort();
192 
193 
194 protected:
195 
196  /**
197  * Create ( additional ) actions for the context menus.
198  **/
199  void createActions();
200 
201  /**
202  * Create the context menu for items that are not installed.
203  *
204  * Reimplemented from YQPkgObjList.
205  **/
206  virtual void createNotInstalledContextMenu();
207 
208  /**
209  * Create the context menu for installed items.
210  *
211  * Reimplemented from YQPkgObjList.
212  **/
213  virtual void createInstalledContextMenu();
214 
215  /**
216  * Create context menu for source RPMs.
217  **/
219 
220  /**
221  * Sets the currently selected item's source RPM status.
222  * Automatically selects the next item if 'selectNextItem' is 'true'.
223  **/
224  void setInstallCurrentSourceRpm( bool inst, bool selectNextItem = false );
225 
226  /**
227  * Sets the source RPM status of all items in this list.
228  **/
229  void setInstallListSourceRpms( bool inst );
230 
231  /**
232  * Resets the optimal column width values.
233  * Needed for empty list.
234  **/
236 
237  /**
238  * Set and save optimal column widths depending on content only
239  * There is currently no way to get the optimal widths without setting them, so we have to do it.
240  **/
241  void updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg);
242 
243  /**
244  * Optimizes the column widths depending on content and the available horizontal space.
245  **/
246  void optimizeColumnWidths();
247 
248  /**
249  * Handler for resize events.
250  * Triggers column width optimization.
251  **/
252  void resizeEvent(QResizeEvent *event);
253 
254 
255  // *** Data members:
256 
257  int _srpmStatusCol;
258  QMenu * _sourceRpmContextMenu;
259  // Optimal (sized-to-content) column widths:
260  int _optimalColWidth_statusIcon;
261  int _optimalColWidth_name;
262  int _optimalColWidth_summary;
263  int _optimalColWidth_version;
264  int _optimalColWidth_instVersion;
265  int _optimalColWidth_size;
266 
267 
268 public:
269 
270  QAction * actionInstallSourceRpm;
271  QAction * actionDontInstallSourceRpm;
272  QAction * actionInstallListSourceRpms;
273  QAction * actionDontInstallListSourceRpms;
274 };
275 
276 
277 
279 {
280 public:
281 
282  /**
283  * Constructor. Creates a YQPkgList item that corresponds to the package
284  * manager object that 'pkg' refers to.
285  **/
286  YQPkgListItem( YQPkgList * pkgList,
287  ZyppSel selectable,
288  ZyppPkg zyppPkg );
289 
290  /**
291  * Destructor
292  **/
293  virtual ~YQPkgListItem();
294 
295  /**
296  * Returns the parent package list.
297  **/
298  YQPkgList * pkgList() { return _pkgList; }
299 
300  /**
301  * Returns the original object within the package manager backend.
302  **/
303  ZyppPkg zyppPkg() const { return _zyppPkg; }
304 
305  /**
306  * Returns the source RPM package status:
307  * Should the source RPM be installed?
308  **/
309  bool installSourceRpm() const;
310 
311  /**
312  * Set the source RPM status
313  **/
314  void setInstallSourceRpm( bool installSourceRpm );
315 
316  /**
317  * Cycle the source package status to the next valid value.
318  **/
319  void toggleSourceRpmStatus();
320 
321  /**
322  * Returns whether or not a source RPM is available for this package.
323  **/
324  bool hasSourceRpm() const;
325 
326  /**
327  * sorting function
328  */
329  virtual bool operator< ( const QTreeWidgetItem & other ) const;
330 
331  /**
332  * Update this item's data completely.
333  * Triggered by QY2ListView::updateAllItemData().
334  *
335  * Reimplemented from YQPkgObjList.
336  **/
337  virtual void updateData();
338 
339  /**
340  * Returns a tool tip text for a specific column of this item.
341  * 'column' is -1 if the mouse pointer is in the tree indentation area.
342  *
343  * Reimplemented from YQPkgObjList.
344  **/
345  virtual QString toolTip( int column );
346 
347  /**
348  * Returns true if this package is to be displayed dimmed,
349  * i.e. with grey text foreground rather than the normal black.
350  **/
351  bool isDimmed() const { return _dimmed; }
352 
353  /**
354  * Set the 'dimmed' flag.
355  **/
356  void setDimmed( bool d = true ) { _dimmed = d; }
357 
358 
359  // Columns
360 
361  int srpmStatusCol() const { return _pkgList->srpmStatusCol(); }
362 
363 
364 protected:
365 
366  /**
367  * Set the suitable icon for the source RPM status.
368  **/
369  void setSourceRpmIcon();
370 
371 
372  // Data members
373 
374  YQPkgList * _pkgList;
375  ZyppPkg _zyppPkg;
376  bool _dimmed;
377 };
378 
379 
380 #endif // ifndef YQPkgList_h
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:68
void addPkgItem(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list.
Definition: YQPkgList.cc:138
int globalSetPkgStatus(ZyppStatus newStatus, bool force, bool countOnly)
Set the status of all packages in the pool to a new value.
Definition: YQPkgList.cc:678
virtual void createInstalledContextMenu()
Create the context menu for installed items.
Definition: YQPkgList.cc:480
void resetOptimalColumnWidthValues()
Resets the optimal column width values.
Definition: YQPkgList.cc:305
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: Take care of source RPM status.
Definition: YQPkgList.cc:193
virtual void updateActions(YQPkgObjListItem *item)
Update the internal actions: What actions are available for &#39;item&#39;?
Definition: YQPkgList.cc:558
static bool haveInstalledPkgs()
Returns &#39;true&#39; if there are any installed packages.
Definition: YQPkgList.cc:178
bool isDimmed() const
Returns true if this package is to be displayed dimmed, i.e.
Definition: YQPkgList.h:351
void optimizeColumnWidths()
Optimizes the column widths depending on content and the available horizontal space.
Definition: YQPkgList.cc:379
void addPkgItemDimmed(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list, but display it dimmed (grey text foreground rather than normal black)...
Definition: YQPkgList.cc:145
ZyppPkg zyppPkg() const
Returns the original object within the package manager backend.
Definition: YQPkgList.h:303
YQPkgList * pkgList()
Returns the parent package list.
Definition: YQPkgList.h:298
void selectNextItem()
Select the next item, i.e.
virtual QSize sizeHint() const
Reimplemented from QListView / QWidget: Reserve a reasonable amount of space.
Definition: YQPkgList.cc:230
Display a list of zypp::Package objects.
Definition: YQPkgList.h:54
virtual void createNotInstalledContextMenu()
Create the context menu for items that are not installed.
Definition: YQPkgList.cc:461
void resort()
Sort the tree widget again according to the column selected and its current sort order.
Definition: YQPkgList.cc:441
YQPkgList(QWidget *parent)
Constructor.
Definition: YQPkgList.cc:70
void exportList(const QString filename, bool interactive) const
Save the pkg list to a file.
Definition: YQPkgList.cc:589
void clear()
Clears the tree-widgets content, resets the optimal column width values.
Definition: YQPkgList.cc:432
void setDimmed(bool d=true)
Set the &#39;dimmed&#39; flag.
Definition: YQPkgList.h:356
void askExportList() const
Ask for a file name and save the current pkg list to file.
Definition: YQPkgList.cc:578
void updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg)
Set and save optimal column widths depending on content only There is currently no way to get the opt...
Definition: YQPkgList.cc:317
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Add a submenu "All in this list..." to &#39;menu&#39;.
Definition: YQPkgList.cc:501
void createActions()
Create ( additional ) actions for the context menus.
Definition: YQPkgList.cc:524
void createSourceRpmContextMenu()
Create context menu for source RPMs.
Definition: YQPkgList.cc:237
void resizeEvent(QResizeEvent *event)
Handler for resize events.
Definition: YQPkgList.cc:450
virtual ~YQPkgList()
Destructor.
Definition: YQPkgList.cc:132