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( parent, SIGNAL( currentChanged(QWidget *) ),
79 this, SLOT (
reload (QWidget *) ) );
93 if ( 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 );
149 setPalette( QApplication::palette().color( QPalette::Active, QPalette::Base ) );
150 setAutoFillBackground(
true );
152 _content->setPalette( QApplication::palette().color( QPalette::Active, QPalette::Base ) );
153 _content->setAutoFillBackground(
true );
155 QLabel * pkgNameLabel =
new QLabel(
this );
157 if ( ! selectable->theObj() )
160 _layout->addWidget( pkgNameLabel );
162 QFont font = pkgNameLabel->font();
163 font.setBold(
true );
165 QFontMetrics fm( font) ;
166 font.setPixelSize( (
int) ( fm.height() * 1.1 ) );
168 pkgNameLabel->setFont( font );
169 pkgNameLabel->setText( fromUTF8(selectable->theObj()->name().c_str()) );
173 QListIterator<QAbstractButton*> it( _buttons->buttons() );
175 while ( it.hasNext() )
182 qDeleteAll( _installed );
185 if ( selectable->multiversionInstall() )
191 zypp::ui::Selectable::picklist_iterator it = selectable->picklistBegin();
194 while ( it != selectable->picklistEnd() )
198 _installed.push_back( version );
199 _layout->addWidget( version );
201 connect (version, SIGNAL(statusChanged()),
this, SLOT(slotRefreshDetails()));
202 connect (
this, SIGNAL(multiversionSelectionChanged()), version, SLOT(update()));
214 zypp::ui::Selectable::installed_iterator it = selectable->installedBegin();
216 while ( it != selectable->installedEnd() )
218 QString text = _(
"%1-%2 from vendor %3 (installed)" )
219 .arg( fromUTF8( (*it)->edition().asString().c_str() ) )
220 .arg( fromUTF8( (*it)->arch().asString().c_str() ) )
221 .arg( fromUTF8( (*it)->vendor().c_str() ) ) ;
223 QWidget * installedVersion =
new QWidget(
this );
224 QHBoxLayout * instLayout =
new QHBoxLayout( installedVersion );
225 instLayout->setContentsMargins( 0, 0, 0, 0 );
227 QLabel * icon =
new QLabel( installedVersion );
228 icon->setPixmap( YQIconPool::pkgSatisfied() );
229 instLayout->addWidget( icon );
231 QLabel * textLabel =
new QLabel( text, installedVersion );
232 instLayout->addWidget( textLabel );
233 instLayout->addStretch();
235 _installed.push_back( installedVersion );
236 _layout->addWidget( installedVersion );
248 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
250 while ( it != selectable->availableEnd() )
252 QRadioButton *radioButton =
new YQPkgVersion(
this, selectable, *it, _userCanSwitch );
255 _buttons->addButton( radioButton );
256 _layout->addWidget( radioButton );
259 if ( selectable->hasCandidateObj() &&
260 selectable->candidateObj()->edition() == (*it)->edition() &&
261 selectable->candidateObj()->arch() == (*it)->arch() )
263 radioButton->setChecked(
true);
271 _layout->addStretch();
272 setWidget( _content );
280 QListIterator<QAbstractButton*> it( _buttons->buttons() );
282 while ( it.hasNext() )
286 if ( versionItem && versionItem->isChecked() )
288 ZyppObj newCandidate = versionItem->
zyppObj();
290 if ( _selectable && newCandidate != _selectable->candidateObj() )
292 yuiMilestone() <<
"Candidate changed" << endl;
296 ZyppStatus status = _selectable->status();
298 if ( !_selectable->installedEmpty() &&
299 _selectable->installedObj()->arch() == newCandidate->arch() &&
300 _selectable->installedObj()->edition() == newCandidate->edition() )
304 status = S_KeepInstalled;
310 case S_KeepInstalled:
329 _selectable->setStatus( status );
334 _selectable->setCandidate( newCandidate );
347 return QSize( 0, 0 );
359 : QRadioButton( parent )
360 , _selectable( selectable )
361 , _zyppObj( zyppObj )
372 setText( _(
"%1-%2 from %3 with priority %4 and vendor %5" )
373 .arg( fromUTF8( zyppObj->edition().asString().c_str() ) )
374 .arg( fromUTF8( zyppObj->arch().asString().c_str() ) )
375 .arg( fromUTF8( zyppObj->repository().info().name().c_str() ) )
376 .arg( zyppObj->repository().info().priority() )
377 .arg( fromUTF8( zyppObj->vendor().c_str() ) ) );
393 tip = _(
"This version is installed in your system." );
403 ZyppPoolItem zyppPoolItem,
405 : QCheckBox( parent )
406 , _selectable( selectable )
407 , _zyppPoolItem( zyppPoolItem )
409 setText (_(
"%1-%2 from %3 with priority %4 and vendor %5" )
410 .arg( fromUTF8( zyppPoolItem->edition().asString().c_str() ) )
411 .arg( fromUTF8( zyppPoolItem->arch().asString().c_str() ) )
412 .arg( fromUTF8( zyppPoolItem->repository().info().name().c_str() ) )
413 .arg( zyppPoolItem->repository().info().priority() )
414 .arg( fromUTF8( zyppPoolItem->vendor().c_str() ) ));
417 connect(
this, SIGNAL (toggled(
bool)),
this, SLOT( slotIconClicked()));
427 void YQPkgMultiVersion::slotIconClicked()
430 bool oldBlock = blockSignals(
true );
432 blockSignals( oldBlock );
440 ZyppStatus oldStatus = _selectable->pickStatus( _zyppPoolItem );
441 ZyppStatus newStatus = oldStatus;
446 newStatus = S_NoInst;
450 newStatus = _selectable->identicalAvailable( _zyppPoolItem ) ?
451 S_KeepInstalled: S_NoInst;
455 newStatus = _selectable->identicalInstalled( _zyppPoolItem ) ?
456 S_KeepInstalled : S_NoInst;
459 case S_KeepInstalled:
460 newStatus = _selectable->identicalAvailable( _zyppPoolItem ) ?
469 newStatus = S_KeepInstalled;
474 newStatus = S_KeepInstalled;
478 if ( _selectable->identicalAvailable( _zyppPoolItem ) )
480 newStatus = S_Install;
484 yuiWarning() <<
"No candidate for " << _selectable->theObj()->name() << endl;
485 newStatus = S_NoInst;
492 newStatus = S_NoInst;
497 setStatus( newStatus );
498 yuiMilestone() <<
"oldStatus:" << oldStatus << endl;
499 yuiMilestone() <<
"newStatus:" << newStatus << endl;
504 void YQPkgMultiVersion::setStatus( ZyppStatus newStatus )
506 _selectable->setPickStatus( _zyppPoolItem, newStatus );
508 emit statusChanged();
516 QStylePainter p(
this);
517 QStyleOptionButton opt;
518 initStyleOption(&opt);
519 p.drawControl(QStyle::CE_CheckBox, opt);
523 QRect elementRect = style()->subElementRect ( QStyle::SE_CheckBoxIndicator, &opt);
524 QPixmap icon = statusIcon( _selectable->pickStatus(_zyppPoolItem) );
526 QPoint start = elementRect.center() - icon.rect().center();
527 QRect rect = QRect(start.x() - ICONOFFSET, start.y(), icon.width(), icon.height());
529 p.drawItemPixmap( rect, 0, icon );
533 QPixmap YQPkgMultiVersion::statusIcon( ZyppStatus status )
535 QPixmap icon = YQIconPool::pkgNoInst();
539 case S_Del: icon = YQIconPool::pkgDel();
break;
540 case S_Install: icon = YQIconPool::pkgInstall();
break;
541 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled();
break;
542 case S_NoInst: icon = QPixmap();
break;
543 case S_Protected: icon = YQIconPool::pkgProtected();
break;
544 case S_Taboo: icon = YQIconPool::pkgTaboo();
break;
545 case S_Update: icon = YQIconPool::pkgUpdate();
break;
547 case S_AutoDel: icon = YQIconPool::pkgAutoDel();
break;
548 case S_AutoInstall: icon = YQIconPool::pkgAutoInstall();
break;
549 case S_AutoUpdate: icon = YQIconPool::pkgAutoUpdate();
break;
559 #include "YQPkgVersionsView.moc"
void reload(QWidget *newCurrent)
virtual QSize minimumSizeHint() const
virtual QString toolTip(int column)
YQPkgMultiVersion(QWidget *parent, ZyppSel selectable, ZyppPoolItem zyppPoolItem, bool enabled=true)
YQPkgVersion(QWidget *parent, ZyppSel selectable, ZyppObj zyppObj, bool enabled=true)
void showDetailsIfVisible(ZyppSel selectable)
YQPkgVersionsView(QWidget *parent, bool userCanSwitchVersions)
virtual ~YQPkgMultiVersion()
ZyppSel selectable() const
void paintEvent(QPaintEvent *)
void checkForChangedCandidate()
void candidateChanged(ZyppObj newCandidate)
virtual ~YQPkgVersionsView()
void showDetails(ZyppSel selectable)