1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPatternSelector.cc
14 See also: YQPatternSelectorHelp.cc
16 Author: Stefan Hundhammer <sh@suse.de>
18 Textdomain "packages-qt"
22 #include <QApplication>
23 #include <QHeaderView>
24 #include <QPushButton>
27 #define y2log_component "qt-pkg"
28 #include <ycp/y2log.h>
30 #include "QY2LayoutUtils.h"
32 #include "YQPatternSelector.h"
33 #include "YQPkgConflictDialog.h"
34 #include "YQPkgSelDescriptionView.h"
35 #include "YQPkgDiskUsageList.h"
36 #include "YQPkgPatternList.h"
37 #include "YQPkgSelList.h"
46 #define ALWAYS_SOLVE_IMMEDIATELY 1
55 YQPatternSelector::YQPatternSelector( YWidget * parent, long modeFlags )
56 : YQPackageSelectorBase( parent, modeFlags )
61 _wizard = findWizard();
68 _patternList->fillList();
69 _patternList->selectSomething();
74 _selList->selectSomething();
77 if ( zyppPool().empty<zypp::Pattern >() &&
78 zyppPool().empty<zypp::Selection>() )
80 y2warning( "Neither patterns nor selections in ZyppPool" );
85 _diskUsageList->updateDiskUsage();
91 YQPatternSelector::findWizard() const
93 YQWizard * wizard = 0;
95 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
98 wizard = dialog->findWizard();
106 YQPatternSelector::basicLayout()
108 QVBoxLayout *vbox = new QVBoxLayout( this );
110 QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
111 Q_CHECK_PTR( outer_splitter );
113 vbox->addWidget( outer_splitter );
115 QWidget * left_pane = layoutLeftPane ( outer_splitter );
116 QWidget * right_pane = layoutRightPane( outer_splitter );
118 int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
119 left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
121 outer_splitter->setStretchFactor(outer_splitter->indexOf(left_pane), 0);
122 outer_splitter->setStretchFactor(outer_splitter->indexOf(right_pane), 1);
125 layoutButtons( this );
131 YQPatternSelector::layoutLeftPane( QWidget * parent )
133 QWidget *vbox = new QWidget(parent);
134 QVBoxLayout * layout = new QVBoxLayout( vbox );
136 layout->setMargin( MARGIN );
137 vbox->setLayout(layout);
139 if ( ! zyppPool().empty<zypp::Pattern>() )
145 _patternList = new YQPkgPatternList( vbox,
146 false, // no autoFill - need to connect to details view first
147 false ); // no autoFilter - filterMatch() is not connected
148 Q_CHECK_PTR( _patternList );
149 layout->addWidget(_patternList);
150 _patternList->header()->hide();
153 if ( ! _patternList )
156 // Fallback: selections list
160 * Create a selections list even if there are no selections, otherwise
161 * the layout will look very weird. An empty selections list still
162 * looks better than a lot of grey empty space.
165 y2warning( "No patterns in ZyppPool - using selections instead" );
166 _selList = new YQPkgSelList( vbox,
167 false, // no autoFill - need to connect to details view first
168 false ); // no autoFilter - filterMatch() is not connected
169 Q_CHECK_PTR( _selList );
170 layout->addWidget(_selList);
171 _selList->header()->hide();
174 if ( _wizard ) // No button box - add "Details..." button here
180 layout->addSpacing( SPACING );
182 QHBoxLayout * hbox = new QHBoxLayout();
184 layout->addLayout(hbox);
186 QPushButton * details_button = new QPushButton( _( "&Details..." ), vbox );
187 Q_CHECK_PTR( details_button );
188 hbox->addWidget(details_button);
190 connect( details_button, SIGNAL( clicked() ),
191 this, SLOT ( detailedPackageSelection() ) );
202 YQPatternSelector::layoutRightPane( QWidget * parent )
204 QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
205 Q_CHECK_PTR( splitter );
206 //splitter->setMargin( MARGIN );
210 // Selection / Pattern description
212 QWidget *upper_vbox = new QWidget(splitter);
213 QVBoxLayout * layout = new QVBoxLayout(upper_vbox);
215 Q_CHECK_PTR( upper_vbox );
217 _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
218 Q_CHECK_PTR( _descriptionView );
219 layout->addWidget(_descriptionView);
221 layout->addSpacing( MARGIN );
228 QWidget *lower_vbox = new QWidget(splitter);
229 layout = new QVBoxLayout(upper_vbox);
231 Q_CHECK_PTR( lower_vbox );
232 layout->addSpacing( MARGIN );
234 _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
235 Q_CHECK_PTR( _diskUsageList );
236 layout->addWidget(_diskUsageList);
238 splitter->setStretchFactor( 0, 0 );
239 splitter->setStretchFactor( 0, 1 );
247 YQPatternSelector::layoutButtons( QWidget * parent )
249 QWidget *button_box = new QWidget(parent);
250 QHBoxLayout *layout = new QHBoxLayout(button_box);
252 Q_CHECK_PTR( button_box );
253 layout->setMargin ( MARGIN );
254 layout->setSpacing( SPACING );
256 button_box->setLayout(layout);
258 QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
259 layout->addWidget(details_button);
260 Q_CHECK_PTR( details_button );
261 details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
263 connect( details_button, SIGNAL( clicked() ),
264 this, SLOT ( detailedPackageSelection() ) );
267 layout->addStretch();
269 QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
270 Q_CHECK_PTR( cancel_button );
271 layout->addWidget(cancel_button);
272 cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
274 connect( cancel_button, SIGNAL( clicked() ),
275 this, SLOT ( reject() ) );
278 QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
279 Q_CHECK_PTR( accept_button );
280 layout->addWidget(accept_button);
281 accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
283 connect( accept_button, SIGNAL( clicked() ),
284 this, SLOT ( accept() ) );
286 button_box->setFixedHeight( button_box->sizeHint().height() );
292 YQPatternSelector::makeConnections()
296 #if ALWAYS_SOLVE_IMMEDIATELY
297 connect( _patternList, SIGNAL( statusChanged() ),
298 this, SLOT ( resolveDependencies() ) );
300 if ( _pkgConflictDialog )
302 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
303 _patternList, SLOT ( updateItemStates() ) );
307 if ( _descriptionView )
309 connect( _patternList, SIGNAL( currentItemChanged( ZyppSel ) ),
310 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
313 if ( _diskUsageList )
315 connect( _patternList, SIGNAL( updatePackages() ),
316 _diskUsageList, SLOT ( updateDiskUsage() ) );
323 #if ALWAYS_SOLVE_IMMEDIATELY
324 connect( _selList, SIGNAL( statusChanged() ),
325 this, SLOT ( resolveDependencies() ) );
327 if ( _pkgConflictDialog )
329 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
330 _selList, SLOT ( updateItemStates() ) );
335 if ( _descriptionView )
337 connect( _selList, SIGNAL( currentItemChanged( ZyppSel ) ),
338 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
341 if ( _diskUsageList )
343 connect( _selList, SIGNAL( updatePackages() ),
344 _diskUsageList, SLOT ( updateDiskUsage() ) );
348 y2milestone( "Connection set up" );
353 connect( _wizard, SIGNAL( nextClicked() ),
354 this, SLOT ( accept() ) );
356 connect( _wizard, SIGNAL( backClicked() ),
357 this, SLOT ( reject() ) );
359 connect( _wizard, SIGNAL( abortClicked() ),
360 this, SLOT ( reject() ) );
366 YQPatternSelector::detailedPackageSelection()
368 y2milestone( "\"Details..\" button clicked" );
369 YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
374 YQPatternSelector::debugTrace()
376 y2warning( "debugTrace" );
381 #include "YQPatternSelector.moc"