]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPatternSelector.cc
fa422c097f8432a65978cdb5a022d505c609be20
[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     QVBoxLayout *vbox = new QVBoxLayout( this );
112
113     QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
114     Q_CHECK_PTR( outer_splitter );
115
116     vbox->addWidget( outer_splitter );
117
118     QWidget * left_pane  = layoutLeftPane ( outer_splitter );
119     QWidget * right_pane = layoutRightPane( outer_splitter );
120
121     int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
122     left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
123
124     outer_splitter->setResizeMode( left_pane,  QSplitter::KeepSize );
125     outer_splitter->setResizeMode( right_pane, QSplitter::Stretch  );
126
127     if ( ! _wizard )
128         layoutButtons( this );
129 }
130
131
132
133 QWidget *
134 YQPatternSelector::layoutLeftPane( QWidget * parent )
135 {
136     Q3VBox * vbox = new Q3VBox( parent );
137     Q_CHECK_PTR( vbox );
138     vbox->setMargin( MARGIN );
139
140     if ( ! zyppPool().empty<zypp::Pattern>() )
141     {
142         //
143         // Patterns list
144         //
145
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         //FIXME _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         //FIXME _selList->header()->hide();
171     }
172
173     if ( _wizard )      // No button box - add "Details..." button here
174     {
175         //
176         // "Details" button
177         //
178
179         addVSpacing( vbox, SPACING );
180
181         Q3HBox * hbox = new Q3HBox( vbox );
182         Q_CHECK_PTR( hbox );
183
184         QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
185         Q_CHECK_PTR( details_button );
186
187         connect( details_button, SIGNAL( clicked() ),
188                  this,           SLOT  ( detailedPackageSelection() ) );
189
190         addHStretch( hbox );
191     }
192
193     return vbox;
194 }
195
196
197
198 QWidget *
199 YQPatternSelector::layoutRightPane( QWidget * parent )
200 {
201     QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
202     Q_CHECK_PTR( splitter );
203     splitter->setMargin( MARGIN );
204
205
206     //
207     // Selection / Pattern description
208     //
209
210     Q3VBox * upper_vbox = new Q3VBox( splitter );
211     Q_CHECK_PTR( upper_vbox );
212
213     _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
214     Q_CHECK_PTR( _descriptionView );
215
216     addVSpacing( upper_vbox, MARGIN );
217
218
219     //
220     // Disk usage
221     //
222
223     Q3VBox * lower_vbox = new Q3VBox( splitter );
224     Q_CHECK_PTR( lower_vbox );
225     addVSpacing( lower_vbox, MARGIN );
226
227     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
228     Q_CHECK_PTR( _diskUsageList );
229
230     splitter->setResizeMode( upper_vbox, QSplitter::Stretch );
231     splitter->setResizeMode( lower_vbox, QSplitter::KeepSize );
232
233     return splitter;
234 }
235
236
237
238 void
239 YQPatternSelector::layoutButtons( QWidget * parent )
240 {
241     Q3HBox * button_box = new Q3HBox( parent );
242     Q_CHECK_PTR( button_box );
243     button_box->setMargin ( MARGIN  );
244     button_box->setSpacing( SPACING );
245
246     parent->layout()->addWidget( button_box );
247
248     QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
249     Q_CHECK_PTR( details_button );
250     details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
251
252     connect( details_button,    SIGNAL( clicked() ),
253              this,              SLOT  ( detailedPackageSelection() ) );
254
255
256     addHStretch( button_box );
257
258     QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
259     Q_CHECK_PTR( cancel_button );
260     cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
261
262     connect( cancel_button, SIGNAL( clicked() ),
263              this,          SLOT  ( reject()   ) );
264
265
266     QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
267     Q_CHECK_PTR( accept_button );
268     accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
269
270     connect( accept_button, SIGNAL( clicked() ),
271              this,          SLOT  ( accept()   ) );
272
273     button_box->setFixedHeight( button_box->sizeHint().height() );
274 }
275
276
277
278 void
279 YQPatternSelector::makeConnections()
280 {
281     if ( _patternList )
282     {
283 #if ALWAYS_SOLVE_IMMEDIATELY
284         connect( _patternList,          SIGNAL( statusChanged()         ),
285                  this,                  SLOT  ( resolveDependencies()   ) );
286
287         if ( _pkgConflictDialog )
288         {
289             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
290                      _patternList,       SLOT  ( updateItemStates()     ) );
291         }
292 #endif
293
294         if ( _descriptionView )
295         {
296             connect( _patternList,      SIGNAL( currentItemChanged( ZyppSel ) ),
297                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
298         }
299
300         if ( _diskUsageList )
301         {
302             connect( _patternList,      SIGNAL( updatePackages()  ),
303                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
304         }
305
306     }
307
308     if ( _selList )
309     {
310 #if ALWAYS_SOLVE_IMMEDIATELY
311         connect( _selList,              SIGNAL( statusChanged()         ),
312                  this,                  SLOT  ( resolveDependencies()   ) );
313
314         if ( _pkgConflictDialog )
315         {
316             connect( _pkgConflictDialog, SIGNAL( updatePackages()       ),
317                      _selList,           SLOT  ( updateItemStates()     ) );
318         }
319
320 #endif
321
322         if ( _descriptionView )
323         {
324             connect( _selList,          SIGNAL( currentItemChanged( ZyppSel ) ),
325                      _descriptionView,  SLOT  ( showDetails     ( ZyppSel ) ) );
326         }
327
328         if ( _diskUsageList )
329         {
330             connect( _selList,          SIGNAL( updatePackages()  ),
331                      _diskUsageList,    SLOT  ( updateDiskUsage() ) );
332         }
333     }
334
335     y2milestone( "Connection set up" );
336
337
338     if ( _wizard )
339     {
340         connect( _wizard,       SIGNAL( nextClicked()   ),
341                  this,          SLOT  ( accept()        ) );
342
343         connect( _wizard,       SIGNAL( backClicked()   ),
344                  this,          SLOT  ( reject()        ) );
345
346         connect( _wizard,       SIGNAL( abortClicked()  ),
347                  this,          SLOT  ( reject()        ) );
348     }
349 }
350
351
352 void
353 YQPatternSelector::detailedPackageSelection()
354 {
355     y2milestone( "\"Details..\" button clicked" );
356     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
357 }
358
359
360 void
361 YQPatternSelector::debugTrace()
362 {
363     y2warning( "debugTrace" );
364 }
365
366
367
368 #include "YQPatternSelector.moc"