]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgStatusFilterView.cc
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / pkg / YQPkgStatusFilterView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgStatusFilterView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <qcheckbox.h>
22 #include <qlabel.h>
23 #include <qlayout.h>
24 #include <qpushbutton.h>
25 #include <q3groupbox.h>
26 //Added by qt3to4:
27 #include <qpixmap.h>
28
29 #define y2log_component "qt-pkg"
30 #include <ycp/y2log.h>
31
32 #include "YQPkgStatusFilterView.h"
33 #include "YQIconPool.h"
34 #include "YQi18n.h"
35 #include "QY2LayoutUtils.h"
36 #include "utf8.h"
37 #include "YQUI.h"
38
39
40 #define SPACING                 6       // between subwidgets
41 #define MARGIN                  4       // around the widget
42
43
44 YQPkgStatusFilterView::YQPkgStatusFilterView( QWidget * parent )
45     : Q3VBox( parent )
46 {
47     setMargin( MARGIN );
48     setSpacing( SPACING );
49
50     addVStretch( this );
51
52 #if 0
53     // Headline
54     QLabel * label = new QLabel( _( "Changes Overview" ), this );
55     Q_CHECK_PTR( label );
56     label->setFont( YQUI::ui()->headingFont() );
57 #endif
58
59
60     //
61     // Packages with what status to show
62     //
63
64     Q3GroupBox * gbox = new Q3GroupBox( 3, Qt::Horizontal, _( "Show packages with status" ), this );
65     Q_CHECK_PTR( gbox );
66
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 );
75
76     addVSpacing( gbox, 8 );
77     addHStretch( gbox ); // For the other columns of the QGroupBox ( prevent wraparound )
78     addHStretch( gbox );
79
80     _showKeepInstalled  = addStatusCheckBox( gbox, _( "Keep" ),           YQIconPool::disabledPkgKeepInstalled(), false );
81     _showNoInst         = addStatusCheckBox( gbox, _( "Do not install" ), YQIconPool::disabledPkgNoInst(),        false );
82
83     addVStretch( this );
84
85
86     // Box for refresh button
87     Q3HBox * hbox = new Q3HBox( this );
88     Q_CHECK_PTR( hbox );
89
90     addHStretch( hbox );
91
92     // Refresh button
93     _refreshButton = new QPushButton( _( "&Refresh List" ), hbox );
94     Q_CHECK_PTR( _refreshButton );
95     addHStretch( hbox );
96
97     connect( _refreshButton,    SIGNAL( clicked() ),
98              this,              SLOT  ( filter()  ) );
99
100     for ( int i=0; i < 6; i++ )
101         addVStretch( this );
102 }
103
104
105 YQPkgStatusFilterView::~YQPkgStatusFilterView()
106 {
107     // NOP
108 }
109
110
111
112 QCheckBox *
113 YQPkgStatusFilterView::addStatusCheckBox( QWidget *             parent,
114                                           const QString &       text,
115                                           const QPixmap &       icon,
116                                           bool                  initiallyChecked )
117 {
118     QCheckBox * checkBox = new QCheckBox( text, parent );
119     Q_CHECK_PTR( checkBox );
120     checkBox->setChecked( initiallyChecked );
121
122     QLabel * label = new QLabel( parent );
123     Q_CHECK_PTR( label );
124     label->setPixmap( icon );
125
126     addHStretch( parent );
127
128     connect( checkBox,  SIGNAL( clicked() ),
129              this,      SLOT  ( filter()  ) );
130
131     return checkBox;
132 }
133
134
135 QSize
136 YQPkgStatusFilterView::minimumSizeHint() const
137 {
138     return QSize( 0, 0 );
139 }
140
141
142 void
143 YQPkgStatusFilterView::filterIfVisible()
144 {
145     if ( isVisible() )
146         filter();
147 }
148
149
150 void
151 YQPkgStatusFilterView::filter()
152 {
153     emit filterStart();
154
155     for ( ZyppPoolIterator it = zyppPkgBegin();
156           it != zyppPkgEnd();
157           ++it )
158     {
159         ZyppSel selectable = *it;
160
161         bool match =
162             check( selectable, selectable->candidateObj() ) ||
163             check( selectable, selectable->installedObj() );
164
165         // If there is neither an installed nor a candidate package, check
166         // any other instance.
167
168         if ( ! match                      &&
169              ! selectable->candidateObj() &&
170              ! selectable->installedObj()   )
171             check( selectable,  selectable->theObj() );
172     }
173
174     emit filterFinished();
175 }
176
177
178 bool
179 YQPkgStatusFilterView::check( ZyppSel   selectable,
180                               ZyppObj   zyppObj )
181 {
182     bool match = false;
183
184     if ( ! zyppObj )
185         return false;
186
187     switch ( selectable->status() )
188     {
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;
199
200             // Intentionally omitting 'default' branch so the compiler can
201             // catch unhandled enum states
202     }
203
204     if ( match )
205     {
206         ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
207
208         if ( zyppPkg )
209             emit filterMatch( selectable, zyppPkg );
210     }
211
212     return match;
213 }
214
215
216
217 void YQPkgStatusFilterView::clear()
218 {
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 );
229 }
230
231
232 void YQPkgStatusFilterView::showTransactions()
233 {
234     showManualTransactions();
235     showAutoTransactions();
236 }
237
238
239 void YQPkgStatusFilterView::showManualTransactions()
240 {
241     _showDel->setChecked( true );
242     _showInstall->setChecked( true );
243     _showUpdate->setChecked( true );
244 }
245
246
247 void YQPkgStatusFilterView::showAutoTransactions()
248 {
249     _showAutoDel->setChecked( true );
250     _showAutoInstall->setChecked( true );
251     _showAutoUpdate->setChecked( true );
252 }
253
254
255 void YQPkgStatusFilterView::showLocks()
256 {
257     _showTaboo->setChecked( true );
258     _showProtected->setChecked( true );
259 }
260
261
262 void YQPkgStatusFilterView::showInstalled()
263 {
264     _showKeepInstalled->setChecked( true );
265 }
266
267
268 void YQPkgStatusFilterView::showNotInstalled()
269 {
270     _showNoInst->setChecked( true );
271 }
272
273
274
275 #include "YQPkgStatusFilterView.moc"