libyui-qt-pkg  2.45.6
YQPkgRpmGroupTagsFilterView.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
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 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgRpmGroupTagsFilterView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 
43 #define YUILogComponent "qt-pkg"
44 #include "YUILog.h"
45 
46 #include "YQPkgRpmGroupTagsFilterView.h"
47 #include "YQi18n.h"
48 #include "utf8.h"
49 
50 using std::endl;
51 
52 
53 YRpmGroupsTree * YQPkgRpmGroupTagsFilterView::_rpmGroupsTree = 0;
54 
55 
57  : QTreeWidget( parent )
58 {
59  setHeaderLabels( QStringList(_( "Package Groups" )) );
60  setRootIsDecorated( true );
61  cloneTree( rpmGroupsTree()->root(), 0 );
62 
63  new YQPkgRpmGroupTag( this, _( "zzz All" ), 0 );
64 
65  connect( this, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
66  this, SLOT ( slotSelectionChanged ( QTreeWidgetItem * ) ) );
67 
69 }
70 
71 
73 {
74 }
75 
76 
77 YRpmGroupsTree *
79 {
80  if ( ! _rpmGroupsTree )
81  {
82  _rpmGroupsTree = new YRpmGroupsTree();
83  Q_CHECK_PTR( _rpmGroupsTree );
85  }
86 
87  return _rpmGroupsTree;
88 }
89 
90 
91 void
93 {
94  yuiDebug() << "Filling RPM groups tree" << endl;
95 
96  for ( ZyppPoolIterator it = zyppPkgBegin();
97  it != zyppPkgEnd();
98  ++it )
99  {
100  ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
101 
102  if ( zyppPkg )
103  rpmGroupsTree()->addRpmGroup( zyppPkg->group() );
104  }
105 
106  yuiDebug() << "Filling RPM groups tree done" << endl;
107 }
108 
109 
110 void
111 YQPkgRpmGroupTagsFilterView::cloneTree( YStringTreeItem * parentRpmGroup,
112  YQPkgRpmGroupTag * parentClone )
113 {
114  YStringTreeItem * child = parentRpmGroup->firstChild();
115  YQPkgRpmGroupTag * clone;
116 
117  while ( child )
118  {
119  if ( parentClone )
120  clone = new YQPkgRpmGroupTag( this, parentClone, child );
121  else
122  clone = new YQPkgRpmGroupTag( this, child );
123 
124  Q_CHECK_PTR( clone );
125  //FIXME clone->setExpanded( clone->depth() < 1 );
126  clone->setExpanded( true );
127  cloneTree( child, clone );
128  child = child->next();
129  }
130 }
131 
132 
133 void
135 {
136 // FIXME
137 // QTreeWidgetItem * item = children().first();
138 //
139 // if ( item )
140 // setCurrentItem(item);
141 }
142 
143 
144 void
146 {
147  if ( isVisible() )
148  filter();
149 }
150 
151 
152 void
154 {
155  emit filterStart();
156  // yuiDebug() << "Filtering packages for RPM group \"" << selectedRpmGroup() << "\"" << endl;
157 
158  if ( selection() )
159  {
160  for ( ZyppPoolIterator it = zyppPkgBegin();
161  it != zyppPkgEnd();
162  ++it )
163  {
164  ZyppSel selectable = *it;
165 
166  // Multiple instances of this package may or may not be in the same
167  // RPM group, so let's check both the installed version (if there
168  // is any) and the candidate version.
169  //
170  // Make sure we emit only one filterMatch() signal if both exist
171  // and both are in the same RPM group. We don't want multiple list
172  // entries for the same package!
173 
174  bool match =
175  check( selectable, tryCastToZyppPkg( selectable->candidateObj() ) ) ||
176  check( selectable, tryCastToZyppPkg( selectable->installedObj() ) );
177 
178  // If there is neither an installed nor a candidate package, check
179  // any other instance.
180 
181  if ( ! match &&
182  ! selectable->candidateObj() &&
183  ! selectable->installedObj() )
184  check( selectable, tryCastToZyppPkg( selectable->theObj() ) );
185  }
186  }
187 
188  emit filterFinished();
189 }
190 
191 
192 void
193 YQPkgRpmGroupTagsFilterView::slotSelectionChanged( QTreeWidgetItem * newSelection )
194 {
195  YQPkgRpmGroupTag * sel = dynamic_cast<YQPkgRpmGroupTag *>( newSelection );
196 
197  if ( sel )
198  {
199  if ( sel->rpmGroup() )
200  _selectedRpmGroup = rpmGroupsTree()->rpmGroup( sel->rpmGroup() );
201  else
202  _selectedRpmGroup = "*"; // "zzz_All"
203  }
204  else
205  {
206  _selectedRpmGroup = "";
207  }
208 
209  filter();
210 }
211 
212 
213 bool
215  ZyppPkg pkg )
216 {
217  if ( ! pkg || ! selection() )
218  return false;
219 
220  if ( selection()->rpmGroup() == 0 ) // Special case: All packages
221  {
222  emit filterMatch( selectable, pkg );
223  return true;
224  }
225 
226  if ( selectedRpmGroup().empty() )
227  return false;
228 
229  if ( pkg->group() == selectedRpmGroup() || // full match?
230  pkg->group().find( selectedRpmGroup() + "/" ) == 0 ) // starts with selected?
231  {
232  emit filterMatch( selectable, pkg );
233  return true;
234  }
235 
236  return false;
237 }
238 
239 
242 {
243  QTreeWidgetItem * item = currentItem();
244 
245  if ( ! item )
246  return 0;
247 
248  return dynamic_cast<YQPkgRpmGroupTag *> ( item );
249 }
250 
251 
252 
253 
254 
255 
257  YStringTreeItem * rpmGroup )
258  : QTreeWidgetItem( parentFilterView )
259  , _filterView( parentFilterView )
260  , _rpmGroup( rpmGroup )
261 {
262  setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
263 }
264 
265 
267  YQPkgRpmGroupTag * parentGroupTag,
268  YStringTreeItem * rpmGroup )
269  : QTreeWidgetItem( parentGroupTag )
270  , _filterView( parentFilterView )
271  , _rpmGroup( rpmGroup )
272 {
273  setText( 0, fromUTF8( _rpmGroup->value().translation() ) );
274 }
275 
276 
278  const QString & rpmGroupName,
279  YStringTreeItem * rpmGroup )
280  : QTreeWidgetItem( parentFilterView )
281  , _filterView( parentFilterView )
282  , _rpmGroup( rpmGroup )
283 {
284  setText( 0, rpmGroupName );
285 }
286 
287 
289 {
290  // NOP
291 }
292 
293 
294 
295 #include "YQPkgRpmGroupTagsFilterView.moc"
virtual ~YQPkgRpmGroupTag()
Destructor.
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.
void filterFinished()
Emitted when filtering is finished.
void filter()
Filter according to the view&#39;s rules and current selection.
void filterStart()
Emitted when the filtering starts.
void slotSelectionChanged(QTreeWidgetItem *newSelection)
Update _selectedRpmGroup and filter data.
YQPkgRpmGroupTag(YQPkgRpmGroupTagsFilterView *parentFilterView, YStringTreeItem *rpmGroup)
Constructor for toplevel RPM group tags.
void selectSomething()
Select a list entry (if there is any).
static void fillRpmGroupsTree()
Fill the internal RPM groups tree with RPM groups of all packages currently in the pool...
void cloneTree(YStringTreeItem *parentRpmGroup, YQPkgRpmGroupTag *parentClone=0)
Recursively clone the RPM group tag tree for the QListView widget: Make a deep copy of the tree start...
YQPkgRpmGroupTagsFilterView(QWidget *parent)
Constructor.
const YStringTreeItem * rpmGroup() const
Returns the original tree item.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
static YRpmGroupsTree * rpmGroupsTree()
Returns the internal RPM groups tree and fills it if it doesn&#39;t exist yet.
const string & selectedRpmGroup() const
Returns the (untranslated!) currently selected RPM group as string.
YQPkgRpmGroupTag * selection() const
Returns the currently selected item or 0 if there is none.
virtual ~YQPkgRpmGroupTagsFilterView()
Destructor.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.