42 #define YUILogComponent "qt-pkg"
45 #include <zypp/Repository.h>
49 #include <QHeaderView>
50 #include <QStylePainter>
51 #include <QStyleOptionButton>
52 #include <QApplication>
55 #include "YQPkgVersionsView.h"
56 #include "YQPkgRepoList.h"
57 #include "YQIconPool.h"
61 #define ICONOFFSET 3 // the status icons have an asymmetrical transparent border
66 : QScrollArea( parent )
71 _parentTab =
dynamic_cast<QTabWidget *
> (parent);
72 _userCanSwitch = userCanSwitch;
74 _buttons =
new QButtonGroup(
this);
78 connect( _parentTab, &QTabWidget::currentChanged,
93 if ( _parentTab && _parentTab->widget( newCurrent ) == this )
99 YQPkgVersionsView::slotRefreshDetails( )
101 emit multiversionSelectionChanged( );
108 _selectable = selectable;
110 yuiMilestone() <<
"showDetailsIfVis" << endl;
114 if ( _parentTab->currentWidget() == this )
127 yuiMilestone() <<
"showDetails" << endl;
129 _selectable = selectable;
134 qDeleteAll( _installed );
137 _content =
new QWidget(
this );
138 setWidget( _content );
144 _content =
new QWidget(
this );
145 _layout =
new QVBoxLayout( _content );
146 _content->setLayout( _layout );
148 QLabel * pkgNameLabel =
new QLabel(
this );
150 if ( ! selectable->theObj() )
153 _layout->addWidget( pkgNameLabel );
155 QFont font = pkgNameLabel->font();
156 font.setBold(
true );
158 QFontMetrics fm( font) ;
159 font.setPixelSize( (
int) ( fm.height() * 1.1 ) );
161 pkgNameLabel->setFont( font );
162 pkgNameLabel->setText( fromUTF8(selectable->theObj()->name().c_str()) );
166 QListIterator<QAbstractButton*> it( _buttons->buttons() );
168 while ( it.hasNext() )
175 qDeleteAll( _installed );
178 if ( selectable->multiversionInstall() )
184 zypp::ui::Selectable::picklist_iterator it = selectable->picklistBegin();
187 while ( it != selectable->picklistEnd() )
191 _installed.push_back( version );
192 _layout->addWidget( version );
194 connect (version, SIGNAL(statusChanged()),
this, SLOT(slotRefreshDetails()));
195 connect (
this, SIGNAL(multiversionSelectionChanged()), version, SLOT(update()));
207 zypp::ui::Selectable::installed_iterator it = selectable->installedBegin();
209 while ( it != selectable->installedEnd() )
211 QString text = _(
"%1-%2 from vendor %3 (installed)" )
212 .arg( fromUTF8( (*it)->edition().asString().c_str() ) )
213 .arg( fromUTF8( (*it)->arch().asString().c_str() ) )
214 .arg( fromUTF8( (*it)->vendor().c_str() ) ) ;
216 QWidget * installedVersion =
new QWidget(
this );
217 QHBoxLayout * instLayout =
new QHBoxLayout( installedVersion );
218 instLayout->setContentsMargins( 0, 0, 0, 0 );
220 QLabel * icon =
new QLabel( installedVersion );
221 icon->setPixmap( YQIconPool::pkgSatisfied() );
222 instLayout->addWidget( icon );
224 QLabel * textLabel =
new QLabel( text, installedVersion );
225 instLayout->addWidget( textLabel );
226 instLayout->addStretch();
228 _installed.push_back( installedVersion );
229 _layout->addWidget( installedVersion );
241 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
243 while ( it != selectable->availableEnd() )
245 QRadioButton *radioButton =
new YQPkgVersion(
this, selectable, *it, _userCanSwitch );
248 _buttons->addButton( radioButton );
249 _layout->addWidget( radioButton );
252 if ( selectable->hasCandidateObj() &&
253 selectable->candidateObj()->edition() == (*it)->edition() &&
254 selectable->candidateObj()->arch() == (*it)->arch() )
256 radioButton->setChecked(
true);
264 _layout->addStretch();
265 setWidget( _content );
273 QListIterator<QAbstractButton*> it( _buttons->buttons() );
275 while ( it.hasNext() )
279 if ( versionItem && versionItem->isChecked() )
281 ZyppObj newCandidate = versionItem->
zyppObj();
283 if ( _selectable && newCandidate != _selectable->candidateObj() )
285 yuiMilestone() <<
"Candidate changed" << endl;
289 ZyppStatus status = _selectable->status();
291 if ( !_selectable->installedEmpty() &&
292 _selectable->installedObj()->arch() == newCandidate->arch() &&
293 _selectable->installedObj()->edition() == newCandidate->edition() )
297 status = S_KeepInstalled;
303 case S_KeepInstalled:
322 _selectable->setStatus( status );
327 _selectable->setCandidate( newCandidate );
340 return QSize( 0, 0 );
352 : QRadioButton( parent )
353 , _selectable( selectable )
354 , _zyppObj( zyppObj )
365 setText( _(
"%1-%2 from %3 with priority %4 and vendor %5" )
366 .arg( fromUTF8( zyppObj->edition().asString().c_str() ) )
367 .arg( fromUTF8( zyppObj->arch().asString().c_str() ) )
368 .arg( fromUTF8( zyppObj->repository().info().name().c_str() ) )
369 .arg( zyppObj->repository().info().priority() )
370 .arg( fromUTF8( zyppObj->vendor().c_str() ) ) );
386 tip = _(
"This version is installed in your system." );
396 ZyppPoolItem zyppPoolItem,
398 : QCheckBox( parent )
399 , _selectable( selectable )
400 , _zyppPoolItem( zyppPoolItem )
402 setText (_(
"%1-%2 from %3 with priority %4 and vendor %5" )
403 .arg( fromUTF8( zyppPoolItem->edition().asString().c_str() ) )
404 .arg( fromUTF8( zyppPoolItem->arch().asString().c_str() ) )
405 .arg( fromUTF8( zyppPoolItem->repository().info().name().c_str() ) )
406 .arg( zyppPoolItem->repository().info().priority() )
407 .arg( fromUTF8( zyppPoolItem->vendor().c_str() ) ));
410 connect(
this, SIGNAL (toggled(
bool)),
this, SLOT( slotIconClicked()));
420 void YQPkgMultiVersion::slotIconClicked()
423 bool oldBlock = blockSignals(
true );
425 blockSignals( oldBlock );
433 ZyppStatus oldStatus = _selectable->pickStatus( _zyppPoolItem );
434 ZyppStatus newStatus = oldStatus;
439 newStatus = S_NoInst;
443 newStatus = _selectable->identicalAvailable( _zyppPoolItem ) ?
444 S_KeepInstalled: S_NoInst;
448 newStatus = _selectable->identicalInstalled( _zyppPoolItem ) ?
449 S_KeepInstalled : S_NoInst;
452 case S_KeepInstalled:
453 newStatus = _selectable->identicalAvailable( _zyppPoolItem ) ?
462 newStatus = S_KeepInstalled;
467 newStatus = S_KeepInstalled;
471 if ( _selectable->identicalAvailable( _zyppPoolItem ) )
473 newStatus = S_Install;
477 yuiWarning() <<
"No candidate for " << _selectable->theObj()->name() << endl;
478 newStatus = S_NoInst;
485 newStatus = S_NoInst;
490 setStatus( newStatus );
491 yuiMilestone() <<
"oldStatus:" << oldStatus << endl;
492 yuiMilestone() <<
"newStatus:" << newStatus << endl;
497 void YQPkgMultiVersion::setStatus( ZyppStatus newStatus )
499 _selectable->setPickStatus( _zyppPoolItem, newStatus );
501 emit statusChanged();
509 QStylePainter p(
this);
510 QStyleOptionButton opt;
511 initStyleOption(&opt);
512 p.drawControl(QStyle::CE_CheckBox, opt);
516 QRect elementRect = style()->subElementRect ( QStyle::SE_CheckBoxIndicator, &opt);
517 QPixmap icon = statusIcon( _selectable->pickStatus(_zyppPoolItem) );
519 QPoint start = elementRect.center() - icon.rect().center();
520 QRect rect = QRect(start.x() - ICONOFFSET, start.y(), icon.width(), icon.height());
522 p.drawItemPixmap( rect, 0, icon );
526 QPixmap YQPkgMultiVersion::statusIcon( ZyppStatus status )
528 QPixmap icon = YQIconPool::pkgNoInst();
532 case S_Del: icon = YQIconPool::pkgDel();
break;
533 case S_Install: icon = YQIconPool::pkgInstall();
break;
534 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled();
break;
535 case S_NoInst: icon = QPixmap();
break;
536 case S_Protected: icon = YQIconPool::pkgProtected();
break;
537 case S_Taboo: icon = YQIconPool::pkgTaboo();
break;
538 case S_Update: icon = YQIconPool::pkgUpdate();
break;
540 case S_AutoDel: icon = YQIconPool::pkgAutoDel();
break;
541 case S_AutoInstall: icon = YQIconPool::pkgAutoInstall();
break;
542 case S_AutoUpdate: icon = YQIconPool::pkgAutoUpdate();
break;
552 #include "YQPkgVersionsView.moc"
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
YQPkgMultiVersion(QWidget *parent, ZyppSel selectable, ZyppPoolItem zyppPoolItem, bool enabled=true)
Constructor.
YQPkgVersion(QWidget *parent, ZyppSel selectable, ZyppObj zyppObj, bool enabled=true)
Constructor.
void showDetailsIfVisible(ZyppSel selectable)
Show details for the specified package.
virtual ~YQPkgVersion()
Destructor.
YQPkgVersionsView(QWidget *parent, bool userCanSwitchVersions)
Constructor.
virtual ~YQPkgMultiVersion()
Destructor.
ZyppSel selectable() const
Returns the original ZYPP selectable.
void paintEvent(QPaintEvent *)
Paints checkboxes with status icons instead of a checkmark.
void checkForChangedCandidate()
Check for changed candidates.
void candidateChanged(ZyppObj newCandidate)
Emitted when the user changes the.
ZyppObj zyppObj() const
Returns the original ZYPP object.
virtual ~YQPkgVersionsView()
Destructor.
void cycleStatus()
Cycle the package status to the next valid value.
void reload(int newCurrent)
Show data for the last package.
void showDetails(ZyppSel selectable)
Show details for the specified package.