1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatchFilterView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <qcombobox.h>
27 #include <qsplitter.h>
28 #include <qtabwidget.h>
29 #include <qdatetime.h>
32 #include <zypp/ui/PatchContents.h>
34 #include "YQPkgPatchFilterView.h"
35 #include "YQPkgPatchList.h"
36 #include "YQPkgDescriptionView.h"
37 #include "YQPkgSelList.h"
38 #include "QY2LayoutUtils.h"
41 typedef zypp::ui::PatchContents ZyppPatchContents;
42 typedef zypp::ui::PatchContents::const_iterator ZyppPatchContentsIterator;
46 #define ENABLE_TOTAL_DOWNLOAD_SIZE 0
48 #define SPACING 6 // between subwidgets
49 #define MARGIN 4 // around the widget
52 YQPkgPatchFilterView::YQPkgPatchFilterView( QWidget * parent )
56 _haveUpdateStackPatches = YQPkgPatchList::haveUpdateStackPatches();
58 _splitter = new QSplitter( QSplitter::Vertical, this ); CHECK_PTR( _splitter );
59 vbox = new QVBox( _splitter ); CHECK_PTR( vbox );
60 _patchList = new YQPkgPatchList( vbox ); CHECK_PTR( _patchList );
62 addVSpacing( vbox, 4 );
64 QHBox * hbox = new QHBox( vbox ); CHECK_PTR( hbox );
65 hbox->setSpacing( SPACING );
67 QLabel * label = new QLabel( _( "&Show Patch Category:" ), hbox );
69 _patchFilter = new QComboBox( hbox );
70 CHECK_PTR( _patchFilter );
74 if ( _haveUpdateStackPatches )
75 // Translators: This is about patches that patch the update engine (libzypp, YaST) itself
76 _patchFilter->insertItem( _( "Update Stack Patches" ), index++ );
78 _patchFilter->insertItem( _( "Installable Patches" ), index++ );
79 _patchFilter->insertItem( _( "Installable and Installed Patches" ), index++ );
80 _patchFilter->insertItem( _( "All Patches" ), index++ );
81 _patchFilter->setCurrentItem( 0 );
82 _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
83 label->setBuddy( _patchFilter );
85 connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
86 addVSpacing( vbox, 4 );
88 vbox = new QVBox( _splitter ); CHECK_PTR( vbox );
89 addVSpacing( vbox, 8 );
91 _detailsViews = new QTabWidget( vbox ); CHECK_PTR( _detailsViews );
92 _detailsViews->setMargin( MARGIN );
94 _descriptionView = new YQPkgDescriptionView( _detailsViews ); CHECK_PTR( _descriptionView );
96 _descriptionView->setMinimumSize( 0, 0 );
97 _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
100 #if ENABLE_TOTAL_DOWNLOAD_SIZE
102 // HBox for total download size
105 addVSpacing( vbox, 4 );
106 hbox = new QHBox( vbox ); CHECK_PTR( hbox );
109 new QLabel( _( "Estimated Download Size:" ) + " ", hbox );
110 _totalDownloadSize = new QLabel( FSize(0).asString().c_str(), hbox );
111 CHECK_PTR( _totalDownloadSize );
114 // Give the total download size a 3D look
116 _totalDownloadSize->setFrameStyle( QFrame::Panel | QFrame::Sunken );
117 _totalDownloadSize->setLineWidth(1);
118 _totalDownloadSize->setMidLineWidth(2);
122 connect( _patchList, SIGNAL( selectionChanged ( ZyppSel ) ),
123 _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
125 connect( _patchList, SIGNAL( statusChanged() ),
126 this, SLOT ( updateTotalDownloadSize() ) );
129 updateTotalDownloadSize();
133 YQPkgPatchFilterView::~YQPkgPatchFilterView()
140 YQPkgPatchFilterView::updateTotalDownloadSize()
142 set<ZyppSel> selectablesToInstall;
146 for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
147 patches_it != zyppPatchesEnd();
150 ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
154 ZyppPatchContents patchContents( patch );
156 for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
157 contents_it != patchContents.end();
160 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
164 sel = _selMapper.findZyppSel( pkg );
168 switch ( sel->status() )
174 // Insert the patch contents selectables into a set,
175 // don't immediately sum up their sizes: The same
176 // package could be in more than one patch, but of
177 // course it will be downloaded only once.
179 selectablesToInstall.insert( sel );
185 case S_KeepInstalled:
190 // intentionally omitting 'default' branch so the compiler can
191 // catch unhandled enum states
202 for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
203 it != selectablesToInstall.end();
206 if ( (*it)->candidateObj() )
207 totalSize += (*it)->candidateObj()->size();
210 #if ENABLE_TOTAL_DOWNLOAD_SIZE
211 _totalDownloadSize->setText( totalSize.asString().c_str() );
214 y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
219 YQPkgPatchFilterView::fillPatchList()
221 int currentIndex = _patchFilter->currentItem();
223 if ( _haveUpdateStackPatches )
226 switch ( currentIndex )
228 case -1: _patchList->setFilterCriteria( YQPkgPatchList::UpdateStackPatches ); break;
229 case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
230 case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
231 case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
232 default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
235 _patchList->fillList();
236 _patchList->selectSomething();
240 #include "YQPkgPatchFilterView.moc"