libyui-qt-pkg  2.42.13
 All Classes Functions Variables Enumerations
YQPkgSelList.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: YQPkgSelList.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 #include <qregexp.h>
46 #include <zypp/ZYppFactory.h>
47 #include <zypp/Resolver.h>
48 
49 #include "YQi18n.h"
50 #include "utf8.h"
51 #include "YQPkgSelList.h"
52 
53 using std::set;
54 
55 
56 YQPkgSelList::YQPkgSelList( QWidget * parent, bool autoFill, bool autoFilter )
57  : YQPkgObjList( parent )
58 {
59  yuiDebug() << "Creating selection list" << endl;
60 
61 #if FIXME
62  int numCol = 0;
63  addColumn( "" ); _statusCol = numCol++;
64  addColumn( _( "Selection" ) ); _summaryCol = numCol++;
65  setAllColumnsShowFocus( true );
66 #endif
67 
68  _satisfiedIconCol = _summaryCol;
69  _brokenIconCol = _summaryCol;
70 
71  if ( autoFilter )
72  {
73  connect( this, SIGNAL( currentItemChanged( QTreeWidgetItem * ) ),
74  this, SLOT ( filter() ) );
75  }
76 
77  if ( autoFill )
78  {
79  fillList();
80  selectSomething();
81  }
82 
83  yuiDebug() << "Creating selection list done" << endl;
84 }
85 
86 
88 {
89  // NOP
90 }
91 
92 
93 void
95 {
96  clear();
97  yuiDebug() << "Filling selection list" << endl;
98 
99 
100  for ( ZyppPoolIterator it = zyppSelectionsBegin();
101  it != zyppSelectionsEnd();
102  ++it )
103  {
104  ZyppSelection zyppSelection = tryCastToZyppSelection( (*it)->theObj() );
105 
106  if ( zyppSelection )
107  {
108  if ( zyppSelection->visible() && ! zyppSelection->isBase() )
109  {
110  addPkgSelItem( *it, zyppSelection );
111  }
112  }
113  else
114  {
115  yuiError() << "Found non-Selection selectable" << endl;
116  }
117  }
118 
119  yuiDebug() << "Selection list filled" << endl;
120 }
121 
122 
123 void
125 {
126  if ( isVisible() )
127  filter();
128 }
129 
130 
131 void
133 {
134  emit filterStart();
135 
136  if ( selection() ) // The seleted QListViewItem
137  {
138  ZyppSelection zyppSelection = selection()->zyppSelection();
139 
140  if ( zyppSelection )
141  {
142  set<string> wanted = zyppSelection->install_packages();
143 
144  for ( ZyppPoolIterator it = zyppPkgBegin();
145  it != zyppPkgEnd();
146  ++it )
147  {
148  string name = (*it)->theObj()->name();
149 
150  if ( contains( wanted, name ) )
151  {
152  ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
153 
154  if ( zyppPkg )
155  {
156  emit filterMatch( *it, zyppPkg );
157  }
158  }
159  }
160  }
161  }
162 
163  emit filterFinished();
164 }
165 
166 
167 void
168 YQPkgSelList::addPkgSelItem( ZyppSel selectable,
169  ZyppSelection zyppSelection )
170 {
171  if ( ! selectable )
172  {
173  yuiError() << "NULL ZyppSel!" << endl;
174  return;
175  }
176 
177  YQPkgSelListItem * item = new YQPkgSelListItem( this, selectable, zyppSelection );
178  applyExcludeRules( item );
179 }
180 
181 
184 {
185 #if FIXME
186  QTreeWidgetItem * item = selectedItem();
187 
188  if ( ! item )
189  return 0;
190 
191  return dynamic_cast<YQPkgSelListItem *> (item);
192 #else
193  return 0;
194 #endif
195 }
196 
197 
198 
199 
200 
201 
203  ZyppSel selectable,
204  ZyppSelection zyppSelection )
205  : YQPkgObjListItem( pkgSelList, selectable, zyppSelection )
206  , _pkgSelList( pkgSelList )
207  , _zyppSelection( zyppSelection )
208 {
209  if ( ! _zyppSelection )
210  _zyppSelection = tryCastToZyppSelection( selectable->theObj() );
211 
212  QString text = fromUTF8( _zyppSelection->summary() );
213 
214  // You don't want to know why we need this.
215  text.replace( QRegExp( "Graphical Basis System" ), "Graphical Base System" );
216  text.replace( QRegExp( "Gnome" ), "GNOME" );
217 
218  setText( summaryCol(), text );
219 
220  setStatusIcon();
221 }
222 
223 
225 {
226  // NOP
227 }
228 
229 
230 void
232 {
234 }
235 
236 
237 /**
238  * Comparison function used for sorting the list.
239  * Returns:
240  * -1 if this < other
241  * 0 if this == other
242  * +1 if this > other
243  **/
244 int
245 YQPkgSelListItem::compare( QTreeWidgetItem * otherListViewItem,
246  int col,
247  bool ascending ) const
248 {
249  YQPkgSelListItem * other = ( YQPkgSelListItem * ) otherListViewItem;
250 
251  if ( ! _zyppSelection || ! other || ! other->zyppSelection() )
252  return 0;
253 
254  return _zyppSelection->order().compare( other->zyppSelection()->order() );
255 }
256 
257 
258 
259 #include "YQPkgSelList.moc"
Abstract base class to display a list of zypp::ResObjects. Handles most generic stuff like setting st...
Definition: YQPkgObjList.h:68
void setText(int column, const string text)
void fillList()
Definition: YQPkgSelList.cc:94
Display a list of zypp::Selection objects.
Definition: YQPkgSelList.h:53
void addPkgSelItem(ZyppSel selectable, ZyppSelection selection)
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
virtual void applyChanges()
void filterStart()
virtual void clear()
virtual int compare(QTreeWidgetItem *other, int col, bool ascending) const
virtual ~YQPkgSelListItem()
void filterIfVisible()
virtual ~YQPkgSelList()
Definition: YQPkgSelList.cc:87
void applyExcludeRules()
void filterFinished()
void currentItemChanged(ZyppSel selectable)
ZyppSelection zyppSelection() const
Definition: YQPkgSelList.h:156
YQPkgSelListItem * selection() const
void solveResolvableCollections()
YQPkgSelList(QWidget *parent, bool autoFill=true, bool autoFilter=true)
Definition: YQPkgSelList.cc:56
YQPkgSelListItem(YQPkgSelList *pkgSelList, ZyppSel selectable, ZyppSelection zyppSelection)
virtual void setStatusIcon()