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(this);
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 );
68 QHBoxLayout *hlayout = new QHBoxLayout;
69 gbox->setLayout(hlayout);
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 );
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);
89 hlayout->addSpacing( 8 );
90 hlayout->addStretch(); // For the other columns of the QGroupBox ( prevent wraparound )
91 hlayout->addStretch();
93 _showKeepInstalled = addStatusCheckBox( gbox, _( "Keep" ), YQIconPool::disabledPkgKeepInstalled(), false );
94 _showNoInst = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(), false );
99 // Box for refresh button
100 hlayout = new QHBoxLayout();
101 layout->addLayout(hlayout);
103 hlayout->addStretch();
106 _refreshButton = new QPushButton( _( "&Refresh List" ), this );
107 Q_CHECK_PTR( _refreshButton );
108 hlayout->addWidget(_refreshButton);
110 hlayout->addStretch();
112 connect( _refreshButton, SIGNAL( clicked() ),
113 this, SLOT ( filter() ) );
115 for ( int i=0; i < 6; i++ )
116 layout->addStretch();
120 YQPkgStatusFilterView::~YQPkgStatusFilterView()
128 YQPkgStatusFilterView::addStatusCheckBox( QWidget * parent,
129 const QString & text,
130 const QPixmap & icon,
131 bool initiallyChecked )
133 QCheckBox * checkBox = new QCheckBox( text, parent );
134 Q_CHECK_PTR( checkBox );
135 checkBox->setChecked( initiallyChecked );
137 QLabel * label = new QLabel( parent );
138 Q_CHECK_PTR( label );
139 label->setPixmap( icon );
141 addHStretch( parent );
143 connect( checkBox, SIGNAL( clicked() ),
144 this, SLOT ( filter() ) );
151 YQPkgStatusFilterView::minimumSizeHint() const
153 return QSize( 0, 0 );
158 YQPkgStatusFilterView::filterIfVisible()
166 YQPkgStatusFilterView::filter()
170 for ( ZyppPoolIterator it = zyppPkgBegin();
174 ZyppSel selectable = *it;
177 check( selectable, selectable->candidateObj() ) ||
178 check( selectable, selectable->installedObj() );
180 // If there is neither an installed nor a candidate package, check
181 // any other instance.
184 ! selectable->candidateObj() &&
185 ! selectable->installedObj() )
186 check( selectable, selectable->theObj() );
189 emit filterFinished();
194 YQPkgStatusFilterView::check( ZyppSel selectable,
202 switch ( selectable->status() )
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;
215 // Intentionally omitting 'default' branch so the compiler can
216 // catch unhandled enum states
221 ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
224 emit filterMatch( selectable, zyppPkg );
232 void YQPkgStatusFilterView::clear()
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 );
247 void YQPkgStatusFilterView::showTransactions()
249 showManualTransactions();
250 showAutoTransactions();
254 void YQPkgStatusFilterView::showManualTransactions()
256 _showDel->setChecked( true );
257 _showInstall->setChecked( true );
258 _showUpdate->setChecked( true );
262 void YQPkgStatusFilterView::showAutoTransactions()
264 _showAutoDel->setChecked( true );
265 _showAutoInstall->setChecked( true );
266 _showAutoUpdate->setChecked( true );
270 void YQPkgStatusFilterView::showLocks()
272 _showTaboo->setChecked( true );
273 _showProtected->setChecked( true );
277 void YQPkgStatusFilterView::showInstalled()
279 _showKeepInstalled->setChecked( true );
283 void YQPkgStatusFilterView::showNotInstalled()
285 _showNoInst->setChecked( true );
290 #include "YQPkgStatusFilterView.moc"