]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgSelList.cc
0ada2cee16a13970dcd8fedb03fc9493504c3940
[duncan/yast2-qt4.git] / src / pkg / YQPkgSelList.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgSelList.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 #include <qregexp.h>
25 #include <zypp/ZYppFactory.h>
26 #include <zypp/Resolver.h>
27
28
29 #include "YQi18n.h"
30 #include "utf8.h"
31 #include "YQPkgSelList.h"
32
33
34 YQPkgSelList::YQPkgSelList( QWidget * parent, bool autoFill, bool autoFilter )
35     : YQPkgObjList( parent )
36 {
37     y2debug( "Creating selection list" );
38
39     int numCol = 0;
40     addColumn( ""               );      _statusCol      = numCol++;
41     addColumn( _( "Selection" ) );      _summaryCol     = numCol++;
42     setAllColumnsShowFocus( true );
43
44     _satisfiedIconCol   = _summaryCol;
45     _brokenIconCol      = _summaryCol;
46     
47     if ( autoFilter )
48     {
49         connect( this, SIGNAL( selectionChanged( QTreeWidgetItem * ) ),
50                  this, SLOT  ( filter()                            ) );
51     }
52
53     if ( autoFill )
54     {
55         fillList();
56         selectSomething();
57     }
58
59     y2debug( "Creating selection list done" );
60 }
61
62
63 YQPkgSelList::~YQPkgSelList()
64 {
65     // NOP
66 }
67
68
69 void
70 YQPkgSelList::fillList()
71 {
72     clear();
73     y2debug( "Filling selection list" );
74
75
76     for ( ZyppPoolIterator it = zyppSelectionsBegin();
77           it != zyppSelectionsEnd();
78           ++it )
79     {
80         ZyppSelection zyppSelection = tryCastToZyppSelection( (*it)->theObj() );
81
82         if ( zyppSelection )
83         {
84             if ( zyppSelection->visible() && ! zyppSelection->isBase() )
85             {
86                 addPkgSelItem( *it, zyppSelection );
87             }
88         }
89         else
90         {
91             y2error( "Found non-Selection selectable" );
92         }
93     }
94
95     y2debug( "Selection list filled" );
96 }
97
98
99 void
100 YQPkgSelList::filterIfVisible()
101 {
102     if ( isVisible() )
103         filter();
104 }
105
106
107 void
108 YQPkgSelList::filter()
109 {
110     emit filterStart();
111
112     if ( selection() )  // The seleted QListViewItem
113     {
114         ZyppSelection zyppSelection = selection()->zyppSelection();
115
116         if ( zyppSelection )
117         {
118             set<string> wanted = zyppSelection->install_packages();
119
120             for ( ZyppPoolIterator it = zyppPkgBegin();
121                   it != zyppPkgEnd();
122                   ++it )
123             {
124                 string name = (*it)->theObj()->name();
125
126                 if ( contains( wanted, name ) )
127                 {
128                     ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
129
130                     if ( zyppPkg )
131                     {
132                         emit filterMatch( *it, zyppPkg );
133                     }
134                 }
135             }
136         }
137     }
138
139     emit filterFinished();
140 }
141
142
143 void
144 YQPkgSelList::addPkgSelItem( ZyppSel            selectable,
145                              ZyppSelection      zyppSelection )
146 {
147     if ( ! selectable )
148     {
149         y2error( "NULL ZyppSel!" );
150         return;
151     }
152
153     YQPkgSelListItem * item = new YQPkgSelListItem( this, selectable, zyppSelection );
154     applyExcludeRules( item );
155 }
156
157
158 YQPkgSelListItem *
159 YQPkgSelList::selection() const
160 {
161     QTreeWidgetItem * item = selectedItem();
162
163     if ( ! item )
164         return 0;
165
166     return dynamic_cast<YQPkgSelListItem *> (item);
167 }
168
169
170
171
172
173
174 YQPkgSelListItem::YQPkgSelListItem( YQPkgSelList *      pkgSelList,
175                                     ZyppSel             selectable,
176                                     ZyppSelection       zyppSelection )
177     : YQPkgObjListItem( pkgSelList, selectable, zyppSelection )
178     , _pkgSelList( pkgSelList )
179     , _zyppSelection( zyppSelection )
180 {
181     if ( ! _zyppSelection )
182         _zyppSelection = tryCastToZyppSelection( selectable->theObj() );
183
184     QString text = fromUTF8( _zyppSelection->summary() );
185
186     // You don't want to know why we need this.
187     text.replace( QRegExp( "Graphical Basis System" ), "Graphical Base System" );
188     text.replace( QRegExp( "Gnome" ), "GNOME" );
189
190     setText( summaryCol(), text );
191
192     setStatusIcon();
193 }
194
195
196 YQPkgSelListItem::~YQPkgSelListItem()
197 {
198     // NOP
199 }
200
201
202 void
203 YQPkgSelListItem::applyChanges()
204 {
205     solveResolvableCollections();
206 }
207
208
209 /**
210  * Comparison function used for sorting the list.
211  * Returns:
212  * -1 if this <  other
213  *  0 if this == other
214  * +1 if this >  other
215  **/
216 int
217 YQPkgSelListItem::compare( QTreeWidgetItem *    otherListViewItem,
218                            int                  col,
219                            bool                 ascending ) const
220 {
221     YQPkgSelListItem * other = ( YQPkgSelListItem * ) otherListViewItem;
222
223     if ( ! _zyppSelection || ! other || ! other->zyppSelection() )
224         return 0;
225
226     return _zyppSelection->order().compare( other->zyppSelection()->order() );
227 }
228
229
230
231 #include "YQPkgSelList.moc"