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;
55 addColumn( _( "Version" ) ); _versionCol = numCol++;
56 addColumn( _( "Arch." ) ); _archCol = numCol++;
57 addColumn( _( "Product" ) ); _productCol = numCol++;
58 addColumn( _( "Repository" ) ); _repoCol = numCol++;
59 addColumn( _( "URL" ) ); _urlCol = numCol++;
61 _statusCol = _productCol;
63 _nameCol = _versionCol;
64 _summaryCol = _repoCol;
66 setSortByInsertionSequence( true );
68 // saveColumnWidths(); // Minimize column widths
74 connect( parent, SIGNAL( currentChanged(QWidget *) ),
75 this, SLOT ( reload (QWidget *) ) );
78 connect( this, SIGNAL( selectionChanged () ),
79 this, SLOT ( checkForChangedCandidate() ) );
83 YQPkgVersionsView::~YQPkgVersionsView()
90 YQPkgVersionsView::reload( QWidget * newCurrent )
92 if ( newCurrent == this )
93 showDetailsIfVisible( _selectable );
98 YQPkgVersionsView::showDetailsIfVisible( ZyppSel selectable )
100 _selectable = selectable;
102 if ( _parentTab ) // Is this view embedded into a tab widget?
104 if ( _parentTab->currentPage() == this ) // Is this page the topmost?
105 showDetails( selectable );
107 else // No tab parent - simply show data unconditionally.
109 showDetails( selectable );
115 YQPkgVersionsView::showDetails( ZyppSel selectable )
117 _selectable = selectable;
124 QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str(),
125 Q3CheckListItem::Controller );
127 root->setOpen( true );
129 bool installedIsAvailable = false;
131 zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
133 while ( it != selectable->availableEnd() )
135 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
137 if ( selectable->installedObj() &&
138 selectable->installedObj()->edition() == (*it)->edition() &&
139 selectable->installedObj()->arch() == (*it)->arch() )
140 // FIXME: In future releases, also the vendor will make a difference
141 installedIsAvailable = true;
145 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
146 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
147 new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
153 if ( selectable->hasInstalledObj() && ! installedIsAvailable )
154 new YQPkgVersion( this, root, selectable, selectable->installedObj(), false );
161 YQPkgVersionsView::checkForChangedCandidate()
164 if ( ! firstChild() || ! _selectable )
167 Q3ListViewItem * item = firstChild()->firstChild();
171 YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (item);
173 if ( versionItem && versionItem->isOn() )
175 ZyppObj newCandidate = versionItem->zyppObj();
177 if ( newCandidate != _selectable->candidateObj() )
179 y2milestone( "Candidate changed" );
181 // Change status of selectable
183 ZyppStatus status = _selectable->status();
185 if ( _selectable->installedObj() &&
186 _selectable->installedObj()->arch() == newCandidate->arch() &&
187 _selectable->installedObj()->edition() == newCandidate->edition() )
189 // Switch back to the original instance -
190 // the version that was previously installed
191 status = S_KeepInstalled;
197 case S_KeepInstalled:
216 _selectable->set_status( status );
221 _selectable->setCandidate( newCandidate );
222 emit candidateChanged( newCandidate );
227 item = item->nextSibling();
234 YQPkgVersionsView::minimumSizeHint() const
236 return QSize( 0, 0 );
244 YQPkgVersion::YQPkgVersion( YQPkgVersionsView * pkgVersionList,
245 QY2CheckListItem * parent,
249 : QY2CheckListItem( parent, "" /*
251 Q3CheckListItem::RadioButton :
252 Q3CheckListItem::Controller */ ) // cheap way to make it read-only
253 , _pkgVersionList( pkgVersionList )
254 , _selectable( selectable )
255 , _zyppObj( zyppObj )
257 // FIXME setOn( _zyppObj == _selectable->candidateObj() );
259 if ( versionCol() >= 0 ) setText( versionCol(), zyppObj->edition().asString().c_str() );
260 if ( archCol() >= 0 ) setText( archCol(), zyppObj->arch().asString().c_str() );
261 if ( repoCol() >= 0 ) setText( repoCol(), fromUTF8(zyppObj->repository().info().alias()) );
262 if ( productCol() >= 0 )
264 ZyppProduct product = YQPkgRepoListItem::singleProduct( zyppObj->repository() );
267 setText( productCol(), QString::fromStdString( product->summary() ) );
273 if ( ! zyppObj->repository().info().baseUrlsEmpty() )
274 repoUrl = *zyppObj->repository().info().baseUrlsBegin();
276 setText( urlCol(), repoUrl.asString().c_str() );
279 if ( _selectable->hasInstalledObj() )
281 if ( _zyppObj->edition() == _selectable->installedObj()->edition() &&
282 _zyppObj->arch() == _selectable->installedObj()->arch() )
284 // FIXME setPixmap( statusCol(), YQIconPool::pkgKeepInstalled() );
285 setBackgroundColor( QColor( 0xF0, 0xF0, 0xF0 ) ); // light grey
286 setTextColor( QColor( 0, 0x90, 0 ) ); // green
292 YQPkgVersion::~YQPkgVersion()
299 YQPkgVersion::toolTip(int)
303 if ( zyppObj() == selectable()->installedObj() )
304 tip = _( "This version is installed in your system." );
311 * Comparison function used for sorting the list.
318 YQPkgVersion::compare( QTreeWidgetItem * otherListViewItem,
320 bool ascending ) const
322 YQPkgVersion * other = dynamic_cast<YQPkgVersion *> (otherListViewItem);
326 if ( this->zyppObj()->edition() < other->zyppObj()->edition() ) return -1;
327 if ( this->zyppObj()->edition() > other->zyppObj()->edition() ) return 1;
331 // Fallback: Use parent class method
332 return QY2CheckListItem::compare( otherListViewItem, col, ascending );
337 #include "YQPkgVersionsView.moc"