libyui-qt-pkg  2.45.6
 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  : QScrollArea( parent )
66 {
67  QWidget * content = new QWidget;
68  QVBoxLayout *layout = new QVBoxLayout();
69  content->setLayout(layout);
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" ), content );
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" ), content );
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  setWidgetResizable(true);
133  setWidget(content);
134 }
135 
136 
138 {
139  // NOP
140 }
141 
142 
143 
144 QCheckBox *
146  const QString & text,
147  const QPixmap & icon,
148  bool initiallyChecked )
149 {
150  QBoxLayout *layout = dynamic_cast<QBoxLayout*>(parent->layout());
151 
152  QHBoxLayout *hbox = new QHBoxLayout;
153  layout->addLayout(hbox);
154 
155  QCheckBox * checkBox = new QCheckBox( text, parent );
156  Q_CHECK_PTR( checkBox );
157  checkBox->setChecked( initiallyChecked );
158 
159  hbox->addWidget(checkBox);
160 
161  QLabel * label = new QLabel( parent );
162  Q_CHECK_PTR( label );
163  label->setPixmap( icon );
164 
165  hbox->addWidget(label);
166 
167  layout->addStretch();
168 
169  connect( checkBox, SIGNAL( clicked() ),
170  this, SLOT ( filter() ) );
171 
172  return checkBox;
173 }
174 
175 
176 QSize
178 {
179  return QSize( 0, 0 );
180 }
181 
182 
183 void
185 {
186  if ( isVisible() )
187  filter();
188 }
189 
190 
191 void
193 {
194  emit filterStart();
195 
196  for ( ZyppPoolIterator it = zyppPkgBegin();
197  it != zyppPkgEnd();
198  ++it )
199  {
200  ZyppSel selectable = *it;
201 
202  bool match =
203  check( selectable, selectable->candidateObj() ) ||
204  check( selectable, selectable->installedObj() );
205 
206  // If there is neither an installed nor a candidate package, check
207  // any other instance.
208 
209  if ( ! match &&
210  ! selectable->candidateObj() &&
211  ! selectable->installedObj() )
212  check( selectable, selectable->theObj() );
213  }
214 
215  emit filterFinished();
216 }
217 
218 
219 bool
220 YQPkgStatusFilterView::check( ZyppSel selectable,
221  ZyppObj zyppObj )
222 {
223  bool match = false;
224 
225  if ( ! zyppObj )
226  return false;
227 
228  switch ( selectable->status() )
229  {
230  case S_AutoDel: match = _showAutoDel->isChecked(); break;
231  case S_AutoInstall: match = _showAutoInstall->isChecked(); break;
232  case S_AutoUpdate: match = _showAutoUpdate->isChecked(); break;
233  case S_Del: match = _showDel->isChecked(); break;
234  case S_Install: match = _showInstall->isChecked(); break;
235  case S_KeepInstalled: match = _showKeepInstalled->isChecked(); break;
236  case S_NoInst: match = _showNoInst->isChecked(); break;
237  case S_Protected: match = _showProtected->isChecked(); break;
238  case S_Taboo: match = _showTaboo->isChecked(); break;
239  case S_Update: match = _showUpdate->isChecked(); break;
240 
241  // Intentionally omitting 'default' branch so the compiler can
242  // catch unhandled enum states
243  }
244 
245  if ( match )
246  {
247  ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
248 
249  if ( zyppPkg )
250  emit filterMatch( selectable, zyppPkg );
251  }
252 
253  return match;
254 }
255 
256 
257 
259 {
260  _showDel->setChecked( false );
261  _showInstall->setChecked( false );
262  _showUpdate->setChecked( false );
263  _showAutoDel->setChecked( false );
264  _showAutoInstall->setChecked( false );
265  _showAutoUpdate->setChecked( false );
266  _showTaboo->setChecked( false );
267  _showProtected->setChecked( false );
268  _showKeepInstalled->setChecked( false );
269  _showNoInst->setChecked( false );
270 }
271 
272 
274 {
277 }
278 
279 
281 {
282  _showDel->setChecked( true );
283  _showInstall->setChecked( true );
284  _showUpdate->setChecked( true );
285 }
286 
287 
289 {
290  _showAutoDel->setChecked( true );
291  _showAutoInstall->setChecked( true );
292  _showAutoUpdate->setChecked( true );
293 }
294 
295 
297 {
298  _showTaboo->setChecked( true );
299  _showProtected->setChecked( true );
300 }
301 
302 
304 {
305  _showKeepInstalled->setChecked( true );
306 }
307 
308 
310 {
311  _showNoInst->setChecked( true );
312 }
313 
314 
315 
316 #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.