]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgStatusFilterView.cc
1fa314c97fec45c72fcc3bfbc910c70ad7c61a27
[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     QHBoxLayout *hlayout = new QHBoxLayout;
69     gbox->setLayout(hlayout);
70
71     _showDel            = addStatusCheckBox( gbox, _( "Delete" ),       YQIconPool::disabledPkgDel(),           true );
72     _showInstall        = addStatusCheckBox( gbox, _( "Install" ),      YQIconPool::disabledPkgInstall(),       true );
73     _showUpdate         = addStatusCheckBox( gbox, _( "Update" ),       YQIconPool::disabledPkgUpdate(),        true );
74     _showAutoDel        = addStatusCheckBox( gbox, _( "Autodelete" ),   YQIconPool::disabledPkgAutoDel(),       true );
75     _showAutoInstall    = addStatusCheckBox( gbox, _( "Autoinstall" ),  YQIconPool::disabledPkgAutoInstall(),   true );
76     _showAutoUpdate     = addStatusCheckBox( gbox, _( "Autoupdate" ),   YQIconPool::disabledPkgAutoUpdate(),    true );
77     _showTaboo          = addStatusCheckBox( gbox, _( "Taboo" ),        YQIconPool::disabledPkgTaboo(),         true );
78     _showProtected      = addStatusCheckBox( gbox, _( "Protected" ),    YQIconPool::disabledPkgProtected(),     true );
79
80     hlayout->addWidget(_showDel);
81     hlayout->addWidget(_showInstall);
82     hlayout->addWidget(_showUpdate);
83     hlayout->addWidget(_showAutoDel);
84     hlayout->addWidget(_showAutoInstall);
85     hlayout->addWidget(_showAutoUpdate);
86     hlayout->addWidget(_showTaboo);
87     hlayout->addWidget(_showProtected);
88
89     hlayout->addSpacing( 8 );
90     hlayout->addStretch(); // For the other columns of the QGroupBox ( prevent wraparound )
91     hlayout->addStretch();
92
93     _showKeepInstalled  = addStatusCheckBox( gbox, _( "Keep" ),           YQIconPool::disabledPkgKeepInstalled(), false );
94     _showNoInst         = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(),        false );
95
96     layout->addStretch();
97
98
99     // Box for refresh button
100     hlayout = new QHBoxLayout();
101     layout->addLayout(hlayout);
102
103     hlayout->addStretch();
104
105     // Refresh button
106     _refreshButton = new QPushButton( _( "&Refresh List" ), this );
107     Q_CHECK_PTR( _refreshButton );
108     hlayout->addWidget(_refreshButton);
109
110     hlayout->addStretch();
111
112     connect( _refreshButton,    SIGNAL( clicked() ),
113              this,              SLOT  ( filter()  ) );
114
115     for ( int i=0; i < 6; i++ )
116         layout->addStretch();
117 }
118
119
120 YQPkgStatusFilterView::~YQPkgStatusFilterView()
121 {
122     // NOP
123 }
124
125
126
127 QCheckBox *
128 YQPkgStatusFilterView::addStatusCheckBox( QWidget *             parent,
129                                           const QString &       text,
130                                           const QPixmap &       icon,
131                                           bool                  initiallyChecked )
132 {
133     QCheckBox * checkBox = new QCheckBox( text, parent );
134     Q_CHECK_PTR( checkBox );
135     checkBox->setChecked( initiallyChecked );
136
137     QLabel * label = new QLabel( parent );
138     Q_CHECK_PTR( label );
139     label->setPixmap( icon );
140
141     addHStretch( parent );
142
143     connect( checkBox,  SIGNAL( clicked() ),
144              this,      SLOT  ( filter()  ) );
145
146     return checkBox;
147 }
148
149
150 QSize
151 YQPkgStatusFilterView::minimumSizeHint() const
152 {
153     return QSize( 0, 0 );
154 }
155
156
157 void
158 YQPkgStatusFilterView::filterIfVisible()
159 {
160     if ( isVisible() )
161         filter();
162 }
163
164
165 void
166 YQPkgStatusFilterView::filter()
167 {
168     emit filterStart();
169
170     for ( ZyppPoolIterator it = zyppPkgBegin();
171           it != zyppPkgEnd();
172           ++it )
173     {
174         ZyppSel selectable = *it;
175
176         bool match =
177             check( selectable, selectable->candidateObj() ) ||
178             check( selectable, selectable->installedObj() );
179
180         // If there is neither an installed nor a candidate package, check
181         // any other instance.
182
183         if ( ! match                      &&
184              ! selectable->candidateObj() &&
185              ! selectable->installedObj()   )
186             check( selectable,  selectable->theObj() );
187     }
188
189     emit filterFinished();
190 }
191
192
193 bool
194 YQPkgStatusFilterView::check( ZyppSel   selectable,
195                               ZyppObj   zyppObj )
196 {
197     bool match = false;
198
199     if ( ! zyppObj )
200         return false;
201
202     switch ( selectable->status() )
203     {
204         case S_AutoDel:         match = _showAutoDel->isChecked();              break;
205         case S_AutoInstall:     match = _showAutoInstall->isChecked();          break;
206         case S_AutoUpdate:      match = _showAutoUpdate->isChecked();           break;
207         case S_Del:             match = _showDel->isChecked();                  break;
208         case S_Install:         match = _showInstall->isChecked();              break;
209         case S_KeepInstalled:   match = _showKeepInstalled->isChecked();        break;
210         case S_NoInst:          match = _showNoInst->isChecked();               break;
211         case S_Protected:       match = _showProtected->isChecked();            break;
212         case S_Taboo:           match = _showTaboo->isChecked();                break;
213         case S_Update:          match = _showUpdate->isChecked();               break;
214
215             // Intentionally omitting 'default' branch so the compiler can
216             // catch unhandled enum states
217     }
218
219     if ( match )
220     {
221         ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
222
223         if ( zyppPkg )
224             emit filterMatch( selectable, zyppPkg );
225     }
226
227     return match;
228 }
229
230
231
232 void YQPkgStatusFilterView::clear()
233 {
234     _showDel->setChecked( false );
235     _showInstall->setChecked( false );
236     _showUpdate->setChecked( false );
237     _showAutoDel->setChecked( false );
238     _showAutoInstall->setChecked( false );
239     _showAutoUpdate->setChecked( false );
240     _showTaboo->setChecked( false );
241     _showProtected->setChecked( false );
242     _showKeepInstalled->setChecked( false );
243     _showNoInst->setChecked( false );
244 }
245
246
247 void YQPkgStatusFilterView::showTransactions()
248 {
249     showManualTransactions();
250     showAutoTransactions();
251 }
252
253
254 void YQPkgStatusFilterView::showManualTransactions()
255 {
256     _showDel->setChecked( true );
257     _showInstall->setChecked( true );
258     _showUpdate->setChecked( true );
259 }
260
261
262 void YQPkgStatusFilterView::showAutoTransactions()
263 {
264     _showAutoDel->setChecked( true );
265     _showAutoInstall->setChecked( true );
266     _showAutoUpdate->setChecked( true );
267 }
268
269
270 void YQPkgStatusFilterView::showLocks()
271 {
272     _showTaboo->setChecked( true );
273     _showProtected->setChecked( true );
274 }
275
276
277 void YQPkgStatusFilterView::showInstalled()
278 {
279     _showKeepInstalled->setChecked( true );
280 }
281
282
283 void YQPkgStatusFilterView::showNotInstalled()
284 {
285     _showNoInst->setChecked( true );
286 }
287
288
289
290 #include "YQPkgStatusFilterView.moc"