]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgStatusFilterView.cc
- installation summary looks nice
[duncan/yast2-qt4.git] / src / pkg / YQPkgStatusFilterView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgStatusFilterView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <QCheckBox>
22 #include <QLabel>
23 #include <QLayout>
24 #include <QPushButton>
25 #include <QGroupBox>
26 #include <QPixmap>
27
28 #define y2log_component "qt-pkg"
29 #include <ycp/y2log.h>
30
31 #include "YQPkgStatusFilterView.h"
32 #include "YQIconPool.h"
33 #include "YQi18n.h"
34 #include "QY2LayoutUtils.h"
35 #include "utf8.h"
36 #include "YQUI.h"
37
38
39 #define SPACING                 6       // between subwidgets
40 #define MARGIN                  4       // around the widget
41
42
43 YQPkgStatusFilterView::YQPkgStatusFilterView( QWidget * parent )
44     : QWidget( parent )
45 {
46     QVBoxLayout *layout = new QVBoxLayout();
47     setLayout(layout);
48  
49     layout->setMargin( MARGIN );
50     layout->setSpacing( SPACING );
51
52     layout->addStretch();
53
54 #if 0
55     // Headline
56     QLabel * label = new QLabel( _( "Changes Overview" ), this );
57     Q_CHECK_PTR( label );
58     label->setFont( YQUI::ui()->headingFont() );
59 #endif
60
61
62     //
63     // Packages with what status to show
64     //
65
66     QGroupBox * gbox = new QGroupBox( _( "Show packages with status" ), this );
67     Q_CHECK_PTR( gbox );
68
69     QVBoxLayout *box = new QVBoxLayout;
70     gbox->setLayout(box);
71     layout->addWidget(gbox);
72
73     _showDel            = addStatusCheckBox( gbox, _( "Delete" ),       YQIconPool::disabledPkgDel(),           true );
74     _showInstall        = addStatusCheckBox( gbox, _( "Install" ),      YQIconPool::disabledPkgInstall(),       true );
75     _showUpdate         = addStatusCheckBox( gbox, _( "Update" ),       YQIconPool::disabledPkgUpdate(),        true );
76     _showAutoDel        = addStatusCheckBox( gbox, _( "Autodelete" ),   YQIconPool::disabledPkgAutoDel(),       true );
77     _showAutoInstall    = addStatusCheckBox( gbox, _( "Autoinstall" ),  YQIconPool::disabledPkgAutoInstall(),   true );
78     _showAutoUpdate     = addStatusCheckBox( gbox, _( "Autoupdate" ),   YQIconPool::disabledPkgAutoUpdate(),    true );
79     _showTaboo          = addStatusCheckBox( gbox, _( "Taboo" ),        YQIconPool::disabledPkgTaboo(),         true );
80     _showProtected      = addStatusCheckBox( gbox, _( "Protected" ),    YQIconPool::disabledPkgProtected(),     true );
81
82     box->addSpacing( 8 );
83     box->addStretch(); // For the other columns of the QGroupBox ( prevent wraparound )
84     box->addStretch();
85
86     _showKeepInstalled  = addStatusCheckBox( gbox, _( "Keep" ),           YQIconPool::disabledPkgKeepInstalled(), false );
87     _showNoInst         = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(),        false );
88
89     layout->addStretch();
90
91
92     // Box for refresh button
93     QHBoxLayout *hbox = new QHBoxLayout();
94     layout->addLayout(hbox);
95
96     hbox->addStretch();
97
98     // Refresh button
99     _refreshButton = new QPushButton( _( "&Refresh List" ), this );
100     Q_CHECK_PTR( _refreshButton );
101     hbox->addWidget(_refreshButton);
102
103     hbox->addStretch();
104
105     connect( _refreshButton,    SIGNAL( clicked() ),
106              this,              SLOT  ( filter()  ) );
107
108     for ( int i=0; i < 6; i++ )
109         layout->addStretch();
110 }
111
112
113 YQPkgStatusFilterView::~YQPkgStatusFilterView()
114 {
115     // NOP
116 }
117
118
119
120 QCheckBox *
121 YQPkgStatusFilterView::addStatusCheckBox( QWidget *             parent,
122                                           const QString &       text,
123                                           const QPixmap &       icon,
124                                           bool                  initiallyChecked )
125 {
126     QBoxLayout *layout = dynamic_cast<QBoxLayout*>(parent->layout());
127
128     QHBoxLayout *hbox = new QHBoxLayout;
129     layout->addLayout(hbox);
130
131     QCheckBox * checkBox = new QCheckBox( text, parent );
132     Q_CHECK_PTR( checkBox );
133     checkBox->setChecked( initiallyChecked );
134
135     hbox->addWidget(checkBox);
136
137     QLabel * label = new QLabel( parent );
138     Q_CHECK_PTR( label );
139     label->setPixmap( icon );
140
141     hbox->addWidget(label);
142
143     layout->addStretch();
144
145     connect( checkBox,  SIGNAL( clicked() ),
146              this,      SLOT  ( filter()  ) );
147
148     return checkBox;
149 }
150
151
152 QSize
153 YQPkgStatusFilterView::minimumSizeHint() const
154 {
155     return QSize( 0, 0 );
156 }
157
158
159 void
160 YQPkgStatusFilterView::filterIfVisible()
161 {
162     if ( isVisible() )
163         filter();
164 }
165
166
167 void
168 YQPkgStatusFilterView::filter()
169 {
170     emit filterStart();
171
172     for ( ZyppPoolIterator it = zyppPkgBegin();
173           it != zyppPkgEnd();
174           ++it )
175     {
176         ZyppSel selectable = *it;
177
178         bool match =
179             check( selectable, selectable->candidateObj() ) ||
180             check( selectable, selectable->installedObj() );
181
182         // If there is neither an installed nor a candidate package, check
183         // any other instance.
184
185         if ( ! match                      &&
186              ! selectable->candidateObj() &&
187              ! selectable->installedObj()   )
188             check( selectable,  selectable->theObj() );
189     }
190
191     emit filterFinished();
192 }
193
194
195 bool
196 YQPkgStatusFilterView::check( ZyppSel   selectable,
197                               ZyppObj   zyppObj )
198 {
199     bool match = false;
200
201     if ( ! zyppObj )
202         return false;
203
204     switch ( selectable->status() )
205     {
206         case S_AutoDel:         match = _showAutoDel->isChecked();              break;
207         case S_AutoInstall:     match = _showAutoInstall->isChecked();          break;
208         case S_AutoUpdate:      match = _showAutoUpdate->isChecked();           break;
209         case S_Del:             match = _showDel->isChecked();                  break;
210         case S_Install:         match = _showInstall->isChecked();              break;
211         case S_KeepInstalled:   match = _showKeepInstalled->isChecked();        break;
212         case S_NoInst:          match = _showNoInst->isChecked();               break;
213         case S_Protected:       match = _showProtected->isChecked();            break;
214         case S_Taboo:           match = _showTaboo->isChecked();                break;
215         case S_Update:          match = _showUpdate->isChecked();               break;
216
217             // Intentionally omitting 'default' branch so the compiler can
218             // catch unhandled enum states
219     }
220
221     if ( match )
222     {
223         ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
224
225         if ( zyppPkg )
226             emit filterMatch( selectable, zyppPkg );
227     }
228
229     return match;
230 }
231
232
233
234 void YQPkgStatusFilterView::clear()
235 {
236     _showDel->setChecked( false );
237     _showInstall->setChecked( false );
238     _showUpdate->setChecked( false );
239     _showAutoDel->setChecked( false );
240     _showAutoInstall->setChecked( false );
241     _showAutoUpdate->setChecked( false );
242     _showTaboo->setChecked( false );
243     _showProtected->setChecked( false );
244     _showKeepInstalled->setChecked( false );
245     _showNoInst->setChecked( false );
246 }
247
248
249 void YQPkgStatusFilterView::showTransactions()
250 {
251     showManualTransactions();
252     showAutoTransactions();
253 }
254
255
256 void YQPkgStatusFilterView::showManualTransactions()
257 {
258     _showDel->setChecked( true );
259     _showInstall->setChecked( true );
260     _showUpdate->setChecked( true );
261 }
262
263
264 void YQPkgStatusFilterView::showAutoTransactions()
265 {
266     _showAutoDel->setChecked( true );
267     _showAutoInstall->setChecked( true );
268     _showAutoUpdate->setChecked( true );
269 }
270
271
272 void YQPkgStatusFilterView::showLocks()
273 {
274     _showTaboo->setChecked( true );
275     _showProtected->setChecked( true );
276 }
277
278
279 void YQPkgStatusFilterView::showInstalled()
280 {
281     _showKeepInstalled->setChecked( true );
282 }
283
284
285 void YQPkgStatusFilterView::showNotInstalled()
286 {
287     _showNoInst->setChecked( true );
288 }
289
290
291
292 #include "YQPkgStatusFilterView.moc"