42 #define YUILogComponent "qt-pkg" 45 #include <zypp/ZYppFactory.h> 46 #include <zypp/Resolver.h> 48 #include <QHeaderView> 51 #include <QItemDelegate> 55 #include "YQPackageSelector.h" 56 #include "YQPkgPatternList.h" 57 #include "YQIconPool.h" 58 #include "YQApplication.h" 76 virtual void paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const 85 QFont f = painter->font();
86 f.setWeight( QFont::Bold );
88 f.setPixelSize( (
int) ( fm.height() * 1.1 ) );
89 citem->setFont( _view->summaryCol(), f );
91 QItemDelegate::paint( painter, option, index );
103 QColor background = option.palette.color(QPalette::Window);
104 painter->setBackground( background );
106 float percent = (item->totalPackages() > 0)
107 ? (((
float)item->installedPackages()*100) / (
float)item->totalPackages())
110 QColor fillColor = option.palette.color(QPalette::Mid);
112 if ( percent > 100.0 ) percent = 100.0;
113 if ( percent < 0.0 ) percent = 0.0;
114 int x = option.rect.left() + 1;
115 int y = option.rect.top() + 1;
116 int w = option.rect.width() - 2;
117 int h = (int) ( ( (
float) option.rect.height() )/2 );
121 fillWidth = (int) ( w * percent / 100.0 );
125 painter->fillRect( x, y, fillWidth, h, fillColor );
127 QString percentageText;
128 percentageText.sprintf(
"%d/%d", item->installedPackages(), item->totalPackages());
130 painter->setPen( _view->palette().color( QPalette::Base ) );
131 painter->drawText( QRect( x, y,
133 Qt::AlignHCenter, percentageText );
143 QItemDelegate::paint(painter, option, index);
154 yuiDebug() <<
"Creating pattern list" << std::endl;
159 headers <<
""; _statusCol = numCol++;
168 headers <<
""; _iconCol = numCol++;
169 headers << _(
"Pattern" ); _summaryCol = numCol++;
173 setColumnCount( numCol );
174 setHeaderLabels(headers);
186 _satisfiedIconCol = -42;
187 _brokenIconCol = -42;
192 setSortingEnabled(
true );
193 sortByColumn( summaryCol(), Qt::AscendingOrder );
195 setAllColumnsShowFocus(
true );
197 header()->setSectionResizeMode( statusCol(), QHeaderView::Fixed );
198 header()->setSectionResizeMode( summaryCol(), QHeaderView::Stretch );
199 header()->setSectionResizeMode( howmanyCol(), QHeaderView::Fixed );
201 header()->resizeSection( statusCol(), 25 );
202 setColumnWidth( statusCol(), 25 );
203 setColumnWidth( summaryCol(), 100 );
204 setColumnWidth( howmanyCol(), 15 );
213 QTreeWidgetItem * ) ),
214 this, SLOT (
filter() ) );
217 setIconSize(QSize(32,32));
218 header()->resizeSection( iconCol(), 34 );
227 yuiDebug() <<
"Creating pattern list done" << std::endl;
243 yuiDebug() <<
"Filling pattern list" << std::endl;
245 for ( ZyppPoolIterator it = zyppPatternsBegin();
246 it != zyppPatternsEnd();
249 ZyppPattern zyppPattern = tryCastToZyppPattern( (*it)->theObj() );
253 if ( zyppPattern->userVisible() )
258 yuiDebug() <<
"Pattern " << zyppPattern->name()
259 <<
" is not user-visible" << std::endl;
263 yuiError() <<
"Found non-Pattern selectable" << std::endl;
267 yuiDebug() <<
"Pattern list filled" << std::endl;
268 resizeColumnToContents(_iconCol);
269 resizeColumnToContents(_statusCol);
270 resizeColumnToContents(_howmanyCol);
277 if ( categoryName.isEmpty() )
284 yuiDebug() <<
"New pattern category \""<< categoryName <<
"\"" << std::endl;
288 _categories.insert( categoryName, cat );
318 zypp::Pattern::Contents c(zyppPattern->contents());
319 for ( zypp::Pattern::Contents::Selectable_iterator it = c.selectableBegin();
320 it != c.selectableEnd();
323 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
326 if ( (*it)->installedSize() > 0 )
333 selection()->setInstalledPackages(installed);
340 resizeColumnToContents(_howmanyCol);
346 ZyppPattern zyppPattern )
350 yuiError() <<
"NULL ZyppSelectable!" << std::endl;
366 resizeColumnToContents(_howmanyCol);
367 resizeColumnToContents(_summaryCol);
369 addTopLevelItem(item);
377 QTreeWidgetItem * item = currentItem();
388 QTreeWidgetItem * listViewItem,
397 if ( button == Qt::LeftButton )
401 categoryItem->setExpanded( ! categoryItem->isExpanded() );
417 QTreeWidgetItemIterator it(
this );
421 QY2ListViewItem * item =
dynamic_cast<QY2ListViewItem *
> (*it);
425 if ( item && item->isSelectable() && ! categoryItem )
427 setSelected( item,
true );
439 ZyppPattern zyppPattern )
441 , _patternList( patternList )
442 , _zyppPattern( zyppPattern )
443 , _total(0), _installed(0)
452 ZyppPattern zyppPattern )
454 , _patternList( patternList )
455 , _zyppPattern( zyppPattern )
456 , _total(0), _installed(0)
466 if ( ! _zyppPattern )
467 _zyppPattern = tryCastToZyppPattern(
selectable()->theObj() );
471 string iconName = _zyppPattern->icon().basename();
472 if ( iconName.empty() )
473 iconName =
"pattern-generic";
475 setIcon( _patternList->iconCol(), YQUI::ui()->loadIcon( iconName ) );
481 setFirstColumnSpanned (
false );
495 if ( ! _editable || ! _pkgObjList->
editable() )
498 ZyppStatus oldStatus =
status();
499 ZyppStatus newStatus = oldStatus;
504 newStatus = S_NoInst;
513 newStatus = S_Install;
517 newStatus = S_NoInst;
524 if ( oldStatus != newStatus )
546 std::string infoToolTip;
547 infoToolTip += (
"<p>" +
zyppPattern()->description() +
"</p>");
549 if ( totalPackages() > 0 )
551 infoToolTip += (
"<p>" + zypp::str::form(
"%d / %d", installedPackages(), totalPackages() ) +
"</p>");
554 setToolTip(_patternList->summaryCol(), fromUTF8(infoToolTip));
569 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->
zyppPattern() )
571 if ( _zyppPattern->order() != otherPatternListitem->
zyppPattern()->order() )
572 return _zyppPattern->order() < otherPatternListitem->
zyppPattern()->order();
574 return _zyppPattern->name() < otherPatternListitem->
zyppPattern()->name();
579 if ( otherCategoryItem )
582 return QTreeWidgetItem::operator<( otherListViewItem );
587 const QString & category )
588 : QY2ListViewItem( patternList )
589 , _patternList( patternList )
591 setText( _patternList->summaryCol(), category );
607 if ( ! _firstPattern )
609 _firstPattern = pattern;
613 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
614 _firstPattern = pattern;
620 YQPkgPatternCategoryItem::setExpanded(
bool open )
622 QTreeWidgetItem::setExpanded( open );
632 YQIconPool::arrowDown() :
633 YQIconPool::arrowRight() );
642 if ( _firstPattern && otherCategoryItem && otherCategoryItem->
firstPattern() )
643 return _firstPattern->order() < otherCategoryItem->
firstPattern()->order();
648 if ( otherPatternListitem )
651 return QTreeWidgetItem::operator<( otherListViewItem );
virtual void selectSomething()
Select the first selectable list entry that is not a pattern category.
void setTreeIcon(void)
Set a suitable tree open/close icon depending on this category's open/close status.
ZyppPattern firstPattern() const
Returns the first pattern.
void init()
Initialize things common to all constructors.
void filterFinished()
Emitted when filtering is finished.
Abstract base class to display a list of zypp::ResObjects.
virtual void applyChanges()
Propagate status changes in this list to other lists: Have the solver transact all patterns...
virtual ~YQPkgPatternCategoryItem()
Destructor.
YQPkgPatternCategoryItem * category(const QString &categoryName)
Returns the category item with the specified name.
void fillList()
Fill the pattern list.
bool showLicenseAgreement()
Display this item's license agreement (if there is any) that corresponds to its current status (S_Ins...
YQPkgPatternListItem(YQPkgPatternList *patternList, ZyppSel selectable, ZyppPattern zyppPattern)
Constructor for root items.
virtual void clear()
Reimplemented from QY2ListView: Emit currentItemChanged() signal after clearing the list...
virtual void setStatus(ZyppStatus newStatus, bool sendSignals=true)
Set the (binary RPM) package status.
virtual ~YQPkgPatternListItem()
Destructor.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: cycle status depending on column.
virtual ~YQPkgPatternList()
Destructor.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
void sendStatusChanged()
Emit a statusChanged() signal for the specified zypp::ResObject.
void filter()
Filter according to the view's rules and current selection.
virtual ZyppStatus status() const
Returns the (binary RPM) package status.
YQPkgPatternCategoryItem(YQPkgPatternList *patternList, const QString &category)
Constructor.
Display a list of zypp::Pattern objects.
bool editable() const
Return whether or not items in this list are generally editable, i.e.
void filterStart()
Emitted when the filtering starts.
void applyExcludeRules()
Apply all exclude rules of this list to all items, including those that are currently excluded...
YQPkgPatternList(QWidget *parent, bool autoFill=true, bool autoFilter=true)
Constructor.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
ZyppPattern zyppPattern() const
Returns the original object within the package manager backend.
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
void currentItemChanged(ZyppSel selectable)
Emitted when a zypp::ui::Selectable is selected.
virtual void cycleStatus()
Cycle the package status to the next valid value.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
void solveResolvableCollections()
Do a "small" solver run for all "resolvable collections", i.e., for selections, patterns, languages, patches.
void showNotifyTexts(ZyppStatus status)
Display this item's notify text (if there is any) that corresponds to the specified status (S_Install...
void addPattern(ZyppPattern pattern)
Add a pattern to this category.
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: cycle status depending on column.
virtual void setStatusIcon()
Set a status icon according to the package's status.
void addPatternItem(ZyppSel selectable, ZyppPattern pattern)
Add a pattern to the list.
void resetToolTip()
resets the tooltip with the current available information
YQPkgPatternListItem * selection() const
Returns the currently selected item or 0 if there is none.