]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQSimplePatchSelector.cc
d13ff63de70787249ffeeea52e6775280d5d884c
[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>
22 #include <QBoxLayout>
23 #include <QHeaderView>
24 #include <QPushButton>
25 #include <QSplitter>
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( Qt::Vertical, this );
97     Q_CHECK_PTR( splitter );
98
99     //
100     // PatchFilterView
101     //
102
103     QBoxLayout *layout = new QVBoxLayout;
104     layout->setMargin( MARGIN );
105     QWidget * upper_vbox = new QWidget( splitter );
106     Q_CHECK_PTR( upper_vbox );
107     upper_vbox->setLayout(layout);
108     splitter->addWidget(upper_vbox);
109
110
111     splitter->setStretchFactor( 0, 1 );
112
113     _patchFilterView = new YQPkgPatchFilterView( upper_vbox );
114     Q_CHECK_PTR( _patchFilterView );
115     layout->addWidget(_patchFilterView);
116
117     _patchList = _patchFilterView->patchList();
118     Q_CHECK_PTR( _patchList );
119     
120     //addVSpacing( upper_vbox, MARGIN );
121
122     //
123     // Disk Usage
124     //
125
126
127 #if SHOW_DISK_USAGE
128     layout = new QVBoxLayout;
129     QWidget * lower_vbox = new QWidget( splitter );
130     lower_vbox->setLayout(layout);
131
132     Q_CHECK_PTR( lower_vbox );
133     //addVSpacing( lower_vbox, MARGIN );
134
135     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
136     Q_CHECK_PTR( _diskUsageList );
137     layout->addWidget(_diskUsageList);
138     
139     splitter->setResizeMode( lower_vbox, QSplitter::FollowSizeHint );
140 #endif
141
142
143     //
144     // Buttons
145     //
146     
147     if ( _wizard )      // No button box - add "Details..." button here
148     {
149         //
150         // "Details" button
151         //
152
153         //addVSpacing( this, SPACING );
154         layout = new QHBoxLayout;
155         QWidget * hbox = new QWidget( this );
156         Q_CHECK_PTR( hbox );
157         hbox->setLayout(layout);
158         QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
159         layout->addWidget(details_button);
160         Q_CHECK_PTR( details_button );
161
162         connect( details_button, SIGNAL( clicked() ),
163                  this,           SLOT  ( detailedPackageSelection() ) );
164
165         //addHStretch( hbox );
166     }
167     else // ! _wizard
168     {
169         layoutButtons( this );
170     }
171 }
172
173
174 void
175 YQSimplePatchSelector::layoutButtons( QWidget * parent )
176 {
177     Q3HBox * button_box = new Q3HBox( parent );
178     Q_CHECK_PTR( button_box );
179     button_box->setMargin ( MARGIN  );
180     button_box->setSpacing( SPACING );
181
182
183     QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
184     Q_CHECK_PTR( details_button );
185     details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
186
187     connect( details_button,    SIGNAL( clicked() ),
188              this,              SLOT  ( detailedPackageSelection() ) );
189
190
191     addHStretch( button_box );
192
193     QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
194     Q_CHECK_PTR( cancel_button );
195     cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
196
197     connect( cancel_button, SIGNAL( clicked() ),
198              this,          SLOT  ( reject()   ) );
199
200
201     QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
202     Q_CHECK_PTR( accept_button );
203     accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
204
205     connect( accept_button, SIGNAL( clicked() ),
206              this,          SLOT  ( accept()   ) );
207
208     button_box->setFixedHeight( button_box->sizeHint().height() );
209 }
210
211
212
213 void
214 YQSimplePatchSelector::makeConnections()
215 {
216     if ( _patchList && _diskUsageList )
217     {
218         connect( _patchList,     SIGNAL( updatePackages()  ),
219                  _diskUsageList, SLOT  ( updateDiskUsage() ) );
220     }
221
222     y2milestone( "Connection set up" );
223
224     if ( _wizard )
225     {
226         connect( _wizard,       SIGNAL( nextClicked()   ),
227                  this,          SLOT  ( accept()        ) );
228
229         connect( _wizard,       SIGNAL( backClicked()   ),
230                  this,          SLOT  ( reject()        ) );
231
232         connect( _wizard,       SIGNAL( abortClicked()  ),
233                  this,          SLOT  ( reject()        ) );
234     }
235 }
236
237
238 void
239 YQSimplePatchSelector::detailedPackageSelection()
240 {
241     y2milestone( "\"Details..\" button clicked" );
242     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
243 }
244
245
246 void
247 YQSimplePatchSelector::debugTrace()
248 {
249     y2warning( "debugTrace" );
250 }
251
252
253
254 #include "YQSimplePatchSelector.moc"