1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgStatusFilterView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
24 #include <QPushButton>
28 #define y2log_component "qt-pkg"
29 #include <ycp/y2log.h>
31 #include "YQPkgStatusFilterView.h"
32 #include "YQIconPool.h"
34 #include "QY2LayoutUtils.h"
39 #define SPACING 6 // between subwidgets
40 #define MARGIN 4 // around the widget
43 YQPkgStatusFilterView::YQPkgStatusFilterView( QWidget * parent )
46 QVBoxLayout *layout = new QVBoxLayout();
49 layout->setMargin( MARGIN );
50 layout->setSpacing( SPACING );
56 QLabel * label = new QLabel( _( "Changes Overview" ), this );
58 label->setFont( YQUI::ui()->headingFont() );
63 // Packages with what status to show
66 QGroupBox * gbox = new QGroupBox( _( "Show packages with status" ), this );
69 QVBoxLayout *box = new QVBoxLayout;
71 layout->addWidget(gbox);
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 );
83 box->addStretch(); // For the other columns of the QGroupBox ( prevent wraparound )
86 _showKeepInstalled = addStatusCheckBox( gbox, _( "Keep" ), YQIconPool::disabledPkgKeepInstalled(), false );
87 _showNoInst = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(), false );
92 // Box for refresh button
93 QHBoxLayout *hbox = new QHBoxLayout();
94 layout->addLayout(hbox);
99 _refreshButton = new QPushButton( _( "&Refresh List" ), this );
100 Q_CHECK_PTR( _refreshButton );
101 hbox->addWidget(_refreshButton);
105 connect( _refreshButton, SIGNAL( clicked() ),
106 this, SLOT ( filter() ) );
108 for ( int i=0; i < 6; i++ )
109 layout->addStretch();
113 YQPkgStatusFilterView::~YQPkgStatusFilterView()
121 YQPkgStatusFilterView::addStatusCheckBox( QWidget * parent,
122 const QString & text,
123 const QPixmap & icon,
124 bool initiallyChecked )
126 QBoxLayout *layout = dynamic_cast<QBoxLayout*>(parent->layout());
128 QHBoxLayout *hbox = new QHBoxLayout;
129 layout->addLayout(hbox);
131 QCheckBox * checkBox = new QCheckBox( text, parent );
132 Q_CHECK_PTR( checkBox );
133 checkBox->setChecked( initiallyChecked );
135 hbox->addWidget(checkBox);
137 QLabel * label = new QLabel( parent );
138 Q_CHECK_PTR( label );
139 label->setPixmap( icon );
141 hbox->addWidget(label);
143 layout->addStretch();
145 connect( checkBox, SIGNAL( clicked() ),
146 this, SLOT ( filter() ) );
153 YQPkgStatusFilterView::minimumSizeHint() const
155 return QSize( 0, 0 );
160 YQPkgStatusFilterView::filterIfVisible()
168 YQPkgStatusFilterView::filter()
172 for ( ZyppPoolIterator it = zyppPkgBegin();
176 ZyppSel selectable = *it;
179 check( selectable, selectable->candidateObj() ) ||
180 check( selectable, selectable->installedObj() );
182 // If there is neither an installed nor a candidate package, check
183 // any other instance.
186 ! selectable->candidateObj() &&
187 ! selectable->installedObj() )
188 check( selectable, selectable->theObj() );
191 emit filterFinished();
196 YQPkgStatusFilterView::check( ZyppSel selectable,
204 switch ( selectable->status() )
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;
217 // Intentionally omitting 'default' branch so the compiler can
218 // catch unhandled enum states
223 ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
226 emit filterMatch( selectable, zyppPkg );
234 void YQPkgStatusFilterView::clear()
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 );
249 void YQPkgStatusFilterView::showTransactions()
251 showManualTransactions();
252 showAutoTransactions();
256 void YQPkgStatusFilterView::showManualTransactions()
258 _showDel->setChecked( true );
259 _showInstall->setChecked( true );
260 _showUpdate->setChecked( true );
264 void YQPkgStatusFilterView::showAutoTransactions()
266 _showAutoDel->setChecked( true );
267 _showAutoInstall->setChecked( true );
268 _showAutoUpdate->setChecked( true );
272 void YQPkgStatusFilterView::showLocks()
274 _showTaboo->setChecked( true );
275 _showProtected->setChecked( true );
279 void YQPkgStatusFilterView::showInstalled()
281 _showKeepInstalled->setChecked( true );
285 void YQPkgStatusFilterView::showNotInstalled()
287 _showNoInst->setChecked( true );
292 #include "YQPkgStatusFilterView.moc"