1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #ifndef YQPkgObjList_h
21 #define YQPkgObjList_h
27 #include <QY2ListView.h>
29 #include <zypp/Edition.h>
32 class YQPkgObjListItem;
40 * @short Abstract base class to display a list of zypp::ResObjects.
41 * Handles most generic stuff like setting status etc.
43 class YQPkgObjList : public QY2ListView
49 * Constructor. Does not add any QListView columns!
51 YQPkgObjList( QWidget * parent );
56 virtual ~YQPkgObjList();
63 int statusCol() const { return _statusCol; }
64 int nameCol() const { return _nameCol; }
65 int summaryCol() const { return _summaryCol; }
66 int sizeCol() const { return _sizeCol; }
67 int versionCol() const { return _versionCol; }
68 int instVersionCol() const { return _instVersionCol; }
69 int brokenIconCol() const { return _brokenIconCol; }
70 int satisfiedIconCol() const { return _satisfiedIconCol; }
73 * Return whether or not items in this list are generally editable,
74 * i.e. the user can change their status. Note that individual items can be
75 * set to non-editable even if the list is generally editable.
76 * Lists are editable by default.
78 bool editable() const { return _editable; }
81 * Set the list's editable status.
83 void setEditable( bool editable = true ) { _editable = editable; }
86 * Sets the currently selected item's status.
87 * Automatically selects the next item if 'selectNextItem' is 'true'.
89 void setCurrentStatus( ZyppStatus newStatus,
90 bool selectNextItem = false );
93 * Sets the status of all (toplevel) list items to 'newStatus', if possible.
94 * Only one single statusChanged() signal is emitted.
96 * 'force' overrides sensible defaults like setting only zypp::ResObjects to
97 * 'update' that really come with a newer version.
99 void setAllItemStatus( ZyppStatus newStatus, bool force = false );
102 * Add a submenu "All in this list..." to 'menu'.
103 * Returns the newly created submenu.
105 virtual QPopupMenu * addAllInListSubMenu( QPopupMenu * menu );
108 * Returns the suitable icon for a zypp::ResObject status - the regular
109 * icon if 'enabled' is 'true' or the insensitive icon if 'enabled' is
110 * 'false. 'bySelection' is relevant only for auto-states: This uses the
111 * icon for 'auto-by-selection" rather than the default auto-icon.
113 virtual QPixmap statusIcon( ZyppStatus status,
115 bool bySelection = false );
118 * Returns a short (one line) descriptive text for a zypp::ResObject status.
120 virtual QString statusText( ZyppStatus status ) const;
126 * Add an exclude rule to this list.
128 void addExcludeRule( YQPkgObjList::ExcludeRule * rule );
131 * Apply all exclude rules of this list to all items,
132 * including those that are currently excluded.
134 void applyExcludeRules();
137 * Apply all exclude rules of this list to one item.
139 void applyExcludeRules( QListViewItem * );
142 * Exclude or include an item, i.e. remove it from the visible items
143 * and add it to the internal exclude list or vice versa.
145 void exclude( YQPkgObjListItem * item, bool exclude );
151 * Add a zypp::ResObject to the list. Connect a filter's filterMatch()
152 * signal to this slot. Remember to connect filterStart() to clear()
153 * (inherited from QListView).
155 * 'zyppObj' has to be one of the objects of 'selectable'. If it is 0,
156 * selectable->theObject() will be used.
158 * Intentionally NOT named addItem() so the calling class cannot confuse
159 * this method with overlaid methods of the same name that were simply
160 * forgotten to implement!
162 void addPkgObjItem( ZyppSel selectable,
163 ZyppObj zyppObj = 0 );
166 * Add a purely passive list item that has a name and optional summary and
169 void addPassiveItem( const QString & name,
170 const QString & summary = QString::null,
174 * Dispatcher slot for mouse click: cycle status depending on column.
176 virtual void pkgObjClicked( int button,
177 QListViewItem * item,
179 const QPoint & pos );
182 * Reimplemented from QY2ListView:
183 * Emit selectionChanged() signal after clearing the list.
185 virtual void clear();
188 * Update the internal actions: What actions are available for 'item'?
190 virtual void updateActions( YQPkgObjListItem * item );
193 * Update the internal actions for the currently selected item ( if any ).
194 * This only calls updateActions( YQPkgObjListItem * ) with the currently
195 * selected item as argument, so there is normally no need to reimplement
196 * this method, too, if the other one is reimplemented.
198 virtual void updateActions();
201 * Emit an updatePackages() signal.
203 void sendUpdatePackages() { emit updatePackages(); }
206 * Select the next item, i.e. move the selection one item further down the
209 void selectNextItem();
212 * Emit a statusChanged() signal for the specified zypp::ResObject.
214 void sendStatusChanged() { emit statusChanged(); }
217 * Display a one-line message in the list.
219 virtual void message( const QString & text );
222 * Write statistics about excluded items to the log, if there are any.
224 void logExcludeStatistics();
227 // Direct access to some states for menu actions
229 void setCurrentInstall() { setCurrentStatus( S_Install ); }
230 void setCurrentDontInstall() { setCurrentStatus( S_NoInst ); }
231 void setCurrentKeepInstalled() { setCurrentStatus( S_KeepInstalled ); }
232 void setCurrentDelete() { setCurrentStatus( S_Del ); }
233 void setCurrentUpdate() { setCurrentStatus( S_Update ); }
234 void setCurrentTaboo() { setCurrentStatus( S_Taboo ); }
235 void setCurrentProtected() { setCurrentStatus( S_Protected ); }
237 void setListInstall() { setAllItemStatus( S_Install ); }
238 void setListDontInstall() { setAllItemStatus( S_NoInst ); }
239 void setListKeepInstalled() { setAllItemStatus( S_KeepInstalled ); }
240 void setListDelete() { setAllItemStatus( S_Del ); }
241 void setListUpdate() { setAllItemStatus( S_Update ); }
242 void setListUpdateForce() { setAllItemStatus( S_Update, true ); }
243 void setListTaboo() { setAllItemStatus( S_Taboo ); }
244 void setListProtected() { setAllItemStatus( S_Protected ); }
250 * Dispatcher slot for selection change - internal only.
252 virtual void selectionChangedInternal( QListViewItem * item );
259 * Emitted when a zypp::ui::Selectable is selected.
260 * May be called with a null poiner if no zypp::ResObject is selected.
262 void selectionChanged( ZyppSel selectable );
265 * Emitted when the status of a zypp::ResObject is changed.
267 void statusChanged();
270 * Emitted when it's time to update displayed package information,
271 * e.g., package states.
273 void updatePackages();
279 * Event handler for keyboard input.
280 * Only very special keys are processed here.
282 * Reimplemented from QListView / QWidget.
284 virtual void keyPressEvent( QKeyEvent * ev );
287 * Returns the context menu for items that are not installed.
288 * Creates the menu upon the first call.
290 virtual QPopupMenu * installedContextMenu();
293 * Returns the context menu for items that are installed.
294 * Creates the menu upon the first call.
296 virtual QPopupMenu * notInstalledContextMenu();
299 * Create the context menu for items that are not installed.
301 virtual void createNotInstalledContextMenu();
304 * Create the context menu for installed items.
306 virtual void createInstalledContextMenu();
309 * Create the actions for the context menus.
310 * Note: This is intentionally not virtual!
312 void createActions();
315 * Create an action based on a zypp::ResObject status - automatically
316 * retrieve the corresponding status icons (both sensitive and insensitive)
317 * and text. 'key' is only a descriptive text, no true accelerator.
319 QAction * createAction( ZyppStatus status,
320 const QString & key = QString::null,
321 bool enabled = false );
324 * Low-level: Create an action.
325 * 'key' is only a descriptive text, no true accelerator.
327 QAction * createAction( const QString & text,
328 const QPixmap & icon = QPixmap(),
329 const QPixmap & insensitiveIcon = QPixmap(),
330 const QString & key = QString::null,
331 bool enabled = false );
344 int _satisfiedIconCol;
348 typedef list<ExcludeRule *> ExcludeRuleList;
350 ExcludeRuleList _excludeRules;
351 ExcludedItems * _excludedItems;
353 QPopupMenu * _installedContextMenu;
354 QPopupMenu * _notInstalledContextMenu;
359 QAction * actionSetCurrentInstall;
360 QAction * actionSetCurrentDontInstall;
361 QAction * actionSetCurrentKeepInstalled;
362 QAction * actionSetCurrentDelete;
363 QAction * actionSetCurrentUpdate;
364 QAction * actionSetCurrentTaboo;
365 QAction * actionSetCurrentProtected;
367 QAction * actionSetListInstall;
368 QAction * actionSetListDontInstall;
369 QAction * actionSetListKeepInstalled;
370 QAction * actionSetListDelete;
371 QAction * actionSetListUpdate;
372 QAction * actionSetListUpdateForce;
373 QAction * actionSetListTaboo;
374 QAction * actionSetListProtected;
383 class YQPkgObjListItem: public QY2ListViewItem
388 * Constructor for root items: Creates a YQPkgObjList item that corresponds
389 * to the ZYPP selectable that 'selectable' refers to. 'zyppObj' has to be
390 * one object of 'selectable'. If it is 0, selectable->theObject() will be
393 YQPkgObjListItem( YQPkgObjList * pkgObjList,
395 ZyppObj zyppObj = 0 );
399 * Constructor for non-root items.
401 YQPkgObjListItem( YQPkgObjList * pkgObjList,
402 QY2ListViewItem * parent,
404 ZyppObj zyppObj = 0 );
411 virtual ~YQPkgObjListItem();
414 * Returns the original selectable within the package manager backend.
416 ZyppSel selectable() const { return _selectable; }
419 * Returns the original object within the package manager backend.
421 ZyppObj zyppObj() const { return _zyppObj; }
424 * Return whether or not this items is editable, i.e. the user can change
425 * its status. This requires the corresponding list to be editable, too.
426 * Items are editable by default.
428 bool editable() const { return _editable; }
431 * Set this item's editable status.
433 void setEditable( bool editable = true ) { _editable = editable; }
436 * Returns the (binary RPM) package status
438 ZyppStatus status() const;
441 * Returns 'true' if this selectable's status is set by a selection
442 * (rather than by the user or by the dependency solver).
444 bool bySelection() const;
447 * Set the (binary RPM) package status.
449 * If 'sendSignals' is 'true' (default), the parent list will be requested
450 * to send update signals. List operations might want to use this for
451 * optimizations to send the signals only once after all changes are done.
453 virtual void setStatus( ZyppStatus newStatus, bool sendSignals = true );
456 * Set a status icon according to the package's status.
458 virtual void setStatusIcon();
461 * Update this item's status.
462 * Triggered by QY2ListView::updateAllItemStates().
463 * Overwritten from QY2ListViewItem.
465 virtual void updateStatus();
468 * Cycle the package status to the next valid value.
470 virtual void cycleStatus();
473 * Check if the candidate is newer than the installed version.
475 bool candidateIsNewer() const { return _candidateIsNewer; }
478 * Check if the installed version is newer than the candidate.
480 bool installedIsNewer() const { return _installedIsNewer; }
483 * Check if this item is satisfied, even though it is not installed.
484 * This is useful for package collections, e.g., patterns and patches:
485 * 'true' is returned if all requirements are fulfilled, but the object
486 * itself is not installed.
488 bool isSatisfied() const;
491 * Check if this item is "broken": If it is installed, but any of its
492 * dependencies are no longer satisfied.
493 * This is useful for package collections, e.g., patterns and patches.
495 bool isBroken() const;
498 * Display this item's notify text (if there is any) that corresponds to
499 * the specified status (S_Install, S_Del) in a pop-up window.
501 void showNotifyTexts( ZyppStatus status );
504 * Display a selectable's license agreement (if there is any) that
505 * corresponds to its current status (S_Install, S_Update) in a pop-up
508 * Returns 'true' if the user agreed to that license , 'false' otherwise.
509 * The item's status may have changed to S_Taboo, S_Proteced or S_Del if
510 * the user disagreed with the license.
512 static bool showLicenseAgreement( ZyppSel sel );
515 * Display this item's license agreement (if there is any) that corresponds
516 * to its current status (S_Install, S_Update) in a pop-up window.
518 bool showLicenseAgreement();
521 * Comparison function used for sorting the list.
527 * Reimplemented from QListViewItem
529 virtual int compare( QListViewItem * other,
531 bool ascending ) const;
534 * Calculate a numerical value to compare versions, based on version
537 * - Installed newer than candidate (red)
538 * - Candidate newer than installed (blue) - worthwhile updating
540 * - Not installed, but candidate available
542 int versionPoints() const;
545 * Update this item's data completely.
546 * Triggered by QY2ListView::updateAllItemData().
548 * Reimplemented from QY2ListViewItem.
550 virtual void updateData();
553 * Returns a tool tip text for a specific column of this item.
554 * 'column' is -1 if the mouse pointer is in the tree indentation area.
556 * Reimplemented from QY2ListViewItem.
558 virtual QString toolTip( int column );
561 * Returns 'true' if this item is excluded.
563 bool isExcluded() const { return _excluded; }
566 * Set this item's exclude flag.
567 * Note that this is just a marker. It is the caller's responsibility
568 * to add or remove it from exclude lists etc.
570 void setExcluded( bool exclude = true );
573 // Handle Debug isBroken and isSatisfied flags
575 bool debugIsBroken() const { return _debugIsBroken; }
576 bool debugIsSatisfied() const { return _debugIsSatisfied; }
577 void setDebugIsBroken ( bool val = true ) { _debugIsBroken = val; }
578 void setDebugIsSatisfied( bool val = true ) { _debugIsSatisfied = val; }
579 void toggleDebugIsBroken() { _debugIsBroken = ! _debugIsBroken; }
580 void toggleDebugIsSatisfied() { _debugIsSatisfied = ! _debugIsSatisfied; }
585 int statusCol() const { return _pkgObjList->statusCol(); }
586 int nameCol() const { return _pkgObjList->nameCol(); }
587 int summaryCol() const { return _pkgObjList->summaryCol(); }
588 int sizeCol() const { return _pkgObjList->sizeCol(); }
589 int versionCol() const { return _pkgObjList->versionCol(); }
590 int instVersionCol() const { return _pkgObjList->instVersionCol(); }
591 int brokenIconCol() const { return _pkgObjList->brokenIconCol(); }
592 int satisfiedIconCol() const { return _pkgObjList->satisfiedIconCol(); }
598 * Initialize internal data and set fields accordingly.
603 * Apply changes hook. This is called each time the user changes the status
604 * of a list item manually (if the old status is different from the new
605 * one). Insert code to propagate changes to other objects here, for
606 * example to trigger a "small" solver run (Resolver::transactObjKind()
609 * This default implementation does nothing.
611 virtual void applyChanges() {}
614 * Do a "small" solver run for all "resolvable collections", i.e., for
615 * selections, patterns, languages, patches.
617 void solveResolvableCollections();
620 * Set a column text via STL string.
621 * ( QListViewItem::setText() expects a QString! )
623 void setText( int column, const string text );
626 * Re-declare ordinary setText() method so the compiler doesn't get
627 * confused which one to use.
629 void setText( int column, const QString & text )
630 { QListViewItem::setText( column, text ); }
633 * Set a column text via Edition.
635 void setText( int column, const zypp::Edition & edition );
642 YQPkgObjList * _pkgObjList;
646 bool _candidateIsNewer:1;
647 bool _installedIsNewer:1;
649 bool _debugIsBroken:1;
650 bool _debugIsSatisfied:1;
656 class YQPkgObjList::ExcludeRule
661 * Constructor: Creates a new exclude rule with a regular expression
662 * to check against the text of the specified column of each list
665 * The parent YQPkgObjList will assume ownership of this exclude rule
666 * and destroy it when the parent is destroyed.
668 ExcludeRule( YQPkgObjList * parent,
669 const QRegExp & regexp,
673 // Intentionally omitting virtual destructor:
674 // No allocated objects, no other virtual methods,
675 // no need to have a vtable for each instance of this class.
677 // virtual ~ExcludeRule();
680 * Enable or disable this exclude rule.
681 * New exclude rules are enabled by default.
683 void enable( bool enable = true );
686 * Returns 'true' if this exclude rule is enabled,
689 bool isEnabled() const { return _enabled; }
692 * Change the regular expression after creation.
694 void setRegexp( const QRegExp & regexp );
697 * Returns the regexp.
699 QRegExp regexp() const { return _regexp; };
702 * Change the column number to check against after creation.
704 void setColumn( int column = 0 );
707 * Returns the column number.
709 int column() const { return _column; }
712 * Returns this exclude rule's parent YQPkgObjList.
714 YQPkgObjList * parent() const { return _parent; }
717 * Check a list item against this exclude rule.
718 * Returns 'true' if the item matches this exclude rule,
719 * i.e. if it should be excluded.
721 bool match( QListViewItem * item );
725 YQPkgObjList * _parent;
732 class YQPkgObjList::ExcludedItems
736 typedef std::map <QListViewItem *, QListViewItem *> ItemMap;
737 typedef std::pair<QListViewItem *, QListViewItem *> ItemPair;
738 typedef ItemMap::iterator iterator;
743 ExcludedItems( YQPkgObjList * parent );
748 virtual ~ExcludedItems();
751 * Add a list item to the excluded items and transfer ownership to this
754 * oldParent is the previous parent item of this item
755 * or 0 if it was a root item.
757 void add( QListViewItem * item, QListViewItem * oldParent );
760 * Remove a list item from the excluded items and transfer ownership back
763 void remove( QListViewItem * item );
766 * Clear the excluded items. Delete all items still excluded.
771 * Returns 'true' if the specified item is in the excluded items.
773 bool contains( QListViewItem * item );
776 * Returns the old parent of this item so it can be reparented
777 * or 0 if it was a root item.
779 QListViewItem * oldParentItem( QListViewItem * item );
782 * Returns the number of items
784 int size() const { return (int) _excludeMap.size(); }
787 * Returns an iterator that points to the first excluded item.
789 iterator begin() { return _excludeMap.begin(); }
792 * Returns an iterator that points after the last excluded item.
794 iterator end() { return _excludeMap.end(); }
799 YQPkgObjList * _pkgObjList;
803 #endif // ifndef YQPkgObjList_h