1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgStatusFilterView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #include <qcheckbox.h>
24 #include <qpushbutton.h>
25 #include <q3groupbox.h>
29 #define y2log_component "qt-pkg"
30 #include <ycp/y2log.h>
32 #include "YQPkgStatusFilterView.h"
33 #include "YQIconPool.h"
35 #include "QY2LayoutUtils.h"
40 #define SPACING 6 // between subwidgets
41 #define MARGIN 4 // around the widget
44 YQPkgStatusFilterView::YQPkgStatusFilterView( QWidget * parent )
48 setSpacing( SPACING );
54 QLabel * label = new QLabel( _( "Changes Overview" ), this );
56 label->setFont( YQUI::ui()->headingFont() );
61 // Packages with what status to show
64 Q3GroupBox * gbox = new Q3GroupBox( 3, Qt::Horizontal, _( "Show packages with status" ), this );
67 _showDel = addStatusCheckBox( gbox, _( "Delete" ), YQIconPool::disabledPkgDel(), true );
68 _showInstall = addStatusCheckBox( gbox, _( "Install" ), YQIconPool::disabledPkgInstall(), true );
69 _showUpdate = addStatusCheckBox( gbox, _( "Update" ), YQIconPool::disabledPkgUpdate(), true );
70 _showAutoDel = addStatusCheckBox( gbox, _( "Autodelete" ), YQIconPool::disabledPkgAutoDel(), true );
71 _showAutoInstall = addStatusCheckBox( gbox, _( "Autoinstall" ), YQIconPool::disabledPkgAutoInstall(), true );
72 _showAutoUpdate = addStatusCheckBox( gbox, _( "Autoupdate" ), YQIconPool::disabledPkgAutoUpdate(), true );
73 _showTaboo = addStatusCheckBox( gbox, _( "Taboo" ), YQIconPool::disabledPkgTaboo(), true );
74 _showProtected = addStatusCheckBox( gbox, _( "Protected" ), YQIconPool::disabledPkgProtected(), true );
76 addVSpacing( gbox, 8 );
77 addHStretch( gbox ); // For the other columns of the QGroupBox ( prevent wraparound )
80 _showKeepInstalled = addStatusCheckBox( gbox, _( "Keep" ), YQIconPool::disabledPkgKeepInstalled(), false );
81 _showNoInst = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(), false );
86 // Box for refresh button
87 Q3HBox * hbox = new Q3HBox( this );
93 _refreshButton = new QPushButton( _( "&Refresh List" ), hbox );
94 Q_CHECK_PTR( _refreshButton );
97 connect( _refreshButton, SIGNAL( clicked() ),
98 this, SLOT ( filter() ) );
100 for ( int i=0; i < 6; i++ )
105 YQPkgStatusFilterView::~YQPkgStatusFilterView()
113 YQPkgStatusFilterView::addStatusCheckBox( QWidget * parent,
114 const QString & text,
115 const QPixmap & icon,
116 bool initiallyChecked )
118 QCheckBox * checkBox = new QCheckBox( text, parent );
119 Q_CHECK_PTR( checkBox );
120 checkBox->setChecked( initiallyChecked );
122 QLabel * label = new QLabel( parent );
123 Q_CHECK_PTR( label );
124 label->setPixmap( icon );
126 addHStretch( parent );
128 connect( checkBox, SIGNAL( clicked() ),
129 this, SLOT ( filter() ) );
136 YQPkgStatusFilterView::minimumSizeHint() const
138 return QSize( 0, 0 );
143 YQPkgStatusFilterView::filterIfVisible()
151 YQPkgStatusFilterView::filter()
155 for ( ZyppPoolIterator it = zyppPkgBegin();
159 ZyppSel selectable = *it;
162 check( selectable, selectable->candidateObj() ) ||
163 check( selectable, selectable->installedObj() );
165 // If there is neither an installed nor a candidate package, check
166 // any other instance.
169 ! selectable->candidateObj() &&
170 ! selectable->installedObj() )
171 check( selectable, selectable->theObj() );
174 emit filterFinished();
179 YQPkgStatusFilterView::check( ZyppSel selectable,
187 switch ( selectable->status() )
189 case S_AutoDel: match = _showAutoDel->isChecked(); break;
190 case S_AutoInstall: match = _showAutoInstall->isChecked(); break;
191 case S_AutoUpdate: match = _showAutoUpdate->isChecked(); break;
192 case S_Del: match = _showDel->isChecked(); break;
193 case S_Install: match = _showInstall->isChecked(); break;
194 case S_KeepInstalled: match = _showKeepInstalled->isChecked(); break;
195 case S_NoInst: match = _showNoInst->isChecked(); break;
196 case S_Protected: match = _showProtected->isChecked(); break;
197 case S_Taboo: match = _showTaboo->isChecked(); break;
198 case S_Update: match = _showUpdate->isChecked(); break;
200 // Intentionally omitting 'default' branch so the compiler can
201 // catch unhandled enum states
206 ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
209 emit filterMatch( selectable, zyppPkg );
217 void YQPkgStatusFilterView::clear()
219 _showDel->setChecked( false );
220 _showInstall->setChecked( false );
221 _showUpdate->setChecked( false );
222 _showAutoDel->setChecked( false );
223 _showAutoInstall->setChecked( false );
224 _showAutoUpdate->setChecked( false );
225 _showTaboo->setChecked( false );
226 _showProtected->setChecked( false );
227 _showKeepInstalled->setChecked( false );
228 _showNoInst->setChecked( false );
232 void YQPkgStatusFilterView::showTransactions()
234 showManualTransactions();
235 showAutoTransactions();
239 void YQPkgStatusFilterView::showManualTransactions()
241 _showDel->setChecked( true );
242 _showInstall->setChecked( true );
243 _showUpdate->setChecked( true );
247 void YQPkgStatusFilterView::showAutoTransactions()
249 _showAutoDel->setChecked( true );
250 _showAutoInstall->setChecked( true );
251 _showAutoUpdate->setChecked( true );
255 void YQPkgStatusFilterView::showLocks()
257 _showTaboo->setChecked( true );
258 _showProtected->setChecked( true );
262 void YQPkgStatusFilterView::showInstalled()
264 _showKeepInstalled->setChecked( true );
268 void YQPkgStatusFilterView::showNotInstalled()
270 _showNoInst->setChecked( true );
275 #include "YQPkgStatusFilterView.moc"