]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgRepoFilterView.cc
restart qt4 porting
[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 "YQPkgRepoFilterView.h"
30 #include "YQPkgRepoList.h"
31 #include "YQPkgRpmGroupTagsFilterView.h"
32 #include "YQPkgSearchFilterView.h"
33 #include "YQPkgStatusFilterView.h"
34 #include "YQi18n.h"
35
36 #define MARGIN                  4
37
38
39 YQPkgRepoFilterView::YQPkgRepoFilterView( QWidget * parent )
40     : QVBox( parent )
41 {
42     QSplitter * splitter = new QSplitter( QSplitter::Vertical, this );
43     CHECK_PTR( splitter );
44
45     QVBox * upper_vbox = new QVBox( splitter );
46     _repoList = new YQPkgRepoList( upper_vbox );
47     CHECK_PTR( _repoList );
48     _repoList->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert
49
50     addVSpacing( upper_vbox, MARGIN );
51
52
53     // Directly propagate signals filterStart() and filterFinished()
54     // from primary filter to the outside
55
56     connect( _repoList, SIGNAL( filterStart() ),
57              this,              SIGNAL( filterStart() ) );
58
59     connect( _repoList, SIGNAL( filterFinished() ),
60              this,              SIGNAL( filterFinished() ) );
61
62
63     // Redirect filterMatch() and filterNearMatch() signals to secondary filter
64
65     connect( _repoList, SIGNAL( filterMatch             ( ZyppSel, ZyppPkg ) ),
66              this,              SLOT  ( primaryFilterMatch      ( ZyppSel, ZyppPkg ) ) );
67
68     connect( _repoList, SIGNAL( filterNearMatch         ( ZyppSel, ZyppPkg ) ),
69              this,              SLOT  ( primaryFilterNearMatch  ( ZyppSel, ZyppPkg ) ) );
70
71 #if 0
72     QWidget * secondary_filters =
73 #endif
74     layoutSecondaryFilters( splitter );
75
76 #if 0
77     splitter->setResizeMode( _repoList, QSplitter::Stretch        );
78     splitter->setResizeMode( secondary_filters, QSplitter::FollowSizeHint );
79 #endif
80 }
81
82
83 YQPkgRepoFilterView::~YQPkgRepoFilterView()
84 {
85     // NOP
86 }
87
88
89 QWidget *
90 YQPkgRepoFilterView::layoutSecondaryFilters( QWidget * parent )
91 {
92     QVBox *vbox = new QVBox( parent );
93     CHECK_PTR( vbox );
94     addVSpacing( vbox, MARGIN );
95
96     // Translators: This is a combo box where the user can apply a secondary filter
97     // in addition to the primary filter by repository - one of
98     // "all packages", "RPM groups", "search", "summary"
99     _secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ), vbox );
100     CHECK_PTR( _secondaryFilters );
101
102     _secondaryFilters->setFrameStyle( QFrame::Plain );
103     _secondaryFilters->setLineWidth( 0 );
104     _secondaryFilters->setMidLineWidth( 0 );
105     _secondaryFilters->setMargin( 0 );
106
107
108     //
109     // All Packages
110     //
111
112     _allPackages = new QWidget( vbox );
113     CHECK_PTR( _allPackages );
114     _secondaryFilters->addPage( _( "All Packages" ), _allPackages );
115
116
117     //
118     // RPM Groups
119     //
120
121     _rpmGroupTagsFilterView = new YQPkgRpmGroupTagsFilterView( vbox );
122     CHECK_PTR( _rpmGroupTagsFilterView );
123     _secondaryFilters->addPage( _( "Package Groups" ), _rpmGroupTagsFilterView );
124
125     connect( _rpmGroupTagsFilterView,   SIGNAL( filterStart() ),
126              _repoList,         SLOT  ( filter()      ) );
127
128
129     //
130     // Package search view
131     //
132
133     _searchFilterView = new YQPkgSearchFilterView( vbox );
134     CHECK_PTR( _searchFilterView );
135     _secondaryFilters->addPage( _( "Search" ), _searchFilterView );
136
137     connect( _searchFilterView, SIGNAL( filterStart() ),
138              _repoList, SLOT  ( filter()      ) );
139
140     connect( _secondaryFilters, SIGNAL( currentChanged( QWidget * ) ),
141              this,              SLOT  ( filter()                  ) );
142
143
144     //
145     // Status change view
146     //
147
148     _statusFilterView = new YQPkgStatusFilterView( parent );
149     CHECK_PTR( _statusFilterView );
150     _secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );
151
152     connect( _statusFilterView, SIGNAL( filterStart() ),
153              _repoList, SLOT  ( filter()      ) );
154
155
156     return _secondaryFilters;
157 }
158
159
160 void YQPkgRepoFilterView::filter()
161 {
162     _repoList->filter();
163 }
164
165
166 void YQPkgRepoFilterView::filterIfVisible()
167 {
168     _repoList->filterIfVisible();
169 }
170
171
172 void YQPkgRepoFilterView::primaryFilterMatch( ZyppSel   selectable,
173                                                  ZyppPkg        pkg )
174 {
175     if ( secondaryFilterMatch( selectable, pkg ) )
176         emit filterMatch( selectable, pkg );
177 }
178
179
180 void YQPkgRepoFilterView::primaryFilterNearMatch( ZyppSel       selectable,
181                                                      ZyppPkg    pkg )
182 {
183     if ( secondaryFilterMatch( selectable, pkg ) )
184         emit filterNearMatch( selectable, pkg );
185 }
186
187
188 bool
189 YQPkgRepoFilterView::secondaryFilterMatch( ZyppSel      selectable,
190                                               ZyppPkg   pkg )
191 {
192     if ( _allPackages->isVisible() )
193     {
194         return true;
195     }
196     else if ( _rpmGroupTagsFilterView->isVisible() )
197     {
198         return _rpmGroupTagsFilterView->check( selectable, pkg );
199     }
200     else if ( _searchFilterView->isVisible() )
201     {
202         return _searchFilterView->check( selectable, pkg );
203     }
204     else if ( _statusFilterView->isVisible() )
205     {
206         return _statusFilterView->check( selectable, pkg );
207     }
208     else
209     {
210         return true;
211     }
212 }
213
214
215
216
217
218
219 #include "YQPkgRepoFilterView.moc"