libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgStatusFilterView.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgStatusFilterView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #include <QCheckBox>
43 #include <QLabel>
44 #include <QLayout>
45 #include <QPushButton>
46 #include <QGroupBox>
47 #include <QPixmap>
48 
49 #define YUILogComponent "qt-pkg"
50 #include "YUILog.h"
51 
52 #include "YQPkgStatusFilterView.h"
53 #include "YQIconPool.h"
54 #include "YQi18n.h"
55 #include "QY2LayoutUtils.h"
56 #include "utf8.h"
57 #include "YQUI.h"
58 
59 
60 #define SPACING 6 // between subwidgets
61 #define MARGIN 4 // around the widget
62 
63 
65  : QWidget( parent )
66 {
67  QVBoxLayout *layout = new QVBoxLayout();
68  setLayout(layout);
69 
70  layout->setMargin( MARGIN );
71  layout->setSpacing( SPACING );
72 
73  layout->addStretch();
74 
75 #if 0
76  // Headline
77  QLabel * label = new QLabel( _( "Changes Overview" ), this );
78  Q_CHECK_PTR( label );
79  label->setFont( YQUI::ui()->headingFont() );
80 #endif
81 
82 
83  //
84  // Packages with what status to show
85  //
86 
87  QGroupBox * gbox = new QGroupBox( _( "Show packages with status" ), this );
88  Q_CHECK_PTR( gbox );
89 
90  QVBoxLayout *box = new QVBoxLayout;
91  gbox->setLayout(box);
92  layout->addWidget(gbox);
93 
94  _showDel = addStatusCheckBox( gbox, _( "Delete" ), YQIconPool::disabledPkgDel(), true );
95  _showInstall = addStatusCheckBox( gbox, _( "Install" ), YQIconPool::disabledPkgInstall(), true );
96  _showUpdate = addStatusCheckBox( gbox, _( "Update" ), YQIconPool::disabledPkgUpdate(), true );
97  _showAutoDel = addStatusCheckBox( gbox, _( "Autodelete" ), YQIconPool::disabledPkgAutoDel(), true );
98  _showAutoInstall = addStatusCheckBox( gbox, _( "Autoinstall" ), YQIconPool::disabledPkgAutoInstall(), true );
99  _showAutoUpdate = addStatusCheckBox( gbox, _( "Autoupdate" ), YQIconPool::disabledPkgAutoUpdate(), true );
100  _showTaboo = addStatusCheckBox( gbox, _( "Taboo" ), YQIconPool::disabledPkgTaboo(), true );
101  _showProtected = addStatusCheckBox( gbox, _( "Protected" ), YQIconPool::disabledPkgProtected(), true );
102 
103  box->addSpacing( 8 );
104  box->addStretch(); // For the other columns of the QGroupBox ( prevent wraparound )
105  box->addStretch();
106 
107  _showKeepInstalled = addStatusCheckBox( gbox, _( "Keep" ), YQIconPool::disabledPkgKeepInstalled(), false );
108  _showNoInst = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(), false );
109 
110  layout->addStretch();
111 
112 
113  // Box for refresh button
114  QHBoxLayout *hbox = new QHBoxLayout();
115  layout->addLayout(hbox);
116 
117  hbox->addStretch();
118 
119  // Refresh button
120  _refreshButton = new QPushButton( _( "&Refresh List" ), this );
121  Q_CHECK_PTR( _refreshButton );
122  hbox->addWidget(_refreshButton);
123 
124  hbox->addStretch();
125 
126  connect( _refreshButton, SIGNAL( clicked() ),
127  this, SLOT ( filter() ) );
128 
129  for ( int i=0; i < 6; i++ )
130  layout->addStretch();
131 }
132 
133 
135 {
136  // NOP
137 }
138 
139 
140 
141 QCheckBox *
143  const QString & text,
144  const QPixmap & icon,
145  bool initiallyChecked )
146 {
147  QBoxLayout *layout = dynamic_cast<QBoxLayout*>(parent->layout());
148 
149  QHBoxLayout *hbox = new QHBoxLayout;
150  layout->addLayout(hbox);
151 
152  QCheckBox * checkBox = new QCheckBox( text, parent );
153  Q_CHECK_PTR( checkBox );
154  checkBox->setChecked( initiallyChecked );
155 
156  hbox->addWidget(checkBox);
157 
158  QLabel * label = new QLabel( parent );
159  Q_CHECK_PTR( label );
160  label->setPixmap( icon );
161 
162  hbox->addWidget(label);
163 
164  layout->addStretch();
165 
166  connect( checkBox, SIGNAL( clicked() ),
167  this, SLOT ( filter() ) );
168 
169  return checkBox;
170 }
171 
172 
173 QSize
175 {
176  return QSize( 0, 0 );
177 }
178 
179 
180 void
182 {
183  if ( isVisible() )
184  filter();
185 }
186 
187 
188 void
190 {
191  emit filterStart();
192 
193  for ( ZyppPoolIterator it = zyppPkgBegin();
194  it != zyppPkgEnd();
195  ++it )
196  {
197  ZyppSel selectable = *it;
198 
199  bool match =
200  check( selectable, selectable->candidateObj() ) ||
201  check( selectable, selectable->installedObj() );
202 
203  // If there is neither an installed nor a candidate package, check
204  // any other instance.
205 
206  if ( ! match &&
207  ! selectable->candidateObj() &&
208  ! selectable->installedObj() )
209  check( selectable, selectable->theObj() );
210  }
211 
212  emit filterFinished();
213 }
214 
215 
216 bool
217 YQPkgStatusFilterView::check( ZyppSel selectable,
218  ZyppObj zyppObj )
219 {
220  bool match = false;
221 
222  if ( ! zyppObj )
223  return false;
224 
225  switch ( selectable->status() )
226  {
227  case S_AutoDel: match = _showAutoDel->isChecked(); break;
228  case S_AutoInstall: match = _showAutoInstall->isChecked(); break;
229  case S_AutoUpdate: match = _showAutoUpdate->isChecked(); break;
230  case S_Del: match = _showDel->isChecked(); break;
231  case S_Install: match = _showInstall->isChecked(); break;
232  case S_KeepInstalled: match = _showKeepInstalled->isChecked(); break;
233  case S_NoInst: match = _showNoInst->isChecked(); break;
234  case S_Protected: match = _showProtected->isChecked(); break;
235  case S_Taboo: match = _showTaboo->isChecked(); break;
236  case S_Update: match = _showUpdate->isChecked(); break;
237 
238  // Intentionally omitting 'default' branch so the compiler can
239  // catch unhandled enum states
240  }
241 
242  if ( match )
243  {
244  ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
245 
246  if ( zyppPkg )
247  emit filterMatch( selectable, zyppPkg );
248  }
249 
250  return match;
251 }
252 
253 
254 
256 {
257  _showDel->setChecked( false );
258  _showInstall->setChecked( false );
259  _showUpdate->setChecked( false );
260  _showAutoDel->setChecked( false );
261  _showAutoInstall->setChecked( false );
262  _showAutoUpdate->setChecked( false );
263  _showTaboo->setChecked( false );
264  _showProtected->setChecked( false );
265  _showKeepInstalled->setChecked( false );
266  _showNoInst->setChecked( false );
267 }
268 
269 
271 {
274 }
275 
276 
278 {
279  _showDel->setChecked( true );
280  _showInstall->setChecked( true );
281  _showUpdate->setChecked( true );
282 }
283 
284 
286 {
287  _showAutoDel->setChecked( true );
288  _showAutoInstall->setChecked( true );
289  _showAutoUpdate->setChecked( true );
290 }
291 
292 
294 {
295  _showTaboo->setChecked( true );
296  _showProtected->setChecked( true );
297 }
298 
299 
301 {
302  _showKeepInstalled->setChecked( true );
303 }
304 
305 
307 {
308  _showNoInst->setChecked( true );
309 }
310 
311 
312 
313 #include "YQPkgStatusFilterView.moc"
void filterStart()
Emitted when the filtering starts.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
void filterFinished()
Emitted when filtering is finished.
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
QCheckBox * addStatusCheckBox(QWidget *parent, const QString &label, const QPixmap &icon, bool initiallyChecked)
Add a check box.
virtual ~YQPkgStatusFilterView()
Destructor.
void showManualTransactions()
Set up the check boxes so pending manual transactions (no "auto" states) are displayed.
void showLocks()
Set the check boxes for locked packages ("Taboo" and "Protected") to "on".
void showInstalled()
Set the check box for installed packages to "on".
void showAutoTransactions()
Set up the check boxes so pending automatic transactions (the "auto" states) are displayed.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
void clear()
Reset all check boxes (set them all to "off")
void showTransactions()
Set up the check boxes so all pending transactions are displayed.
YQPkgStatusFilterView(QWidget *parent)
Constructor.
void filter()
Filter according to the view's rules and current selection.
void showNotInstalled()
Set the check box for not installed packages to "on".
bool check(ZyppSel selectable, ZyppObj pkg)
Check if pkg matches the filter criteria.