1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgConflictDialog.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 <zypp/ZYppFactory.h>
26 #include <zypp/Resolver.h>
31 #include <qpopupmenu.h>
32 #include <qpushbutton.h>
33 #include <qdatetime.h>
35 #include <qmessagebox.h>
37 #include "YQPkgConflictDialog.h"
38 #include "YQPkgConflictList.h"
41 #include "QY2LayoutUtils.h"
47 #define SPACING 6 // between subwidgets
48 #define MARGIN 4 // around the widget
51 // The busy dialog ("Checking Dependencies") will only be shown if solving
52 // (on average) takes longer than this many seconds. The first one will be
55 #define SUPPRESS_BUSY_DIALOG_SECONDS 1.5
58 YQPkgConflictDialog::YQPkgConflictDialog( QWidget * parent )
62 _totalSolveTime = 0.0;
65 // Set the dialog title.
67 // "Dependency conflict" is already used as the conflict list header just
68 // some pixels below that, so don't use this twice. This dialog title may
69 // or may not be visible, depending on whether or not there is a window
70 // manager running (and configured to show any dialog titles).
72 setCaption( _( "Warning" ) );
74 // Enable dialog resizing even without window manager
75 setSizeGripEnabled( true );
78 // Layout for the dialog (can't simply insert a QVbox)
80 QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
85 _conflictList = new YQPkgConflictList( this );
86 CHECK_PTR( _conflictList );
87 layout->addWidget( _conflictList );
88 layout->addSpacing(8);
90 connect( _conflictList, SIGNAL( updatePackages() ),
91 this, SIGNAL( updatePackages() ) );
96 QHBox * buttonBox = new QHBox( this );
97 CHECK_PTR( buttonBox );
98 buttonBox->setSpacing( SPACING );
99 buttonBox->setMargin ( MARGIN );
100 layout->addWidget( buttonBox );
105 QPushButton * button = new QPushButton( _( "&OK -- Try Again" ), buttonBox );
107 button->setDefault( true );
109 connect( button, SIGNAL( clicked() ),
110 this, SLOT ( solveAndShowConflicts() ) );
112 addHStretch( buttonBox );
115 // "Expert" menu button
117 button = new QPushButton( _( "&Expert" ), buttonBox );
120 addHStretch( buttonBox );
125 _expertMenu = new QPopupMenu( button );
126 CHECK_PTR( _expertMenu );
127 button->setPopup( _expertMenu );
129 _expertMenu->insertItem( _( "&Save This List to a File..." ),
130 _conflictList, SLOT( askSaveToFile() ) );
135 button = new QPushButton( _( "&Cancel" ), buttonBox );
138 connect( button, SIGNAL( clicked() ),
139 this, SLOT ( reject() ) );
144 _busyPopup = new QLabel( " " + _( "Checking Dependencies..." ) + " ", parent, 0,
145 WStyle_Customize | WStyle_DialogBorder | WStyle_Dialog );
147 CHECK_PTR( _busyPopup );
148 _busyPopup->setCaption( "" );
149 _busyPopup->resize( _busyPopup->sizeHint() );
150 YQDialog::center( _busyPopup, parent );
153 // Here comes a real nasty hack.
155 // The busy popup is needed to indicate that the application is (you
156 // guessed right) busy. But as long as it is busy, it doesn't process X
157 // events, either, and I didn't manage to convince Qt to please paint this
158 // popup before the solver's calculations (which take quite a while) start
159 // - all combinations of show(), repaint(), XSync(), XFlush(),
160 // processEvents() etc. failed.
162 // So, let's do it the hard way: Give this popup a background pixmap into
163 // which we render the text to display. The X server draws background
164 // pixmaps immediately, so we don't have to wait until the X server, the
165 // window manager and this application are finished negotiating all their
168 // Create a pixmap. Make it large enough so it isn't replicated (i.e. the
169 // text is displayed several times) if some window manager chooses not to
170 // honor the size hints (KDM for example uses double the height we
173 QSize size = _busyPopup->sizeHint();
174 QPixmap pixmap( 3 * size.width(), 3 * size.height() );
176 // Clear the pixmap with the widget's normal background color.
177 pixmap.fill( _busyPopup->paletteBackgroundColor() );
179 // Render the text - aligned top and left because otherwise it will of
180 // course be centered inside the pixmap which is usually much larger than
181 // the popup, thus the text would be cut off.
182 QPainter painter( &pixmap );
183 painter.drawText( pixmap.rect(), AlignLeft | AlignTop, _busyPopup->text() );
186 _busyPopup->setPaletteBackgroundPixmap( pixmap );
188 // If the application manages to render the true contents of the label we
189 // just misused so badly, the real label will interfere with the background
190 // pixmap with (maybe) a few pixels offset (bug #25647). Fast or
191 // multiprocessor machines tend to have this problem.
192 // So let's get rid of the label text and solely rely on the background
194 _busyPopup->setText( "" );
196 // Make sure the newly emptied text doesn't cause the busy dialog to be
197 // resized to nil (or a window manager dependent minimum size).
198 _busyPopup->setFixedSize( _busyPopup->size() );
202 YQPkgConflictDialog::~YQPkgConflictDialog()
209 YQPkgConflictDialog::sizeHint() const
211 return limitToScreenSize( this, 550, 450 );
216 YQPkgConflictDialog::solveAndShowConflicts()
220 y2debug( "Solving..." );
226 bool success = zypp::getZYpp()->resolver()->resolvePool();
228 _totalSolveTime += solveTime.elapsed() / 1000.0;
230 y2debug( "Solving done in %f s - average: %f s",
231 solveTime.elapsed() / 1000.0, averageSolveTime() );
233 return processSolverResult( success );
238 YQPkgConflictDialog::verifySystem()
242 y2debug( "Verifying system..." );
246 bool success = zypp::getZYpp()->resolver()->verifySystem( true ); // considerNewHardware
248 y2debug( "System verified in %f s", solveTime.elapsed() / 1000.0 );
250 return processSolverResult( success );
255 YQPkgConflictDialog::prepareSolving()
257 CHECK_PTR( _conflictList );
258 YQUI::ui()->busyCursor();
262 // This is not only the starting point for all the dependency solving
263 // magic, it is also used internally when clicking the "OK - Try again"
264 // button. Thus, before doing anything else, check if the conflict list
265 // still contains anything, and if so, apply any conflict resolutions
266 // the user selected - but only if this dialog is already visible.
268 _conflictList->applyResolutions();
272 // Initialize for next round of solving.
273 _conflictList->clear();
275 if ( _solveCount++ == 0 || averageSolveTime() > SUPPRESS_BUSY_DIALOG_SECONDS )
277 YQDialog::center( _busyPopup, parentWidget() );
280 // No _busyPopup->repaint() - that doesn't help anyway: Qt doesn't do
281 // any actual painting until the window is mapped. We just rely on the
282 // background pixmap we provided in the constructor.
284 // Make sure show() gets processed - usually, a window manager catches
285 // the show() (XMap) events, positions and maybe resizes the window and
286 // only then sends off an event that makes the window appear. This
287 // event needs to be processed.
288 qApp->processEvents();
294 YQPkgConflictDialog::processSolverResult( bool success )
296 if ( _busyPopup->isVisible() )
299 // Package states may have changed: The solver may have set packages to
300 // autoInstall or autoUpdate. Make those changes known.
301 emit updatePackages();
303 YQUI::ui()->normalCursor();
304 int result = QDialog::Accepted;
306 if ( success ) // Solving went without any complaints?
308 result = QDialog::Accepted;
311 accept(); // Pop down the dialog.
313 else // There were solving problems.
315 y2debug( "Dependency conflict!" );
316 YQUI::ui()->busyCursor();
318 _conflictList->fill( zypp::getZYpp()->resolver()->problems() );
319 YQUI::ui()->normalCursor();
323 // Pop up the dialog and run a local event loop.
328 return result; // QDialog::Accepted or QDialog::Rejected
333 YQPkgConflictDialog::resetIgnoredDependencyProblems()
335 zypp::getZYpp()->resolver()->undo();
340 YQPkgConflictDialog::averageSolveTime() const
342 if ( _solveCount < 1 )
345 return _totalSolveTime / _solveCount;
350 YQPkgConflictDialog::askCreateSolverTestCase()
352 QString testCaseDir = "/var/log/YaST2/solverTestcase";
353 // Heading for popup dialog
354 QString heading = QString( "<h2>%1</h2>" ).arg( _( "Create Dependency Resolver Test Case" ) );
357 _( "<p>Use this to generate extensive logs to help tracking down bugs in the dependency resolver."
358 "The logs will be stored in directory <br><tt>%1</tt></p>" ).arg( testCaseDir );
360 int button_no = QMessageBox::information( 0, // parent
361 _( "Solver Test Case" ), // caption
363 _( "C&ontinue" ), // button #0
364 _( "&Cancel" ) ); // button #1
366 if ( button_no == 1 ) // Cancel
369 y2milestone( "Generating solver test case START" );
370 bool success = zypp::getZYpp()->resolver()->createSolverTestcase( testCaseDir.ascii() );
371 y2milestone( "Generating solver test case END" );
376 _( "<p>Dependency resolver test case written to <br><tt>%1</tt></p>"
377 "<p>Prepare <tt>y2logs.tgz tar</tt> archive to attach to Bugzilla?</p>" ).arg( testCaseDir ),
378 button_no = QMessageBox::question( 0, // parent
379 _( "Success" ), // caption
381 QMessageBox::Yes | QMessageBox::Default,
383 QMessageBox::Cancel | QMessageBox::Escape );
385 if ( button_no & QMessageBox::Yes ) // really binary (not logical) '&' - QMessageBox::Default is still in there
386 YQUI::ui()->askSaveLogs();
390 QMessageBox::warning( 0, // parent
391 _( "Error" ), // caption
392 _( "<p><b>Error</b> creating dependency resolver test case</p>"
393 "<p>Please check disk space and permissions for <tt>%1</tt></p>" ).arg( testCaseDir ),
394 QMessageBox::Ok | QMessageBox::Default,
395 QMessageBox::NoButton,
396 QMessageBox::NoButton );
401 YQPkgConflictDialog::keyPressEvent( QKeyEvent * event )
403 if ( event && event->key() == Qt::Key_Print )
405 YQUI::ui()->makeScreenShot( "" );
408 QWidget::keyPressEvent( event );
413 #include "YQPkgConflictDialog.moc"