libyui-qt-pkg
YQPkgObjList.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: YQPkgObjList.h
35 
36  Author: Stefan Hundhammer <shundhammer.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgObjList_h
42 #define YQPkgObjList_h
43 
44 #include <QPixmap>
45 #include <QRegExp>
46 #include <QMenu>
47 #include <QEvent>
48 
49 #include <map>
50 #include <list>
51 
52 #include <yui/FSize.h>
53 #include <yui/qt/QY2ListView.h>
54 #include <zypp/Edition.h>
55 #include "YQZypp.h"
56 
57 class YQPkgObjListItem;
58 class QAction;
59 class QMenu;
60 using std::string;
61 using std::list;
62 
63 
68 class YQPkgObjList : public QY2ListView
69 {
70  Q_OBJECT
71 
72 protected:
76  YQPkgObjList( QWidget * parent );
77 
81  virtual ~YQPkgObjList();
82 
83  // avoiding warning about virtuals
84  using QTreeWidget::currentItemChanged;
85 
86 public:
87 
88  // make it public
89  QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const
90  { return QY2ListView::itemFromIndex(index); }
91 
92  // Column numbers
93 
94  int iconCol() const { return _iconCol; }
95  int statusCol() const { return _statusCol; }
96  int nameCol() const { return _nameCol; }
97  int summaryCol() const { return _summaryCol; }
98  int sizeCol() const { return _sizeCol; }
99  int versionCol() const { return _versionCol; }
100  int instVersionCol() const { return _instVersionCol; }
101  int brokenIconCol() const { return _brokenIconCol; }
102  int satisfiedIconCol() const { return _satisfiedIconCol; }
103 
110  bool editable() const { return _editable; }
111 
115  void setEditable( bool editable = true ) { _editable = editable; }
116 
121  void setCurrentStatus( ZyppStatus newStatus,
122  bool selectNextItem = false,
123  bool ifNewerOnly = false );
124 
125 
133  void setAllItemStatus( ZyppStatus newStatus, bool force = false );
134 
139  virtual QMenu * addAllInListSubMenu( QMenu * menu );
140 
147  virtual QPixmap statusIcon( ZyppStatus status,
148  bool enabled = true,
149  bool bySelection = false );
150 
154  virtual QString statusText( ZyppStatus status ) const;
155 
156 
157  class ExcludeRule;
158 
163 
168  void applyExcludeRules();
169 
173  void applyExcludeRules( QTreeWidgetItem * );
174 
179  void exclude( YQPkgObjListItem * item, bool exclude );
180 
181 
182 public slots:
183 
196  void addPkgObjItem( ZyppSel selectable,
197  ZyppObj zyppObj = 0 );
198 
203  void addPassiveItem( const QString & name,
204  const QString & summary = QString(),
205  FSize size = -1 );
206 
210  virtual void pkgObjClicked( int button,
211  QTreeWidgetItem * item,
212  int col,
213  const QPoint & pos );
214 
219  virtual void clear();
220 
227  virtual void updateActions( YQPkgObjListItem * item = 0);
228 
233 
238  void selectNextItem();
239 
243  void sendStatusChanged() { emit statusChanged(); }
244 
248  virtual void message( const QString & text );
249 
253  void logExcludeStatistics();
254 
255 
256  // Direct access to some states for menu actions
257 
258  void setCurrentInstall() { setCurrentStatus( S_Install ); }
259  void setCurrentDontInstall() { setCurrentStatus( S_NoInst ); }
260  void setCurrentKeepInstalled() { setCurrentStatus( S_KeepInstalled ); }
261  void setCurrentDelete() { setCurrentStatus( S_Del ); }
262  void setCurrentUpdate() { setCurrentStatus( S_Update, false, true ); }
263  void setCurrentUpdateForce() { setCurrentStatus( S_Update ); }
264  void setCurrentTaboo() { setCurrentStatus( S_Taboo ); }
265  void setCurrentProtected() { setCurrentStatus( S_Protected ); }
266 
267  void setListInstall() { setAllItemStatus( S_Install ); }
268  void setListDontInstall() { setAllItemStatus( S_NoInst ); }
269  void setListKeepInstalled() { setAllItemStatus( S_KeepInstalled ); }
270  void setListDelete() { setAllItemStatus( S_Del ); }
271  void setListUpdate() { setAllItemStatus( S_Update ); }
272  void setListUpdateForce() { setAllItemStatus( S_Update, true ); }
273  void setListTaboo() { setAllItemStatus( S_Taboo ); }
274  void setListProtected() { setAllItemStatus( S_Protected ); }
275 
276 
277 protected slots:
278 
282  virtual void currentItemChangedInternal( QTreeWidgetItem * item );
283 
287  void slotCustomContextMenu(const QPoint& pos);
288 
289 
290 signals:
291 
292 
297  void currentItemChanged( ZyppSel selectable );
298 
302  void statusChanged();
303 
308  void updatePackages();
309 
310 
311 protected:
312 
319  virtual void keyPressEvent( QKeyEvent * ev );
320 
325  virtual QMenu * installedContextMenu();
326 
331  virtual QMenu * notInstalledContextMenu();
332 
336  virtual void createNotInstalledContextMenu();
337 
341  virtual void createInstalledContextMenu();
342 
347  void createActions();
348 
354  QAction * createAction( ZyppStatus status,
355  const QString & key = QString(),
356  bool enabled = false );
357 
362  QAction * createAction( const QString & text,
363  const QPixmap & icon = QPixmap(),
364  const QPixmap & insensitiveIcon = QPixmap(),
365  const QString & key = QString(),
366  bool enabled = false );
367 
368  // Data members
369 
370  int _iconCol;
371  int _statusCol;
372  int _nameCol;
373  int _summaryCol;
374  int _sizeCol;
375  int _versionCol;
376  int _instVersionCol;
377  int _brokenIconCol;
378  int _satisfiedIconCol;
379  bool _editable;
380  bool _debug;
381  int _excludedItemsCount;
382 
383  typedef list<ExcludeRule *> ExcludeRuleList;
384 
385  ExcludeRuleList _excludeRules;
386 
387  QMenu * _installedContextMenu;
388  QMenu * _notInstalledContextMenu;
389 
390 
391 public:
392 
393  QAction * actionSetCurrentInstall;
394  QAction * actionSetCurrentDontInstall;
395  QAction * actionSetCurrentKeepInstalled;
396  QAction * actionSetCurrentDelete;
397  QAction * actionSetCurrentUpdate;
398  QAction * actionSetCurrentUpdateForce;
399  QAction * actionSetCurrentTaboo;
400  QAction * actionSetCurrentProtected;
401 
402  QAction * actionSetListInstall;
403  QAction * actionSetListDontInstall;
404  QAction * actionSetListKeepInstalled;
405  QAction * actionSetListDelete;
406  QAction * actionSetListUpdate;
407  QAction * actionSetListUpdateForce;
408  QAction * actionSetListTaboo;
409  QAction * actionSetListProtected;
410 };
411 
412 
413 
414 class YQPkgObjListItem: public QY2ListViewItem
415 {
416 public:
417 
424  YQPkgObjListItem( YQPkgObjList * pkgObjList,
425  ZyppSel selectable,
426  ZyppObj zyppObj = 0 );
427 
433  YQPkgObjListItem( YQPkgObjList * pkgObjList );
434 
435 protected:
439  YQPkgObjListItem( YQPkgObjList * pkgObjList,
440  QY2ListViewItem * parent,
441  ZyppSel selectable,
442  ZyppObj zyppObj = 0 );
443 
444 public:
445 
449  virtual ~YQPkgObjListItem();
450 
454  ZyppSel selectable() const { return _selectable; }
455 
459  ZyppObj zyppObj() const { return _zyppObj; }
460 
466  bool editable() const { return _editable; }
467 
471  void setEditable( bool editable = true ) { _editable = editable; }
472 
476  virtual ZyppStatus status() const;
477 
482  virtual bool bySelection() const;
483 
491  virtual void setStatus( ZyppStatus newStatus, bool sendSignals = true );
492 
493 
497  virtual void setStatusIcon();
498 
504  virtual void updateStatus();
505 
509  virtual void cycleStatus();
510 
514  bool candidateIsNewer() const { return _candidateIsNewer; }
515 
519  bool installedIsNewer() const { return _installedIsNewer; }
520 
527  bool isSatisfied() const;
528 
534  bool isBroken() const;
535 
540  void showNotifyTexts( ZyppStatus status );
541 
551  static bool showLicenseAgreement( ZyppSel sel );
552 
557  bool showLicenseAgreement();
558 
562  virtual bool operator< ( const QTreeWidgetItem & other ) const;
563 
573  int versionPoints() const;
574 
581  virtual void updateData();
582 
589  virtual QString toolTip( int column );
590 
594  bool isExcluded() const { return _excluded; }
595 
601  void setExcluded( bool exclude = true );
602 
603 
604  // Handle Debug isBroken and isSatisfied flags
605 
606  bool debugIsBroken() const { return _debugIsBroken; }
607  bool debugIsSatisfied() const { return _debugIsSatisfied; }
608  void setDebugIsBroken ( bool val = true ) { _debugIsBroken = val; }
609  void setDebugIsSatisfied( bool val = true ) { _debugIsSatisfied = val; }
610  void toggleDebugIsBroken() { _debugIsBroken = ! _debugIsBroken; }
611  void toggleDebugIsSatisfied() { _debugIsSatisfied = ! _debugIsSatisfied; }
612 
613 
614  // Columns
615 
616  int statusCol() const { return _pkgObjList->statusCol(); }
617  int nameCol() const { return _pkgObjList->nameCol(); }
618  int summaryCol() const { return _pkgObjList->summaryCol(); }
619  int sizeCol() const { return _pkgObjList->sizeCol(); }
620  int versionCol() const { return _pkgObjList->versionCol(); }
621  int instVersionCol() const { return _pkgObjList->instVersionCol(); }
622  int brokenIconCol() const { return _pkgObjList->brokenIconCol(); }
623  int satisfiedIconCol() const { return _pkgObjList->satisfiedIconCol(); }
624 
625 
626 protected:
627 
632  void init();
633 
643  virtual void applyChanges() {}
644 
650 
655  void setText( int column, const string text );
656 
657  public:
662  void setText( int column, const QString & text )
663  { QTreeWidgetItem::setText( column, text ); }
664  protected:
668  void setText( int column, const zypp::Edition & edition );
669 
670 
671  //
672  // Data members
673  //
674 
675  YQPkgObjList * _pkgObjList;
676  ZyppSel _selectable;
677  ZyppObj _zyppObj;
678  bool _editable:1;
679  bool _candidateIsNewer:1;
680  bool _installedIsNewer:1;
681 
682  bool _debugIsBroken:1;
683  bool _debugIsSatisfied:1;
684  bool _excluded:1;
685 };
686 
687 
688 
690 {
691 public:
692 
702  const QRegExp & regexp,
703  int column = 0 );
704 
705 
706  // Intentionally omitting virtual destructor:
707  // No allocated objects, no other virtual methods,
708  // no need to have a vtable for each instance of this class.
709  //
710  // virtual ~ExcludeRule();
711 
716  void enable( bool enable = true );
717 
722  bool isEnabled() const { return _enabled; }
723 
727  void setRegexp( const QRegExp & regexp );
728 
732  QRegExp regexp() const { return _regexp; };
733 
737  void setColumn( int column = 0 );
738 
742  int column() const { return _column; }
743 
747  YQPkgObjList * parent() const { return _parent; }
748 
754  bool match( QTreeWidgetItem * item );
755 
756 private:
757 
758  YQPkgObjList * _parent;
759  QRegExp _regexp;
760  int _column;
761  bool _enabled;
762 };
763 
764 
765 #endif // ifndef YQPkgObjList_h
bool installedIsNewer() const
Definition: YQPkgObjList.h:519
bool candidateIsNewer() const
Definition: YQPkgObjList.h:514
bool isExcluded() const
Definition: YQPkgObjList.h:594
Abstract base class to display a list of zypp::ResObjects. Handles most generic stuff like setting st...
Definition: YQPkgObjList.h:68
void statusChanged()
void setText(int column, const string text)
Definition: YQPkgObjList.cc:1028
void setExcluded(bool exclude=true)
Definition: YQPkgObjList.cc:1523
int column() const
Definition: YQPkgObjList.h:742
virtual QPixmap statusIcon(ZyppStatus status, bool enabled=true, bool bySelection=false)
Definition: YQPkgObjList.cc:216
void addPkgObjItem(ZyppSel selectable, ZyppObj zyppObj=0)
Definition: YQPkgObjList.cc:138
YQPkgObjListItem(YQPkgObjList *pkgObjList, ZyppSel selectable, ZyppObj zyppObj=0)
Definition: YQPkgObjList.cc:860
void setEditable(bool editable=true)
Definition: YQPkgObjList.h:471
virtual bool operator<(const QTreeWidgetItem &other) const
Definition: YQPkgObjList.cc:1444
void addExcludeRule(YQPkgObjList::ExcludeRule *rule)
Definition: YQPkgObjList.cc:739
virtual void createInstalledContextMenu()
Definition: YQPkgObjList.cc:503
virtual QString statusText(ZyppStatus status) const
Definition: YQPkgObjList.cc:266
void addPassiveItem(const QString &name, const QString &summary=QString(), FSize size=-1)
Definition: YQPkgObjList.cc:152
void setAllItemStatus(ZyppStatus newStatus, bool force=false)
Definition: YQPkgObjList.cc:322
YQPkgObjList * parent() const
Definition: YQPkgObjList.h:747
virtual QMenu * notInstalledContextMenu()
Definition: YQPkgObjList.cc:539
bool showLicenseAgreement()
Definition: YQPkgObjList.cc:1308
virtual void updateData()
Definition: YQPkgObjList.cc:1021
virtual void clear()
Definition: YQPkgObjList.cc:206
void setColumn(int column=0)
Definition: YQPkgObjList.cc:1561
virtual void message(const QString &text)
Definition: YQPkgObjList.cc:729
virtual void updateStatus()
Definition: YQPkgObjList.cc:1095
ExcludeRule(YQPkgObjList *parent, const QRegExp &regexp, int column=0)
Definition: YQPkgObjList.cc:1528
void createActions()
Definition: YQPkgObjList.cc:387
virtual void setStatus(ZyppStatus newStatus, bool sendSignals=true)
Definition: YQPkgObjList.cc:1066
QRegExp regexp() const
Definition: YQPkgObjList.h:732
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Definition: YQPkgObjList.cc:172
void enable(bool enable=true)
Definition: YQPkgObjList.cc:1541
void logExcludeStatistics()
Definition: YQPkgObjList.cc:767
virtual void currentItemChangedInternal(QTreeWidgetItem *item)
Definition: YQPkgObjList.cc:197
bool isBroken() const
Definition: YQPkgObjList.cc:1156
bool editable() const
Definition: YQPkgObjList.h:466
virtual void updateActions(YQPkgObjListItem *item=0)
Definition: YQPkgObjList.cc:559
void sendStatusChanged()
Definition: YQPkgObjList.h:243
void exclude(YQPkgObjListItem *item, bool exclude)
Definition: YQPkgObjList.cc:842
void selectNextItem()
Definition: YQPkgObjList.cc:370
void updatePackages()
void setText(int column, const QString &text)
Definition: YQPkgObjList.h:662
void setEditable(bool editable=true)
Definition: YQPkgObjList.h:115
virtual ZyppStatus status() const
Definition: YQPkgObjList.cc:1042
bool match(QTreeWidgetItem *item)
Definition: YQPkgObjList.cc:1568
bool editable() const
Definition: YQPkgObjList.h:110
Definition: YQPkgObjList.h:689
virtual void applyChanges()
Definition: YQPkgObjList.h:643
void applyExcludeRules()
Definition: YQPkgObjList.cc:746
void setRegexp(const QRegExp &regexp)
Definition: YQPkgObjList.cc:1554
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Definition: YQPkgObjList.cc:518
ZyppSel selectable() const
Definition: YQPkgObjList.h:454
bool isSatisfied() const
Definition: YQPkgObjList.cc:1144
void currentItemChanged(ZyppSel selectable)
Definition: YQPkgObjList.h:414
QAction * createAction(ZyppStatus status, const QString &key=QString(), bool enabled=false)
Definition: YQPkgObjList.cc:447
void slotCustomContextMenu(const QPoint &pos)
Definition: YQPkgObjList.cc:1582
void setCurrentStatus(ZyppStatus newStatus, bool selectNextItem=false, bool ifNewerOnly=false)
Definition: YQPkgObjList.cc:287
void sendUpdatePackages()
Definition: YQPkgObjList.h:232
virtual void createNotInstalledContextMenu()
Definition: YQPkgObjList.cc:489
virtual QMenu * installedContextMenu()
Definition: YQPkgObjList.cc:549
virtual bool bySelection() const
Definition: YQPkgObjList.cc:1055
bool isEnabled() const
Definition: YQPkgObjList.h:722
virtual QString toolTip(int column)
Definition: YQPkgObjList.cc:1394
void solveResolvableCollections()
Definition: YQPkgObjList.cc:1087
virtual ~YQPkgObjList()
Definition: YQPkgObjList.cc:132
void showNotifyTexts(ZyppStatus status)
Definition: YQPkgObjList.cc:1274
virtual void keyPressEvent(QKeyEvent *ev)
Definition: YQPkgObjList.cc:610
YQPkgObjList(QWidget *parent)
Definition: YQPkgObjList.cc:73
int versionPoints() const
Definition: YQPkgObjList.cc:1509
virtual ~YQPkgObjListItem()
Definition: YQPkgObjList.cc:900
virtual void setStatusIcon()
Definition: YQPkgObjList.cc:1102
ZyppObj zyppObj() const
Definition: YQPkgObjList.h:459
virtual void cycleStatus()
Definition: YQPkgObjList.cc:1193
void init()
Definition: YQPkgObjList.cc:907