libyui-qt-pkg  2.47.5
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 "YQPkgSearchFilterView.h"
34 #include "YQPkgStatusFilterView.h"
35 #include "YQi18n.h"
36 
37 
39  : QWidget( parent )
40 {
41 }
42 
43 void YQPkgSecondaryFilterView::init(QWidget * primary_widget)
44 {
45  QHBoxLayout *layout = new QHBoxLayout(this);
46  YUI_CHECK_NEW( layout );
47  layout->setContentsMargins(0,0,0,0);
48 
49  QSplitter * splitter = new QSplitter( Qt::Vertical, this );
50  YUI_CHECK_NEW( splitter );
51 
52  layout->addWidget( splitter );
53  splitter->addWidget(primary_widget);
54 
55  primary_widget->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert
56 
57  // Directly propagate signals filterStart() and filterFinished()
58  // from primary filter to the outside
59  connect( primary_widget, SIGNAL( filterStart() ),
60  this, SIGNAL( filterStart() ) );
61 
62  connect( primary_widget, SIGNAL( filterFinished() ),
63  this, SIGNAL( filterFinished() ) );
64 
65  // Redirect filterMatch() and filterNearMatch() signals to secondary filter
66  connect( primary_widget, SIGNAL( filterMatch ( ZyppSel, ZyppPkg ) ),
67  this, SLOT ( primaryFilterMatch ( ZyppSel, ZyppPkg ) ) );
68 
69  connect( primary_widget, SIGNAL( filterNearMatch ( ZyppSel, ZyppPkg ) ),
70  this, SLOT ( primaryFilterNearMatch ( ZyppSel, ZyppPkg ) ) );
71 
72  layoutSecondaryFilters( splitter, primary_widget );
73 
74  splitter->setStretchFactor(0, 5);
75  splitter->setStretchFactor(1, 1);
76  splitter->setStretchFactor(2, 3);
77 }
78 
80 {
81  // NOP
82 }
83 
84 QWidget *
85 YQPkgSecondaryFilterView::layoutSecondaryFilters( QWidget * parent, QWidget * primary_widget )
86 {
87  QWidget *vbox = new QWidget( parent );
88  YUI_CHECK_NEW( vbox );
89 
90  QVBoxLayout *layout = new QVBoxLayout();
91  YUI_CHECK_NEW( layout );
92 
93  vbox->setLayout( layout );
94  layout->setContentsMargins( 0, 0, 0, 0 );
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  //
100  // And yes, the colon really belongs there since this is one of the very
101  // few cases where a combo box label is left to the combo box rather than
102  // above it.
103  _secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ));
104  YUI_CHECK_NEW( _secondaryFilters );
105  layout->addWidget(_secondaryFilters);
106 
107  //
108  // All Packages
109  //
110  _allPackages = new QWidget( this );
111  YUI_CHECK_NEW( _allPackages );
112  _secondaryFilters->addPage( _( "All Packages" ), _allPackages );
113 
114 
115  // Unmaintained packages: Packages that are not provided in any of
116  // the configured repositories
117  _unmaintainedPackages = new QWidget( this );
118  YUI_CHECK_NEW( _unmaintainedPackages );
119  _secondaryFilters->addPage( _( "Unmaintained Packages" ), _unmaintainedPackages );
120 
121  //
122  // Package search view
123  //
124 
125  _searchFilterView = new YQPkgSearchFilterView( this );
126  YUI_CHECK_NEW( _searchFilterView );
127  _secondaryFilters->addPage( _( "Search" ), _searchFilterView );
128 
129  connect( _searchFilterView, SIGNAL( filterStart() ),
130  primary_widget, SLOT ( filter() ) );
131 
132  connect( _secondaryFilters, &QY2ComboTabWidget::currentChanged,
134 
135  //
136  // Status change view
137  //
138  _statusFilterView = new YQPkgStatusFilterView( parent );
139  YUI_CHECK_NEW( _statusFilterView );
140  _secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );
141 
142  connect( _statusFilterView, SIGNAL( filterStart() ),
143  primary_widget, SLOT ( filter() ) );
144 
145  return _secondaryFilters;
146 }
147 
149 {
150  primaryFilter();
151 }
152 
154 {
155  primaryFilterIfVisible();
156 }
157 
159  ZyppPkg pkg )
160 {
161  if ( secondaryFilterMatch( selectable, pkg ) )
162  emit filterMatch( selectable, pkg );
163 }
164 
166  ZyppPkg pkg )
167 {
168  if ( secondaryFilterMatch( selectable, pkg ) )
169  emit filterNearMatch( selectable, pkg );
170 }
171 
172 bool
174  ZyppPkg pkg )
175 {
176  if ( _allPackages->isVisible() )
177  {
178  return true;
179  }
180  else if ( _unmaintainedPackages->isVisible() )
181  {
182  return ( selectable->availableSize() == 0 );
183  }
184  else if ( _searchFilterView->isVisible() )
185  {
186  return _searchFilterView->check( selectable, pkg );
187  }
188  else if ( _statusFilterView->isVisible() )
189  {
190  return _statusFilterView->check( selectable, pkg );
191  }
192 
193  return true;
194 }
195 
void filterNearMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter and the candidate package does not come...
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.