1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgPatchFilterView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <qcombobox.h>
28 #include <qsplitter.h>
29 #include <qtabwidget.h>
30 #include <qdatetime.h>
35 #include <zypp/ui/PatchContents.h>
37 #include "YQPkgPatchFilterView.h"
38 #include "YQPkgPatchList.h"
39 #include "YQPkgDescriptionView.h"
40 #include "YQPkgSelList.h"
41 #include "QY2LayoutUtils.h"
44 typedef zypp::ui::PatchContents ZyppPatchContents;
45 typedef zypp::ui::PatchContents::const_iterator ZyppPatchContentsIterator;
49 #define ENABLE_TOTAL_DOWNLOAD_SIZE 0
51 #define SPACING 6 // between subwidgets
52 #define MARGIN 4 // around the widget
55 YQPkgPatchFilterView::YQPkgPatchFilterView( QWidget * parent )
60 _splitter = new QSplitter( Qt::Vertical, this ); Q_CHECK_PTR( _splitter );
61 vbox = new Q3VBox( _splitter ); Q_CHECK_PTR( vbox );
62 _patchList = new YQPkgPatchList( vbox ); Q_CHECK_PTR( _patchList );
64 addVSpacing( vbox, 4 );
66 Q3HBox * hbox = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
67 hbox->setSpacing( SPACING );
69 QLabel * label = new QLabel( _( "&Show Patch Category:" ), hbox );
71 _patchFilter = new QComboBox( hbox );
72 Q_CHECK_PTR( _patchFilter );
74 _patchFilter->insertItem( _( "Installable Patches" ), 0 );
75 _patchFilter->insertItem( _( "Installable and Installed Patches" ), 1 );
76 _patchFilter->insertItem( _( "All Patches" ), 2 );
77 _patchFilter->setCurrentItem( 0 );
78 _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
79 label->setBuddy( _patchFilter );
81 connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
82 addVSpacing( vbox, 4 );
84 vbox = new Q3VBox( _splitter ); Q_CHECK_PTR( vbox );
85 addVSpacing( vbox, 8 );
87 _detailsViews = new QTabWidget( vbox ); Q_CHECK_PTR( _detailsViews );
88 _detailsViews->setMargin( MARGIN );
90 _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
92 _descriptionView->setMinimumSize( 0, 0 );
93 _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
96 #if ENABLE_TOTAL_DOWNLOAD_SIZE
98 // HBox for total download size
101 addVSpacing( vbox, 4 );
102 hbox = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
105 new QLabel( _( "Estimated Download Size:" ) + " ", hbox );
106 _totalDownloadSize = new QLabel( FSize(0).asString().c_str(), hbox );
107 Q_CHECK_PTR( _totalDownloadSize );
110 // Give the total download size a 3D look
112 _totalDownloadSize->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
113 _totalDownloadSize->setLineWidth(1);
114 _totalDownloadSize->setMidLineWidth(2);
118 connect( _patchList, SIGNAL( currentItemChanged ( ZyppSel ) ),
119 _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
121 connect( _patchList, SIGNAL( statusChanged() ),
122 this, SLOT ( updateTotalDownloadSize() ) );
124 updateTotalDownloadSize();
128 YQPkgPatchFilterView::~YQPkgPatchFilterView()
135 YQPkgPatchFilterView::updateTotalDownloadSize()
137 set<ZyppSel> selectablesToInstall;
141 for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
142 patches_it != zyppPatchesEnd();
145 ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
149 ZyppPatchContents patchContents( patch );
151 for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
152 contents_it != patchContents.end();
155 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
159 sel = _selMapper.findZyppSel( pkg );
163 switch ( sel->status() )
169 // Insert the patch contents selectables into a set,
170 // don't immediately sum up their sizes: The same
171 // package could be in more than one patch, but of
172 // course it will be downloaded only once.
174 selectablesToInstall.insert( sel );
180 case S_KeepInstalled:
185 // intentionally omitting 'default' branch so the compiler can
186 // catch unhandled enum states
197 for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
198 it != selectablesToInstall.end();
201 if ( (*it)->candidateObj() )
202 totalSize += (*it)->candidateObj()->size();
205 #if ENABLE_TOTAL_DOWNLOAD_SIZE
206 _totalDownloadSize->setText( totalSize.asString().c_str() );
209 y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
214 YQPkgPatchFilterView::fillPatchList()
216 switch ( _patchFilter->currentItem() )
218 case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
219 case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
220 case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
221 default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
224 _patchList->fillList();
225 _patchList->selectSomething();
229 #include "YQPkgPatchFilterView.moc"