]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgChangesDialog.cc
6f55ea21dbfaa9c3ab7cfbc76db6ca48e3c8259f
[duncan/yast2-qt4.git] / src / pkg / YQPkgChangesDialog.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgChangesDialog.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 <qapplication.h>
26 #include <qhbox.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
29 #include <qpushbutton.h>
30 #include <qstyle.h>
31
32 #include "YQZypp.h"
33 #include <zypp/ResStatus.h>
34 #include <zypp/ui/UserWantedPackages.h>
35
36 #include "YQPkgChangesDialog.h"
37 #include "YQPkgList.h"
38 #include "QY2LayoutUtils.h"
39 #include "YQi18n.h"
40 #include "YQUI.h"
41
42 using std::set;
43 using std::string;
44
45
46 #define SPACING                 2       // between subwidgets
47 #define MARGIN                  4       // around the widget
48
49
50 YQPkgChangesDialog::YQPkgChangesDialog( QWidget *               parent,
51                                         const QString &         message,
52                                         const QString &         acceptButtonLabel,
53                                         const QString &         rejectButtonLabel )
54     : QDialog( parent )
55 {
56     // Dialog title
57     setCaption( _( "Changed Packages" ) );
58
59     // Enable dialog resizing even without window manager
60     setSizeGripEnabled( true );
61
62     // Limit dialog size to available screen size
63     setMaximumSize( qApp->desktop()->availableGeometry().size() );
64
65     // Layout for the dialog ( can't simply insert a QVBox )
66
67     QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
68     CHECK_PTR( layout );
69
70
71     // HBox for icon and message
72
73     QHBox * hbox = new QHBox( this );
74     CHECK_PTR( hbox );
75     layout->addWidget( hbox );
76
77
78     // Icon
79
80     addHSpacing( hbox );
81     QLabel * iconLabel = new QLabel( hbox );
82     CHECK_PTR( iconLabel );
83     iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
84     iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
85     addHSpacing( hbox );
86
87     // Label for the message
88
89     QLabel * label = new QLabel( message, hbox );
90     CHECK_PTR( label );
91     label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
92
93
94     // Pkg list
95
96     _pkgList = new YQPkgList( this );
97     CHECK_PTR( _pkgList );
98     _pkgList->setEditable( false );
99
100     layout->addWidget( _pkgList );
101
102
103     // Button box
104
105     hbox = new QHBox( this );
106     CHECK_PTR( hbox );
107     hbox->setSpacing( SPACING );
108     hbox->setMargin ( MARGIN  );
109     layout->addWidget( hbox );
110
111     addHStretch( hbox );
112
113
114     // Accept button - usually "OK" or "Continue"
115
116     QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
117     CHECK_PTR( button );
118     button->setDefault( true );
119
120     connect( button,    SIGNAL( clicked() ),
121              this,      SLOT  ( accept()  ) );
122
123     addHStretch( hbox );
124
125
126     if ( ! rejectButtonLabel.isEmpty() )
127     {
128         // Reject button ( if desired ) - usually "Cancel"
129
130         button = new QPushButton( rejectButtonLabel, hbox );
131         CHECK_PTR( button );
132
133         connect( button,        SIGNAL( clicked() ),
134                  this,          SLOT  ( reject()  ) );
135
136         addHStretch( hbox );
137     }
138 }
139
140
141 void
142 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
143 {
144     filter( QRegExp( "" ), byAuto, byApp, byUser );
145 }
146
147
148 void
149 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
150 {
151     YQUI::ui()->busyCursor();
152     _pkgList->clear();
153
154     set<string> ignoredNames;
155     
156     if ( ! byUser || ! byApp )
157         ignoredNames = zypp::ui::userWantedPackageNames();
158
159     for ( ZyppPoolIterator it = zyppPkgBegin();
160           it != zyppPkgEnd();
161           ++it )
162     {
163         ZyppSel selectable = *it;
164
165         if ( selectable->toModify() )
166         {
167             zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
168
169             if ( ( modifiedBy == zypp::ResStatus::SOLVER     ) && byAuto ||
170                  ( modifiedBy == zypp::ResStatus::APPL_LOW ||
171                    modifiedBy == zypp::ResStatus::APPL_HIGH  ) && byApp  ||
172                  ( modifiedBy == zypp::ResStatus::USER       ) && byUser   )
173             {
174                 if ( regexp.isEmpty() || regexp.search( selectable->name().c_str() ) >= 0 )
175                 {
176                     if ( ! contains( ignoredNames, selectable->name() ) )
177                         _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
178                 }
179             }
180         }
181     }
182
183     YQUI::ui()->normalCursor();
184 }
185
186
187 bool
188 YQPkgChangesDialog::isEmpty() const
189 {
190     return _pkgList->firstChild() == 0;
191 }
192
193
194 QSize
195 YQPkgChangesDialog::sizeHint() const
196 {
197     return limitToScreenSize( this, QDialog::sizeHint() );
198 }
199
200
201 bool
202 YQPkgChangesDialog::showChangesDialog( const QString &  message,
203                                        const QString &  acceptButtonLabel,
204                                        const QString &  rejectButtonLabel,
205                                        bool             showIfListEmpty   )
206 {
207     YQPkgChangesDialog dialog( 0,
208                                message,
209                                acceptButtonLabel,
210                                rejectButtonLabel );
211     dialog.filter();
212
213     if ( dialog.isEmpty() && ! showIfListEmpty )
214         return true;
215
216     dialog.exec();
217
218     return dialog.result() == QDialog::Accepted;
219 }
220
221
222 bool
223 YQPkgChangesDialog::showChangesDialog( const QString &  message,
224                                        const QRegExp &  regexp,
225                                        const QString &  acceptButtonLabel,
226                                        const QString &  rejectButtonLabel,
227                                        bool             showIfListEmpty   )
228 {
229     YQPkgChangesDialog dialog( 0,
230                                message,
231                                acceptButtonLabel,
232                                rejectButtonLabel );
233     dialog.filter( regexp, true, true, true );
234
235     if ( dialog.isEmpty() && ! showIfListEmpty )
236         return true;
237
238     dialog.exec();
239
240     return dialog.result() == QDialog::Accepted;
241 }
242
243
244
245
246 #include "YQPkgChangesDialog.moc"