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