]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgVersionsView.cc
#ifdefed out everything not compiling so it can be ported
[duncan/yast2-qt4.git] / src / pkg / YQPkgVersionsView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgVersionsView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #define y2log_component "qt-pkg"
22
23 #include <YQZypp.h>
24 #include <zypp/Repository.h>
25 #include <ycp/y2log.h>
26 #include <qtabwidget.h>
27 #include <qregexp.h>
28 #include <q3header.h>
29
30 #include "YQPkgVersionsView.h"
31 #include "YQPkgRepoList.h"
32 #include "YQIconPool.h"
33 #include "YQi18n.h"
34 #include "utf8.h"
35
36
37 YQPkgVersionsView::YQPkgVersionsView( QWidget * parent, bool userCanSwitch )
38     : QY2ListView( parent )
39 {
40     _selectable         = 0;
41     _parentTab          = dynamic_cast<QTabWidget *> (parent);
42     _userCanSwitch      = userCanSwitch;
43
44     _versionCol = -42;
45     _archCol    = -42;
46     _productCol = -42;
47     _urlCol     = -42;
48     _repoCol    = -42;
49     _statusCol  = -42;
50     _nameCol    = -42;
51     _summaryCol = -42;
52
53 #if FIXME
54     int numCol = 0;
55     addColumn( _( "Version"     ) );    _versionCol     = numCol++;
56     addColumn( _( "Arch."       ) );    _archCol        = numCol++;
57     addColumn( _( "Product"     ) );    _productCol     = numCol++;
58     addColumn( _( "Repository"  ) );    _repoCol        = numCol++;
59     addColumn( _( "URL"         ) );    _urlCol         = numCol++;
60 #endif
61     _statusCol  = _productCol;
62
63     _nameCol    = _versionCol;
64     _summaryCol = _repoCol;
65
66     setSortByInsertionSequence( true );
67
68     // saveColumnWidths();      // Minimize column widths
69     // header()->hide();
70
71
72     if ( _parentTab )
73     {
74         connect( parent, SIGNAL( currentChanged(QWidget *) ),
75                  this,   SLOT  ( reload        (QWidget *) ) );
76     }
77
78     connect( this,      SIGNAL( selectionChanged        () ),
79              this,      SLOT  ( checkForChangedCandidate() ) );
80 }
81
82
83 YQPkgVersionsView::~YQPkgVersionsView()
84 {
85     // NOP
86 }
87
88
89 void
90 YQPkgVersionsView::reload( QWidget * newCurrent )
91 {
92     if ( newCurrent == this )
93         showDetailsIfVisible( _selectable );
94 }
95
96
97 void
98 YQPkgVersionsView::showDetailsIfVisible( ZyppSel selectable )
99 {
100     _selectable = selectable;
101
102     if ( _parentTab )           // Is this view embedded into a tab widget?
103     {
104         if ( _parentTab->currentPage() == this )  // Is this page the topmost?
105             showDetails( selectable );
106     }
107     else        // No tab parent - simply show data unconditionally.
108     {
109         showDetails( selectable );
110     }
111 }
112
113
114 void
115 YQPkgVersionsView::showDetails( ZyppSel selectable )
116 {
117     _selectable = selectable;
118     clear();
119
120     if ( ! selectable )
121         return;
122
123 #if FIXME
124     QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str(),
125                                                     Q3CheckListItem::Controller );
126     Q_CHECK_PTR( root );
127     root->setOpen( true );
128
129     bool installedIsAvailable = false;
130
131     zypp::ui::Selectable::available_iterator it = selectable->availableBegin();
132
133     while ( it != selectable->availableEnd() )
134     {
135         new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
136
137         if ( selectable->installedObj() &&
138              selectable->installedObj()->edition() == (*it)->edition() &&
139              selectable->installedObj()->arch()    == (*it)->arch()      )
140             // FIXME: In future releases, also the vendor will make a difference
141             installedIsAvailable = true;
142
143 #if 0
144         // DEBUG
145         new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
146         new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
147         new YQPkgVersion( this, root, selectable, *it, _userCanSwitch );
148         // DEBUG
149 #endif
150         ++it;
151     }
152
153     if ( selectable->hasInstalledObj() && ! installedIsAvailable )
154         new YQPkgVersion( this, root, selectable, selectable->installedObj(), false );
155
156 #endif
157 }
158
159
160 void
161 YQPkgVersionsView::checkForChangedCandidate()
162 {
163 #if FIXME
164     if ( ! firstChild() || ! _selectable )
165         return;
166
167     Q3ListViewItem * item = firstChild()->firstChild();
168
169     while ( item )
170     {
171         YQPkgVersion * versionItem = dynamic_cast<YQPkgVersion *> (item);
172
173         if ( versionItem && versionItem->isOn() )
174         {
175             ZyppObj newCandidate = versionItem->zyppObj();
176
177             if ( newCandidate != _selectable->candidateObj() )
178             {
179                 y2milestone( "Candidate changed" );
180
181                 // Change status of selectable
182
183                 ZyppStatus status = _selectable->status();
184
185                 if ( _selectable->installedObj() &&
186                      _selectable->installedObj()->arch()    == newCandidate->arch() &&
187                      _selectable->installedObj()->edition() == newCandidate->edition() )
188                 {
189                     // Switch back to the original instance -
190                     // the version that was previously installed
191                     status = S_KeepInstalled;
192                 }
193                 else
194                 {
195                     switch ( status )
196                     {
197                         case S_KeepInstalled:
198                         case S_Protected:
199                         case S_AutoDel:
200                         case S_AutoUpdate:
201                         case S_Del:
202                         case S_Update:
203
204                             status = S_Update;
205                             break;
206
207                         case S_NoInst:
208                         case S_Taboo:
209                         case S_Install:
210                         case S_AutoInstall:
211                             status = S_Install;
212                             break;
213                     }
214                 }
215
216                 _selectable->set_status( status );
217
218
219                 // Set candidate
220
221                 _selectable->setCandidate( newCandidate );
222                 emit candidateChanged( newCandidate );
223                 return;
224             }
225         }
226
227         item = item->nextSibling();
228     }
229 #endif
230 }
231
232
233 QSize
234 YQPkgVersionsView::minimumSizeHint() const
235 {
236     return QSize( 0, 0 );
237 }
238
239
240
241
242
243
244 YQPkgVersion::YQPkgVersion( YQPkgVersionsView * pkgVersionList,
245                             QY2CheckListItem *  parent,
246                             ZyppSel             selectable,
247                             ZyppObj             zyppObj,
248                             bool                enabled )
249     : QY2CheckListItem( parent, "" /*
250                         enabled ?
251                         Q3CheckListItem::RadioButton :
252                         Q3CheckListItem::Controller */ )        // cheap way to make it read-only
253     , _pkgVersionList( pkgVersionList )
254     , _selectable( selectable )
255     , _zyppObj( zyppObj )
256 {
257     // FIXME setOn( _zyppObj == _selectable->candidateObj() );
258
259     if ( versionCol() >= 0 )    setText( versionCol(), zyppObj->edition().asString().c_str() );
260     if ( archCol()    >= 0 )    setText( archCol(),    zyppObj->arch().asString().c_str() );
261     if ( repoCol() >= 0 )       setText( repoCol(), fromUTF8(zyppObj->repository().info().alias()) );
262     if ( productCol() >= 0 )
263     {
264         ZyppProduct product = YQPkgRepoListItem::singleProduct( zyppObj->repository() );
265
266         if ( product )
267             setText( productCol(), QString::fromStdString( product->summary() ) );
268     }
269     if ( urlCol() >= 0 )
270     {
271         zypp::Url repoUrl;
272
273         if ( ! zyppObj->repository().info().baseUrlsEmpty() )
274             repoUrl = *zyppObj->repository().info().baseUrlsBegin();
275
276         setText( urlCol(), repoUrl.asString().c_str() );
277     }
278
279     if ( _selectable->hasInstalledObj() )
280     {
281         if ( _zyppObj->edition() == _selectable->installedObj()->edition() &&
282              _zyppObj->arch()    == _selectable->installedObj()->arch()      )
283         {
284             // FIXME setPixmap( statusCol(), YQIconPool::pkgKeepInstalled() );
285             setBackgroundColor( QColor( 0xF0, 0xF0, 0xF0 ) );   // light grey
286             setTextColor( QColor( 0, 0x90, 0 ) );               // green
287         }
288     }
289 }
290
291
292 YQPkgVersion::~YQPkgVersion()
293 {
294     // NOP
295 }
296
297
298 QString
299 YQPkgVersion::toolTip(int)
300 {
301     QString tip;
302
303     if ( zyppObj() == selectable()->installedObj() )
304         tip = _( "This version is installed in your system." );
305
306     return tip;
307 }
308
309
310 /**
311  * Comparison function used for sorting the list.
312  * Returns:
313  * -1 if this <  other
314  *  0 if this == other
315  * +1 if this >  other
316  **/
317 int
318 YQPkgVersion::compare( QTreeWidgetItem *        otherListViewItem,
319                        int              col,
320                        bool             ascending ) const
321 {
322     YQPkgVersion * other = dynamic_cast<YQPkgVersion *> (otherListViewItem);
323
324     if ( other )
325     {
326         if ( this->zyppObj()->edition() < other->zyppObj()->edition() ) return -1;
327         if ( this->zyppObj()->edition() > other->zyppObj()->edition() ) return  1;
328         return 0;
329     }
330
331     // Fallback: Use parent class method
332     return QY2CheckListItem::compare( otherListViewItem, col, ascending );
333 }
334
335
336
337 #include "YQPkgVersionsView.moc"