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" 71 virtual void paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const 80 QFont f = painter->font();
81 f.setWeight(QFont::Bold);
83 f.setPixelSize( (
int) ( fm.height() * 1.1 ) );
84 citem->setFont(_view->summaryCol(), f);
86 QItemDelegate::paint(painter, option, index);
100 QColor background = option.palette.color(QPalette::Window);
101 painter->setBackground( background );
103 float percent = (item->totalPackages() > 0)
104 ? (((
float)item->installedPackages()*100) / (
float)item->totalPackages())
107 QColor fillColor = option.palette.color(QPalette::Mid);
109 if ( percent > 100.0 ) percent = 100.0;
110 if ( percent < 0.0 ) percent = 0.0;
111 int x = option.rect.left() + 1;
112 int y = option.rect.top() + 1;
113 int w = option.rect.width() - 2;
114 int h = (int) ( ( (
float) option.rect.height() )/2 );
118 fillWidth = (int) ( w * percent / 100.0 );
123 painter->fillRect( x, y, fillWidth, h,
126 QString percentageText;
127 percentageText.sprintf(
"%d/%d", item->installedPackages(), item->totalPackages());
129 painter->setPen( _view->palette().color( QPalette::Base ) );
130 painter->drawText( QRect( x, y,
132 Qt::AlignHCenter, percentageText );
143 QItemDelegate::paint(painter, option, index);
155 yuiDebug() <<
"Creating pattern list" << std::endl;
160 headers <<
""; _statusCol = numCol++;
169 headers <<
""; _iconCol = numCol++;
170 headers << _(
"Pattern" ); _summaryCol = numCol++;
174 setColumnCount( numCol );
175 setHeaderLabels(headers);
187 _satisfiedIconCol = -42;
188 _brokenIconCol = -42;
193 setSortingEnabled(
true );
194 sortByColumn( summaryCol(), Qt::AscendingOrder );
196 setAllColumnsShowFocus(
true );
198 header()->setSectionResizeMode( statusCol(), QHeaderView::Fixed );
199 header()->setSectionResizeMode( summaryCol(), QHeaderView::Stretch );
200 header()->setSectionResizeMode( howmanyCol(), QHeaderView::Fixed );
202 header()->resizeSection( statusCol(), 25 );
203 setColumnWidth( statusCol(), 25 );
204 setColumnWidth( summaryCol(), 100 );
205 setColumnWidth( howmanyCol(), 15 );
214 this, SLOT (
filter() ) );
217 setIconSize(QSize(32,32));
218 header()->resizeSection( iconCol(), 34 );
226 yuiDebug() <<
"Creating pattern list done" << std::endl;
242 yuiDebug() <<
"Filling pattern list" << std::endl;
244 for ( ZyppPoolIterator it = zyppPatternsBegin();
245 it != zyppPatternsEnd();
248 ZyppPattern zyppPattern = tryCastToZyppPattern( (*it)->theObj() );
252 if ( zyppPattern->userVisible() )
257 yuiDebug() <<
"Pattern " << zyppPattern->name()
258 <<
" is not user-visible" << std::endl;
262 yuiError() <<
"Found non-Pattern selectable" << std::endl;
266 yuiDebug() <<
"Pattern list filled" << std::endl;
267 resizeColumnToContents(_iconCol);
268 resizeColumnToContents(_statusCol);
269 resizeColumnToContents(_howmanyCol);
276 if ( categoryName.isEmpty() )
283 yuiDebug() <<
"New pattern category \""<< categoryName <<
"\"" << std::endl;
287 _categories.insert( categoryName, cat );
317 zypp::Pattern::Contents c(zyppPattern->contents());
318 for ( zypp::Pattern::Contents::Selectable_iterator it = c.selectableBegin();
319 it != c.selectableEnd();
322 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
325 if ( (*it)->installedSize() > 0 )
332 selection()->setInstalledPackages(installed);
339 resizeColumnToContents(_howmanyCol);
345 ZyppPattern zyppPattern )
349 yuiError() <<
"NULL ZyppSelectable!" << std::endl;
365 resizeColumnToContents(_howmanyCol);
366 resizeColumnToContents(_summaryCol);
368 addTopLevelItem(item);
376 QTreeWidgetItem * item = currentItem();
387 QTreeWidgetItem * listViewItem,
396 if ( button == Qt::LeftButton )
400 categoryItem->setExpanded( ! categoryItem->isExpanded() );
416 QTreeWidgetItemIterator it(
this );
420 QY2ListViewItem * item =
dynamic_cast<QY2ListViewItem *
> (*it);
424 if ( item && item->isSelectable() && ! categoryItem )
426 setSelected( item,
true );
437 ZyppPattern zyppPattern )
439 , _patternList( patternList )
440 , _zyppPattern( zyppPattern )
441 , _total(0), _installed(0)
450 ZyppPattern zyppPattern )
452 , _patternList( patternList )
453 , _zyppPattern( zyppPattern )
454 , _total(0), _installed(0)
464 if ( ! _zyppPattern )
465 _zyppPattern = tryCastToZyppPattern(
selectable()->theObj() );
469 string icon = _zyppPattern->icon().asString();
471 if ( (icon == zypp::Pathname(
"yast-system").asString()) ||
473 icon =
"pattern-generic";
477 QString iconName = QString::fromStdString(icon);
478 if ( QIcon::hasThemeIcon(iconName) )
480 setIcon( _patternList->iconCol(), QIcon::fromTheme(iconName) );
485 setIcon(_patternList->iconCol(), QIcon(QString(iconpath.c_str())));
493 setFirstColumnSpanned (
false );
507 if ( ! _editable || ! _pkgObjList->
editable() )
510 ZyppStatus oldStatus =
status();
511 ZyppStatus newStatus = oldStatus;
516 newStatus = S_NoInst;
525 newStatus = S_Install;
529 newStatus = S_NoInst;
536 if ( oldStatus != newStatus )
558 std::string infoToolTip;
559 infoToolTip += (
"<p>" +
zyppPattern()->description() +
"</p>");
561 if ( totalPackages() > 0 )
563 infoToolTip += (
"<p>" + zypp::str::form(
"%d / %d", installedPackages(), totalPackages() ) +
"</p>");
566 setToolTip(_patternList->summaryCol(), fromUTF8(infoToolTip));
583 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->
zyppPattern() )
585 if ( _zyppPattern->order() != otherPatternListitem->
zyppPattern()->order() )
586 return _zyppPattern->order() < otherPatternListitem->
zyppPattern()->order();
588 return _zyppPattern->name() < otherPatternListitem->
zyppPattern()->name();
593 if ( otherCategoryItem )
596 return QTreeWidgetItem::operator<( otherListViewItem );
600 const QString & category )
601 : QY2ListViewItem( patternList )
602 , _patternList( patternList )
604 setText( _patternList->summaryCol(), category );
619 if ( ! _firstPattern )
621 _firstPattern = pattern;
625 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
626 _firstPattern = pattern;
632 YQPkgPatternCategoryItem::setExpanded(
bool open )
634 QTreeWidgetItem::setExpanded( open );
644 YQIconPool::treeMinus() :
645 YQIconPool::treePlus() );
654 if ( _firstPattern && otherCategoryItem && otherCategoryItem->
firstPattern() )
655 return _firstPattern->order() < otherCategoryItem->
firstPattern()->order();
660 if ( otherPatternListitem )
663 return QTreeWidgetItem::operator<( otherListViewItem );
668 #include "YQPkgPatternList.moc" 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.
static std::string iconPath(const std::string &name, int size)
returns the full path for an icon of a given size
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.