1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatchFilterView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
30 #include <QVBoxLayout>
33 #include <zypp/ui/PatchContents.h>
35 #include "YQPkgPatchFilterView.h"
36 #include "YQPkgPatchList.h"
37 #include "YQPkgDescriptionView.h"
38 #include "YQPkgSelList.h"
39 #include "QY2LayoutUtils.h"
42 typedef zypp::ui::PatchContents ZyppPatchContents;
43 typedef zypp::ui::PatchContents::const_iterator ZyppPatchContentsIterator;
47 #define ENABLE_TOTAL_DOWNLOAD_SIZE 0
49 #define SPACING 6 // between subwidgets
50 #define MARGIN 4 // around the widget
53 YQPkgPatchFilterView::YQPkgPatchFilterView( QWidget * parent )
56 QVBoxLayout *layout = new QVBoxLayout();
60 _splitter = new QSplitter( Qt::Vertical, this ); Q_CHECK_PTR( _splitter );
61 layout->addWidget(_splitter);
62 QVBoxLayout * vbox = new QVBoxLayout(_splitter);
64 layout->addLayout(vbox);
65 _patchList = new YQPkgPatchList( this ); Q_CHECK_PTR( _patchList );
66 vbox->addWidget(_patchList);
68 //addVSpacing( vbox, 4 );
70 QHBoxLayout * hbox = new QHBoxLayout(); Q_CHECK_PTR( hbox );
71 vbox->addLayout(hbox);
72 hbox->setSpacing( SPACING );
74 QLabel * label = new QLabel( _( "&Show Patch Category:" ), this );
75 hbox->addWidget(label);
77 _patchFilter = new QComboBox( this );
78 Q_CHECK_PTR( _patchFilter );
79 hbox->addWidget(_patchFilter);
81 _patchFilter->addItem( _( "Installable Patches" ));
82 _patchFilter->addItem( _( "Installable and Installed Patches" ));
83 _patchFilter->addItem( _( "All Patches" ), 2 );
84 _patchFilter->setCurrentIndex( 0 );
85 _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
86 label->setBuddy( _patchFilter );
88 connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
89 //addVSpacing( vbox, 4 );
91 vbox = new QVBoxLayout( _splitter ); Q_CHECK_PTR( vbox );
92 //addVSpacing( vbox, 8 );
94 _detailsViews = new QTabWidget( this ); Q_CHECK_PTR( _detailsViews );
95 vbox->addWidget(_detailsViews);
97 _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
99 _descriptionView->setMinimumSize( 0, 0 );
100 _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
103 #if ENABLE_TOTAL_DOWNLOAD_SIZE
105 // HBox for total download size
108 hbox = new QHBoxLayout(); Q_CHECK_PTR( hbox );
109 vbox->addLayout(hbox);
110 //addHStretch( hbox );
112 hbox->addWidget(new QLabel( _( "Estimated Download Size:" ) + " ", this ));
113 _totalDownloadSize = new QLabel( FSize(0).asString().c_str(), this );
114 hbox->addWidget(_totalDownloadSize);
115 Q_CHECK_PTR( _totalDownloadSize );
118 // Give the total download size a 3D look
120 _totalDownloadSize->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
121 _totalDownloadSize->setLineWidth(1);
122 _totalDownloadSize->setMidLineWidth(2);
126 connect( _patchList, SIGNAL( currentItemChanged ( ZyppSel ) ),
127 _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
129 connect( _patchList, SIGNAL( statusChanged() ),
130 this, SLOT ( updateTotalDownloadSize() ) );
132 updateTotalDownloadSize();
136 YQPkgPatchFilterView::~YQPkgPatchFilterView()
143 YQPkgPatchFilterView::updateTotalDownloadSize()
145 set<ZyppSel> selectablesToInstall;
149 for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
150 patches_it != zyppPatchesEnd();
153 ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
157 ZyppPatchContents patchContents( patch );
159 for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
160 contents_it != patchContents.end();
163 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
167 sel = _selMapper.findZyppSel( pkg );
171 switch ( sel->status() )
177 // Insert the patch contents selectables into a set,
178 // don't immediately sum up their sizes: The same
179 // package could be in more than one patch, but of
180 // course it will be downloaded only once.
182 selectablesToInstall.insert( sel );
188 case S_KeepInstalled:
193 // intentionally omitting 'default' branch so the compiler can
194 // catch unhandled enum states
205 for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
206 it != selectablesToInstall.end();
209 if ( (*it)->candidateObj() )
210 totalSize += (*it)->candidateObj()->size();
213 #if ENABLE_TOTAL_DOWNLOAD_SIZE
214 _totalDownloadSize->setText( totalSize.asString().c_str() );
217 y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
222 YQPkgPatchFilterView::fillPatchList()
224 switch ( _patchFilter->currentIndex() )
226 case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
227 case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
228 case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
229 default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
232 _patchList->fillList();
233 _patchList->selectSomething();
237 #include "YQPkgPatchFilterView.moc"