42 #define YUILogComponent "qt-pkg" 45 #include <zypp/Repository.h> 49 #include <QHeaderView> 50 #include <QStylePainter> 51 #include <QStyleOptionButton> 52 #include <QMessageBox> 53 #include <QApplication> 56 #include "YQPkgVersionsView.h" 57 #include "YQPkgRepoList.h" 58 #include "YQIconPool.h" 59 #include "YQSignalBlocker.h" 63 #define ICONOFFSET 3 // the status icons have an asymmetrical transparent border 68 : QScrollArea( parent )
73 _isMixedMultiVersion =
false;
74 _parentTab =
dynamic_cast<QTabWidget *
> (parent);
76 _buttons =
new QButtonGroup(
this);
80 connect( _parentTab, SIGNAL( currentChanged(
int ) ),
81 this, SLOT (
reload (
int ) ) );
95 if ( _parentTab && _parentTab->widget( newCurrent ) == this )
103 _selectable = selectable;
108 if ( _parentTab->currentWidget() == this )
121 _selectable = selectable;
127 qDeleteAll( _installed );
130 _content =
new QWidget(
this );
131 setWidget( _content );
137 _content =
new QWidget(
this );
138 _layout =
new QVBoxLayout( _content );
139 _content->setLayout( _layout );
141 QLabel * pkgNameLabel =
new QLabel(
this );
143 if ( ! selectable->theObj() )
146 _layout->addWidget( pkgNameLabel );
148 QFont font = pkgNameLabel->font();
149 font.setBold(
true );
151 QFontMetrics fm( font) ;
152 font.setPixelSize( (
int) ( fm.height() * 1.1 ) );
154 pkgNameLabel->setFont( font );
155 pkgNameLabel->setText( fromUTF8(selectable->theObj()->name().c_str()) );
159 QListIterator<QAbstractButton*> it( _buttons->buttons() );
161 while ( it.hasNext() )
168 qDeleteAll( _installed );
171 if ( selectable->multiversionInstall() )
177 zypp::ui::Selectable::picklist_iterator it = selectable->picklistBegin();
179 while ( it != selectable->picklistEnd() )
183 _installed.push_back( version );
184 _layout->addWidget( version );
190 version, SLOT ( update() ) );
203 zypp::ui::Selectable::installed_iterator it = selectable->installedBegin();
205 while ( it != selectable->installedEnd() )
207 QString text = _(
"%1-%2 from vendor %3 (installed)" )
208 .arg( fromUTF8( (*it)->edition().asString().c_str() ) )
209 .arg( fromUTF8( (*it)->arch().asString().c_str() ) )
210 .arg( fromUTF8( (*it)->vendor().c_str() ) ) ;
212 QWidget * installedVersion =
new QWidget(
this );
213 QHBoxLayout * instLayout =
new QHBoxLayout( installedVersion );
214 instLayout->setContentsMargins( 0, 0, 0, 0 );
216 QLabel * icon =
new QLabel( installedVersion );
217 icon->setPixmap( YQIconPool::pkgSatisfied() );
218 instLayout->addWidget( icon );
220 QLabel * textLabel =
new QLabel( text, installedVersion );
221 instLayout->addWidget( textLabel );
222 instLayout->addStretch();
224 _installed.push_back( installedVersion );
225 _layout->addWidget( installedVersion );
237 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
239 while ( it != selectable->availableEnd() )
241 QRadioButton *radioButton =
new YQPkgVersion(
this, selectable, *it );
242 connect( radioButton, SIGNAL( clicked(
bool ) ),
245 _buttons->addButton( radioButton );
246 _layout->addWidget( radioButton );
249 if ( selectable->hasCandidateObj() &&
250 selectable->candidateObj()->edition() == (*it)->edition() &&
251 selectable->candidateObj()->arch() == (*it)->arch() )
253 radioButton->setChecked(
true);
261 _layout->addStretch();
262 setWidget( _content );
270 QListIterator<QAbstractButton*> it( _buttons->buttons() );
272 while ( it.hasNext() )
276 if ( versionItem && versionItem->isChecked() )
278 ZyppObj newCandidate = versionItem->
zyppObj();
280 if ( _selectable && *newCandidate != _selectable->candidateObj() )
282 yuiMilestone() <<
"Candidate changed" << endl;
286 ZyppStatus status = _selectable->status();
288 if ( !_selectable->installedEmpty() &&
289 _selectable->installedObj()->arch() == newCandidate->arch() &&
290 _selectable->installedObj()->edition() == newCandidate->edition() )
294 status = S_KeepInstalled;
300 case S_KeepInstalled:
319 _selectable->setStatus( status );
324 _selectable->setCandidate( newCandidate );
336 return QSize( 0, 0 );
344 Q_CHECK_PTR( poolItem );
346 bool multiVersion = poolItem->multiversionInstall();
348 yuiMilestone() <<
"Selected: " 349 << ( multiVersion ?
"Multiversion " :
"Non-Multiversion " )
350 << newSelected->text()
355 yuiMilestone() <<
"Multiversion and non-multiversion conflict!" << endl;
360 _selectable->setPickStatus( poolItem, S_Install );
382 QString msg = _(
"You are trying to install multiversion-capable\n" 383 "and non-multiversion-capable versions of this\n" 384 "package at the same time." );
390 _(
"This version is multiversion-capable.\n" 392 "Press \"Continue\" to install this version\n" 393 "and unselect the non-multiversion-capable version,\n" 394 "\"Cancel\" to unselect this version and keep the other one." );
399 _(
"This version is not multiversion-capable.\n" 401 "Press \"Continue\" to install only this version\n" 402 "and unselect all other versions,\n" 403 "\"Cancel\" to unselect this version and keep the other ones." );
407 QString heading = _(
"Incompatible Package Versions" );
409 int buttonNo = QMessageBox::question( 0,
414 yuiMilestone() <<
"User hit " << (buttonNo == 0 ?
"[Continue]" :
"[Cancel]" ) << endl;
416 return buttonNo == 0;
427 zypp::ui::Selectable::available_iterator it = _selectable->availableBegin();
429 while ( it != _selectable->availableEnd() )
431 if ( it->multiversionInstall() == multiversion )
433 switch ( _selectable->pickStatus( *it ) )
437 yuiMilestone() <<
"Found " << ( multiversion ?
"multiversion" :
"non-multiversion" )
438 <<
" to install" << endl;
449 yuiMilestone() <<
"No " << ( multiversion ?
"multiversion" :
"non-multiversion" )
450 <<
" to install" << endl;
461 zypp::ui::Selectable::available_iterator it = _selectable->availableBegin();
463 while ( it != _selectable->availableEnd() )
465 if ( it->multiversionInstall() )
467 switch ( _selectable->pickStatus( *it ) )
471 _selectable->setPickStatus( *it, S_NoInst );
472 yuiMilestone() <<
"Unselecting " << *it << endl;
491 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
493 if ( it == selectable->availableEnd() )
496 bool multiversion = it->multiversionInstall();
498 while ( it != selectable->availableEnd() )
500 if ( it->multiversionInstall() != multiversion )
502 yuiMilestone() <<
"Mixed multiversion" << endl;
520 : QRadioButton( parent )
521 , _selectable( selectable )
522 , _zyppObj( zyppObj )
533 setText( _(
"%1-%2 from %3 with priority %4 and vendor %5" )
534 .arg( fromUTF8( zyppObj->edition().asString().c_str() ) )
535 .arg( fromUTF8( zyppObj->arch().asString().c_str() ) )
536 .arg( fromUTF8( zyppObj->repository().info().name().c_str() ) )
537 .arg( zyppObj->repository().info().priority() )
538 .arg( fromUTF8( zyppObj->vendor().c_str() ) ) );
554 tip = _(
"This version is installed in your system." );
564 ZyppPoolItem zyppPoolItem )
565 : QCheckBox( parent )
567 , _selectable( selectable )
568 , _zyppPoolItem( zyppPoolItem )
570 setText (_(
"%1-%2 from %3 with priority %4 and vendor %5" )
571 .arg( fromUTF8( zyppPoolItem->edition().asString().c_str() ) )
572 .arg( fromUTF8( zyppPoolItem->arch().asString().c_str() ) )
573 .arg( fromUTF8( zyppPoolItem->repository().info().name().c_str() ) )
574 .arg( zyppPoolItem->repository().info().priority() )
575 .arg( fromUTF8( zyppPoolItem->vendor().c_str() ) ));
577 connect(
this, SIGNAL( toggled(
bool) ),
578 this, SLOT ( slotIconClicked() ) );
588 void YQPkgMultiVersion::slotIconClicked()
591 YQSignalBlocker sigBlocker(
this );
601 ZyppStatus oldStatus = _selectable->pickStatus( _zyppPoolItem );
602 ZyppStatus newStatus = oldStatus;
609 newStatus = S_NoInst;
612 case S_KeepInstalled:
621 newStatus = S_KeepInstalled;
626 newStatus = S_Install;
630 bool handled =
false;
633 newStatus == S_Install &&
634 oldStatus != newStatus )
640 setStatus( newStatus );
642 yuiMilestone() <<
"oldStatus: " << oldStatus << endl;
643 ZyppStatus actualStatus = _selectable->pickStatus( _zyppPoolItem );
645 if ( actualStatus != newStatus )
646 yuiWarning() <<
"FAILED to set new status: " << newStatus
647 <<
" actual Status: " << actualStatus << endl;
649 yuiMilestone() <<
"newStatus:" << newStatus << endl;
651 if ( oldStatus != actualStatus )
659 void YQPkgMultiVersion::setStatus( ZyppStatus newStatus )
661 yuiMilestone() <<
"Setting pick status to " << newStatus << endl;
662 _selectable->setPickStatus( _zyppPoolItem, newStatus );
669 QStylePainter p(
this);
670 QStyleOptionButton opt;
671 initStyleOption(&opt);
672 p.drawControl(QStyle::CE_CheckBox, opt);
676 QRect elementRect = style()->subElementRect ( QStyle::SE_CheckBoxIndicator, &opt);
677 QPixmap icon = statusIcon( _selectable->pickStatus(_zyppPoolItem) );
679 QPoint start = elementRect.center() - icon.rect().center();
680 QRect rect = QRect(start.x() - ICONOFFSET, start.y(), icon.width(), icon.height());
682 p.drawItemPixmap( rect, 0, icon );
686 QPixmap YQPkgMultiVersion::statusIcon( ZyppStatus status )
688 QPixmap icon = YQIconPool::pkgNoInst();
692 case S_Del: icon = YQIconPool::pkgDel();
break;
693 case S_Install: icon = YQIconPool::pkgInstall();
break;
694 case S_KeepInstalled: icon = YQIconPool::pkgKeepInstalled();
break;
695 case S_NoInst: icon = QPixmap();
break;
696 case S_Protected: icon = YQIconPool::pkgProtected();
break;
697 case S_Taboo: icon = YQIconPool::pkgTaboo();
break;
698 case S_Update: icon = YQIconPool::pkgUpdate();
break;
700 case S_AutoDel: icon = YQIconPool::pkgAutoDel();
break;
701 case S_AutoInstall: icon = YQIconPool::pkgAutoInstall();
break;
702 case S_AutoUpdate: icon = YQIconPool::pkgAutoUpdate();
break;
712 #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(YQPkgVersionsView *parent, ZyppSel selectable, ZyppPoolItem zyppPoolItem)
Constructor.
YQPkgVersion(QWidget *parent, ZyppSel selectable, ZyppObj zyppObj)
Constructor.
void showDetailsIfVisible(ZyppSel selectable)
Show details for the specified package.
virtual ~YQPkgVersion()
Destructor.
virtual ~YQPkgMultiVersion()
Destructor.
bool mixedMultiVersionPopup(bool multiversion) const
Ask user if he really wants to install incompatible package versions.
bool isMixedMultiVersion() const
Return the cached value for the current selectable.
ZyppSel selectable() const
Returns the original ZYPP selectable.
YQPkgVersionsView(QWidget *parent)
Constructor.
Package version selector: Display a list of available versions from all the different installation so...
void paintEvent(QPaintEvent *)
Paints checkboxes with status icons instead of a checkmark.
bool anyMultiVersionToInstall(bool multiversion) const
Check if any package version is marked for installation where its 'multiversion' flag is set to 'mult...
void checkForChangedCandidate()
Check for changed candidates.
void unselectAllMultiVersion()
Unselect all multiversion package versions.
void candidateChanged(ZyppObj newCandidate)
Emitted when the user changes the candidate.
ZyppObj zyppObj() const
Returns the original ZYPP object.
virtual ~YQPkgVersionsView()
Destructor.
bool handleMixedMultiVersion(YQPkgMultiVersion *newSelected)
Negotiate between multiversion and non-multiversion packages if there are both kinds in that selectab...
void statusChanged()
Emitted when the status of this package version is changed.
void cycleStatus()
Cycle the package status to the next valid value.
static bool isMixedMultiVersion(ZyppSel selectable)
Return 'true' if 'selectable' has mixed multiversion flags, 'false' if all its pool items are of the ...
void statusChanged()
Emitted when the status of any package changed.
void reload(int newCurrent)
Show data for the current package.
ZyppPoolItem zyppPoolItem() const
Returns the original ZYPP object.
void showDetails(ZyppSel selectable)
Show details for the specified package.