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>
34 #include <zypp/ui/PatchContents.h>
36 #include "YQPkgPatchFilterView.h"
37 #include "YQPkgPatchList.h"
38 #include "YQPkgDescriptionView.h"
39 #include "YQPkgSelList.h"
40 #include "QY2LayoutUtils.h"
43 typedef zypp::ui::PatchContents ZyppPatchContents;
44 typedef zypp::ui::PatchContents::const_iterator ZyppPatchContentsIterator;
48 #define ENABLE_TOTAL_DOWNLOAD_SIZE 0
50 #define SPACING 6 // between subwidgets
51 #define MARGIN 4 // around the widget
54 YQPkgPatchFilterView::YQPkgPatchFilterView( QWidget * parent )
59 _splitter = new QSplitter( Qt::Vertical, this ); Q_CHECK_PTR( _splitter );
60 vbox = new Q3VBox( _splitter ); Q_CHECK_PTR( vbox );
61 _patchList = new YQPkgPatchList( vbox ); Q_CHECK_PTR( _patchList );
63 addVSpacing( vbox, 4 );
65 Q3HBox * hbox = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
66 hbox->setSpacing( SPACING );
68 QLabel * label = new QLabel( _( "&Show Patch Category:" ), hbox );
70 _patchFilter = new QComboBox( hbox );
71 Q_CHECK_PTR( _patchFilter );
73 _patchFilter->insertItem( _( "Installable Patches" ), 0 );
74 _patchFilter->insertItem( _( "Installable and Installed Patches" ), 1 );
75 _patchFilter->insertItem( _( "All Patches" ), 2 );
76 _patchFilter->setCurrentItem( 0 );
77 _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
78 label->setBuddy( _patchFilter );
80 connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
81 addVSpacing( vbox, 4 );
83 vbox = new Q3VBox( _splitter ); Q_CHECK_PTR( vbox );
84 addVSpacing( vbox, 8 );
86 _detailsViews = new QTabWidget( vbox ); Q_CHECK_PTR( _detailsViews );
87 _detailsViews->setMargin( MARGIN );
89 _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
91 _descriptionView->setMinimumSize( 0, 0 );
92 _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
95 #if ENABLE_TOTAL_DOWNLOAD_SIZE
97 // HBox for total download size
100 addVSpacing( vbox, 4 );
101 hbox = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
104 new QLabel( _( "Estimated Download Size:" ) + " ", hbox );
105 _totalDownloadSize = new QLabel( FSize(0).asString().c_str(), hbox );
106 Q_CHECK_PTR( _totalDownloadSize );
109 // Give the total download size a 3D look
111 _totalDownloadSize->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
112 _totalDownloadSize->setLineWidth(1);
113 _totalDownloadSize->setMidLineWidth(2);
117 connect( _patchList, SIGNAL( selectionChanged ( ZyppSel ) ),
118 _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
120 connect( _patchList, SIGNAL( statusChanged() ),
121 this, SLOT ( updateTotalDownloadSize() ) );
123 updateTotalDownloadSize();
127 YQPkgPatchFilterView::~YQPkgPatchFilterView()
134 YQPkgPatchFilterView::updateTotalDownloadSize()
136 set<ZyppSel> selectablesToInstall;
140 for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
141 patches_it != zyppPatchesEnd();
144 ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
148 ZyppPatchContents patchContents( patch );
150 for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
151 contents_it != patchContents.end();
154 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
158 sel = _selMapper.findZyppSel( pkg );
162 switch ( sel->status() )
168 // Insert the patch contents selectables into a set,
169 // don't immediately sum up their sizes: The same
170 // package could be in more than one patch, but of
171 // course it will be downloaded only once.
173 selectablesToInstall.insert( sel );
179 case S_KeepInstalled:
184 // intentionally omitting 'default' branch so the compiler can
185 // catch unhandled enum states
196 for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
197 it != selectablesToInstall.end();
200 if ( (*it)->candidateObj() )
201 totalSize += (*it)->candidateObj()->size();
204 #if ENABLE_TOTAL_DOWNLOAD_SIZE
205 _totalDownloadSize->setText( totalSize.asString().c_str() );
208 y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
213 YQPkgPatchFilterView::fillPatchList()
215 switch ( _patchFilter->currentItem() )
217 case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
218 case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
219 case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
220 default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
223 _patchList->fillList();
224 _patchList->selectSomething();
228 #include "YQPkgPatchFilterView.moc"