libyui-qt-pkg  2.42.5
 All Classes Functions Variables Enumerations
YQPkgPatchFilterView.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: YQPkgPatchFilterView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #define YUILogComponent "qt-pkg"
43 #include "YUILog.h"
44 
45 #include <QComboBox>
46 #include <QLabel>
47 #include <QSplitter>
48 #include <QTabWidget>
49 #include <QDateTime>
50 #include <QFrame>
51 #include <QVBoxLayout>
52 
53 #include <FSize.h>
54 #include <zypp/Patch.h>
55 
56 #include "YQPkgPatchFilterView.h"
57 #include "YQPkgPatchList.h"
58 #include "YQPkgDescriptionView.h"
59 #include "QY2LayoutUtils.h"
60 #include "YQi18n.h"
61 
62 typedef zypp::Patch::Contents ZyppPatchContents;
63 typedef zypp::Patch::Contents::const_iterator ZyppPatchContentsIterator;
64 
65 using std::set;
66 using std::endl;
67 
68 #define ENABLE_TOTAL_DOWNLOAD_SIZE 0
69 
71  : QWidget( parent )
72 {
73  QVBoxLayout *layout = new QVBoxLayout();
74  layout->setContentsMargins(0,0,0,0);
75  setLayout(layout);
76 
77  _splitter = new QSplitter( Qt::Vertical, this ); Q_CHECK_PTR( _splitter );
78  layout->addWidget(_splitter);
79 
80  QWidget *upper_box = new QWidget( _splitter );
81  QVBoxLayout *vbox = new QVBoxLayout( upper_box );
82  _patchList = new YQPkgPatchList( upper_box );
83  Q_CHECK_PTR( _patchList );
84 
85  vbox->addWidget( _patchList );
86 
87  QHBoxLayout * hbox = new QHBoxLayout(); Q_CHECK_PTR( hbox );
88  vbox->addLayout(hbox);
89  vbox->setContentsMargins(0,0,0,0);
90 
91 
92  QLabel * label = new QLabel( _( "&Show Patch Category:" ), upper_box );
93  hbox->addWidget(label);
94 
95  _patchFilter = new QComboBox( upper_box );
96  Q_CHECK_PTR( _patchFilter );
97  hbox->addWidget(_patchFilter);
98 
99  _patchFilter->addItem( _( "Needed Patches" ));
100  _patchFilter->addItem( _( "Unneeded Patches" ));
101  _patchFilter->addItem( _( "All Patches" ), 2 );
102  _patchFilter->setCurrentIndex( 0 );
103 
104  label->setBuddy( _patchFilter );
105 
106  connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
107 
108  _detailsViews = new QTabWidget( _splitter ); Q_CHECK_PTR( _detailsViews );
109 
110  _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
111 
112  _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
113 
114  connect( _patchList, SIGNAL( currentItemChanged ( ZyppSel ) ),
115  _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
116 
117  connect( _patchList, SIGNAL( statusChanged() ),
118  this, SLOT ( updateTotalDownloadSize() ) );
119 
121 }
122 
123 
125 {
126  // NOP
127 }
128 
129 
130 void
132 {
133  set<ZyppSel> selectablesToInstall;
134  QTime calcTime;
135  calcTime.start();
136 
137  for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
138  patches_it != zyppPatchesEnd();
139  ++patches_it )
140  {
141  ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
142 
143  if ( patch )
144  {
145  ZyppPatchContents patchContents( patch->contents() );
146 
147  for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
148  contents_it != patchContents.end();
149  ++contents_it )
150  {
151  ZyppPkg pkg = zypp::make<zypp::Package>(*contents_it);
152  ZyppSel sel;
153 
154  if ( pkg )
155  sel = _selMapper.findZyppSel( pkg );
156 
157  if ( sel )
158  {
159  switch ( sel->status() )
160  {
161  case S_Install:
162  case S_AutoInstall:
163  case S_Update:
164  case S_AutoUpdate:
165  // Insert the patch contents selectables into a set,
166  // don't immediately sum up their sizes: The same
167  // package could be in more than one patch, but of
168  // course it will be downloaded only once.
169 
170  selectablesToInstall.insert( sel );
171  break;
172 
173  case S_Del:
174  case S_AutoDel:
175  case S_NoInst:
176  case S_KeepInstalled:
177  case S_Taboo:
178  case S_Protected:
179  break;
180 
181  // intentionally omitting 'default' branch so the compiler can
182  // catch unhandled enum states
183  }
184 
185  }
186  }
187  }
188  }
189 
190 
191  FSize totalSize = 0;
192 
193  for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
194  it != selectablesToInstall.end();
195  ++it )
196  {
197  if ( (*it)->candidateObj() )
198  totalSize += (*it)->candidateObj()->installSize();
199  }
200 
201 #if ENABLE_TOTAL_DOWNLOAD_SIZE
202  _totalDownloadSize->setText( totalSize.asString().c_str() );
203 #endif
204 
205  yuiDebug() << "Calculated total download size in "
206  << calcTime.elapsed() << " millisec"
207  << endl;
208 }
209 
210 
211 void
213 {
214  switch ( _patchFilter->currentIndex() )
215  {
216  case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
217  case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
218  case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
219  default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
220  }
221 
222  _patchList->fillList();
223  _patchList->selectSomething();
224 }
225 
226 
227 #include "YQPkgPatchFilterView.moc"