1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgChangesDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
24 #include <QApplication>
25 #include <QDesktopWidget>
28 #include <QPushButton>
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 setWindowTitle( _( "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 );
68 Q_CHECK_PTR( layout );
69 layout->setMargin(MARGIN);
70 layout->setSpacing(SPACING);
73 // HBox for icon and message
75 QHBoxLayout * hbox = new QHBoxLayout( this );
77 layout->addLayout( hbox );
82 hbox->addSpacing(SPACING);
83 QLabel * iconLabel = new QLabel( this );
84 Q_CHECK_PTR( iconLabel );
85 hbox->addWidget(iconLabel);
87 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
89 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
90 hbox->addSpacing(SPACING);
92 // Label for the message
94 QLabel * label = new QLabel( message, this );
96 hbox->addWidget(label);
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 QHBoxLayout( this );
113 hbox->setSpacing( SPACING );
114 hbox->setMargin ( MARGIN );
115 layout->addLayout( hbox );
120 // Accept button - usually "OK" or "Continue"
122 QPushButton * button = new QPushButton( acceptButtonLabel, this );
123 Q_CHECK_PTR( button );
124 layout->addWidget( button );
125 button->setDefault( true );
127 connect( button, SIGNAL( clicked() ),
128 this, SLOT ( accept() ) );
133 if ( ! rejectButtonLabel.isEmpty() )
135 // Reject button ( if desired ) - usually "Cancel"
137 button = new QPushButton( rejectButtonLabel, this );
138 Q_CHECK_PTR( button );
139 hbox->addWidget(button);
140 connect( button, SIGNAL( clicked() ),
141 this, SLOT ( reject() ) );
149 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
151 filter( QRegExp( "" ), byAuto, byApp, byUser );
156 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
158 YQUI::ui()->busyCursor();
161 set<string> ignoredNames;
163 if ( ! byUser || ! byApp )
164 ignoredNames = zypp::ui::userWantedPackageNames();
166 for ( ZyppPoolIterator it = zyppPkgBegin();
170 ZyppSel selectable = *it;
172 if ( selectable->toModify() )
174 zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
176 if ( ( modifiedBy == zypp::ResStatus::SOLVER ) && byAuto ||
177 ( modifiedBy == zypp::ResStatus::APPL_LOW ||
178 modifiedBy == zypp::ResStatus::APPL_HIGH ) && byApp ||
179 ( modifiedBy == zypp::ResStatus::USER ) && byUser )
181 if ( regexp.isEmpty() || regexp.indexIn( selectable->name().c_str() ) >= 0 )
183 if ( ! contains( ignoredNames, selectable->name() ) )
184 _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
190 YQUI::ui()->normalCursor();
195 YQPkgChangesDialog::isEmpty() const
197 return _pkgList->topLevelItemCount() == 0;
202 YQPkgChangesDialog::sizeHint() const
204 return limitToScreenSize( this, QDialog::sizeHint() );
209 YQPkgChangesDialog::showChangesDialog( const QString & message,
210 const QString & acceptButtonLabel,
211 const QString & rejectButtonLabel,
212 bool showIfListEmpty )
214 YQPkgChangesDialog dialog( 0,
220 if ( dialog.isEmpty() && ! showIfListEmpty )
225 return dialog.result() == QDialog::Accepted;
230 YQPkgChangesDialog::showChangesDialog( const QString & message,
231 const QRegExp & regexp,
232 const QString & acceptButtonLabel,
233 const QString & rejectButtonLabel,
234 bool showIfListEmpty )
236 YQPkgChangesDialog dialog( 0,
240 dialog.filter( regexp, true, true, true );
242 if ( dialog.isEmpty() && ! showIfListEmpty )
247 return dialog.result() == QDialog::Accepted;
253 #include "YQPkgChangesDialog.moc"