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( QTreeWidgetItem * );
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 QTreeWidgetItem * 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 for the currently selected item ( if any ).
192 * This only calls updateActions( YQPkgObjListItem * ) with the currently
193 * selected item as argument, so there is normally no need to reimplement
194 * this method, too, if the other one is reimplemented.
196 virtual void updateActions( YQPkgObjListItem * item = 0);
199 * Emit an updatePackages() signal.
201 void sendUpdatePackages() { emit updatePackages(); }
204 * Select the next item, i.e. move the selection one item further down the
207 void selectNextItem();
210 * Emit a statusChanged() signal for the specified zypp::ResObject.
212 void sendStatusChanged() { emit statusChanged(); }
215 * Display a one-line message in the list.
217 virtual void message( const QString & text );
220 * Write statistics about excluded items to the log, if there are any.
222 void logExcludeStatistics();
225 // Direct access to some states for menu actions
227 void setCurrentInstall() { setCurrentStatus( S_Install ); }
228 void setCurrentDontInstall() { setCurrentStatus( S_NoInst ); }
229 void setCurrentKeepInstalled() { setCurrentStatus( S_KeepInstalled ); }
230 void setCurrentDelete() { setCurrentStatus( S_Del ); }
231 void setCurrentUpdate() { setCurrentStatus( S_Update ); }
232 void setCurrentTaboo() { setCurrentStatus( S_Taboo ); }
233 void setCurrentProtected() { setCurrentStatus( S_Protected ); }
235 void setListInstall() { setAllItemStatus( S_Install ); }
236 void setListDontInstall() { setAllItemStatus( S_NoInst ); }
237 void setListKeepInstalled() { setAllItemStatus( S_KeepInstalled ); }
238 void setListDelete() { setAllItemStatus( S_Del ); }
239 void setListUpdate() { setAllItemStatus( S_Update ); }
240 void setListUpdateForce() { setAllItemStatus( S_Update, true ); }
241 void setListTaboo() { setAllItemStatus( S_Taboo ); }
242 void setListProtected() { setAllItemStatus( S_Protected ); }
248 * Dispatcher slot for selection change - internal only.
250 virtual void selectionChangedInternal( QTreeWidgetItem * item );
257 * Emitted when a zypp::ui::Selectable is selected.
258 * May be called with a null poiner if no zypp::ResObject is selected.
260 void selectionChanged( ZyppSel selectable );
263 * Emitted when the status of a zypp::ResObject is changed.
265 void statusChanged();
268 * Emitted when it's time to update displayed package information,
269 * e.g., package states.
271 void updatePackages();
277 * Event handler for keyboard input.
278 * Only very special keys are processed here.
280 * Reimplemented from QListView / QWidget.
282 virtual void keyPressEvent( QKeyEvent * ev );
285 * Returns the context menu for items that are not installed.
286 * Creates the menu upon the first call.
288 virtual Q3PopupMenu * installedContextMenu();
291 * Returns the context menu for items that are installed.
292 * Creates the menu upon the first call.
294 virtual Q3PopupMenu * notInstalledContextMenu();
297 * Create the context menu for items that are not installed.
299 virtual void createNotInstalledContextMenu();
302 * Create the context menu for installed items.
304 virtual void createInstalledContextMenu();
307 * Create the actions for the context menus.
308 * Note: This is intentionally not virtual!
310 void createActions();
313 * Create an action based on a zypp::ResObject status - automatically
314 * retrieve the corresponding status icons (both sensitive and insensitive)
315 * and text. 'key' is only a descriptive text, no true accelerator.
317 Q3Action * createAction( ZyppStatus status,
318 const QString & key = QString::null,
319 bool enabled = false );
322 * Low-level: Create an action.
323 * 'key' is only a descriptive text, no true accelerator.
325 Q3Action * createAction( const QString & text,
326 const QPixmap & icon = QPixmap(),
327 const QPixmap & insensitiveIcon = QPixmap(),
328 const QString & key = QString::null,
329 bool enabled = false );
342 int _satisfiedIconCol;
346 typedef list<ExcludeRule *> ExcludeRuleList;
348 ExcludeRuleList _excludeRules;
349 ExcludedItems * _excludedItems;
351 Q3PopupMenu * _installedContextMenu;
352 Q3PopupMenu * _notInstalledContextMenu;
357 Q3Action * actionSetCurrentInstall;
358 Q3Action * actionSetCurrentDontInstall;
359 Q3Action * actionSetCurrentKeepInstalled;
360 Q3Action * actionSetCurrentDelete;
361 Q3Action * actionSetCurrentUpdate;
362 Q3Action * actionSetCurrentTaboo;
363 Q3Action * actionSetCurrentProtected;
365 Q3Action * actionSetListInstall;
366 Q3Action * actionSetListDontInstall;
367 Q3Action * actionSetListKeepInstalled;
368 Q3Action * actionSetListDelete;
369 Q3Action * actionSetListUpdate;
370 Q3Action * actionSetListUpdateForce;
371 Q3Action * actionSetListTaboo;
372 Q3Action * actionSetListProtected;
381 class YQPkgObjListItem: public QY2ListViewItem
386 * Constructor for root items: Creates a YQPkgObjList item that corresponds
387 * to the ZYPP selectable that 'selectable' refers to. 'zyppObj' has to be
388 * one object of 'selectable'. If it is 0, selectable->theObject() will be
391 YQPkgObjListItem( YQPkgObjList * pkgObjList,
393 ZyppObj zyppObj = 0 );
397 * Constructor for non-root items.
399 YQPkgObjListItem( YQPkgObjList * pkgObjList,
400 QY2ListViewItem * parent,
402 ZyppObj zyppObj = 0 );
409 virtual ~YQPkgObjListItem();
412 * Returns the original selectable within the package manager backend.
414 ZyppSel selectable() const { return _selectable; }
417 * Returns the original object within the package manager backend.
419 ZyppObj zyppObj() const { return _zyppObj; }
422 * Return whether or not this items is editable, i.e. the user can change
423 * its status. This requires the corresponding list to be editable, too.
424 * Items are editable by default.
426 bool editable() const { return _editable; }
429 * Set this item's editable status.
431 void setEditable( bool editable = true ) { _editable = editable; }
434 * Returns the (binary RPM) package status
436 ZyppStatus status() const;
439 * Returns 'true' if this selectable's status is set by a selection
440 * (rather than by the user or by the dependency solver).
442 bool bySelection() const;
445 * Set the (binary RPM) package status.
447 * If 'sendSignals' is 'true' (default), the parent list will be requested
448 * to send update signals. List operations might want to use this for
449 * optimizations to send the signals only once after all changes are done.
451 virtual void setStatus( ZyppStatus newStatus, bool sendSignals = true );
454 * Set a status icon according to the package's status.
456 virtual void setStatusIcon();
459 * Update this item's status.
460 * Triggered by QY2ListView::updateAllItemStates().
461 * Overwritten from QY2ListViewItem.
463 virtual void updateStatus();
466 * Cycle the package status to the next valid value.
468 virtual void cycleStatus();
471 * Check if the candidate is newer than the installed version.
473 bool candidateIsNewer() const { return _candidateIsNewer; }
476 * Check if the installed version is newer than the candidate.
478 bool installedIsNewer() const { return _installedIsNewer; }
481 * Check if this item is satisfied, even though it is not installed.
482 * This is useful for package collections, e.g., patterns and patches:
483 * 'true' is returned if all requirements are fulfilled, but the object
484 * itself is not installed.
486 bool isSatisfied() const;
489 * Check if this item is "broken": If it is installed, but any of its
490 * dependencies are no longer satisfied.
491 * This is useful for package collections, e.g., patterns and patches.
493 bool isBroken() const;
496 * Display this item's notify text (if there is any) that corresponds to
497 * the specified status (S_Install, S_Del) in a pop-up window.
499 void showNotifyTexts( ZyppStatus status );
502 * Display a selectable's license agreement (if there is any) that
503 * corresponds to its current status (S_Install, S_Update) in a pop-up
506 * Returns 'true' if the user agreed to that license , 'false' otherwise.
507 * The item's status may have changed to S_Taboo, S_Proteced or S_Del if
508 * the user disagreed with the license.
510 static bool showLicenseAgreement( ZyppSel sel );
513 * Display this item's license agreement (if there is any) that corresponds
514 * to its current status (S_Install, S_Update) in a pop-up window.
516 bool showLicenseAgreement();
519 * Comparison function used for sorting the list.
525 * Reimplemented from QListViewItem
527 virtual int compare( QTreeWidgetItem * other,
529 bool ascending ) const;
532 * Calculate a numerical value to compare versions, based on version
535 * - Installed newer than candidate (red)
536 * - Candidate newer than installed (blue) - worthwhile updating
538 * - Not installed, but candidate available
540 int versionPoints() const;
543 * Update this item's data completely.
544 * Triggered by QY2ListView::updateAllItemData().
546 * Reimplemented from QY2ListViewItem.
548 virtual void updateData();
551 * Returns a tool tip text for a specific column of this item.
552 * 'column' is -1 if the mouse pointer is in the tree indentation area.
554 * Reimplemented from QY2ListViewItem.
556 virtual QString toolTip( int column );
559 * Returns 'true' if this item is excluded.
561 bool isExcluded() const { return _excluded; }
564 * Set this item's exclude flag.
565 * Note that this is just a marker. It is the caller's responsibility
566 * to add or remove it from exclude lists etc.
568 void setExcluded( bool exclude = true );
571 // Handle Debug isBroken and isSatisfied flags
573 bool debugIsBroken() const { return _debugIsBroken; }
574 bool debugIsSatisfied() const { return _debugIsSatisfied; }
575 void setDebugIsBroken ( bool val = true ) { _debugIsBroken = val; }
576 void setDebugIsSatisfied( bool val = true ) { _debugIsSatisfied = val; }
577 void toggleDebugIsBroken() { _debugIsBroken = ! _debugIsBroken; }
578 void toggleDebugIsSatisfied() { _debugIsSatisfied = ! _debugIsSatisfied; }
583 int statusCol() const { return _pkgObjList->statusCol(); }
584 int nameCol() const { return _pkgObjList->nameCol(); }
585 int summaryCol() const { return _pkgObjList->summaryCol(); }
586 int sizeCol() const { return _pkgObjList->sizeCol(); }
587 int versionCol() const { return _pkgObjList->versionCol(); }
588 int instVersionCol() const { return _pkgObjList->instVersionCol(); }
589 int brokenIconCol() const { return _pkgObjList->brokenIconCol(); }
590 int satisfiedIconCol() const { return _pkgObjList->satisfiedIconCol(); }
596 * Initialize internal data and set fields accordingly.
601 * Apply changes hook. This is called each time the user changes the status
602 * of a list item manually (if the old status is different from the new
603 * one). Insert code to propagate changes to other objects here, for
604 * example to trigger a "small" solver run (Resolver::transactObjKind()
607 * This default implementation does nothing.
609 virtual void applyChanges() {}
612 * Do a "small" solver run for all "resolvable collections", i.e., for
613 * selections, patterns, languages, patches.
615 void solveResolvableCollections();
618 * Set a column text via STL string.
619 * ( QListViewItem::setText() expects a QString! )
621 void setText( int column, const string text );
624 * Re-declare ordinary setText() method so the compiler doesn't get
625 * confused which one to use.
627 void setText( int column, const QString & text )
628 { QTreeWidgetItem::setText( column, text ); }
631 * Set a column text via Edition.
633 void setText( int column, const zypp::Edition & edition );
640 YQPkgObjList * _pkgObjList;
644 bool _candidateIsNewer:1;
645 bool _installedIsNewer:1;
647 bool _debugIsBroken:1;
648 bool _debugIsSatisfied:1;
654 class YQPkgObjList::ExcludeRule
659 * Constructor: Creates a new exclude rule with a regular expression
660 * to check against the text of the specified column of each list
663 * The parent YQPkgObjList will assume ownership of this exclude rule
664 * and destroy it when the parent is destroyed.
666 ExcludeRule( YQPkgObjList * parent,
667 const QRegExp & regexp,
671 // Intentionally omitting virtual destructor:
672 // No allocated objects, no other virtual methods,
673 // no need to have a vtable for each instance of this class.
675 // virtual ~ExcludeRule();
678 * Enable or disable this exclude rule.
679 * New exclude rules are enabled by default.
681 void enable( bool enable = true );
684 * Returns 'true' if this exclude rule is enabled,
687 bool isEnabled() const { return _enabled; }
690 * Change the regular expression after creation.
692 void setRegexp( const QRegExp & regexp );
695 * Returns the regexp.
697 QRegExp regexp() const { return _regexp; };
700 * Change the column number to check against after creation.
702 void setColumn( int column = 0 );
705 * Returns the column number.
707 int column() const { return _column; }
710 * Returns this exclude rule's parent YQPkgObjList.
712 YQPkgObjList * parent() const { return _parent; }
715 * Check a list item against this exclude rule.
716 * Returns 'true' if the item matches this exclude rule,
717 * i.e. if it should be excluded.
719 bool match( QTreeWidgetItem * item );
723 YQPkgObjList * _parent;
730 class YQPkgObjList::ExcludedItems
734 typedef std::map <QTreeWidgetItem *, QTreeWidgetItem *> ItemMap;
735 typedef std::pair<QTreeWidgetItem *, QTreeWidgetItem *> ItemPair;
736 typedef ItemMap::iterator iterator;
741 ExcludedItems( YQPkgObjList * parent );
746 virtual ~ExcludedItems();
749 * Add a list item to the excluded items and transfer ownership to this
752 * oldParent is the previous parent item of this item
753 * or 0 if it was a root item.
755 void add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent );
758 * Remove a list item from the excluded items and transfer ownership back
761 void remove( QTreeWidgetItem * item );
764 * Clear the excluded items. Delete all items still excluded.
769 * Returns 'true' if the specified item is in the excluded items.
771 bool contains( QTreeWidgetItem * item );
774 * Returns the old parent of this item so it can be reparented
775 * or 0 if it was a root item.
777 QTreeWidgetItem * oldParentItem( QTreeWidgetItem * item );
780 * Returns the number of items
782 int size() const { return (int) _excludeMap.size(); }
785 * Returns an iterator that points to the first excluded item.
787 iterator begin() { return _excludeMap.begin(); }
790 * Returns an iterator that points after the last excluded item.
792 iterator end() { return _excludeMap.end(); }
795 void updateActions();
798 YQPkgObjList * _pkgObjList;
802 #endif // ifndef YQPkgObjList_h