1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #ifndef YQPkgObjList_h
21 #define YQPkgObjList_h
26 #include <q3popupmenu.h>
30 #include <QY2ListView.h>
32 #include <zypp/Edition.h>
35 class YQPkgObjListItem;
43 * @short Abstract base class to display a list of zypp::ResObjects.
44 * Handles most generic stuff like setting status etc.
46 class YQPkgObjList : public QY2ListView
52 * Constructor. Does not add any QListView columns!
54 YQPkgObjList( QWidget * parent );
59 virtual ~YQPkgObjList();
66 int statusCol() const { return _statusCol; }
67 int nameCol() const { return _nameCol; }
68 int summaryCol() const { return _summaryCol; }
69 int sizeCol() const { return _sizeCol; }
70 int versionCol() const { return _versionCol; }
71 int instVersionCol() const { return _instVersionCol; }
72 int brokenIconCol() const { return _brokenIconCol; }
73 int satisfiedIconCol() const { return _satisfiedIconCol; }
76 * Return whether or not items in this list are generally editable,
77 * i.e. the user can change their status. Note that individual items can be
78 * set to non-editable even if the list is generally editable.
79 * Lists are editable by default.
81 bool editable() const { return _editable; }
84 * Set the list's editable status.
86 void setEditable( bool editable = true ) { _editable = editable; }
89 * Sets the currently selected item's status.
90 * Automatically selects the next item if 'selectNextItem' is 'true'.
92 void setCurrentStatus( ZyppStatus newStatus,
93 bool selectNextItem = false );
96 * Sets the status of all (toplevel) list items to 'newStatus', if possible.
97 * Only one single statusChanged() signal is emitted.
99 * 'force' overrides sensible defaults like setting only zypp::ResObjects to
100 * 'update' that really come with a newer version.
102 void setAllItemStatus( ZyppStatus newStatus, bool force = false );
105 * Add a submenu "All in this list..." to 'menu'.
106 * Returns the newly created submenu.
108 virtual Q3PopupMenu * addAllInListSubMenu( Q3PopupMenu * menu );
111 * Returns the suitable icon for a zypp::ResObject status - the regular
112 * icon if 'enabled' is 'true' or the insensitive icon if 'enabled' is
113 * 'false. 'bySelection' is relevant only for auto-states: This uses the
114 * icon for 'auto-by-selection" rather than the default auto-icon.
116 virtual QPixmap statusIcon( ZyppStatus status,
118 bool bySelection = false );
121 * Returns a short (one line) descriptive text for a zypp::ResObject status.
123 virtual QString statusText( ZyppStatus status ) const;
129 * Add an exclude rule to this list.
131 void addExcludeRule( YQPkgObjList::ExcludeRule * rule );
134 * Apply all exclude rules of this list to all items,
135 * including those that are currently excluded.
137 void applyExcludeRules();
140 * Apply all exclude rules of this list to one item.
142 void applyExcludeRules( Q3ListViewItem * );
145 * Exclude or include an item, i.e. remove it from the visible items
146 * and add it to the internal exclude list or vice versa.
148 void exclude( YQPkgObjListItem * item, bool exclude );
154 * Add a zypp::ResObject to the list. Connect a filter's filterMatch()
155 * signal to this slot. Remember to connect filterStart() to clear()
156 * (inherited from QListView).
158 * 'zyppObj' has to be one of the objects of 'selectable'. If it is 0,
159 * selectable->theObject() will be used.
161 * Intentionally NOT named addItem() so the calling class cannot confuse
162 * this method with overlaid methods of the same name that were simply
163 * forgotten to implement!
165 void addPkgObjItem( ZyppSel selectable,
166 ZyppObj zyppObj = 0 );
169 * Add a purely passive list item that has a name and optional summary and
172 void addPassiveItem( const QString & name,
173 const QString & summary = QString::null,
177 * Dispatcher slot for mouse click: cycle status depending on column.
179 virtual void pkgObjClicked( int button,
180 Q3ListViewItem * item,
182 const QPoint & pos );
185 * Reimplemented from QY2ListView:
186 * Emit selectionChanged() signal after clearing the list.
188 virtual void clear();
191 * Update the internal actions: What actions are available for 'item'?
193 virtual void updateActions( YQPkgObjListItem * item );
196 * Update the internal actions for the currently selected item ( if any ).
197 * This only calls updateActions( YQPkgObjListItem * ) with the currently
198 * selected item as argument, so there is normally no need to reimplement
199 * this method, too, if the other one is reimplemented.
201 virtual void updateActions();
204 * Emit an updatePackages() signal.
206 void sendUpdatePackages() { emit updatePackages(); }
209 * Select the next item, i.e. move the selection one item further down the
212 void selectNextItem();
215 * Emit a statusChanged() signal for the specified zypp::ResObject.
217 void sendStatusChanged() { emit statusChanged(); }
220 * Display a one-line message in the list.
222 virtual void message( const QString & text );
225 * Write statistics about excluded items to the log, if there are any.
227 void logExcludeStatistics();
230 // Direct access to some states for menu actions
232 void setCurrentInstall() { setCurrentStatus( S_Install ); }
233 void setCurrentDontInstall() { setCurrentStatus( S_NoInst ); }
234 void setCurrentKeepInstalled() { setCurrentStatus( S_KeepInstalled ); }
235 void setCurrentDelete() { setCurrentStatus( S_Del ); }
236 void setCurrentUpdate() { setCurrentStatus( S_Update ); }
237 void setCurrentTaboo() { setCurrentStatus( S_Taboo ); }
238 void setCurrentProtected() { setCurrentStatus( S_Protected ); }
240 void setListInstall() { setAllItemStatus( S_Install ); }
241 void setListDontInstall() { setAllItemStatus( S_NoInst ); }
242 void setListKeepInstalled() { setAllItemStatus( S_KeepInstalled ); }
243 void setListDelete() { setAllItemStatus( S_Del ); }
244 void setListUpdate() { setAllItemStatus( S_Update ); }
245 void setListUpdateForce() { setAllItemStatus( S_Update, true ); }
246 void setListTaboo() { setAllItemStatus( S_Taboo ); }
247 void setListProtected() { setAllItemStatus( S_Protected ); }
253 * Dispatcher slot for selection change - internal only.
255 virtual void selectionChangedInternal( Q3ListViewItem * item );
262 * Emitted when a zypp::ui::Selectable is selected.
263 * May be called with a null poiner if no zypp::ResObject is selected.
265 void selectionChanged( ZyppSel selectable );
268 * Emitted when the status of a zypp::ResObject is changed.
270 void statusChanged();
273 * Emitted when it's time to update displayed package information,
274 * e.g., package states.
276 void updatePackages();
282 * Event handler for keyboard input.
283 * Only very special keys are processed here.
285 * Reimplemented from QListView / QWidget.
287 virtual void keyPressEvent( QKeyEvent * ev );
290 * Returns the context menu for items that are not installed.
291 * Creates the menu upon the first call.
293 virtual Q3PopupMenu * installedContextMenu();
296 * Returns the context menu for items that are installed.
297 * Creates the menu upon the first call.
299 virtual Q3PopupMenu * notInstalledContextMenu();
302 * Create the context menu for items that are not installed.
304 virtual void createNotInstalledContextMenu();
307 * Create the context menu for installed items.
309 virtual void createInstalledContextMenu();
312 * Create the actions for the context menus.
313 * Note: This is intentionally not virtual!
315 void createActions();
318 * Create an action based on a zypp::ResObject status - automatically
319 * retrieve the corresponding status icons (both sensitive and insensitive)
320 * and text. 'key' is only a descriptive text, no true accelerator.
322 Q3Action * createAction( ZyppStatus status,
323 const QString & key = QString::null,
324 bool enabled = false );
327 * Low-level: Create an action.
328 * 'key' is only a descriptive text, no true accelerator.
330 Q3Action * createAction( const QString & text,
331 const QPixmap & icon = QPixmap(),
332 const QPixmap & insensitiveIcon = QPixmap(),
333 const QString & key = QString::null,
334 bool enabled = false );
347 int _satisfiedIconCol;
351 typedef list<ExcludeRule *> ExcludeRuleList;
353 ExcludeRuleList _excludeRules;
354 ExcludedItems * _excludedItems;
356 Q3PopupMenu * _installedContextMenu;
357 Q3PopupMenu * _notInstalledContextMenu;
362 Q3Action * actionSetCurrentInstall;
363 Q3Action * actionSetCurrentDontInstall;
364 Q3Action * actionSetCurrentKeepInstalled;
365 Q3Action * actionSetCurrentDelete;
366 Q3Action * actionSetCurrentUpdate;
367 Q3Action * actionSetCurrentTaboo;
368 Q3Action * actionSetCurrentProtected;
370 Q3Action * actionSetListInstall;
371 Q3Action * actionSetListDontInstall;
372 Q3Action * actionSetListKeepInstalled;
373 Q3Action * actionSetListDelete;
374 Q3Action * actionSetListUpdate;
375 Q3Action * actionSetListUpdateForce;
376 Q3Action * actionSetListTaboo;
377 Q3Action * actionSetListProtected;
386 class YQPkgObjListItem: public QY2ListViewItem
391 * Constructor for root items: Creates a YQPkgObjList item that corresponds
392 * to the ZYPP selectable that 'selectable' refers to. 'zyppObj' has to be
393 * one object of 'selectable'. If it is 0, selectable->theObject() will be
396 YQPkgObjListItem( YQPkgObjList * pkgObjList,
398 ZyppObj zyppObj = 0 );
402 * Constructor for non-root items.
404 YQPkgObjListItem( YQPkgObjList * pkgObjList,
405 QY2ListViewItem * parent,
407 ZyppObj zyppObj = 0 );
414 virtual ~YQPkgObjListItem();
417 * Returns the original selectable within the package manager backend.
419 ZyppSel selectable() const { return _selectable; }
422 * Returns the original object within the package manager backend.
424 ZyppObj zyppObj() const { return _zyppObj; }
427 * Return whether or not this items is editable, i.e. the user can change
428 * its status. This requires the corresponding list to be editable, too.
429 * Items are editable by default.
431 bool editable() const { return _editable; }
434 * Set this item's editable status.
436 void setEditable( bool editable = true ) { _editable = editable; }
439 * Returns the (binary RPM) package status
441 ZyppStatus status() const;
444 * Returns 'true' if this selectable's status is set by a selection
445 * (rather than by the user or by the dependency solver).
447 bool bySelection() const;
450 * Set the (binary RPM) package status.
452 * If 'sendSignals' is 'true' (default), the parent list will be requested
453 * to send update signals. List operations might want to use this for
454 * optimizations to send the signals only once after all changes are done.
456 virtual void setStatus( ZyppStatus newStatus, bool sendSignals = true );
459 * Set a status icon according to the package's status.
461 virtual void setStatusIcon();
464 * Update this item's status.
465 * Triggered by QY2ListView::updateAllItemStates().
466 * Overwritten from QY2ListViewItem.
468 virtual void updateStatus();
471 * Cycle the package status to the next valid value.
473 virtual void cycleStatus();
476 * Check if the candidate is newer than the installed version.
478 bool candidateIsNewer() const { return _candidateIsNewer; }
481 * Check if the installed version is newer than the candidate.
483 bool installedIsNewer() const { return _installedIsNewer; }
486 * Check if this item is satisfied, even though it is not installed.
487 * This is useful for package collections, e.g., patterns and patches:
488 * 'true' is returned if all requirements are fulfilled, but the object
489 * itself is not installed.
491 bool isSatisfied() const;
494 * Check if this item is "broken": If it is installed, but any of its
495 * dependencies are no longer satisfied.
496 * This is useful for package collections, e.g., patterns and patches.
498 bool isBroken() const;
501 * Display this item's notify text (if there is any) that corresponds to
502 * the specified status (S_Install, S_Del) in a pop-up window.
504 void showNotifyTexts( ZyppStatus status );
507 * Display a selectable's license agreement (if there is any) that
508 * corresponds to its current status (S_Install, S_Update) in a pop-up
511 * Returns 'true' if the user agreed to that license , 'false' otherwise.
512 * The item's status may have changed to S_Taboo, S_Proteced or S_Del if
513 * the user disagreed with the license.
515 static bool showLicenseAgreement( ZyppSel sel );
518 * Display this item's license agreement (if there is any) that corresponds
519 * to its current status (S_Install, S_Update) in a pop-up window.
521 bool showLicenseAgreement();
524 * Comparison function used for sorting the list.
530 * Reimplemented from QListViewItem
532 virtual int compare( Q3ListViewItem * other,
534 bool ascending ) const;
537 * Calculate a numerical value to compare versions, based on version
540 * - Installed newer than candidate (red)
541 * - Candidate newer than installed (blue) - worthwhile updating
543 * - Not installed, but candidate available
545 int versionPoints() const;
548 * Update this item's data completely.
549 * Triggered by QY2ListView::updateAllItemData().
551 * Reimplemented from QY2ListViewItem.
553 virtual void updateData();
556 * Returns a tool tip text for a specific column of this item.
557 * 'column' is -1 if the mouse pointer is in the tree indentation area.
559 * Reimplemented from QY2ListViewItem.
561 virtual QString toolTip( int column );
564 * Returns 'true' if this item is excluded.
566 bool isExcluded() const { return _excluded; }
569 * Set this item's exclude flag.
570 * Note that this is just a marker. It is the caller's responsibility
571 * to add or remove it from exclude lists etc.
573 void setExcluded( bool exclude = true );
576 // Handle Debug isBroken and isSatisfied flags
578 bool debugIsBroken() const { return _debugIsBroken; }
579 bool debugIsSatisfied() const { return _debugIsSatisfied; }
580 void setDebugIsBroken ( bool val = true ) { _debugIsBroken = val; }
581 void setDebugIsSatisfied( bool val = true ) { _debugIsSatisfied = val; }
582 void toggleDebugIsBroken() { _debugIsBroken = ! _debugIsBroken; }
583 void toggleDebugIsSatisfied() { _debugIsSatisfied = ! _debugIsSatisfied; }
588 int statusCol() const { return _pkgObjList->statusCol(); }
589 int nameCol() const { return _pkgObjList->nameCol(); }
590 int summaryCol() const { return _pkgObjList->summaryCol(); }
591 int sizeCol() const { return _pkgObjList->sizeCol(); }
592 int versionCol() const { return _pkgObjList->versionCol(); }
593 int instVersionCol() const { return _pkgObjList->instVersionCol(); }
594 int brokenIconCol() const { return _pkgObjList->brokenIconCol(); }
595 int satisfiedIconCol() const { return _pkgObjList->satisfiedIconCol(); }
601 * Initialize internal data and set fields accordingly.
606 * Apply changes hook. This is called each time the user changes the status
607 * of a list item manually (if the old status is different from the new
608 * one). Insert code to propagate changes to other objects here, for
609 * example to trigger a "small" solver run (Resolver::transactObjKind()
612 * This default implementation does nothing.
614 virtual void applyChanges() {}
617 * Do a "small" solver run for all "resolvable collections", i.e., for
618 * selections, patterns, languages, patches.
620 void solveResolvableCollections();
623 * Set a column text via STL string.
624 * ( QListViewItem::setText() expects a QString! )
626 void setText( int column, const string text );
629 * Re-declare ordinary setText() method so the compiler doesn't get
630 * confused which one to use.
632 void setText( int column, const QString & text )
633 { Q3ListViewItem::setText( column, text ); }
636 * Set a column text via Edition.
638 void setText( int column, const zypp::Edition & edition );
645 YQPkgObjList * _pkgObjList;
649 bool _candidateIsNewer:1;
650 bool _installedIsNewer:1;
652 bool _debugIsBroken:1;
653 bool _debugIsSatisfied:1;
659 class YQPkgObjList::ExcludeRule
664 * Constructor: Creates a new exclude rule with a regular expression
665 * to check against the text of the specified column of each list
668 * The parent YQPkgObjList will assume ownership of this exclude rule
669 * and destroy it when the parent is destroyed.
671 ExcludeRule( YQPkgObjList * parent,
672 const QRegExp & regexp,
676 // Intentionally omitting virtual destructor:
677 // No allocated objects, no other virtual methods,
678 // no need to have a vtable for each instance of this class.
680 // virtual ~ExcludeRule();
683 * Enable or disable this exclude rule.
684 * New exclude rules are enabled by default.
686 void enable( bool enable = true );
689 * Returns 'true' if this exclude rule is enabled,
692 bool isEnabled() const { return _enabled; }
695 * Change the regular expression after creation.
697 void setRegexp( const QRegExp & regexp );
700 * Returns the regexp.
702 QRegExp regexp() const { return _regexp; };
705 * Change the column number to check against after creation.
707 void setColumn( int column = 0 );
710 * Returns the column number.
712 int column() const { return _column; }
715 * Returns this exclude rule's parent YQPkgObjList.
717 YQPkgObjList * parent() const { return _parent; }
720 * Check a list item against this exclude rule.
721 * Returns 'true' if the item matches this exclude rule,
722 * i.e. if it should be excluded.
724 bool match( Q3ListViewItem * item );
728 YQPkgObjList * _parent;
735 class YQPkgObjList::ExcludedItems
739 typedef std::map <Q3ListViewItem *, Q3ListViewItem *> ItemMap;
740 typedef std::pair<Q3ListViewItem *, Q3ListViewItem *> ItemPair;
741 typedef ItemMap::iterator iterator;
746 ExcludedItems( YQPkgObjList * parent );
751 virtual ~ExcludedItems();
754 * Add a list item to the excluded items and transfer ownership to this
757 * oldParent is the previous parent item of this item
758 * or 0 if it was a root item.
760 void add( Q3ListViewItem * item, Q3ListViewItem * oldParent );
763 * Remove a list item from the excluded items and transfer ownership back
766 void remove( Q3ListViewItem * item );
769 * Clear the excluded items. Delete all items still excluded.
774 * Returns 'true' if the specified item is in the excluded items.
776 bool contains( Q3ListViewItem * item );
779 * Returns the old parent of this item so it can be reparented
780 * or 0 if it was a root item.
782 Q3ListViewItem * oldParentItem( Q3ListViewItem * item );
785 * Returns the number of items
787 int size() const { return (int) _excludeMap.size(); }
790 * Returns an iterator that points to the first excluded item.
792 iterator begin() { return _excludeMap.begin(); }
795 * Returns an iterator that points after the last excluded item.
797 iterator end() { return _excludeMap.end(); }
802 YQPkgObjList * _pkgObjList;
806 #endif // ifndef YQPkgObjList_h