libyui-qt-pkg  2.45.15.2
YQPkgSecondaryFilterView.cc
1 /**************************************************************************
2 Copyright (C) 2018 SUSE LLC
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 Textdomain "qt-pkg"
20 
21 */
22 
23 #define YUILogComponent "qt-pkg"
24 #include <YUILog.h>
25 #include <YUIException.h>
26 
27 #include <QVBoxLayout>
28 #include <QSplitter>
29 
30 #include "QY2ComboTabWidget.h"
31 #include "QY2LayoutUtils.h"
32 #include "YQPkgSecondaryFilterView.h"
33 #include "YQPkgRpmGroupTagsFilterView.h"
34 #include "YQPkgSearchFilterView.h"
35 #include "YQPkgStatusFilterView.h"
36 #include "YQi18n.h"
37 
38 
40  : QWidget( parent )
41 {
42 }
43 
44 void YQPkgSecondaryFilterView::init(QWidget * primary_widget)
45 {
46  QHBoxLayout *layout = new QHBoxLayout(this);
47  YUI_CHECK_NEW( layout );
48  layout->setContentsMargins(0,0,0,0);
49 
50  QSplitter * splitter = new QSplitter( Qt::Vertical, this );
51  YUI_CHECK_NEW( splitter );
52 
53  layout->addWidget( splitter );
54  splitter->addWidget(primary_widget);
55 
56  primary_widget->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert
57 
58  // Directly propagate signals filterStart() and filterFinished()
59  // from primary filter to the outside
60  connect( primary_widget, SIGNAL( filterStart() ),
61  this, SIGNAL( filterStart() ) );
62 
63  connect( primary_widget, SIGNAL( filterFinished() ),
64  this, SIGNAL( filterFinished() ) );
65 
66  // Redirect filterMatch() and filterNearMatch() signals to secondary filter
67  connect( primary_widget, SIGNAL( filterMatch ( ZyppSel, ZyppPkg ) ),
68  this, SLOT ( primaryFilterMatch ( ZyppSel, ZyppPkg ) ) );
69 
70  connect( primary_widget, SIGNAL( filterNearMatch ( ZyppSel, ZyppPkg ) ),
71  this, SLOT ( primaryFilterNearMatch ( ZyppSel, ZyppPkg ) ) );
72 
73  layoutSecondaryFilters( splitter, primary_widget );
74 
75  splitter->setStretchFactor(0, 5);
76  splitter->setStretchFactor(1, 1);
77  splitter->setStretchFactor(2, 3);
78 }
79 
81 {
82  // NOP
83 }
84 
85 QWidget *
86 YQPkgSecondaryFilterView::layoutSecondaryFilters( QWidget * parent, QWidget * primary_widget )
87 {
88  QWidget *vbox = new QWidget( parent );
89  YUI_CHECK_NEW( vbox );
90 
91  QVBoxLayout *layout = new QVBoxLayout();
92  YUI_CHECK_NEW( layout );
93 
94  vbox->setLayout( layout );
95  layout->setContentsMargins( 0, 0, 0, 0 );
96 
97  // Translators: This is a combo box where the user can apply a secondary filter
98  // in addition to the primary filter by repository - one of
99  // "All packages", "RPM groups", "search", "summary"
100  //
101  // And yes, the colon really belongs there since this is one of the very
102  // few cases where a combo box label is left to the combo box rather than
103  // above it.
104  _secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ));
105  YUI_CHECK_NEW( _secondaryFilters );
106  layout->addWidget(_secondaryFilters);
107 
108  //
109  // All Packages
110  //
111  _allPackages = new QWidget( this );
112  YUI_CHECK_NEW( _allPackages );
113  _secondaryFilters->addPage( _( "All Packages" ), _allPackages );
114 
115 
116  // Unmaintained packages: Packages that are not provided in any of
117  // the configured repositories
118  _unmaintainedPackages = new QWidget( this );
119  YUI_CHECK_NEW( _unmaintainedPackages );
120  _secondaryFilters->addPage( _( "Unmaintained Packages" ), _unmaintainedPackages );
121 
122  //
123  // RPM Groups
124  //
125  _rpmGroupTagsFilterView = new YQPkgRpmGroupTagsFilterView( this );
126  YUI_CHECK_NEW( _rpmGroupTagsFilterView );
127  _secondaryFilters->addPage( _( "Package Groups" ), _rpmGroupTagsFilterView );
128 
129  connect( _rpmGroupTagsFilterView, SIGNAL( filterStart() ),
130  primary_widget, SLOT ( filter() ) );
131 
132  //
133  // Package search view
134  //
135 
136  _searchFilterView = new YQPkgSearchFilterView( this );
137  YUI_CHECK_NEW( _searchFilterView );
138  _secondaryFilters->addPage( _( "Search" ), _searchFilterView );
139 
140  connect( _searchFilterView, SIGNAL( filterStart() ),
141  primary_widget, SLOT ( filter() ) );
142 
143  connect( _secondaryFilters, &QY2ComboTabWidget::currentChanged,
145 
146  //
147  // Status change view
148  //
149  _statusFilterView = new YQPkgStatusFilterView( parent );
150  YUI_CHECK_NEW( _statusFilterView );
151  _secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );
152 
153  connect( _statusFilterView, SIGNAL( filterStart() ),
154  primary_widget, SLOT ( filter() ) );
155 
156  return _secondaryFilters;
157 }
158 
160 {
161  primaryFilter();
162 }
163 
165 {
166  primaryFilterIfVisible();
167 }
168 
170  ZyppPkg pkg )
171 {
172  if ( secondaryFilterMatch( selectable, pkg ) )
173  emit filterMatch( selectable, pkg );
174 }
175 
177  ZyppPkg pkg )
178 {
179  if ( secondaryFilterMatch( selectable, pkg ) )
180  emit filterNearMatch( selectable, pkg );
181 }
182 
183 bool
185  ZyppPkg pkg )
186 {
187  if ( _allPackages->isVisible() )
188  {
189  return true;
190  }
191  else if ( _unmaintainedPackages->isVisible() )
192  {
193  return ( selectable->availableSize() == 0 );
194  }
195  else if ( _rpmGroupTagsFilterView->isVisible() )
196  {
197  return _rpmGroupTagsFilterView->check( selectable, pkg );
198  }
199  else if ( _searchFilterView->isVisible() )
200  {
201  return _searchFilterView->check( selectable, pkg );
202  }
203  else if ( _statusFilterView->isVisible() )
204  {
205  return _statusFilterView->check( selectable, pkg );
206  }
207 
208  return true;
209 }
210 
211 #include "YQPkgSecondaryFilterView.moc"
void filterNearMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter and the candidate package does not come...
RPM group tags filter view: Display the RPM group tags tree and emit signals if any group tag is sele...
bool check(ZyppSel selectable, ZyppPkg pkg)
Check if &#39;pkg&#39; matches the selected RPM group.
bool check(ZyppSel selectable, ZyppObj zyppObj)
Check one ResObject against the currently selected values.
void filter()
Filter according to the view&#39;s rules and current selection.
QWidget * layoutSecondaryFilters(QWidget *parent, QWidget *primary_widget)
Widget layout for the secondary filters.
void primaryFilterNearMatch(ZyppSel selectable, ZyppPkg pkg)
Propagate a filter near match from the primary filter and appy any selected secondary filter(s) to it...
void init(QWidget *primary_widget)
Initialize the primary widget.
void primaryFilterMatch(ZyppSel selectable, ZyppPkg pkg)
Propagate a filter match from the primary filter and appy any selected secondary filter(s) to it...
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
Filter view for searching within packages.
void filterStart()
Emitted when the filtering starts.
void filterFinished()
Emitted when filtering is finished.
YQPkgSecondaryFilterView(QWidget *parent)
Constructor Because of the circular dependencies you have to call the init() method later with the ne...
Filter view for packages that made problems during update.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter and the candidate package comes from th...
bool secondaryFilterMatch(ZyppSel selectable, ZyppPkg pkg)
Check if pkg matches the the currently selected secondary filter.
virtual ~YQPkgSecondaryFilterView()
Destructor.
bool check(ZyppSel selectable, ZyppObj pkg)
Check if pkg matches the filter criteria.