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();
111 QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
112 Q_CHECK_PTR( outer_splitter );
114 vbox->addWidget( outer_splitter );
116 QWidget * left_pane = layoutLeftPane ( outer_splitter );
117 QWidget * right_pane = layoutRightPane( outer_splitter );
119 int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
120 left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
122 outer_splitter->setStretchFactor(outer_splitter->indexOf(left_pane), 0);
123 outer_splitter->setStretchFactor(outer_splitter->indexOf(right_pane), 1);
126 layoutButtons( this );
132 YQPatternSelector::layoutLeftPane( QWidget * parent )
134 QWidget *vbox = new QWidget(parent);
135 QVBoxLayout * layout = new QVBoxLayout( vbox );
137 layout->setMargin( MARGIN );
138 vbox->setLayout(layout);
140 if ( ! zyppPool().empty<zypp::Pattern>() )
146 _patternList = new YQPkgPatternList( vbox,
147 false, // no autoFill - need to connect to details view first
148 false ); // no autoFilter - filterMatch() is not connected
149 Q_CHECK_PTR( _patternList );
150 layout->addWidget(_patternList);
151 _patternList->header()->hide();
154 if ( ! _patternList )
157 // Fallback: selections list
161 * Create a selections list even if there are no selections, otherwise
162 * the layout will look very weird. An empty selections list still
163 * looks better than a lot of grey empty space.
166 y2warning( "No patterns in ZyppPool - using selections instead" );
167 _selList = new YQPkgSelList( vbox,
168 false, // no autoFill - need to connect to details view first
169 false ); // no autoFilter - filterMatch() is not connected
170 Q_CHECK_PTR( _selList );
171 layout->addWidget(_selList);
172 _selList->header()->hide();
175 if ( _wizard ) // No button box - add "Details..." button here
181 layout->addSpacing( SPACING );
183 QHBoxLayout * hbox = new QHBoxLayout();
185 layout->addLayout(hbox);
187 QPushButton * details_button = new QPushButton( _( "&Details..." ), vbox );
188 Q_CHECK_PTR( details_button );
189 hbox->addWidget(details_button);
191 connect( details_button, SIGNAL( clicked() ),
192 this, SLOT ( detailedPackageSelection() ) );
203 YQPatternSelector::layoutRightPane( QWidget * parent )
205 QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
206 Q_CHECK_PTR( splitter );
207 //splitter->setMargin( MARGIN );
211 // Selection / Pattern description
213 QWidget *upper_vbox = new QWidget(splitter);
214 QVBoxLayout * layout = new QVBoxLayout(upper_vbox);
216 Q_CHECK_PTR( upper_vbox );
218 _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
219 Q_CHECK_PTR( _descriptionView );
220 layout->addWidget(_descriptionView);
222 layout->addSpacing( MARGIN );
229 QWidget *lower_vbox = new QWidget(splitter);
230 layout = new QVBoxLayout(upper_vbox);
232 Q_CHECK_PTR( lower_vbox );
233 layout->addSpacing( MARGIN );
235 _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
236 Q_CHECK_PTR( _diskUsageList );
237 layout->addWidget(_diskUsageList);
239 splitter->setStretchFactor( 0, 0 );
240 splitter->setStretchFactor( 0, 1 );
248 YQPatternSelector::layoutButtons( QWidget * parent )
250 QWidget *button_box = new QWidget(parent);
251 QHBoxLayout *layout = new QHBoxLayout(button_box);
253 Q_CHECK_PTR( button_box );
254 layout->setMargin ( MARGIN );
255 layout->setSpacing( SPACING );
257 button_box->setLayout(layout);
259 QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
260 layout->addWidget(details_button);
261 Q_CHECK_PTR( details_button );
262 details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
264 connect( details_button, SIGNAL( clicked() ),
265 this, SLOT ( detailedPackageSelection() ) );
268 layout->addStretch();
270 QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
271 Q_CHECK_PTR( cancel_button );
272 layout->addWidget(cancel_button);
273 cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
275 connect( cancel_button, SIGNAL( clicked() ),
276 this, SLOT ( reject() ) );
279 QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
280 Q_CHECK_PTR( accept_button );
281 layout->addWidget(accept_button);
282 accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
284 connect( accept_button, SIGNAL( clicked() ),
285 this, SLOT ( accept() ) );
287 button_box->setFixedHeight( button_box->sizeHint().height() );
293 YQPatternSelector::makeConnections()
297 #if ALWAYS_SOLVE_IMMEDIATELY
298 connect( _patternList, SIGNAL( statusChanged() ),
299 this, SLOT ( resolveDependencies() ) );
301 if ( _pkgConflictDialog )
303 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
304 _patternList, SLOT ( updateItemStates() ) );
308 if ( _descriptionView )
310 connect( _patternList, SIGNAL( currentItemChanged( ZyppSel ) ),
311 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
314 if ( _diskUsageList )
316 connect( _patternList, SIGNAL( updatePackages() ),
317 _diskUsageList, SLOT ( updateDiskUsage() ) );
324 #if ALWAYS_SOLVE_IMMEDIATELY
325 connect( _selList, SIGNAL( statusChanged() ),
326 this, SLOT ( resolveDependencies() ) );
328 if ( _pkgConflictDialog )
330 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
331 _selList, SLOT ( updateItemStates() ) );
336 if ( _descriptionView )
338 connect( _selList, SIGNAL( currentItemChanged( ZyppSel ) ),
339 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
342 if ( _diskUsageList )
344 connect( _selList, SIGNAL( updatePackages() ),
345 _diskUsageList, SLOT ( updateDiskUsage() ) );
349 y2milestone( "Connection set up" );
354 connect( _wizard, SIGNAL( nextClicked() ),
355 this, SLOT ( accept() ) );
357 connect( _wizard, SIGNAL( backClicked() ),
358 this, SLOT ( reject() ) );
360 connect( _wizard, SIGNAL( abortClicked() ),
361 this, SLOT ( reject() ) );
367 YQPatternSelector::detailedPackageSelection()
369 y2milestone( "\"Details..\" button clicked" );
370 YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
375 YQPatternSelector::debugTrace()
377 y2warning( "debugTrace" );
382 #include "YQPatternSelector.moc"