libyui-qt-pkg  2.45.6
YQSimplePatchSelector.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: YQSimplePatchSelector.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #include <QApplication>
43 #include <QBoxLayout>
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 "YQSimplePatchSelector.h"
54 #include "YQPkgConflictDialog.h"
55 #include "YQPkgDiskUsageList.h"
56 #include "YQPkgPatchFilterView.h"
57 #include "YQPkgPatchList.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 
67 using std::max;
68 using std::endl;
69 using std::string;
70 
71 #define SHOW_DISK_USAGE 0
72 
73 #define SPACING 6
74 #define MARGIN 6
75 
76 
77 
78 YQSimplePatchSelector::YQSimplePatchSelector( YWidget * parent, long modeFlags )
79  : YQPackageSelectorBase( parent, modeFlags )
80 {
81  _patchFilterView = 0;
82  _patchList = 0;
83  _diskUsageList = 0;
84  _wizard = findWizard();
85 
86  basicLayout();
87  makeConnections();
88 
89 #if 0
90  _patchList->fillList();
91  _patchList->selectSomething();
92 #endif
93 
94  if ( _diskUsageList )
95  _diskUsageList->updateDiskUsage();
96 }
97 
98 
99 
100 YQWizard *
102 {
103  YQWizard * wizard = 0;
104 
105  YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
106 
107  if ( dialog )
108  wizard = dialog->findWizard();
109 
110  return wizard;
111 }
112 
113 
114 
115 void
116 YQSimplePatchSelector::basicLayout()
117 {
118  QSplitter * splitter = new QSplitter( Qt::Vertical, this );
119  Q_CHECK_PTR( splitter );
120 
121  setLayout( new QVBoxLayout( ) );
122  layout()->addWidget(splitter);
123 
124  //
125  // PatchFilterView
126  //
127 
128  QBoxLayout *layout = new QVBoxLayout;
129  layout->setMargin( MARGIN );
130  QWidget * upper_vbox = new QWidget( splitter );
131  Q_CHECK_PTR( upper_vbox );
132  upper_vbox->setLayout(layout);
133  splitter->addWidget(upper_vbox);
134 
135  splitter->setStretchFactor( 0, 1 );
136 
137  _patchFilterView = new YQPkgPatchFilterView( upper_vbox );
138  layout->addWidget( _patchFilterView );
139  Q_CHECK_PTR( _patchFilterView );
140 
141  _patchList = _patchFilterView->patchList();
142  Q_CHECK_PTR( _patchList );
143 
144  //addVSpacing( upper_vbox, MARGIN );
145 
146  //
147  // Disk Usage
148  //
149 
150 
151 #if SHOW_DISK_USAGE
152  layout = new QVBoxLayout;
153  QWidget * lower_vbox = new QWidget( splitter );
154  lower_vbox->setLayout(layout);
155 
156  Q_CHECK_PTR( lower_vbox );
157  //addVSpacing( lower_vbox, MARGIN );
158 
159  _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
160  Q_CHECK_PTR( _diskUsageList );
161  layout->addWidget(_diskUsageList);
162 
163  splitter->setSectionResizeMode( lower_vbox, QSplitter::FollowSizeHint );
164 #endif
165 
166 
167  //
168  // Buttons
169  //
170 
171  if ( _wizard ) // No button box - add "Details..." button here
172  {
173  //
174  // "Details" button
175  //
176 
177  //addVSpacing( this, SPACING );
178  layout = new QHBoxLayout;
179  QWidget * hbox = new QWidget( this );
180  Q_CHECK_PTR( hbox );
181  hbox->setLayout(layout);
182  QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
183  layout->addWidget(details_button);
184  Q_CHECK_PTR( details_button );
185 
186  connect( details_button, SIGNAL( clicked() ),
187  this, SLOT ( detailedPackageSelection() ) );
188 
189  //addHStretch( hbox );
190  }
191  else // ! _wizard
192  {
193  layoutButtons( this );
194  }
195 }
196 
197 
198 void
199 YQSimplePatchSelector::layoutButtons( QWidget * parent )
200 {
201  QWidget * button_box = new QWidget( parent );
202  QHBoxLayout *layout = new QHBoxLayout( button_box );
203  Q_CHECK_PTR( button_box );
204  layout->setMargin ( MARGIN );
205  layout->setSpacing( SPACING );
206 
207 
208  QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
209  Q_CHECK_PTR( details_button );
210  layout->addWidget(details_button);
211  details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
212 
213  connect( details_button, SIGNAL( clicked() ),
214  this, SLOT ( detailedPackageSelection() ) );
215 
216 
217  layout->addStretch();
218 
219  QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
220  Q_CHECK_PTR( cancel_button );
221  layout->addWidget(cancel_button);
222  cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
223 
224  connect( cancel_button, SIGNAL( clicked() ),
225  this, SLOT ( reject() ) );
226 
227 
228  QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
229  Q_CHECK_PTR( accept_button );
230  layout->addWidget(accept_button);
231  accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
232 
233  connect( accept_button, SIGNAL( clicked() ),
234  this, SLOT ( accept() ) );
235 
236  this->layout()->addWidget( button_box );
237 // button_box->setFixedHeight( button_box->sizeHint().height() );
238 }
239 
240 
241 
242 void
244 {
245  if ( _patchList && _diskUsageList )
246  {
247  connect( _patchList, SIGNAL( updatePackages() ),
248  _diskUsageList, SLOT ( updateDiskUsage() ) );
249  }
250 
251  yuiMilestone() << "Connection set up" << endl;
252 
253  if ( _wizard )
254  {
255  connect( _wizard, SIGNAL( nextClicked() ),
256  this, SLOT ( accept() ) );
257 
258  connect( _wizard, SIGNAL( backClicked() ),
259  this, SLOT ( reject() ) );
260 
261  connect( _wizard, SIGNAL( abortClicked() ),
262  this, SLOT ( reject() ) );
263  }
264 }
265 
266 
267 void
269 {
270  yuiMilestone() << "\"Details..\" button clicked" << endl;
271  YQUI::ui()->sendEvent( new YMenuEvent( "details" ) );
272 }
273 
274 
275 void
277 {
278  yuiWarning() << "debugTrace" << endl;
279 }
280 
281 
282 
283 #include "YQSimplePatchSelector.moc"
void makeConnections()
Establish Qt signal / slot connections.
void detailedPackageSelection()
User clicked on "Details..." - start the detailed package selection.
Display a list of zypp::Patch objects and ( below ) details about the currently selected patch...
YQWizard * findWizard() const
Find the wizard in the current dialog, if there is any.
Abstract base class for package selectors.
List of disk usage of all attached partitions.