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 Q3HBox * button_box = new Q3HBox( parent );
250 Q_CHECK_PTR( button_box );
251 button_box->setMargin ( MARGIN );
252 button_box->setSpacing( SPACING );
254 parent->layout()->addWidget( button_box );
256 QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
257 Q_CHECK_PTR( details_button );
258 details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
260 connect( details_button, SIGNAL( clicked() ),
261 this, SLOT ( detailedPackageSelection() ) );
264 addHStretch( button_box );
266 QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
267 Q_CHECK_PTR( cancel_button );
268 cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
270 connect( cancel_button, SIGNAL( clicked() ),
271 this, SLOT ( reject() ) );
274 QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
275 Q_CHECK_PTR( accept_button );
276 accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
278 connect( accept_button, SIGNAL( clicked() ),
279 this, SLOT ( accept() ) );
281 button_box->setFixedHeight( button_box->sizeHint().height() );
287 YQPatternSelector::makeConnections()
291 #if ALWAYS_SOLVE_IMMEDIATELY
292 connect( _patternList, SIGNAL( statusChanged() ),
293 this, SLOT ( resolveDependencies() ) );
295 if ( _pkgConflictDialog )
297 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
298 _patternList, SLOT ( updateItemStates() ) );
302 if ( _descriptionView )
304 connect( _patternList, SIGNAL( currentItemChanged( ZyppSel ) ),
305 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
308 if ( _diskUsageList )
310 connect( _patternList, SIGNAL( updatePackages() ),
311 _diskUsageList, SLOT ( updateDiskUsage() ) );
318 #if ALWAYS_SOLVE_IMMEDIATELY
319 connect( _selList, SIGNAL( statusChanged() ),
320 this, SLOT ( resolveDependencies() ) );
322 if ( _pkgConflictDialog )
324 connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
325 _selList, SLOT ( updateItemStates() ) );
330 if ( _descriptionView )
332 connect( _selList, SIGNAL( currentItemChanged( ZyppSel ) ),
333 _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
336 if ( _diskUsageList )
338 connect( _selList, SIGNAL( updatePackages() ),
339 _diskUsageList, SLOT ( updateDiskUsage() ) );
343 y2milestone( "Connection set up" );
348 connect( _wizard, SIGNAL( nextClicked() ),
349 this, SLOT ( accept() ) );
351 connect( _wizard, SIGNAL( backClicked() ),
352 this, SLOT ( reject() ) );
354 connect( _wizard, SIGNAL( abortClicked() ),
355 this, SLOT ( reject() ) );
361 YQPatternSelector::detailedPackageSelection()
363 y2milestone( "\"Details..\" button clicked" );
364 YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
369 YQPatternSelector::debugTrace()
371 y2warning( "debugTrace" );
376 #include "YQPatternSelector.moc"