]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgPatchFilterView.cc
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / pkg / YQPkgPatchFilterView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgPatchFilterView.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
25 #include <qcombobox.h>
26 #include <qlabel.h>
27 #include <qsplitter.h>
28 #include <qtabwidget.h>
29 #include <qdatetime.h>
30 //Added by qt3to4:
31 #include <q3frame.h>
32
33 #include <FSize.h>
34 #include <zypp/ui/PatchContents.h>
35
36 #include "YQPkgPatchFilterView.h"
37 #include "YQPkgPatchList.h"
38 #include "YQPkgDescriptionView.h"
39 #include "YQPkgSelList.h"
40 #include "QY2LayoutUtils.h"
41 #include "YQi18n.h"
42
43 typedef zypp::ui::PatchContents                 ZyppPatchContents;
44 typedef zypp::ui::PatchContents::const_iterator ZyppPatchContentsIterator;
45
46 using std::set;
47
48 #define ENABLE_TOTAL_DOWNLOAD_SIZE      0
49
50 #define SPACING                 6       // between subwidgets
51 #define MARGIN                  4       // around the widget
52
53
54 YQPkgPatchFilterView::YQPkgPatchFilterView( QWidget * parent )
55     : Q3VBox( parent )
56 {
57     Q3VBox * vbox;
58
59     _splitter                   = new QSplitter( Qt::Vertical, this );  Q_CHECK_PTR( _splitter  );
60     vbox                        = new Q3VBox( _splitter );                      Q_CHECK_PTR( vbox               );
61     _patchList                  = new YQPkgPatchList( vbox );                   Q_CHECK_PTR( _patchList         );
62
63     addVSpacing( vbox, 4 );
64
65     Q3HBox * hbox               = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
66     hbox->setSpacing( SPACING );
67
68     QLabel * label              = new QLabel( _( "&Show Patch Category:" ), hbox );
69
70     _patchFilter                = new QComboBox( hbox );
71     Q_CHECK_PTR( _patchFilter );
72
73     _patchFilter->insertItem( _( "Installable Patches" ),                       0 );
74     _patchFilter->insertItem( _( "Installable and Installed Patches" ), 1 );
75     _patchFilter->insertItem( _( "All Patches" ),                               2 );
76     _patchFilter->setCurrentItem( 0 );
77     _patchFilter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
78     label->setBuddy( _patchFilter );
79
80     connect( _patchFilter, SIGNAL( activated( int ) ), this, SLOT( fillPatchList() ) );
81     addVSpacing( vbox, 4 );
82
83     vbox                        = new Q3VBox( _splitter );                      Q_CHECK_PTR( vbox                       );
84     addVSpacing( vbox, 8 );
85
86     _detailsViews               = new QTabWidget( vbox );                       Q_CHECK_PTR( _detailsViews      );
87     _detailsViews->setMargin( MARGIN );
88
89     _descriptionView            = new YQPkgDescriptionView( _detailsViews );    Q_CHECK_PTR( _descriptionView   );
90
91     _descriptionView->setMinimumSize( 0, 0 );
92     _detailsViews->addTab( _descriptionView, _( "Patch Description" ) );
93
94     
95 #if ENABLE_TOTAL_DOWNLOAD_SIZE
96     //
97     // HBox for total download size
98     //
99
100     addVSpacing( vbox, 4 );
101     hbox = new Q3HBox( vbox ); Q_CHECK_PTR( hbox );
102     addHStretch( hbox );
103
104     new QLabel( _( "Estimated Download Size:" ) + " ", hbox );
105     _totalDownloadSize          = new QLabel( FSize(0).asString().c_str(), hbox );
106     Q_CHECK_PTR( _totalDownloadSize );
107
108
109     // Give the total download size a 3D look
110
111     _totalDownloadSize->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
112     _totalDownloadSize->setLineWidth(1);
113     _totalDownloadSize->setMidLineWidth(2);
114 #endif
115
116
117     connect( _patchList,        SIGNAL( selectionChanged    ( ZyppSel ) ),
118              _descriptionView,  SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
119
120     connect( _patchList,        SIGNAL( statusChanged()                 ),
121              this,              SLOT  ( updateTotalDownloadSize()       ) );
122
123     updateTotalDownloadSize();
124 }
125
126
127 YQPkgPatchFilterView::~YQPkgPatchFilterView()
128 {
129     // NOP
130 }
131
132
133 void
134 YQPkgPatchFilterView::updateTotalDownloadSize()
135 {
136     set<ZyppSel> selectablesToInstall;
137     QTime calcTime;
138     calcTime.start();
139
140     for ( ZyppPoolIterator patches_it = zyppPatchesBegin();
141           patches_it != zyppPatchesEnd();
142           ++patches_it )
143     {
144         ZyppPatch patch = tryCastToZyppPatch( (*patches_it)->theObj() );
145
146         if ( patch )
147         {
148             ZyppPatchContents patchContents( patch );
149
150             for ( ZyppPatchContentsIterator contents_it = patchContents.begin();
151                   contents_it != patchContents.end();
152                   ++contents_it )
153             {
154                 ZyppPkg pkg = tryCastToZyppPkg( *contents_it );
155                 ZyppSel sel;
156
157                 if ( pkg )
158                     sel = _selMapper.findZyppSel( pkg );
159
160                 if ( sel )
161                 {
162                     switch ( sel->status() )
163                     {
164                         case S_Install:
165                         case S_AutoInstall:
166                         case S_Update:
167                         case S_AutoUpdate:
168                             // Insert the patch contents selectables into a set,
169                             // don't immediately sum up their sizes: The same
170                             // package could be in more than one patch, but of
171                             // course it will be downloaded only once.
172
173                             selectablesToInstall.insert( sel );
174                             break;
175
176                         case S_Del:
177                         case S_AutoDel:
178                         case S_NoInst:
179                         case S_KeepInstalled:
180                         case S_Taboo:
181                         case S_Protected:
182                             break;
183
184                             // intentionally omitting 'default' branch so the compiler can
185                             // catch unhandled enum states
186                     }
187
188                 }
189             }
190         }
191     }
192
193
194     FSize totalSize = 0;
195
196     for ( set<ZyppSel>::iterator it = selectablesToInstall.begin();
197           it != selectablesToInstall.end();
198           ++it )
199     {
200         if ( (*it)->candidateObj() )
201             totalSize += (*it)->candidateObj()->size();
202     }
203
204 #if ENABLE_TOTAL_DOWNLOAD_SIZE
205     _totalDownloadSize->setText( totalSize.asString().c_str() );
206 #endif
207
208     y2debug( "Calculated total download size in %d millisec", calcTime.elapsed() );
209 }
210
211
212 void
213 YQPkgPatchFilterView::fillPatchList()
214 {
215     switch ( _patchFilter->currentItem() )
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"