]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPatternSelector.cc
74ad0804e7690ac73421b93d590f527bed26925b
[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 #define QT3_SUPPORT 1
23
24 #include <qapplication.h>
25 #include <q3hbox.h>
26 #include <q3header.h>
27 #include <qpushbutton.h>
28 #include <qsplitter.h>
29
30 #define y2log_component "qt-pkg"
31 #include <ycp/y2log.h>
32
33 #include "QY2LayoutUtils.h"
34
35 #include "YQPatternSelector.h"
36 #include "YQPkgConflictDialog.h"
37 #include "YQPkgSelDescriptionView.h"
38 #include "YQPkgDiskUsageList.h"
39 #include "YQPkgPatternList.h"
40 #include "YQPkgSelList.h"
41 #include "YQWizard.h"
42 #include "YQDialog.h"
43
44 #include "utf8.h"
45 #include "YQUI.h"
46 #include "YEvent.h"
47 #include "YQi18n.h"
48
49 #define ALWAYS_SOLVE_IMMEDIATELY 1
50
51 using std::max;
52 using std::string;
53
54 #define SPACING                 6
55 #define MARGIN                  6
56
57
58 YQPatternSelector::YQPatternSelector( YWidget * parent, long modeFlags )
59     : YQPackageSelectorBase( parent, modeFlags )
60 {
61     _patternList                = 0;
62     _selList                    = 0;
63     _descriptionView            = 0;
64     _wizard                     = findWizard();
65
66     basicLayout();
67     makeConnections();
68
69     if ( _patternList )
70     {
71         _patternList->fillList();
72         _patternList->selectSomething();
73     }
74     else if ( _selList )
75     {
76         _selList->fillList();
77         _selList->selectSomething();
78     }
79
80     if ( zyppPool().empty<zypp::Pattern  >() &&
81          zyppPool().empty<zypp::Selection>()   )
82     {
83         y2warning( "Neither patterns nor selections in ZyppPool" );
84     }
85
86
87     if ( _diskUsageList )
88         _diskUsageList->updateDiskUsage();
89 }
90
91
92
93 YQWizard *
94 YQPatternSelector::findWizard() const
95 {
96     YQWizard * wizard = 0;
97
98     YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
99
100     if ( dialog )
101         wizard = dialog->findWizard();
102
103     return wizard;
104 }
105
106
107
108 void
109 YQPatternSelector::basicLayout()
110 {
111     QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
112     Q_CHECK_PTR( outer_splitter );
113
114     QWidget * left_pane  = layoutLeftPane ( outer_splitter );
115     QWidget * right_pane = layoutRightPane( outer_splitter );
116
117     int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
118     left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
119
120     outer_splitter->setResizeMode( left_pane,  QSplitter::KeepSize );
121     outer_splitter->setResizeMode( right_pane, QSplitter::Stretch  );
122
123     if ( ! _wizard )
124         layoutButtons( this );
125 }
126
127
128
129 QWidget *
130 YQPatternSelector::layoutLeftPane( QWidget * parent )
131 {
132     Q3VBox * vbox = new Q3VBox( parent );
133     Q_CHECK_PTR( vbox );
134     vbox->setMargin( MARGIN );
135
136     if ( ! zyppPool().empty<zypp::Pattern>() )
137     {
138         //
139         // Patterns list
140         //
141
142         _patternList = new YQPkgPatternList( vbox,
143                                              false,     // no autoFill - need to connect to details view first
144                                              false );   // no autoFilter - filterMatch() is not connected
145         Q_CHECK_PTR( _patternList );
146         //FIXME _patternList->header()->hide();
147     }
148
149     if ( ! _patternList )
150     {
151         //
152         // Fallback: selections list
153         //
154
155         /**
156          * Create a selections list even if there are no selections, otherwise
157          * the layout will look very weird. An empty selections list still
158          * looks better than a lot of grey empty space.
159          **/
160
161         y2warning( "No patterns in ZyppPool - using selections instead" );
162         _selList = new YQPkgSelList( vbox,
163                                      false,     // no autoFill - need to connect to details view first
164                                      false );   // no autoFilter - filterMatch() is not connected
165         Q_CHECK_PTR( _selList );
166         //FIXME _selList->header()->hide();
167     }
168
169     if ( _wizard )      // No button box - add "Details..." button here
170     {
171         //
172         // "Details" button
173         //
174
175         addVSpacing( vbox, SPACING );
176
177         Q3HBox * hbox = new Q3HBox( vbox );
178         Q_CHECK_PTR( hbox );
179
180         QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
181         Q_CHECK_PTR( details_button );
182
183         connect( details_button, SIGNAL( clicked() ),
184                  this,           SLOT  ( detailedPackageSelection() ) );
185
186         addHStretch( hbox );
187     }
188
189     return vbox;
190 }
191
192
193
194 QWidget *
195 YQPatternSelector::layoutRightPane( QWidget * parent )
196 {
197     QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
198     Q_CHECK_PTR( splitter );
199     splitter->setMargin( MARGIN );
200
201
202     //
203     // Selection / Pattern description
204     //
205
206     Q3VBox * upper_vbox = new Q3VBox( splitter );
207     Q_CHECK_PTR( upper_vbox );
208
209     _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
210     Q_CHECK_PTR( _descriptionView );
211
212     addVSpacing( upper_vbox, MARGIN );
213
214
215     //
216     // Disk usage
217     //
218
219     Q3VBox * lower_vbox = new Q3VBox( splitter );
220     Q_CHECK_PTR( lower_vbox );
221     addVSpacing( lower_vbox, MARGIN );
222
223     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
224     Q_CHECK_PTR( _diskUsageList );
225
226     splitter->setResizeMode( upper_vbox, QSplitter::Stretch );
227     splitter->setResizeMode( lower_vbox, QSplitter::KeepSize );
228
229     return splitter;
230 }
231
232
233
234 void
235 YQPatternSelector::layoutButtons( QWidget * parent )
236 {
237     Q3HBox * button_box = new Q3HBox( parent );
238     Q_CHECK_PTR( button_box );
239     button_box->setMargin ( MARGIN  );
240     button_box->setSpacing( SPACING );
241
242
243     QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
244     Q_CHECK_PTR( details_button );
245     details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
246
247     connect( details_button,    SIGNAL( clicked() ),
248              this,              SLOT  ( detailedPackageSelection() ) );
249
250
251     addHStretch( button_box );
252
253     QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
254     Q_CHECK_PTR( cancel_button );
255     cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
256
257     connect( cancel_button, SIGNAL( clicked() ),
258              this,          SLOT  ( reject()   ) );
259
260
261     QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
262     Q_CHECK_PTR( accept_button );
263     accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
264
265     connect( accept_button, SIGNAL( clicked() ),
266              this,          SLOT  ( accept()   ) );
267
268     button_box->setFixedHeight( button_box->sizeHint().height() );
269 }
270
271
272
273 void
274 YQPatternSelector::makeConnections()
275 {
276     if ( _patternList )
277     {
278 #if ALWAYS_SOLVE_IMMEDIATELY
279         connect( _patternList,          SIGNAL( statusChanged()         ),
280                  this,                  SLOT  ( resolveDependencies()   ) );
281
282         if ( _pkgConflictDialog )
283         {
284             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
285                      _patternList,       SLOT  ( updateItemStates()     ) );
286         }
287 #endif
288
289         if ( _descriptionView )
290         {
291             connect( _patternList,      SIGNAL( currentItemChanged( ZyppSel ) ),
292                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
293         }
294
295         if ( _diskUsageList )
296         {
297             connect( _patternList,      SIGNAL( updatePackages()  ),
298                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
299         }
300
301     }
302
303     if ( _selList )
304     {
305 #if ALWAYS_SOLVE_IMMEDIATELY
306         connect( _selList,              SIGNAL( statusChanged()         ),
307                  this,                  SLOT  ( resolveDependencies()   ) );
308
309         if ( _pkgConflictDialog )
310         {
311             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
312                      _selList,           SLOT  ( updateItemStates()     ) );
313         }
314
315 #endif
316
317         if ( _descriptionView )
318         {
319             connect( _selList,          SIGNAL( currentItemChanged( ZyppSel ) ),
320                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
321         }
322
323         if ( _diskUsageList )
324         {
325             connect( _selList,          SIGNAL( updatePackages()  ),
326                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
327         }
328     }
329
330     y2milestone( "Connection set up" );
331
332
333     if ( _wizard )
334     {
335         connect( _wizard,       SIGNAL( nextClicked()   ),
336                  this,          SLOT  ( accept()        ) );
337
338         connect( _wizard,       SIGNAL( backClicked()   ),
339                  this,          SLOT  ( reject()        ) );
340
341         connect( _wizard,       SIGNAL( abortClicked()  ),
342                  this,          SLOT  ( reject()        ) );
343     }
344 }
345
346
347 void
348 YQPatternSelector::detailedPackageSelection()
349 {
350     y2milestone( "\"Details..\" button clicked" );
351     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
352 }
353
354
355 void
356 YQPatternSelector::debugTrace()
357 {
358     y2warning( "debugTrace" );
359 }
360
361
362
363 #include "YQPatternSelector.moc"