1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgChangesDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <qapplication.h>
29 #include <qpushbutton.h>
33 #include <zypp/ResStatus.h>
34 #include <zypp/ui/UserWantedPackages.h>
36 #include "YQPkgChangesDialog.h"
37 #include "YQPkgList.h"
38 #include "QY2LayoutUtils.h"
46 #define SPACING 2 // between subwidgets
47 #define MARGIN 4 // around the widget
50 YQPkgChangesDialog::YQPkgChangesDialog( QWidget * parent,
51 const QString & message,
52 const QString & acceptButtonLabel,
53 const QString & rejectButtonLabel )
57 setCaption( _( "Changed Packages" ) );
59 // Enable dialog resizing even without window manager
60 setSizeGripEnabled( true );
62 // Limit dialog size to available screen size
63 setMaximumSize( qApp->desktop()->availableGeometry().size() );
65 // Layout for the dialog ( can't simply insert a QVBox )
67 QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
71 // HBox for icon and message
73 QHBox * hbox = new QHBox( this );
75 layout->addWidget( 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
87 // Label for the message
89 QLabel * label = new QLabel( message, hbox );
91 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
96 _pkgList = new YQPkgList( this );
97 CHECK_PTR( _pkgList );
98 _pkgList->setEditable( false );
100 layout->addWidget( _pkgList );
105 hbox = new QHBox( this );
107 hbox->setSpacing( SPACING );
108 hbox->setMargin ( MARGIN );
109 layout->addWidget( hbox );
114 // Accept button - usually "OK" or "Continue"
116 QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
118 button->setDefault( true );
120 connect( button, SIGNAL( clicked() ),
121 this, SLOT ( accept() ) );
126 if ( ! rejectButtonLabel.isEmpty() )
128 // Reject button ( if desired ) - usually "Cancel"
130 button = new QPushButton( rejectButtonLabel, hbox );
133 connect( button, SIGNAL( clicked() ),
134 this, SLOT ( reject() ) );
142 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
144 filter( QRegExp( "" ), byAuto, byApp, byUser );
149 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
151 YQUI::ui()->busyCursor();
154 set<string> ignoredNames;
156 if ( ! byUser || ! byApp )
157 ignoredNames = zypp::ui::userWantedPackageNames();
159 for ( ZyppPoolIterator it = zyppPkgBegin();
163 ZyppSel selectable = *it;
165 if ( selectable->toModify() )
167 zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
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 )
174 if ( regexp.isEmpty() || regexp.search( selectable->name().c_str() ) >= 0 )
176 if ( ! contains( ignoredNames, selectable->name() ) )
177 _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
183 YQUI::ui()->normalCursor();
188 YQPkgChangesDialog::isEmpty() const
190 return _pkgList->firstChild() == 0;
195 YQPkgChangesDialog::sizeHint() const
197 return limitToScreenSize( this, QDialog::sizeHint() );
202 YQPkgChangesDialog::showChangesDialog( const QString & message,
203 const QString & acceptButtonLabel,
204 const QString & rejectButtonLabel,
205 bool showIfListEmpty )
207 YQPkgChangesDialog dialog( 0,
213 if ( dialog.isEmpty() && ! showIfListEmpty )
218 return dialog.result() == QDialog::Accepted;
223 YQPkgChangesDialog::showChangesDialog( const QString & message,
224 const QRegExp & regexp,
225 const QString & acceptButtonLabel,
226 const QString & rejectButtonLabel,
227 bool showIfListEmpty )
229 YQPkgChangesDialog dialog( 0,
233 dialog.filter( regexp, true, true, true );
235 if ( dialog.isEmpty() && ! showIfListEmpty )
240 return dialog.result() == QDialog::Accepted;
246 #include "YQPkgChangesDialog.moc"