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