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(this);
59 _splitter = new QSplitter( Qt::Vertical, this ); Q_CHECK_PTR( _splitter );
60 layout->addWidget(_splitter);
61 QVBoxLayout * vbox = new QVBoxLayout(_splitter);
63 layout->addLayout(vbox);
64 _patchList = new YQPkgPatchList( this ); Q_CHECK_PTR( _patchList );
65 vbox->addWidget(_patchList);
67 //addVSpacing( vbox, 4 );
69 QHBoxLayout * hbox = new QHBoxLayout( this ); Q_CHECK_PTR( hbox );
70 vbox->addLayout(hbox);
71 hbox->setSpacing( SPACING );
73 QLabel * label = new QLabel( _( "&Show Patch Category:" ), this );
74 hbox->addWidget(label);
76 _patchFilter = new QComboBox( this );
77 Q_CHECK_PTR( _patchFilter );
78 hbox->addWidget(_patchFilter);
80 _patchFilter->addItem( _( "Installable Patches" ));
81 _patchFilter->addItem( _( "Installable and Installed Patches" ));
82 _patchFilter->addItem( _( "All Patches" ), 2 );
83 _patchFilter->setCurrentIndex( 0 );
84 _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
85 label->setBuddy( _patchFilter );
87 connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
88 //addVSpacing( vbox, 4 );
90 vbox = new QVBoxLayout( _splitter ); Q_CHECK_PTR( vbox );
91 //addVSpacing( vbox, 8 );
93 _detailsViews = new QTabWidget( this ); Q_CHECK_PTR( _detailsViews );
94 vbox->addWidget(_detailsViews);
96 _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
98 _descriptionView->setMinimumSize( 0, 0 );
99 _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
102 #if ENABLE_TOTAL_DOWNLOAD_SIZE
104 // HBox for total download size
107 hbox = new QHBoxLayout( this ); Q_CHECK_PTR( hbox );
108 vbox->addLayout(hbox);
109 //addHStretch( hbox );
111 hbox->addWidget(new QLabel( _( "Estimated Download Size:" ) + " ", this ));
112 _totalDownloadSize = new QLabel( FSize(0).asString().c_str(), this );
113 hbox->addWidget(_totalDownloadSize);
114 Q_CHECK_PTR( _totalDownloadSize );
117 // Give the total download size a 3D look
119 _totalDownloadSize->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
120 _totalDownloadSize->setLineWidth(1);
121 _totalDownloadSize->setMidLineWidth(2);
125 connect( _patchList, SIGNAL( currentItemChanged ( ZyppSel ) ),
126 _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
128 connect( _patchList, SIGNAL( statusChanged() ),
129 this, SLOT ( updateTotalDownloadSize() ) );
131 updateTotalDownloadSize();
135 YQPkgPatchFilterView::~YQPkgPatchFilterView()
142 YQPkgPatchFilterView::updateTotalDownloadSize()
144 set<ZyppSel> selectablesToInstall;
148 for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
149 patches_it != zyppPatchesEnd();
152 ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
156 ZyppPatchContents patchContents( patch );
158 for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
159 contents_it != patchContents.end();
162 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
166 sel = _selMapper.findZyppSel( pkg );
170 switch ( sel->status() )
176 // Insert the patch contents selectables into a set,
177 // don't immediately sum up their sizes: The same
178 // package could be in more than one patch, but of
179 // course it will be downloaded only once.
181 selectablesToInstall.insert( sel );
187 case S_KeepInstalled:
192 // intentionally omitting 'default' branch so the compiler can
193 // catch unhandled enum states
204 for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
205 it != selectablesToInstall.end();
208 if ( (*it)->candidateObj() )
209 totalSize += (*it)->candidateObj()->size();
212 #if ENABLE_TOTAL_DOWNLOAD_SIZE
213 _totalDownloadSize->setText( totalSize.asString().c_str() );
216 y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
221 YQPkgPatchFilterView::fillPatchList()
223 switch ( _patchFilter->currentIndex() )
225 case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
226 case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
227 case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
228 default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
231 _patchList->fillList();
232 _patchList->selectSomething();
236 #include "YQPkgPatchFilterView.moc"