]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPatternSelector.cc
0d98c4897dd66bb5982ee1340b71cd7ae035c262
[duncan/yast2-qt4.git] / src / pkg / YQPatternSelector.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPatternSelector.cc
14   See also:   YQPatternSelectorHelp.cc
15
16   Author:     Stefan Hundhammer <sh@suse.de>
17
18   Textdomain "packages-qt"
19
20 /-*/
21
22 #include <QApplication>
23 #include <QHeaderView>
24 #include <QPushButton>
25 #include <QSplitter>
26
27 #define y2log_component "qt-pkg"
28 #include <ycp/y2log.h>
29
30 #include "QY2LayoutUtils.h"
31
32 #include "YQPatternSelector.h"
33 #include "YQPkgConflictDialog.h"
34 #include "YQPkgSelDescriptionView.h"
35 #include "YQPkgDiskUsageList.h"
36 #include "YQPkgPatternList.h"
37 #include "YQPkgSelList.h"
38 #include "YQWizard.h"
39 #include "YQDialog.h"
40
41 #include "utf8.h"
42 #include "YQUI.h"
43 #include "YEvent.h"
44 #include "YQi18n.h"
45
46 #define ALWAYS_SOLVE_IMMEDIATELY 1
47
48 using std::max;
49 using std::string;
50
51 #define SPACING                 6
52 #define MARGIN                  6
53
54
55 YQPatternSelector::YQPatternSelector( YWidget * parent, long modeFlags )
56     : YQPackageSelectorBase( parent, modeFlags )
57 {
58     _patternList                = 0;
59     _selList                    = 0;
60     _descriptionView            = 0;
61     _wizard                     = findWizard();
62
63     basicLayout();
64     makeConnections();
65
66     if ( _patternList )
67     {
68         _patternList->fillList();
69         _patternList->selectSomething();
70     }
71     else if ( _selList )
72     {
73         _selList->fillList();
74         _selList->selectSomething();
75     }
76
77     if ( zyppPool().empty<zypp::Pattern  >() &&
78          zyppPool().empty<zypp::Selection>()   )
79     {
80         y2warning( "Neither patterns nor selections in ZyppPool" );
81     }
82
83
84     if ( _diskUsageList )
85         _diskUsageList->updateDiskUsage();
86 }
87
88
89
90 YQWizard *
91 YQPatternSelector::findWizard() const
92 {
93     YQWizard * wizard = 0;
94
95     YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
96
97     if ( dialog )
98         wizard = dialog->findWizard();
99
100     return wizard;
101 }
102
103
104
105 void
106 YQPatternSelector::basicLayout()
107 {
108     QVBoxLayout *vbox = new QVBoxLayout( this );
109
110     QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
111     Q_CHECK_PTR( outer_splitter );
112
113     vbox->addWidget( outer_splitter );
114
115     QWidget * left_pane  = layoutLeftPane ( outer_splitter );
116     QWidget * right_pane = layoutRightPane( outer_splitter );
117
118     int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
119     left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
120
121     outer_splitter->setStretchFactor(outer_splitter->indexOf(left_pane), 0);
122     outer_splitter->setStretchFactor(outer_splitter->indexOf(right_pane), 1);
123
124     if ( ! _wizard )
125         layoutButtons( this );
126 }
127
128
129
130 QWidget *
131 YQPatternSelector::layoutLeftPane( QWidget * parent )
132 {
133     QWidget *vbox = new QWidget(parent);
134     QVBoxLayout * layout = new QVBoxLayout( vbox );
135     Q_CHECK_PTR( vbox );
136     layout->setMargin( MARGIN );
137     vbox->setLayout(layout);
138
139     if ( ! zyppPool().empty<zypp::Pattern>() )
140     {
141         //
142         // Patterns list
143         //
144
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();
151     }
152
153     if ( ! _patternList )
154     {
155         //
156         // Fallback: selections list
157         //
158
159         /**
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.
163          **/
164
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();
172     }
173
174     if ( _wizard )      // No button box - add "Details..." button here
175     {
176         //
177         // "Details" button
178         //
179
180         layout->addSpacing( SPACING );
181
182         QHBoxLayout * hbox = new QHBoxLayout();
183         Q_CHECK_PTR( hbox );
184   layout->addLayout(hbox);
185
186         QPushButton * details_button = new QPushButton( _( "&Details..." ), vbox );
187         Q_CHECK_PTR( details_button );
188   hbox->addWidget(details_button);
189
190         connect( details_button, SIGNAL( clicked() ),
191                  this,           SLOT  ( detailedPackageSelection() ) );
192
193         hbox->addStretch();
194     }
195
196     return vbox;
197 }
198
199
200
201 QWidget *
202 YQPatternSelector::layoutRightPane( QWidget * parent )
203 {
204     QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
205     Q_CHECK_PTR( splitter );
206     //splitter->setMargin( MARGIN );
207
208
209     //
210     // Selection / Pattern description
211     //
212     QWidget *upper_vbox = new QWidget(splitter);
213     QVBoxLayout * layout = new QVBoxLayout(upper_vbox);
214     
215     Q_CHECK_PTR( upper_vbox );
216
217     _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
218     Q_CHECK_PTR( _descriptionView );
219     layout->addWidget(_descriptionView);
220
221     layout->addSpacing( MARGIN );
222
223
224     //
225     // Disk usage
226     //
227
228     QWidget *lower_vbox = new QWidget(splitter);
229     layout = new QVBoxLayout(upper_vbox);
230
231     Q_CHECK_PTR( lower_vbox );
232     layout->addSpacing( MARGIN );
233
234     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
235     Q_CHECK_PTR( _diskUsageList );
236     layout->addWidget(_diskUsageList);
237
238     splitter->setStretchFactor( 0, 0 );
239     splitter->setStretchFactor( 0, 1 );
240
241     return splitter;
242 }
243
244
245
246 void
247 YQPatternSelector::layoutButtons( QWidget * parent )
248 {
249     Q3HBox * button_box = new Q3HBox( parent );
250     Q_CHECK_PTR( button_box );
251     button_box->setMargin ( MARGIN  );
252     button_box->setSpacing( SPACING );
253
254     parent->layout()->addWidget( button_box );
255
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
259
260     connect( details_button,    SIGNAL( clicked() ),
261              this,              SLOT  ( detailedPackageSelection() ) );
262
263
264     addHStretch( button_box );
265
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
269
270     connect( cancel_button, SIGNAL( clicked() ),
271              this,          SLOT  ( reject()   ) );
272
273
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
277
278     connect( accept_button, SIGNAL( clicked() ),
279              this,          SLOT  ( accept()   ) );
280
281     button_box->setFixedHeight( button_box->sizeHint().height() );
282 }
283
284
285
286 void
287 YQPatternSelector::makeConnections()
288 {
289     if ( _patternList )
290     {
291 #if ALWAYS_SOLVE_IMMEDIATELY
292         connect( _patternList,          SIGNAL( statusChanged()         ),
293                  this,                  SLOT  ( resolveDependencies()   ) );
294
295         if ( _pkgConflictDialog )
296         {
297             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
298                      _patternList,       SLOT  ( updateItemStates()     ) );
299         }
300 #endif
301
302         if ( _descriptionView )
303         {
304             connect( _patternList,      SIGNAL( currentItemChanged( ZyppSel ) ),
305                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
306         }
307
308         if ( _diskUsageList )
309         {
310             connect( _patternList,      SIGNAL( updatePackages()  ),
311                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
312         }
313
314     }
315
316     if ( _selList )
317     {
318 #if ALWAYS_SOLVE_IMMEDIATELY
319         connect( _selList,              SIGNAL( statusChanged()         ),
320                  this,                  SLOT  ( resolveDependencies()   ) );
321
322         if ( _pkgConflictDialog )
323         {
324             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
325                      _selList,           SLOT  ( updateItemStates()     ) );
326         }
327
328 #endif
329
330         if ( _descriptionView )
331         {
332             connect( _selList,          SIGNAL( currentItemChanged( ZyppSel ) ),
333                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
334         }
335
336         if ( _diskUsageList )
337         {
338             connect( _selList,          SIGNAL( updatePackages()  ),
339                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
340         }
341     }
342
343     y2milestone( "Connection set up" );
344
345
346     if ( _wizard )
347     {
348         connect( _wizard,       SIGNAL( nextClicked()   ),
349                  this,          SLOT  ( accept()        ) );
350
351         connect( _wizard,       SIGNAL( backClicked()   ),
352                  this,          SLOT  ( reject()        ) );
353
354         connect( _wizard,       SIGNAL( abortClicked()  ),
355                  this,          SLOT  ( reject()        ) );
356     }
357 }
358
359
360 void
361 YQPatternSelector::detailedPackageSelection()
362 {
363     y2milestone( "\"Details..\" button clicked" );
364     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
365 }
366
367
368 void
369 YQPatternSelector::debugTrace()
370 {
371     y2warning( "debugTrace" );
372 }
373
374
375
376 #include "YQPatternSelector.moc"