]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgRepoFilterView.cc
don't create QObjects in ycp thread - make timeouts work
[duncan/yast2-qt4.git] / src / pkg / YQPkgRepoFilterView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQPkgRepoFilterView.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17   Textdomain    "packages-qt"
18
19 /-*/
20
21
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24
25 #include <qsplitter.h>
26
27 #include "QY2ComboTabWidget.h"
28 #include "QY2LayoutUtils.h"
29 #include <QVBoxLayout>
30 #include <QFrame>
31 #include "YQPkgRepoFilterView.h"
32 #include "YQPkgRepoList.h"
33 #include "YQPkgRpmGroupTagsFilterView.h"
34 #include "YQPkgSearchFilterView.h"
35 #include "YQPkgStatusFilterView.h"
36 #include "YQi18n.h"
37
38 #define MARGIN                  4
39
40
41 YQPkgRepoFilterView::YQPkgRepoFilterView( QWidget * parent )
42     : QWidget( parent )
43 {
44     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
45     Q_CHECK_PTR( splitter );
46
47     QVBoxLayout * upper_vbox = new QVBoxLayout( splitter );
48     
49     _repoList = new YQPkgRepoList( this );
50     upper_vbox->addWidget(_repoList);
51
52     Q_CHECK_PTR( _repoList );
53     _repoList->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert
54
55     //addVSpacing( upper_vbox, MARGIN );
56
57
58     // Directly propagate signals filterStart() and filterFinished()
59     // from primary filter to the outside
60
61     connect( _repoList, SIGNAL( filterStart() ),
62              this,              SIGNAL( filterStart() ) );
63
64     connect( _repoList, SIGNAL( filterFinished() ),
65              this,              SIGNAL( filterFinished() ) );
66
67
68     // Redirect filterMatch() and filterNearMatch() signals to secondary filter
69
70     connect( _repoList, SIGNAL( filterMatch             ( ZyppSel, ZyppPkg ) ),
71              this,              SLOT  ( primaryFilterMatch      ( ZyppSel, ZyppPkg ) ) );
72
73     connect( _repoList, SIGNAL( filterNearMatch         ( ZyppSel, ZyppPkg ) ),
74              this,              SLOT  ( primaryFilterNearMatch  ( ZyppSel, ZyppPkg ) ) );
75
76 #if 0
77     QWidget * secondary_filters =
78 #endif
79     layoutSecondaryFilters( splitter );
80
81 #if 0
82     splitter->setResizeMode( _repoList, QSplitter::Stretch        );
83     splitter->setResizeMode( secondary_filters, QSplitter::FollowSizeHint );
84 #endif
85 }
86
87
88 YQPkgRepoFilterView::~YQPkgRepoFilterView()
89 {
90     // NOP
91 }
92
93
94 QWidget *
95 YQPkgRepoFilterView::layoutSecondaryFilters( QWidget * parent )
96 {
97  
98     QVBoxLayout *vbox = new QVBoxLayout( parent );
99     Q_CHECK_PTR( vbox );
100     //addVSpacing( vbox, MARGIN );
101
102     // Translators: This is a combo box where the user can apply a secondary filter
103     // in addition to the primary filter by repository - one of
104     // "All packages", "RPM groups", "search", "summary"
105     //
106     // And yes, the colon really belongs there since this is one of the very
107     // few cases where a combo box label is left to the combo box rather than
108     // above it.
109     _secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ));
110     vbox->addWidget(_secondaryFilters);
111
112     Q_CHECK_PTR( _secondaryFilters );
113
114 //     _secondaryFilters->setFrameStyle( Q3Frame::Plain );
115 //     _secondaryFilters->setLineWidth( 0 );
116 //     _secondaryFilters->setMidLineWidth( 0 );
117 //     _secondaryFilters->setMargin( 0 );
118
119
120     //
121     // All Packages
122     //
123
124     _allPackages = new QWidget( this );
125     vbox->addWidget(_allPackages);
126     Q_CHECK_PTR( _allPackages );
127     _secondaryFilters->addPage( _( "All Packages" ), _allPackages );
128
129
130     //
131     // RPM Groups
132     //
133
134     _rpmGroupTagsFilterView = new YQPkgRpmGroupTagsFilterView( this );
135     vbox->addWidget(_rpmGroupTagsFilterView);
136
137     Q_CHECK_PTR( _rpmGroupTagsFilterView );
138     _secondaryFilters->addPage( _( "Package Groups" ), _rpmGroupTagsFilterView );
139
140     connect( _rpmGroupTagsFilterView,   SIGNAL( filterStart() ),
141              _repoList,         SLOT  ( filter()      ) );
142
143
144     //
145     // Package search view
146     //
147
148     _searchFilterView = new YQPkgSearchFilterView(this);
149     vbox->addWidget(_searchFilterView);
150     Q_CHECK_PTR( _searchFilterView );
151     _secondaryFilters->addPage( _( "Search" ), _searchFilterView );
152
153     connect( _searchFilterView, SIGNAL( filterStart() ),
154              _repoList, SLOT  ( filter()      ) );
155
156     connect( _secondaryFilters, SIGNAL( currentChanged( QWidget * ) ),
157              this,              SLOT  ( filter()                  ) );
158
159
160     //
161     // Status change view
162     //
163
164     _statusFilterView = new YQPkgStatusFilterView( parent );
165     Q_CHECK_PTR( _statusFilterView );
166     _secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );
167
168     connect( _statusFilterView, SIGNAL( filterStart() ),
169              _repoList, SLOT  ( filter()      ) );
170
171
172     return _secondaryFilters;
173 }
174
175
176 void YQPkgRepoFilterView::filter()
177 {
178     _repoList->filter();
179 }
180
181
182 void YQPkgRepoFilterView::filterIfVisible()
183 {
184     _repoList->filterIfVisible();
185 }
186
187
188 void YQPkgRepoFilterView::primaryFilterMatch( ZyppSel   selectable,
189                                                  ZyppPkg        pkg )
190 {
191     if ( secondaryFilterMatch( selectable, pkg ) )
192         emit filterMatch( selectable, pkg );
193 }
194
195
196 void YQPkgRepoFilterView::primaryFilterNearMatch( ZyppSel       selectable,
197                                                      ZyppPkg    pkg )
198 {
199     if ( secondaryFilterMatch( selectable, pkg ) )
200         emit filterNearMatch( selectable, pkg );
201 }
202
203
204 bool
205 YQPkgRepoFilterView::secondaryFilterMatch( ZyppSel      selectable,
206                                               ZyppPkg   pkg )
207 {
208     if ( _allPackages->isVisible() )
209     {
210         return true;
211     }
212     else if ( _rpmGroupTagsFilterView->isVisible() )
213     {
214         return _rpmGroupTagsFilterView->check( selectable, pkg );
215     }
216     else if ( _searchFilterView->isVisible() )
217     {
218         return _searchFilterView->check( selectable, pkg );
219     }
220     else if ( _statusFilterView->isVisible() )
221     {
222         return _statusFilterView->check( selectable, pkg );
223     }
224     else
225     {
226         return true;
227     }
228 }
229
230
231
232
233
234
235 #include "YQPkgRepoFilterView.moc"