libyui-qt-pkg  2.45.6
 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, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
108 
109  _detailsViews = new QTabWidget( _splitter ); Q_CHECK_PTR( _detailsViews );
110 
111  _descriptionView = new YQPkgDescriptionView( _detailsViews ); Q_CHECK_PTR( _descriptionView );
112 
113  _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
114 
115  connect( _patchList, SIGNAL( currentItemChanged ( ZyppSel ) ),
116  _descriptionView, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
117 
118  connect( _patchList, SIGNAL( statusChanged() ),
119  this, SLOT ( updateTotalDownloadSize() ) );
120 
122 }
123 
124 
126 {
127  // NOP
128 }
129 
130 
131 void
133 {
134  set<ZyppSel> selectablesToInstall;
135  QTime calcTime;
136  calcTime.start();
137 
138  for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
139  patches_it != zyppPatchesEnd();
140  ++patches_it )
141  {
142  ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
143 
144  if ( patch )
145  {
146  ZyppPatchContents patchContents( patch->contents() );
147 
148  for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
149  contents_it != patchContents.end();
150  ++contents_it )
151  {
152  ZyppPkg pkg = zypp::make<zypp::Package>(*contents_it);
153  ZyppSel sel;
154 
155  if ( pkg )
156  sel = _selMapper.findZyppSel( pkg );
157 
158  if ( sel )
159  {
160  switch ( sel->status() )
161  {
162  case S_Install:
163  case S_AutoInstall:
164  case S_Update:
165  case S_AutoUpdate:
166  // Insert the patch contents selectables into a set,
167  // don't immediately sum up their sizes: The same
168  // package could be in more than one patch, but of
169  // course it will be downloaded only once.
170 
171  selectablesToInstall.insert( sel );
172  break;
173 
174  case S_Del:
175  case S_AutoDel:
176  case S_NoInst:
177  case S_KeepInstalled:
178  case S_Taboo:
179  case S_Protected:
180  break;
181 
182  // intentionally omitting 'default' branch so the compiler can
183  // catch unhandled enum states
184  }
185 
186  }
187  }
188  }
189  }
190 
191 
192  FSize totalSize = 0;
193 
194  for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
195  it != selectablesToInstall.end();
196  ++it )
197  {
198  if ( (*it)->candidateObj() )
199  totalSize += (*it)->candidateObj()->installSize();
200  }
201 
202 #if ENABLE_TOTAL_DOWNLOAD_SIZE
203  _totalDownloadSize->setText( totalSize.asString().c_str() );
204 #endif
205 
206  yuiDebug() << "Calculated total download size in "
207  << calcTime.elapsed() << " millisec"
208  << endl;
209 }
210 
211 
212 void
214 {
215  switch ( _patchFilter->currentIndex() )
216  {
217  case 0: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
218  case 1: _patchList->setFilterCriteria( YQPkgPatchList::RelevantAndInstalledPatches ); break;
219  case 2: _patchList->setFilterCriteria( YQPkgPatchList::AllPatches ); break;
220  default: _patchList->setFilterCriteria( YQPkgPatchList::RelevantPatches ); break;
221  }
222 
223  _patchList->fillList();
224  _patchList->selectSomething();
225 }
226 
227 
228 #include "YQPkgPatchFilterView.moc"
Display the description of a ZyppObj derived object along with its name and summary.
void fillPatchList()
Fill the patch list with regard to the _patchCategory combo box.
Display a list of zypp::Patch objects.
void fillList()
Fill the patch list according to filterCriteria().
YQPkgPatchFilterView(QWidget *parent)
Constructor.
virtual ~YQPkgPatchFilterView()
Destructor.
ZyppSel findZyppSel(ZyppPkg pkg)
Find the corresponding ZyppSel to a ZyppPkg.
void updateTotalDownloadSize()
Update the "total download size" field.
void setFilterCriteria(FilterCriteria filterCriteria)
Set the filter criteria for fillList().