1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgConflictDialog.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 <zypp/ZYppFactory.h>
25 #include <zypp/Resolver.h>
31 #include <QPushButton>
34 #include <QMessageBox>
35 #include <QDesktopWidget>
39 #include "YQPkgConflictDialog.h"
40 #include "YQPkgConflictList.h"
43 #include "QY2LayoutUtils.h"
49 #define SPACING 6 // between subwidgets
50 #define MARGIN 4 // around the widget
53 // The busy dialog ("Checking Dependencies") will only be shown if solving
54 // (on average) takes longer than this many seconds. The first one will be
57 #define SUPPRESS_BUSY_DIALOG_SECONDS 1.5
60 YQPkgConflictDialog::YQPkgConflictDialog( QWidget * parent )
64 _totalSolveTime = 0.0;
67 // Set the dialog title.
69 // "Dependency conflict" is already used as the conflict list header just
70 // some pixels below that, so don't use this twice. This dialog title may
71 // or may not be visible, depending on whether or not there is a window
72 // manager running (and configured to show any dialog titles).
74 setWindowTitle( _( "Warning" ) );
76 // Enable dialog resizing even without window manager
77 setSizeGripEnabled( true );
80 // Layout for the dialog (can't simply insert a QVbox)
82 QVBoxLayout * layout = new QVBoxLayout();
84 layout->setMargin(MARGIN);
85 layout->setSpacing(SPACING);
87 Q_CHECK_PTR( layout );
91 _conflictList = new YQPkgConflictList( this );
92 Q_CHECK_PTR( _conflictList );
93 layout->addWidget( _conflictList );
94 layout->addSpacing(8);
96 connect( _conflictList, SIGNAL( updatePackages() ),
97 this, SIGNAL( updatePackages() ) );
101 QHBoxLayout * buttonBox = new QHBoxLayout();
102 Q_CHECK_PTR( buttonBox );
103 buttonBox->setSpacing( SPACING );
104 buttonBox->setMargin ( MARGIN );
105 layout->addLayout( buttonBox );
109 QPushButton * button = new QPushButton( _( "&OK -- Try Again" ), this);
110 buttonBox->addWidget(button);
111 Q_CHECK_PTR( button );
112 button->setDefault( true );
114 connect( button, SIGNAL( clicked() ),
115 this, SLOT ( solveAndShowConflicts() ) );
117 // FIXME addHStretch( buttonBox );
120 // "Expert" menu button
122 button = new QPushButton( _( "&Expert" ), this );
123 buttonBox->addWidget(button);
125 Q_CHECK_PTR( button );
127 //FIXME addHStretch( buttonBox );
132 _expertMenu = new QMenu( button );
133 Q_CHECK_PTR( _expertMenu );
134 button->setMenu( _expertMenu );
136 _expertMenu->addAction( _( "&Save This List to a File..." ),
137 _conflictList, SLOT( askSaveToFile() ) );
142 button = new QPushButton( _( "&Cancel" ), this);
143 buttonBox->addWidget(button);
144 Q_CHECK_PTR( button );
146 connect( button, SIGNAL( clicked() ),
147 this, SLOT ( reject() ) );
152 _busyPopup = new QLabel( " " + _( "Checking Dependencies..." ) + " ", parent, 0
154 , WStyle_Customize | WStyle_DialogBorder | WStyle_Dialog | WStyle_Title
157 Q_CHECK_PTR( _busyPopup );
159 _busyPopup->setWindowTitle( "" );
160 _busyPopup->resize( _busyPopup->sizeHint() );
161 YQDialog::center( _busyPopup, parent );
164 // Here comes a real nasty hack.
166 // The busy popup is needed to indicate that the application is (you
167 // guessed right) busy. But as long as it is busy, it doesn't process X
168 // events, either, and I didn't manage to convince Qt to please paint this
169 // popup before the solver's calculations (which take quite a while) start
170 // - all combinations of show(), repaint(), XSync(), XFlush(),
171 // processEvents() etc. failed.
173 // So, let's do it the hard way: Give this popup a background pixmap into
174 // which we render the text to display. The X server draws background
175 // pixmaps immediately, so we don't have to wait until the X server, the
176 // window manager and this application are finished negotiating all their
179 // Create a pixmap. Make it large enough so it isn't replicated (i.e. the
180 // text is displayed several times) if some window manager chooses not to
181 // honor the size hints (KDM for example uses double the height we
184 QSize size = _busyPopup->sizeHint();
185 QPixmap pixmap( 3 * size.width(), 3 * size.height() );
187 // Clear the pixmap with the widget's normal background color.
188 //FIXME pixmap.fill( _busyPopup->paletteBackgroundColor() );
190 // Render the text - aligned top and left because otherwise it will of
191 // course be centered inside the pixmap which is usually much larger than
192 // the popup, thus the text would be cut off.
193 QPainter painter( &pixmap );
194 painter.drawText( pixmap.rect(), Qt::AlignLeft | Qt::AlignTop, _busyPopup->text() );
197 //FIXME _busyPopup->setPaletteBackgroundPixmap( pixmap );
199 // If the application manages to render the true contents of the label we
200 // just misused so badly, the real label will interfere with the background
201 // pixmap with (maybe) a few pixels offset (bug #25647). Fast or
202 // multiprocessor machines tend to have this problem.
203 // So let's get rid of the label text and solely rely on the background
205 _busyPopup->setText( "" );
207 // Make sure the newly emptied text doesn't cause the busy dialog to be
208 // resized to nil (or a window manager dependent minimum size).
209 _busyPopup->setFixedSize( _busyPopup->size() );
213 YQPkgConflictDialog::~YQPkgConflictDialog()
220 YQPkgConflictDialog::sizeHint() const
222 return limitToScreenSize( this, 550, 450 );
227 YQPkgConflictDialog::solveAndShowConflicts()
231 y2debug( "Solving..." );
237 bool success = zypp::getZYpp()->resolver()->resolvePool();
239 _totalSolveTime += solveTime.elapsed() / 1000.0;
241 y2debug( "Solving done in %f s - average: %f s",
242 solveTime.elapsed() / 1000.0, averageSolveTime() );
244 return processSolverResult( success );
249 YQPkgConflictDialog::verifySystem()
253 y2debug( "Verifying system..." );
257 bool success = zypp::getZYpp()->resolver()->verifySystem( true ); // considerNewHardware
259 y2debug( "System verified in %f s", solveTime.elapsed() / 1000.0 );
261 return processSolverResult( success );
266 YQPkgConflictDialog::prepareSolving()
268 Q_CHECK_PTR( _conflictList );
269 YQUI::ui()->busyCursor();
273 // This is not only the starting point for all the dependency solving
274 // magic, it is also used internally when clicking the "OK - Try again"
275 // button. Thus, before doing anything else, check if the conflict list
276 // still contains anything, and if so, apply any conflict resolutions
277 // the user selected - but only if this dialog is already visible.
279 _conflictList->applyResolutions();
283 // Initialize for next round of solving.
284 _conflictList->clear();
286 if ( _solveCount++ == 0 || averageSolveTime() > SUPPRESS_BUSY_DIALOG_SECONDS )
288 YQDialog::center( _busyPopup, parentWidget() );
291 // No _busyPopup->repaint() - that doesn't help anyway: Qt doesn't do
292 // any actual painting until the window is mapped. We just rely on the
293 // background pixmap we provided in the constructor.
295 // Make sure show() gets processed - usually, a window manager catches
296 // the show() (XMap) events, positions and maybe resizes the window and
297 // only then sends off an event that makes the window appear. This
298 // event needs to be processed.
299 qApp->processEvents();
305 YQPkgConflictDialog::processSolverResult( bool success )
307 if ( _busyPopup->isVisible() )
310 // Package states may have changed: The solver may have set packages to
311 // autoInstall or autoUpdate. Make those changes known.
312 emit updatePackages();
314 YQUI::ui()->normalCursor();
315 int result = QDialog::Accepted;
317 if ( success ) // Solving went without any complaints?
319 result = QDialog::Accepted;
322 accept(); // Pop down the dialog.
324 else // There were solving problems.
326 y2debug( "Dependency conflict!" );
327 YQUI::ui()->busyCursor();
329 _conflictList->fill( zypp::getZYpp()->resolver()->problems() );
330 YQUI::ui()->normalCursor();
334 // Pop up the dialog and run a local event loop.
339 return result; // QDialog::Accepted or QDialog::Rejected
344 YQPkgConflictDialog::resetIgnoredDependencyProblems()
346 zypp::getZYpp()->resolver()->undo();
351 YQPkgConflictDialog::averageSolveTime() const
353 if ( _solveCount < 1 )
356 return _totalSolveTime / _solveCount;
361 YQPkgConflictDialog::askCreateSolverTestCase()
363 QString testCaseDir = "/var/log/YaST2/solverTestcase";
364 // Heading for popup dialog
365 QString heading = QString( "<h2>%1</h2>" ).arg( _( "Create Dependency Resolver Test Case" ) );
368 _( "<p>Use this to generate extensive logs to help tracking down bugs in the dependency resolver. "
369 "The logs will be stored in directory <br><tt>%1</tt></p>" ).arg( testCaseDir );
371 int button_no = QMessageBox::information( 0, // parent
372 _( "Solver Test Case" ), // caption
374 _( "C&ontinue" ), // button #0
375 _( "&Cancel" ) ); // button #1
377 if ( button_no == 1 ) // Cancel
380 y2milestone( "Generating solver test case START" );
381 bool success = zypp::getZYpp()->resolver()->createSolverTestcase( qPrintable(testCaseDir) );
382 y2milestone( "Generating solver test case END" );
387 _( "<p>Dependency resolver test case written to <br><tt>%1</tt></p>"
388 "<p>Prepare <tt>y2logs.tgz tar</tt> archive to attach to Bugzilla?</p>" ).arg( testCaseDir ),
389 button_no = QMessageBox::question( 0, // parent
390 _( "Success" ), // caption
392 QMessageBox::Yes | QMessageBox::Default,
394 QMessageBox::Cancel | QMessageBox::Escape );
396 if ( button_no & QMessageBox::Yes ) // really binary (not logical) '&' - QMessageBox::Default is still in there
397 YQUI::ui()->askSaveLogs();
401 QMessageBox::warning( 0, // parent
402 _( "Error" ), // caption
403 _( "<p><b>Error</b> creating dependency resolver test case</p>"
404 "<p>Please check disk space and permissions for <tt>%1</tt></p>" ).arg( testCaseDir ),
405 QMessageBox::Ok | QMessageBox::Default,
406 QMessageBox::NoButton,
407 QMessageBox::NoButton );
412 YQPkgConflictDialog::keyPressEvent( QKeyEvent * event )
414 if ( event && event->key() == Qt::Key_Print )
416 YQUI::ui()->makeScreenShot( "" );
419 QWidget::keyPressEvent( event );
424 #include "YQPkgConflictDialog.moc"