1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgVersionsView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
26 #include <zypp/Repository.h>
27 #include <ycp/y2log.h>
28 #include <qtabwidget.h>
32 #include "YQPkgVersionsView.h"
33 #include "YQPkgRepoList.h"
34 #include "YQIconPool.h"
39 YQPkgVersionsView::YQPkgVersionsView( QWidget * parent, bool userCanSwitch )
40 : QY2ListView( parent )
43 _parentTab = dynamic_cast<QTabWidget *> (parent);
44 _userCanSwitch = userCanSwitch;
57 addColumn( _( "Version" ) ); _versionCol = numCol++;
58 addColumn( _( "Arch." ) ); _archCol = numCol++;
59 addColumn( _( "Product" ) ); _productCol = numCol++;
60 addColumn( _( "Repository" ) ); _repoCol = numCol++;
61 addColumn( _( "URL" ) ); _urlCol = numCol++;
63 _statusCol = _productCol;
65 _nameCol = _versionCol;
66 _summaryCol = _repoCol;
68 setSortByInsertionSequence( true );
70 // saveColumnWidths(); // Minimize column widths
76 connect( parent, SIGNAL( currentChanged(QWidget *) ),
77 this, SLOT ( reload (QWidget *) ) );
80 connect( this, SIGNAL( currentItemChanged () ),
81 this, SLOT ( checkForChangedCandidate() ) );
85 YQPkgVersionsView::~YQPkgVersionsView()
92 YQPkgVersionsView::reload( QWidget * newCurrent )
94 if ( newCurrent == this )
95 showDetailsIfVisible( _selectable );
100 YQPkgVersionsView::showDetailsIfVisible( ZyppSel selectable )
102 _selectable = selectable;
104 if ( _parentTab ) // Is this view embedded into a tab widget?
106 if ( _parentTab->currentPage() == this ) // Is this page the topmost?
107 showDetails( selectable );
109 else // No tab parent - simply show data unconditionally.
111 showDetails( selectable );
117 YQPkgVersionsView::showDetails( ZyppSel selectable )
119 _selectable = selectable;
126 QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str() );
129 root->setExpanded( true );
131 bool installedIsAvailable = false;
133 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
135 while ( it != selectable->availableEnd() )
137 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
139 if ( selectable->installedObj() &&
140 selectable->installedObj()->edition() == (*it)->edition() &&
141 selectable->installedObj()->arch() == (*it)->arch() )
142 // FIXME: In future releases, also the vendor will make a difference
143 installedIsAvailable = true;
147 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
148 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
149 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
155 if ( selectable->hasInstalledObj() && ! installedIsAvailable )
156 new YQPkgVersion( this, root, selectable, selectable->installedObj(), false );
163 YQPkgVersionsView::checkForChangedCandidate()
165 QTreeWidgetItemIterator iter(this);
166 QTreeWidgetItem *first = *iter;
168 if ( ! first || ! _selectable )
172 QTreeWidgetItemIterator iter_c(first);
176 YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (*iter_c);
178 if ( versionItem && versionItem->isOn() )
180 ZyppObj newCandidate = versionItem->zyppObj();
182 if ( newCandidate != _selectable->candidateObj() )
184 y2milestone( "Candidate changed" );
186 // Change status of selectable
188 ZyppStatus status = _selectable->status();
190 if ( _selectable->installedObj() &&
191 _selectable->installedObj()->arch() == newCandidate->arch() &&
192 _selectable->installedObj()->edition() == newCandidate->edition() )
194 // Switch back to the original instance -
195 // the version that was previously installed
196 status = S_KeepInstalled;
202 case S_KeepInstalled:
221 _selectable->set_status( status );
226 _selectable->setCandidate( newCandidate );
227 emit candidateChanged( newCandidate );
239 YQPkgVersionsView::minimumSizeHint() const
241 return QSize( 0, 0 );
249 YQPkgVersion::YQPkgVersion( YQPkgVersionsView * pkgVersionList,
250 QY2CheckListItem * parent,
254 : QY2CheckListItem( parent, "" /*
256 Q3CheckListItem::RadioButton :
257 Q3CheckListItem::Controller */ ) // cheap way to make it read-only
258 , _pkgVersionList( pkgVersionList )
259 , _selectable( selectable )
260 , _zyppObj( zyppObj )
262 // FIXME setOn( _zyppObj == _selectable->candidateObj() );
264 if ( versionCol() >= 0 ) setText( versionCol(), zyppObj->edition().asString().c_str() );
265 if ( archCol() >= 0 ) setText( archCol(), zyppObj->arch().asString().c_str() );
266 if ( repoCol() >= 0 ) setText( repoCol(), fromUTF8(zyppObj->repository().info().alias()) );
267 if ( productCol() >= 0 )
269 ZyppProduct product = YQPkgRepoListItem::singleProduct( zyppObj->repository() );
272 setText( productCol(), QString::fromStdString( product->summary() ) );
278 if ( ! zyppObj->repository().info().baseUrlsEmpty() )
279 repoUrl = *zyppObj->repository().info().baseUrlsBegin();
281 setText( urlCol(), repoUrl.asString().c_str() );
284 if ( _selectable->hasInstalledObj() )
286 if ( _zyppObj->edition() == _selectable->installedObj()->edition() &&
287 _zyppObj->arch() == _selectable->installedObj()->arch() )
289 // FIXME setPixmap( statusCol(), YQIconPool::pkgKeepInstalled() );
290 setBackgroundColor( QColor( 0xF0, 0xF0, 0xF0 ) ); // light grey
291 setTextColor( QColor( 0, 0x90, 0 ) ); // green
297 YQPkgVersion::~YQPkgVersion()
304 YQPkgVersion::toolTip(int)
308 if ( zyppObj() == selectable()->installedObj() )
309 tip = _( "This version is installed in your system." );
316 * Comparison function used for sorting the list.
323 YQPkgVersion::compare( QTreeWidgetItem * otherListViewItem,
325 bool ascending ) const
327 YQPkgVersion * other = dynamic_cast<YQPkgVersion *> (otherListViewItem);
331 if ( this->zyppObj()->edition() < other->zyppObj()->edition() ) return -1;
332 if ( this->zyppObj()->edition() > other->zyppObj()->edition() ) return 1;
336 // Fallback: Use parent class method
337 return QY2CheckListItem::compare( otherListViewItem, col, ascending );
342 #include "YQPkgVersionsView.moc"