]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQSimplePatchSelector.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / pkg / YQSimplePatchSelector.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQSimplePatchSelector.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <qapplication.h>
22 #include <qhbox.h>
23 #include <qheader.h>
24 #include <qpushbutton.h>
25 #include <qsplitter.h>
26
27 #define y2log_component "qt-pkg"
28 #include <ycp/y2log.h>
29
30 #include "QY2LayoutUtils.h"
31
32 #include "YQSimplePatchSelector.h"
33 #include "YQPkgConflictDialog.h"
34 #include "YQPkgDiskUsageList.h"
35 #include "YQPkgPatchFilterView.h"
36 #include "YQPkgPatchList.h"
37 #include "YQWizard.h"
38 #include "YQDialog.h"
39
40 #include "utf8.h"
41 #include "YQUI.h"
42 #include "YEvent.h"
43 #include "YQi18n.h"
44
45
46 using std::max;
47 using std::string;
48
49 #define SHOW_DISK_USAGE         0
50
51 #define SPACING                 6
52 #define MARGIN                  6
53
54
55
56 YQSimplePatchSelector::YQSimplePatchSelector( YWidget * parent, long modeFlags )
57     : YQPackageSelectorBase( parent, modeFlags )
58 {
59     _patchFilterView    = 0;
60     _patchList          = 0;
61     _diskUsageList      = 0;
62     _wizard             = findWizard();
63
64     basicLayout();
65     makeConnections();
66
67 #if 0
68     _patchList->fillList();
69     _patchList->selectSomething();
70 #endif
71
72     if ( _diskUsageList )
73         _diskUsageList->updateDiskUsage();
74 }
75
76
77
78 YQWizard *
79 YQSimplePatchSelector::findWizard() const
80 {
81     YQWizard * wizard = 0;
82
83     YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
84
85     if ( dialog )
86         wizard = dialog->findWizard();
87
88     return wizard;
89 }
90
91
92
93 void
94 YQSimplePatchSelector::basicLayout()
95 {
96     QSplitter * splitter = new QSplitter( QSplitter::Vertical, this );
97     CHECK_PTR( splitter );
98     splitter->setMargin( MARGIN );
99
100     //
101     // PatchFilterView
102     //
103
104     QVBox * upper_vbox = new QVBox( splitter );
105     CHECK_PTR( upper_vbox );
106     splitter->setResizeMode( upper_vbox, QSplitter::Stretch );
107
108     _patchFilterView = new YQPkgPatchFilterView( upper_vbox );
109     CHECK_PTR( _patchFilterView );
110     
111     _patchList = _patchFilterView->patchList();
112     CHECK_PTR( _patchList );
113     
114     addVSpacing( upper_vbox, MARGIN );
115
116     //
117     // Disk Usage
118     //
119
120
121 #if SHOW_DISK_USAGE
122     QVBox * lower_vbox = new QVBox( splitter );
123     CHECK_PTR( lower_vbox );
124     addVSpacing( lower_vbox, MARGIN );
125
126     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
127     CHECK_PTR( _diskUsageList );
128     
129     splitter->setResizeMode( lower_vbox, QSplitter::FollowSizeHint );
130 #endif
131
132
133     //
134     // Buttons
135     //
136     
137     if ( _wizard )      // No button box - add "Details..." button here
138     {
139         //
140         // "Details" button
141         //
142
143         addVSpacing( this, SPACING );
144
145         QHBox * hbox = new QHBox( this );
146         CHECK_PTR( hbox );
147
148         QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
149         CHECK_PTR( details_button );
150
151         connect( details_button, SIGNAL( clicked() ),
152                  this,           SLOT  ( detailedPackageSelection() ) );
153
154         addHStretch( hbox );
155     }
156     else // ! _wizard
157     {
158         layoutButtons( this );
159     }
160 }
161
162
163 void
164 YQSimplePatchSelector::layoutButtons( QWidget * parent )
165 {
166     QHBox * button_box = new QHBox( parent );
167     CHECK_PTR( button_box );
168     button_box->setMargin ( MARGIN  );
169     button_box->setSpacing( SPACING );
170
171
172     QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
173     CHECK_PTR( details_button );
174     details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
175
176     connect( details_button,    SIGNAL( clicked() ),
177              this,              SLOT  ( detailedPackageSelection() ) );
178
179
180     addHStretch( button_box );
181
182     QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
183     CHECK_PTR( cancel_button );
184     cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
185
186     connect( cancel_button, SIGNAL( clicked() ),
187              this,          SLOT  ( reject()   ) );
188
189
190     QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
191     CHECK_PTR( accept_button );
192     accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
193
194     connect( accept_button, SIGNAL( clicked() ),
195              this,          SLOT  ( accept()   ) );
196
197     button_box->setFixedHeight( button_box->sizeHint().height() );
198 }
199
200
201
202 void
203 YQSimplePatchSelector::makeConnections()
204 {
205     if ( _patchList && _diskUsageList )
206     {
207         connect( _patchList,     SIGNAL( updatePackages()  ),
208                  _diskUsageList, SLOT  ( updateDiskUsage() ) );
209     }
210
211     y2milestone( "Connection set up" );
212
213     if ( _wizard )
214     {
215         connect( _wizard,       SIGNAL( nextClicked()   ),
216                  this,          SLOT  ( accept()        ) );
217
218         connect( _wizard,       SIGNAL( backClicked()   ),
219                  this,          SLOT  ( reject()        ) );
220
221         connect( _wizard,       SIGNAL( abortClicked()  ),
222                  this,          SLOT  ( reject()        ) );
223     }
224 }
225
226
227 void
228 YQSimplePatchSelector::detailedPackageSelection()
229 {
230     y2milestone( "\"Details..\" button clicked" );
231     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
232 }
233
234
235 void
236 YQSimplePatchSelector::debugTrace()
237 {
238     y2warning( "debugTrace" );
239 }
240
241
242
243 #include "YQSimplePatchSelector.moc"