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>
26 #include <qtabwidget.h>
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;
54 addColumn( _( "Version" ) ); _versionCol = numCol++;
55 addColumn( _( "Arch." ) ); _archCol = numCol++;
56 addColumn( _( "Product" ) ); _productCol = numCol++;
57 addColumn( _( "Repository" ) ); _repoCol = numCol++;
58 addColumn( _( "URL" ) ); _urlCol = numCol++;
59 _statusCol = _productCol;
61 _nameCol = _versionCol;
62 _summaryCol = _repoCol;
64 setSortByInsertionSequence( true );
66 // saveColumnWidths(); // Minimize column widths
72 connect( parent, SIGNAL( currentChanged(QWidget *) ),
73 this, SLOT ( reload (QWidget *) ) );
76 connect( this, SIGNAL( selectionChanged () ),
77 this, SLOT ( checkForChangedCandidate() ) );
81 YQPkgVersionsView::~YQPkgVersionsView()
88 YQPkgVersionsView::reload( QWidget * newCurrent )
90 if ( newCurrent == this )
91 showDetailsIfVisible( _selectable );
96 YQPkgVersionsView::showDetailsIfVisible( ZyppSel selectable )
98 _selectable = selectable;
100 if ( _parentTab ) // Is this view embedded into a tab widget?
102 if ( _parentTab->currentPage() == this ) // Is this page the topmost?
103 showDetails( selectable );
105 else // No tab parent - simply show data unconditionally.
107 showDetails( selectable );
113 YQPkgVersionsView::showDetails( ZyppSel selectable )
115 _selectable = selectable;
121 QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str(),
122 Q3CheckListItem::Controller );
124 root->setOpen( true );
126 bool installedIsAvailable = false;
128 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
130 while ( it != selectable->availableEnd() )
132 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
134 if ( selectable->installedObj() &&
135 selectable->installedObj()->edition() == (*it)->edition() &&
136 selectable->installedObj()->arch() == (*it)->arch() )
137 // FIXME: In future releases, also the vendor will make a difference
138 installedIsAvailable = true;
142 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
143 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
144 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
150 if ( selectable->hasInstalledObj() && ! installedIsAvailable )
151 new YQPkgVersion( this, root, selectable, selectable->installedObj(), false );
156 YQPkgVersionsView::checkForChangedCandidate()
158 if ( ! firstChild() || ! _selectable )
161 Q3ListViewItem * item = firstChild()->firstChild();
165 YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (item);
167 if ( versionItem && versionItem->isOn() )
169 ZyppObj newCandidate = versionItem->zyppObj();
171 if ( newCandidate != _selectable->candidateObj() )
173 y2milestone( "Candidate changed" );
175 // Change status of selectable
177 ZyppStatus status = _selectable->status();
179 if ( _selectable->installedObj() &&
180 _selectable->installedObj()->arch() == newCandidate->arch() &&
181 _selectable->installedObj()->edition() == newCandidate->edition() )
183 // Switch back to the original instance -
184 // the version that was previously installed
185 status = S_KeepInstalled;
191 case S_KeepInstalled:
210 _selectable->set_status( status );
215 _selectable->setCandidate( newCandidate );
216 emit candidateChanged( newCandidate );
221 item = item->nextSibling();
227 YQPkgVersionsView::minimumSizeHint() const
229 return QSize( 0, 0 );
237 YQPkgVersion::YQPkgVersion( YQPkgVersionsView * pkgVersionList,
238 QY2CheckListItem * parent,
242 : QY2CheckListItem( parent, "",
244 Q3CheckListItem::RadioButton :
245 Q3CheckListItem::Controller ) // cheap way to make it read-only
246 , _pkgVersionList( pkgVersionList )
247 , _selectable( selectable )
248 , _zyppObj( zyppObj )
250 setOn( _zyppObj == _selectable->candidateObj() );
252 if ( versionCol() >= 0 ) setText( versionCol(), zyppObj->edition().asString().c_str() );
253 if ( archCol() >= 0 ) setText( archCol(), zyppObj->arch().asString().c_str() );
254 if ( repoCol() >= 0 ) setText( repoCol(), fromUTF8(zyppObj->repository().info().alias()) );
255 if ( productCol() >= 0 )
257 ZyppProduct product = YQPkgRepoListItem::singleProduct( zyppObj->repository() );
260 setText( productCol(), QString::fromStdString( product->summary() ) );
266 if ( ! zyppObj->repository().info().baseUrlsEmpty() )
267 repoUrl = *zyppObj->repository().info().baseUrlsBegin();
269 setText( urlCol(), repoUrl.asString().c_str() );
272 if ( _selectable->hasInstalledObj() )
274 if ( _zyppObj->edition() == _selectable->installedObj()->edition() &&
275 _zyppObj->arch() == _selectable->installedObj()->arch() )
277 setPixmap( statusCol(), YQIconPool::pkgKeepInstalled() );
278 setBackgroundColor( QColor( 0xF0, 0xF0, 0xF0 ) ); // light grey
279 setTextColor( QColor( 0, 0x90, 0 ) ); // green
285 YQPkgVersion::~YQPkgVersion()
292 YQPkgVersion::toolTip(int)
296 if ( zyppObj() == selectable()->installedObj() )
297 tip = _( "This version is installed in your system." );
304 * Comparison function used for sorting the list.
311 YQPkgVersion::compare( Q3ListViewItem * otherListViewItem,
313 bool ascending ) const
315 YQPkgVersion * other = dynamic_cast<YQPkgVersion *> (otherListViewItem);
319 if ( this->zyppObj()->edition() < other->zyppObj()->edition() ) return -1;
320 if ( this->zyppObj()->edition() > other->zyppObj()->edition() ) return 1;
324 // Fallback: Use parent class method
325 return QY2CheckListItem::compare( otherListViewItem, col, ascending );
330 #include "YQPkgVersionsView.moc"