1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgChangesDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <qapplication.h>
27 #include <qdesktopwidget.h>
31 #include <qpushbutton.h>
34 #include <q3boxlayout.h>
37 #include <zypp/ResStatus.h>
38 #include <zypp/ui/UserWantedPackages.h>
40 #include "YQPkgChangesDialog.h"
41 #include "YQPkgList.h"
42 #include "QY2LayoutUtils.h"
50 #define SPACING 2 // between subwidgets
51 #define MARGIN 4 // around the widget
54 YQPkgChangesDialog::YQPkgChangesDialog( QWidget * parent,
55 const QString & message,
56 const QString & acceptButtonLabel,
57 const QString & rejectButtonLabel )
61 setCaption( _( "Changed Packages" ) );
63 // Enable dialog resizing even without window manager
64 setSizeGripEnabled( true );
66 // Limit dialog size to available screen size
67 setMaximumSize( qApp->desktop()->availableGeometry().size() );
69 // Layout for the dialog ( can't simply insert a QVBox )
71 Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
72 Q_CHECK_PTR( layout );
75 // HBox for icon and message
77 Q3HBox * hbox = new Q3HBox( this );
79 layout->addWidget( hbox );
85 QLabel * iconLabel = new QLabel( hbox );
86 Q_CHECK_PTR( iconLabel );
88 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
90 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
93 // Label for the message
95 QLabel * label = new QLabel( message, hbox );
97 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
102 _pkgList = new YQPkgList( this );
103 Q_CHECK_PTR( _pkgList );
104 _pkgList->setEditable( false );
106 layout->addWidget( _pkgList );
111 hbox = new Q3HBox( this );
113 hbox->setSpacing( SPACING );
114 hbox->setMargin ( MARGIN );
115 layout->addWidget( hbox );
120 // Accept button - usually "OK" or "Continue"
122 QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
123 Q_CHECK_PTR( button );
124 button->setDefault( true );
126 connect( button, SIGNAL( clicked() ),
127 this, SLOT ( accept() ) );
132 if ( ! rejectButtonLabel.isEmpty() )
134 // Reject button ( if desired ) - usually "Cancel"
136 button = new QPushButton( rejectButtonLabel, hbox );
137 Q_CHECK_PTR( button );
139 connect( button, SIGNAL( clicked() ),
140 this, SLOT ( reject() ) );
148 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
150 filter( QRegExp( "" ), byAuto, byApp, byUser );
155 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
157 YQUI::ui()->busyCursor();
160 set<string> ignoredNames;
162 if ( ! byUser || ! byApp )
163 ignoredNames = zypp::ui::userWantedPackageNames();
165 for ( ZyppPoolIterator it = zyppPkgBegin();
169 ZyppSel selectable = *it;
171 if ( selectable->toModify() )
173 zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
175 if ( ( modifiedBy == zypp::ResStatus::SOLVER ) && byAuto ||
176 ( modifiedBy == zypp::ResStatus::APPL_LOW ||
177 modifiedBy == zypp::ResStatus::APPL_HIGH ) && byApp ||
178 ( modifiedBy == zypp::ResStatus::USER ) && byUser )
180 if ( regexp.isEmpty() || regexp.search( selectable->name().c_str() ) >= 0 )
182 if ( ! contains( ignoredNames, selectable->name() ) )
183 _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
189 YQUI::ui()->normalCursor();
194 YQPkgChangesDialog::isEmpty() const
196 return _pkgList->topLevelItemCount() == 0;
201 YQPkgChangesDialog::sizeHint() const
203 return limitToScreenSize( this, QDialog::sizeHint() );
208 YQPkgChangesDialog::showChangesDialog( const QString & message,
209 const QString & acceptButtonLabel,
210 const QString & rejectButtonLabel,
211 bool showIfListEmpty )
213 YQPkgChangesDialog dialog( 0,
219 if ( dialog.isEmpty() && ! showIfListEmpty )
224 return dialog.result() == QDialog::Accepted;
229 YQPkgChangesDialog::showChangesDialog( const QString & message,
230 const QRegExp & regexp,
231 const QString & acceptButtonLabel,
232 const QString & rejectButtonLabel,
233 bool showIfListEmpty )
235 YQPkgChangesDialog dialog( 0,
239 dialog.filter( regexp, true, true, true );
241 if ( dialog.isEmpty() && ! showIfListEmpty )
246 return dialog.result() == QDialog::Accepted;
252 #include "YQPkgChangesDialog.moc"