libyui-qt-pkg  2.45.6
YQPatternSelector.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPatternSelector.cc
35  See also: YQPatternSelectorHelp.cc
36 
37  Author: Stefan Hundhammer <sh@suse.de>
38 
39  Textdomain "qt-pkg"
40 
41 /-*/
42 
43 #include <QApplication>
44 #include <QHeaderView>
45 #include <QPushButton>
46 #include <QSplitter>
47 
48 #define YUILogComponent "qt-pkg"
49 #include "YUILog.h"
50 
51 #include "QY2LayoutUtils.h"
52 
53 #include "YQPatternSelector.h"
54 #include "YQPkgConflictDialog.h"
55 #include "YQPkgSelDescriptionView.h"
56 #include "YQPkgDiskUsageList.h"
57 #include "YQPkgPatternList.h"
58 #include "YQWizard.h"
59 #include "YQDialog.h"
60 
61 #include "utf8.h"
62 #include "YQUI.h"
63 #include "YEvent.h"
64 #include "YQi18n.h"
65 
66 #define ALWAYS_SOLVE_IMMEDIATELY 1
67 
68 using std::max;
69 using std::endl;
70 using std::string;
71 
72 #define SPACING 6
73 #define MARGIN 6
74 
75 
76 YQPatternSelector::YQPatternSelector( YWidget * parent, long modeFlags )
77  : YQPackageSelectorBase( parent, modeFlags )
78 {
79  _patternList = 0;
80  _descriptionView = 0;
81  _wizard = findWizard();
82 
83  basicLayout();
84  makeConnections();
85 
86  if ( _patternList )
87  {
88  _patternList->fillList();
89  _patternList->selectSomething();
90  }
91 
92  if ( zyppPool().empty<zypp::Pattern >() )
93  {
94  yuiWarning() << "Neither patterns nor selections in ZyppPool" << endl;
95  }
96 
97 
98  if ( _diskUsageList )
99  _diskUsageList->updateDiskUsage();
100 }
101 
102 
103 
104 YQWizard *
106 {
107  YQWizard * wizard = 0;
108 
109  YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
110 
111  if ( dialog )
112  wizard = dialog->findWizard();
113 
114  return wizard;
115 }
116 
117 
118 
119 void
120 YQPatternSelector::basicLayout()
121 {
122  QVBoxLayout *vbox = new QVBoxLayout();
123  setLayout(vbox);
124 
125  QSplitter * outer_splitter = new QSplitter( Qt::Horizontal, this );
126  Q_CHECK_PTR( outer_splitter );
127 
128  vbox->addWidget( outer_splitter );
129 
130  QWidget * left_pane = layoutLeftPane ( outer_splitter );
131  QWidget * right_pane = layoutRightPane( outer_splitter );
132 
133  int left_pane_width = (int) ( 0.3 * YQUI::ui()->defaultSize( YD_HORIZ ) );
134  left_pane->resize( QSize( left_pane_width, left_pane->height() ) );
135 
136  outer_splitter->setStretchFactor(outer_splitter->indexOf(left_pane), 0);
137  outer_splitter->setStretchFactor(outer_splitter->indexOf(right_pane), 1);
138 
139  if ( ! _wizard )
140  layoutButtons( this );
141 }
142 
143 
144 
145 QWidget *
146 YQPatternSelector::layoutLeftPane( QWidget * parent )
147 {
148  QWidget *vbox = new QWidget(parent);
149  QVBoxLayout * layout = new QVBoxLayout( vbox );
150  Q_CHECK_PTR( vbox );
151  layout->setMargin( MARGIN );
152  vbox->setLayout(layout);
153 
154  if ( ! zyppPool().empty<zypp::Pattern>() )
155  {
156  //
157  // Patterns list
158  //
159 
160  _patternList = new YQPkgPatternList( vbox,
161  false, // no autoFill - need to connect to details view first
162  false ); // no autoFilter - filterMatch() is not connected
163  Q_CHECK_PTR( _patternList );
164  layout->addWidget(_patternList);
165  //_patternList->header()->hide();
166  }
167 
168  if ( _wizard ) // No button box - add "Details..." button here
169  {
170  //
171  // "Details" button
172  //
173 
174  layout->addSpacing( SPACING );
175 
176  QHBoxLayout * hbox = new QHBoxLayout();
177  Q_CHECK_PTR( hbox );
178  layout->addLayout(hbox);
179 
180  QPushButton * details_button = new QPushButton( _( "&Details..." ), vbox );
181  Q_CHECK_PTR( details_button );
182  hbox->addWidget(details_button);
183 
184  connect( details_button, SIGNAL( clicked() ),
185  this, SLOT ( detailedPackageSelection() ) );
186 
187  hbox->addStretch();
188  }
189 
190  return vbox;
191 }
192 
193 
194 
195 QWidget *
196 YQPatternSelector::layoutRightPane( QWidget * parent )
197 {
198  QSplitter * splitter = new QSplitter( Qt::Vertical, parent );
199  Q_CHECK_PTR( splitter );
200  //splitter->setMargin( MARGIN );
201 
202 
203  //
204  // Selection / Pattern description
205  //
206  QWidget *upper_vbox = new QWidget(splitter);
207  QVBoxLayout * layout = new QVBoxLayout(upper_vbox);
208 
209  Q_CHECK_PTR( upper_vbox );
210 
211  _descriptionView = new YQPkgSelDescriptionView( upper_vbox );
212  Q_CHECK_PTR( _descriptionView );
213  layout->addWidget(_descriptionView);
214 
215  //
216  // Disk usage
217  //
218 
219  QWidget *lower_vbox = new QWidget(splitter);
220  layout = new QVBoxLayout( lower_vbox);
221 
222  Q_CHECK_PTR( lower_vbox );
223 
224  _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
225  Q_CHECK_PTR( _diskUsageList );
226  layout->addWidget(_diskUsageList);
227 
228  splitter->setStretchFactor( 0, 3 );
229  splitter->setStretchFactor( 0, 1 );
230 
231  return splitter;
232 }
233 
234 
235 
236 void
237 YQPatternSelector::layoutButtons( QWidget * parent )
238 {
239  QWidget *button_box = new QWidget(parent);
240  Q_CHECK_PTR( button_box );
241 
242  parent->layout()->addWidget( button_box );
243  QHBoxLayout *layout = new QHBoxLayout(button_box);
244 
245  layout->setMargin ( MARGIN );
246  layout->setSpacing( SPACING );
247 
248  QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
249  layout->addWidget(details_button);
250  Q_CHECK_PTR( details_button );
251  details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
252 
253  connect( details_button, SIGNAL( clicked() ),
254  this, SLOT ( detailedPackageSelection() ) );
255 
256 
257  layout->addStretch();
258 
259  QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
260  Q_CHECK_PTR( cancel_button );
261  layout->addWidget(cancel_button);
262  cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
263 
264  connect( cancel_button, SIGNAL( clicked() ),
265  this, SLOT ( reject() ) );
266 
267 
268  QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
269  Q_CHECK_PTR( accept_button );
270  layout->addWidget(accept_button);
271  accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
272 
273  connect( accept_button, SIGNAL( clicked() ),
274  this, SLOT ( accept() ) );
275 
276  button_box->setFixedHeight( button_box->sizeHint().height() );
277 }
278 
279 
280 
281 void
283 {
284  if ( _patternList )
285  {
286 #if ALWAYS_SOLVE_IMMEDIATELY
287  connect( _patternList, SIGNAL( statusChanged() ),
288  this, SLOT ( resolveDependencies() ) );
289 
290  if ( _pkgConflictDialog )
291  {
292  connect( _pkgConflictDialog, SIGNAL( updatePackages() ),
293  _patternList, SLOT ( updateItemStates() ) );
294  }
295 #endif
296 
297  if ( _descriptionView )
298  {
299  connect( _patternList, SIGNAL( currentItemChanged( ZyppSel ) ),
300  _descriptionView, SLOT ( showDetails ( ZyppSel ) ) );
301  }
302 
303  if ( _diskUsageList )
304  {
305  connect( _patternList, SIGNAL( updatePackages() ),
306  _diskUsageList, SLOT ( updateDiskUsage() ) );
307  }
308 
309  }
310 
311  yuiMilestone() << "Connection set up" << endl;
312 
313 
314  if ( _wizard )
315  {
316  connect( _wizard, SIGNAL( nextClicked() ),
317  this, SLOT ( accept() ) );
318 
319  connect( _wizard, SIGNAL( backClicked() ),
320  this, SLOT ( reject() ) );
321 
322  connect( _wizard, SIGNAL( abortClicked() ),
323  this, SLOT ( reject() ) );
324  }
325 }
326 
327 
328 void
330 {
331  yuiMilestone() << "\"Details..\" button clicked" << endl;
332  YQUI::ui()->sendEvent( new YMenuEvent( "details" ) );
333 }
334 
335 
336 void
338 {
339  yuiWarning() << "debugTrace" << endl;
340 }
341 
342 
343 
344 #include "YQPatternSelector.moc"
void debugTrace()
Debugging.
YQWizard * findWizard() const
Find the wizard in the current dialog, if there is any.
Display a list of zypp::Pattern objects.
void makeConnections()
Establish Qt signal / slot connections.
void detailedPackageSelection()
User clicked on "Details..." - start the detailed package selection.
Abstract base class for package selectors.
Display the description of a zypp::ResObject derived object along with its name and summary...
List of disk usage of all attached partitions.