1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgVersionsView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
24 #include <zypp/Repository.h>
25 #include <ycp/y2log.h>
28 #include <QHeaderView>
30 #include "YQPkgVersionsView.h"
31 #include "YQPkgRepoList.h"
32 #include "YQIconPool.h"
37 YQPkgVersionsView::YQPkgVersionsView( QWidget * parent, bool userCanSwitch )
38 : QY2ListView( parent )
41 _parentTab = dynamic_cast<QTabWidget *> (parent);
42 _userCanSwitch = userCanSwitch;
55 headers << _( "Version" ); _versionCol = numCol++;
56 headers << _( "Arch." ); _archCol = numCol++;
57 headers << _( "Product" ); _productCol = numCol++;
58 headers << _( "Repository" ); _repoCol = numCol++;
59 headers << _( "URL" ); _urlCol = numCol++;
61 setHeaderLabels(headers);
62 _statusCol = _productCol;
64 _nameCol = _versionCol;
65 _summaryCol = _repoCol;
67 setSortByInsertionSequence( true );
69 // saveColumnWidths(); // Minimize column widths
75 connect( parent, SIGNAL( currentChanged(QWidget *) ),
76 this, SLOT ( reload (QWidget *) ) );
79 connect( this, SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * ) ),
80 this, SLOT ( checkForChangedCandidate() ) );
84 YQPkgVersionsView::~YQPkgVersionsView()
91 YQPkgVersionsView::reload( QWidget * newCurrent )
93 if ( newCurrent == this )
94 showDetailsIfVisible( _selectable );
99 YQPkgVersionsView::showDetailsIfVisible( ZyppSel selectable )
101 _selectable = selectable;
103 if ( _parentTab ) // Is this view embedded into a tab widget?
105 if ( _parentTab->currentWidget() == this ) // Is this page the topmost?
106 showDetails( selectable );
108 else // No tab parent - simply show data unconditionally.
110 showDetails( selectable );
116 YQPkgVersionsView::showDetails( ZyppSel selectable )
118 _selectable = selectable;
125 QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str() );
128 root->setExpanded( true );
130 bool installedIsAvailable = false;
132 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
134 while ( it != selectable->availableEnd() )
136 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
138 if ( selectable->installedObj() &&
139 selectable->installedObj()->edition() == (*it)->edition() &&
140 selectable->installedObj()->arch() == (*it)->arch() )
141 // FIXME: In future releases, also the vendor will make a difference
142 installedIsAvailable = true;
146 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
147 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
148 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
154 if ( selectable->hasInstalledObj() && ! installedIsAvailable )
155 new YQPkgVersion( this, root, selectable, selectable->installedObj(), false );
162 YQPkgVersionsView::checkForChangedCandidate()
164 QTreeWidgetItemIterator iter(this);
165 QTreeWidgetItem *first = *iter;
167 if ( ! first || ! _selectable )
171 QTreeWidgetItemIterator iter_c(first);
175 YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (*iter_c);
177 if ( versionItem && (versionItem->checkState(0) == Qt::Checked) )
179 ZyppObj newCandidate = versionItem->zyppObj();
181 if ( newCandidate != _selectable->candidateObj() )
183 y2milestone( "Candidate changed" );
185 // Change status of selectable
187 ZyppStatus status = _selectable->status();
189 if ( _selectable->installedObj() &&
190 _selectable->installedObj()->arch() == newCandidate->arch() &&
191 _selectable->installedObj()->edition() == newCandidate->edition() )
193 // Switch back to the original instance -
194 // the version that was previously installed
195 status = S_KeepInstalled;
201 case S_KeepInstalled:
220 _selectable->set_status( status );
225 _selectable->setCandidate( newCandidate );
226 emit candidateChanged( newCandidate );
237 YQPkgVersionsView::minimumSizeHint() const
239 return QSize( 0, 0 );
247 YQPkgVersion::YQPkgVersion( YQPkgVersionsView * pkgVersionList,
248 QY2CheckListItem * parent,
252 : QY2CheckListItem( parent, "" /*
254 Q3CheckListItem::RadioButton :
255 Q3CheckListItem::Controller */ ) // cheap way to make it read-only
256 , _pkgVersionList( pkgVersionList )
257 , _selectable( selectable )
258 , _zyppObj( zyppObj )
260 // FIXME setOn( _zyppObj == _selectable->candidateObj() );
262 if ( versionCol() >= 0 ) setText( versionCol(), zyppObj->edition().asString().c_str() );
263 if ( archCol() >= 0 ) setText( archCol(), zyppObj->arch().asString().c_str() );
264 if ( repoCol() >= 0 ) setText( repoCol(), fromUTF8(zyppObj->repository().info().alias()) );
265 if ( productCol() >= 0 )
267 ZyppProduct product = YQPkgRepoListItem::singleProduct( zyppObj->repository() );
270 setText( productCol(), QString::fromStdString( product->summary() ) );
276 if ( ! zyppObj->repository().info().baseUrlsEmpty() )
277 repoUrl = *zyppObj->repository().info().baseUrlsBegin();
279 setText( urlCol(), repoUrl.asString().c_str() );
282 if ( _selectable->hasInstalledObj() )
284 if ( _zyppObj->edition() == _selectable->installedObj()->edition() &&
285 _zyppObj->arch() == _selectable->installedObj()->arch() )
287 // FIXME setPixmap( statusCol(), YQIconPool::pkgKeepInstalled() );
288 setBackgroundColor( QColor( 0xF0, 0xF0, 0xF0 ) ); // light grey
289 setTextColor( QColor( 0, 0x90, 0 ) ); // green
295 YQPkgVersion::~YQPkgVersion()
302 YQPkgVersion::toolTip(int)
306 if ( zyppObj() == selectable()->installedObj() )
307 tip = _( "This version is installed in your system." );
313 bool YQPkgVersion::operator< ( const QTreeWidgetItem & otherListViewItem ) const
315 const YQPkgVersion * other = dynamic_cast<const YQPkgVersion *> (&otherListViewItem);
319 return ( this->zyppObj()->edition() < other->zyppObj()->edition() );
322 // Fallback: Use parent class method
323 return QY2CheckListItem::operator<( otherListViewItem );
328 #include "YQPkgVersionsView.moc"