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>
27 #include <QDesktopWidget>
30 #include <QPushButton>
35 #include <zypp/ResStatus.h>
36 #include <zypp/ui/UserWantedPackages.h>
38 #include "YQPkgChangesDialog.h"
39 #include "YQPkgList.h"
40 #include "QY2LayoutUtils.h"
48 #define SPACING 2 // between subwidgets
49 #define MARGIN 4 // around the widget
52 YQPkgChangesDialog::YQPkgChangesDialog( QWidget * parent,
53 const QString & message,
54 const QString & acceptButtonLabel,
55 const QString & rejectButtonLabel )
59 setWindowTitle( _( "Changed Packages" ) );
61 // Enable dialog resizing even without window manager
62 setSizeGripEnabled( true );
64 // Limit dialog size to available screen size
65 setMaximumSize( qApp->desktop()->availableGeometry().size() );
67 // Layout for the dialog ( can't simply insert a QVBox )
69 QVBoxLayout * layout = new QVBoxLayout( this );
70 Q_CHECK_PTR( layout );
71 layout->setMargin(MARGIN);
72 layout->setSpacing(SPACING);
75 // HBox for icon and message
77 QHBoxLayout * hbox = new QHBoxLayout( this );
79 layout->addLayout( hbox );
84 hbox->addSpacing(SPACING);
85 QLabel * iconLabel = new QLabel( this );
86 Q_CHECK_PTR( iconLabel );
87 hbox->addWidget(iconLabel);
89 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
91 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
92 hbox->addSpacing(SPACING);
94 // Label for the message
96 QLabel * label = new QLabel( message, this );
98 hbox->addWidget(label);
99 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
104 _pkgList = new YQPkgList( this );
105 Q_CHECK_PTR( _pkgList );
106 _pkgList->setEditable( false );
108 layout->addWidget( _pkgList );
113 hbox = new QHBoxLayout( this );
115 hbox->setSpacing( SPACING );
116 hbox->setMargin ( MARGIN );
117 layout->addLayout( hbox );
122 // Accept button - usually "OK" or "Continue"
124 QPushButton * button = new QPushButton( acceptButtonLabel, this );
125 Q_CHECK_PTR( button );
126 layout->addWidget( button );
127 button->setDefault( true );
129 connect( button, SIGNAL( clicked() ),
130 this, SLOT ( accept() ) );
135 if ( ! rejectButtonLabel.isEmpty() )
137 // Reject button ( if desired ) - usually "Cancel"
139 button = new QPushButton( rejectButtonLabel, this );
140 Q_CHECK_PTR( button );
141 hbox->addWidget(button);
142 connect( button, SIGNAL( clicked() ),
143 this, SLOT ( reject() ) );
151 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
153 filter( QRegExp( "" ), byAuto, byApp, byUser );
158 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
160 YQUI::ui()->busyCursor();
163 set<string> ignoredNames;
165 if ( ! byUser || ! byApp )
166 ignoredNames = zypp::ui::userWantedPackageNames();
168 for ( ZyppPoolIterator it = zyppPkgBegin();
172 ZyppSel selectable = *it;
174 if ( selectable->toModify() )
176 zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
178 if ( ( modifiedBy == zypp::ResStatus::SOLVER ) && byAuto ||
179 ( modifiedBy == zypp::ResStatus::APPL_LOW ||
180 modifiedBy == zypp::ResStatus::APPL_HIGH ) && byApp ||
181 ( modifiedBy == zypp::ResStatus::USER ) && byUser )
183 if ( regexp.isEmpty() || regexp.search( selectable->name().c_str() ) >= 0 )
185 if ( ! contains( ignoredNames, selectable->name() ) )
186 _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
192 YQUI::ui()->normalCursor();
197 YQPkgChangesDialog::isEmpty() const
199 return _pkgList->topLevelItemCount() == 0;
204 YQPkgChangesDialog::sizeHint() const
206 return limitToScreenSize( this, QDialog::sizeHint() );
211 YQPkgChangesDialog::showChangesDialog( const QString & message,
212 const QString & acceptButtonLabel,
213 const QString & rejectButtonLabel,
214 bool showIfListEmpty )
216 YQPkgChangesDialog dialog( 0,
222 if ( dialog.isEmpty() && ! showIfListEmpty )
227 return dialog.result() == QDialog::Accepted;
232 YQPkgChangesDialog::showChangesDialog( const QString & message,
233 const QRegExp & regexp,
234 const QString & acceptButtonLabel,
235 const QString & rejectButtonLabel,
236 bool showIfListEmpty )
238 YQPkgChangesDialog dialog( 0,
242 dialog.filter( regexp, true, true, true );
244 if ( dialog.isEmpty() && ! showIfListEmpty )
249 return dialog.result() == QDialog::Accepted;
255 #include "YQPkgChangesDialog.moc"