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 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( currentItemChanged () ),
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->currentWidget() == 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() );
127 root->setExpanded( 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()
163 QTreeWidgetItemIterator iter(this);
164 QTreeWidgetItem *first = *iter;
166 if ( ! first || ! _selectable )
170 QTreeWidgetItemIterator iter_c(first);
174 YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (*iter_c);
176 if ( versionItem && versionItem->isOn() )
178 ZyppObj newCandidate = versionItem->zyppObj();
180 if ( newCandidate != _selectable->candidateObj() )
182 y2milestone( "Candidate changed" );
184 // Change status of selectable
186 ZyppStatus status = _selectable->status();
188 if ( _selectable->installedObj() &&
189 _selectable->installedObj()->arch() == newCandidate->arch() &&
190 _selectable->installedObj()->edition() == newCandidate->edition() )
192 // Switch back to the original instance -
193 // the version that was previously installed
194 status = S_KeepInstalled;
200 case S_KeepInstalled:
219 _selectable->set_status( status );
224 _selectable->setCandidate( newCandidate );
225 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." );
314 * Comparison function used for sorting the list.
321 YQPkgVersion::compare( QTreeWidgetItem * otherListViewItem,
323 bool ascending ) const
325 YQPkgVersion * other = dynamic_cast<YQPkgVersion *> (otherListViewItem);
329 if ( this->zyppObj()->edition() < other->zyppObj()->edition() ) return -1;
330 if ( this->zyppObj()->edition() > other->zyppObj()->edition() ) return 1;
334 // Fallback: Use parent class method
335 return QY2CheckListItem::compare( otherListViewItem, col, ascending );
340 #include "YQPkgVersionsView.moc"