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();
61 // avoiding warning about virtuals
62 using QTreeView::selectionChanged;
68 int statusCol() const { return _statusCol; }
69 int nameCol() const { return _nameCol; }
70 int summaryCol() const { return _summaryCol; }
71 int sizeCol() const { return _sizeCol; }
72 int versionCol() const { return _versionCol; }
73 int instVersionCol() const { return _instVersionCol; }
74 int brokenIconCol() const { return _brokenIconCol; }
75 int satisfiedIconCol() const { return _satisfiedIconCol; }
78 * Return whether or not items in this list are generally editable,
79 * i.e. the user can change their status. Note that individual items can be
80 * set to non-editable even if the list is generally editable.
81 * Lists are editable by default.
83 bool editable() const { return _editable; }
86 * Set the list's editable status.
88 void setEditable( bool editable = true ) { _editable = editable; }
91 * Sets the currently selected item's status.
92 * Automatically selects the next item if 'selectNextItem' is 'true'.
94 void setCurrentStatus( ZyppStatus newStatus,
95 bool selectNextItem = false );
98 * Sets the status of all (toplevel) list items to 'newStatus', if possible.
99 * Only one single statusChanged() signal is emitted.
101 * 'force' overrides sensible defaults like setting only zypp::ResObjects to
102 * 'update' that really come with a newer version.
104 void setAllItemStatus( ZyppStatus newStatus, bool force = false );
107 * Add a submenu "All in this list..." to 'menu'.
108 * Returns the newly created submenu.
110 virtual Q3PopupMenu * addAllInListSubMenu( Q3PopupMenu * menu );
113 * Returns the suitable icon for a zypp::ResObject status - the regular
114 * icon if 'enabled' is 'true' or the insensitive icon if 'enabled' is
115 * 'false. 'bySelection' is relevant only for auto-states: This uses the
116 * icon for 'auto-by-selection" rather than the default auto-icon.
118 virtual QPixmap statusIcon( ZyppStatus status,
120 bool bySelection = false );
123 * Returns a short (one line) descriptive text for a zypp::ResObject status.
125 virtual QString statusText( ZyppStatus status ) const;
131 * Add an exclude rule to this list.
133 void addExcludeRule( YQPkgObjList::ExcludeRule * rule );
136 * Apply all exclude rules of this list to all items,
137 * including those that are currently excluded.
139 void applyExcludeRules();
142 * Apply all exclude rules of this list to one item.
144 void applyExcludeRules( QTreeWidgetItem * );
147 * Exclude or include an item, i.e. remove it from the visible items
148 * and add it to the internal exclude list or vice versa.
150 void exclude( YQPkgObjListItem * item, bool exclude );
156 * Add a zypp::ResObject to the list. Connect a filter's filterMatch()
157 * signal to this slot. Remember to connect filterStart() to clear()
158 * (inherited from QListView).
160 * 'zyppObj' has to be one of the objects of 'selectable'. If it is 0,
161 * selectable->theObject() will be used.
163 * Intentionally NOT named addItem() so the calling class cannot confuse
164 * this method with overlaid methods of the same name that were simply
165 * forgotten to implement!
167 void addPkgObjItem( ZyppSel selectable,
168 ZyppObj zyppObj = 0 );
171 * Add a purely passive list item that has a name and optional summary and
174 void addPassiveItem( const QString & name,
175 const QString & summary = QString::null,
179 * Dispatcher slot for mouse click: cycle status depending on column.
181 virtual void pkgObjClicked( int button,
182 QTreeWidgetItem * item,
184 const QPoint & pos );
187 * Reimplemented from QY2ListView:
188 * Emit selectionChanged() signal after clearing the list.
190 virtual void clear();
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( YQPkgObjListItem * item = 0);
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( QTreeWidgetItem * item );
258 * Emitted when a zypp::ui::Selectable is selected.
259 * May be called with a null poiner if no zypp::ResObject is selected.
261 void selectionChanged( ZyppSel selectable );
264 * Emitted when the status of a zypp::ResObject is changed.
266 void statusChanged();
269 * Emitted when it's time to update displayed package information,
270 * e.g., package states.
272 void updatePackages();
278 * Event handler for keyboard input.
279 * Only very special keys are processed here.
281 * Reimplemented from QListView / QWidget.
283 virtual void keyPressEvent( QKeyEvent * ev );
286 * Returns the context menu for items that are not installed.
287 * Creates the menu upon the first call.
289 virtual Q3PopupMenu * installedContextMenu();
292 * Returns the context menu for items that are installed.
293 * Creates the menu upon the first call.
295 virtual Q3PopupMenu * notInstalledContextMenu();
298 * Create the context menu for items that are not installed.
300 virtual void createNotInstalledContextMenu();
303 * Create the context menu for installed items.
305 virtual void createInstalledContextMenu();
308 * Create the actions for the context menus.
309 * Note: This is intentionally not virtual!
311 void createActions();
314 * Create an action based on a zypp::ResObject status - automatically
315 * retrieve the corresponding status icons (both sensitive and insensitive)
316 * and text. 'key' is only a descriptive text, no true accelerator.
318 Q3Action * createAction( ZyppStatus status,
319 const QString & key = QString::null,
320 bool enabled = false );
323 * Low-level: Create an action.
324 * 'key' is only a descriptive text, no true accelerator.
326 Q3Action * createAction( const QString & text,
327 const QPixmap & icon = QPixmap(),
328 const QPixmap & insensitiveIcon = QPixmap(),
329 const QString & key = QString::null,
330 bool enabled = false );
343 int _satisfiedIconCol;
347 typedef list<ExcludeRule *> ExcludeRuleList;
349 ExcludeRuleList _excludeRules;
350 ExcludedItems * _excludedItems;
352 Q3PopupMenu * _installedContextMenu;
353 Q3PopupMenu * _notInstalledContextMenu;
358 Q3Action * actionSetCurrentInstall;
359 Q3Action * actionSetCurrentDontInstall;
360 Q3Action * actionSetCurrentKeepInstalled;
361 Q3Action * actionSetCurrentDelete;
362 Q3Action * actionSetCurrentUpdate;
363 Q3Action * actionSetCurrentTaboo;
364 Q3Action * actionSetCurrentProtected;
366 Q3Action * actionSetListInstall;
367 Q3Action * actionSetListDontInstall;
368 Q3Action * actionSetListKeepInstalled;
369 Q3Action * actionSetListDelete;
370 Q3Action * actionSetListUpdate;
371 Q3Action * actionSetListUpdateForce;
372 Q3Action * actionSetListTaboo;
373 Q3Action * actionSetListProtected;
382 class YQPkgObjListItem: public QY2ListViewItem
387 * Constructor for root items: Creates a YQPkgObjList item that corresponds
388 * to the ZYPP selectable that 'selectable' refers to. 'zyppObj' has to be
389 * one object of 'selectable'. If it is 0, selectable->theObject() will be
392 YQPkgObjListItem( YQPkgObjList * pkgObjList,
394 ZyppObj zyppObj = 0 );
398 * Constructor for non-root items.
400 YQPkgObjListItem( YQPkgObjList * pkgObjList,
401 QY2ListViewItem * parent,
403 ZyppObj zyppObj = 0 );
410 virtual ~YQPkgObjListItem();
413 * Returns the original selectable within the package manager backend.
415 ZyppSel selectable() const { return _selectable; }
418 * Returns the original object within the package manager backend.
420 ZyppObj zyppObj() const { return _zyppObj; }
423 * Return whether or not this items is editable, i.e. the user can change
424 * its status. This requires the corresponding list to be editable, too.
425 * Items are editable by default.
427 bool editable() const { return _editable; }
430 * Set this item's editable status.
432 void setEditable( bool editable = true ) { _editable = editable; }
435 * Returns the (binary RPM) package status
437 ZyppStatus status() const;
440 * Returns 'true' if this selectable's status is set by a selection
441 * (rather than by the user or by the dependency solver).
443 bool bySelection() const;
446 * Set the (binary RPM) package status.
448 * If 'sendSignals' is 'true' (default), the parent list will be requested
449 * to send update signals. List operations might want to use this for
450 * optimizations to send the signals only once after all changes are done.
452 virtual void setStatus( ZyppStatus newStatus, bool sendSignals = true );
455 * Set a status icon according to the package's status.
457 virtual void setStatusIcon();
460 * Update this item's status.
461 * Triggered by QY2ListView::updateAllItemStates().
462 * Overwritten from QY2ListViewItem.
464 virtual void updateStatus();
467 * Cycle the package status to the next valid value.
469 virtual void cycleStatus();
472 * Check if the candidate is newer than the installed version.
474 bool candidateIsNewer() const { return _candidateIsNewer; }
477 * Check if the installed version is newer than the candidate.
479 bool installedIsNewer() const { return _installedIsNewer; }
482 * Check if this item is satisfied, even though it is not installed.
483 * This is useful for package collections, e.g., patterns and patches:
484 * 'true' is returned if all requirements are fulfilled, but the object
485 * itself is not installed.
487 bool isSatisfied() const;
490 * Check if this item is "broken": If it is installed, but any of its
491 * dependencies are no longer satisfied.
492 * This is useful for package collections, e.g., patterns and patches.
494 bool isBroken() const;
497 * Display this item's notify text (if there is any) that corresponds to
498 * the specified status (S_Install, S_Del) in a pop-up window.
500 void showNotifyTexts( ZyppStatus status );
503 * Display a selectable's license agreement (if there is any) that
504 * corresponds to its current status (S_Install, S_Update) in a pop-up
507 * Returns 'true' if the user agreed to that license , 'false' otherwise.
508 * The item's status may have changed to S_Taboo, S_Proteced or S_Del if
509 * the user disagreed with the license.
511 static bool showLicenseAgreement( ZyppSel sel );
514 * Display this item's license agreement (if there is any) that corresponds
515 * to its current status (S_Install, S_Update) in a pop-up window.
517 bool showLicenseAgreement();
520 * Comparison function used for sorting the list.
526 * Reimplemented from QListViewItem
528 virtual int compare( QTreeWidgetItem * other,
530 bool ascending ) const;
533 * Calculate a numerical value to compare versions, based on version
536 * - Installed newer than candidate (red)
537 * - Candidate newer than installed (blue) - worthwhile updating
539 * - Not installed, but candidate available
541 int versionPoints() const;
544 * Update this item's data completely.
545 * Triggered by QY2ListView::updateAllItemData().
547 * Reimplemented from QY2ListViewItem.
549 virtual void updateData();
552 * Returns a tool tip text for a specific column of this item.
553 * 'column' is -1 if the mouse pointer is in the tree indentation area.
555 * Reimplemented from QY2ListViewItem.
557 virtual QString toolTip( int column );
560 * Returns 'true' if this item is excluded.
562 bool isExcluded() const { return _excluded; }
565 * Set this item's exclude flag.
566 * Note that this is just a marker. It is the caller's responsibility
567 * to add or remove it from exclude lists etc.
569 void setExcluded( bool exclude = true );
572 // Handle Debug isBroken and isSatisfied flags
574 bool debugIsBroken() const { return _debugIsBroken; }
575 bool debugIsSatisfied() const { return _debugIsSatisfied; }
576 void setDebugIsBroken ( bool val = true ) { _debugIsBroken = val; }
577 void setDebugIsSatisfied( bool val = true ) { _debugIsSatisfied = val; }
578 void toggleDebugIsBroken() { _debugIsBroken = ! _debugIsBroken; }
579 void toggleDebugIsSatisfied() { _debugIsSatisfied = ! _debugIsSatisfied; }
584 int statusCol() const { return _pkgObjList->statusCol(); }
585 int nameCol() const { return _pkgObjList->nameCol(); }
586 int summaryCol() const { return _pkgObjList->summaryCol(); }
587 int sizeCol() const { return _pkgObjList->sizeCol(); }
588 int versionCol() const { return _pkgObjList->versionCol(); }
589 int instVersionCol() const { return _pkgObjList->instVersionCol(); }
590 int brokenIconCol() const { return _pkgObjList->brokenIconCol(); }
591 int satisfiedIconCol() const { return _pkgObjList->satisfiedIconCol(); }
597 * Initialize internal data and set fields accordingly.
602 * Apply changes hook. This is called each time the user changes the status
603 * of a list item manually (if the old status is different from the new
604 * one). Insert code to propagate changes to other objects here, for
605 * example to trigger a "small" solver run (Resolver::transactObjKind()
608 * This default implementation does nothing.
610 virtual void applyChanges() {}
613 * Do a "small" solver run for all "resolvable collections", i.e., for
614 * selections, patterns, languages, patches.
616 void solveResolvableCollections();
619 * Set a column text via STL string.
620 * ( QListViewItem::setText() expects a QString! )
622 void setText( int column, const string text );
625 * Re-declare ordinary setText() method so the compiler doesn't get
626 * confused which one to use.
628 void setText( int column, const QString & text )
629 { QTreeWidgetItem::setText( column, text ); }
632 * Set a column text via Edition.
634 void setText( int column, const zypp::Edition & edition );
641 YQPkgObjList * _pkgObjList;
645 bool _candidateIsNewer:1;
646 bool _installedIsNewer:1;
648 bool _debugIsBroken:1;
649 bool _debugIsSatisfied:1;
655 class YQPkgObjList::ExcludeRule
660 * Constructor: Creates a new exclude rule with a regular expression
661 * to check against the text of the specified column of each list
664 * The parent YQPkgObjList will assume ownership of this exclude rule
665 * and destroy it when the parent is destroyed.
667 ExcludeRule( YQPkgObjList * parent,
668 const QRegExp & regexp,
672 // Intentionally omitting virtual destructor:
673 // No allocated objects, no other virtual methods,
674 // no need to have a vtable for each instance of this class.
676 // virtual ~ExcludeRule();
679 * Enable or disable this exclude rule.
680 * New exclude rules are enabled by default.
682 void enable( bool enable = true );
685 * Returns 'true' if this exclude rule is enabled,
688 bool isEnabled() const { return _enabled; }
691 * Change the regular expression after creation.
693 void setRegexp( const QRegExp & regexp );
696 * Returns the regexp.
698 QRegExp regexp() const { return _regexp; };
701 * Change the column number to check against after creation.
703 void setColumn( int column = 0 );
706 * Returns the column number.
708 int column() const { return _column; }
711 * Returns this exclude rule's parent YQPkgObjList.
713 YQPkgObjList * parent() const { return _parent; }
716 * Check a list item against this exclude rule.
717 * Returns 'true' if the item matches this exclude rule,
718 * i.e. if it should be excluded.
720 bool match( QTreeWidgetItem * item );
724 YQPkgObjList * _parent;
731 class YQPkgObjList::ExcludedItems
735 typedef std::map <QTreeWidgetItem *, QTreeWidgetItem *> ItemMap;
736 typedef std::pair<QTreeWidgetItem *, QTreeWidgetItem *> ItemPair;
737 typedef ItemMap::iterator iterator;
742 ExcludedItems( YQPkgObjList * parent );
747 virtual ~ExcludedItems();
750 * Add a list item to the excluded items and transfer ownership to this
753 * oldParent is the previous parent item of this item
754 * or 0 if it was a root item.
756 void add( QTreeWidgetItem * item, QTreeWidgetItem * oldParent );
759 * Remove a list item from the excluded items and transfer ownership back
762 void remove( QTreeWidgetItem * item );
765 * Clear the excluded items. Delete all items still excluded.
770 * Returns 'true' if the specified item is in the excluded items.
772 bool contains( QTreeWidgetItem * item );
775 * Returns the old parent of this item so it can be reparented
776 * or 0 if it was a root item.
778 QTreeWidgetItem * oldParentItem( QTreeWidgetItem * item );
781 * Returns the number of items
783 int size() const { return (int) _excludeMap.size(); }
786 * Returns an iterator that points to the first excluded item.
788 iterator begin() { return _excludeMap.begin(); }
791 * Returns an iterator that points after the last excluded item.
793 iterator end() { return _excludeMap.end(); }
796 void updateActions();
799 YQPkgObjList * _pkgObjList;
803 #endif // ifndef YQPkgObjList_h