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>
32 #include <QPushButton>
35 #include <QMessageBox>
36 #include <QDesktopWidget>
40 #include "YQPkgConflictDialog.h"
41 #include "YQPkgConflictList.h"
44 #include "QY2LayoutUtils.h"
50 #define SPACING 6 // between subwidgets
51 #define MARGIN 4 // around the widget
54 // The busy dialog ("Checking Dependencies") will only be shown if solving
55 // (on average) takes longer than this many seconds. The first one will be
58 #define SUPPRESS_BUSY_DIALOG_SECONDS 1.5
61 YQPkgConflictDialog::YQPkgConflictDialog( QWidget * parent )
65 _totalSolveTime = 0.0;
68 // Set the dialog title.
70 // "Dependency conflict" is already used as the conflict list header just
71 // some pixels below that, so don't use this twice. This dialog title may
72 // or may not be visible, depending on whether or not there is a window
73 // manager running (and configured to show any dialog titles).
75 setCaption( _( "Warning" ) );
77 // Enable dialog resizing even without window manager
78 setSizeGripEnabled( true );
81 // Layout for the dialog (can't simply insert a QVbox)
83 QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
84 Q_CHECK_PTR( layout );
88 _conflictList = new YQPkgConflictList( this );
89 Q_CHECK_PTR( _conflictList );
90 layout->addWidget( _conflictList );
91 layout->addSpacing(8);
93 connect( _conflictList, SIGNAL( updatePackages() ),
94 this, SIGNAL( updatePackages() ) );
98 QHBoxLayout * buttonBox = new QHBoxLayout(this);
99 Q_CHECK_PTR( buttonBox );
100 buttonBox->setSpacing( SPACING );
101 buttonBox->setMargin ( MARGIN );
102 layout->addLayout( buttonBox );
106 QPushButton * button = new QPushButton( _( "&OK -- Try Again" ), this);
107 buttonBox->addWidget(button);
108 Q_CHECK_PTR( button );
109 button->setDefault( true );
111 connect( button, SIGNAL( clicked() ),
112 this, SLOT ( solveAndShowConflicts() ) );
114 // FIXME addHStretch( buttonBox );
117 // "Expert" menu button
119 button = new QPushButton( _( "&Expert" ), this );
120 buttonBox->addWidget(button);
122 Q_CHECK_PTR( button );
124 //FIXME addHStretch( buttonBox );
129 _expertMenu = new QMenu( button );
130 Q_CHECK_PTR( _expertMenu );
131 button->setPopup( _expertMenu );
133 _expertMenu->insertItem( _( "&Save This List to a File..." ),
134 _conflictList, SLOT( askSaveToFile() ) );
139 button = new QPushButton( _( "&Cancel" ), this);
140 buttonBox->addWidget(button);
141 Q_CHECK_PTR( button );
143 connect( button, SIGNAL( clicked() ),
144 this, SLOT ( reject() ) );
149 _busyPopup = new QLabel( " " + _( "Checking Dependencies..." ) + " ", parent, 0
151 , WStyle_Customize | WStyle_DialogBorder | WStyle_Dialog | WStyle_Title
154 Q_CHECK_PTR( _busyPopup );
156 _busyPopup->setCaption( "" );
157 _busyPopup->resize( _busyPopup->sizeHint() );
158 YQDialog::center( _busyPopup, parent );
161 // Here comes a real nasty hack.
163 // The busy popup is needed to indicate that the application is (you
164 // guessed right) busy. But as long as it is busy, it doesn't process X
165 // events, either, and I didn't manage to convince Qt to please paint this
166 // popup before the solver's calculations (which take quite a while) start
167 // - all combinations of show(), repaint(), XSync(), XFlush(),
168 // processEvents() etc. failed.
170 // So, let's do it the hard way: Give this popup a background pixmap into
171 // which we render the text to display. The X server draws background
172 // pixmaps immediately, so we don't have to wait until the X server, the
173 // window manager and this application are finished negotiating all their
176 // Create a pixmap. Make it large enough so it isn't replicated (i.e. the
177 // text is displayed several times) if some window manager chooses not to
178 // honor the size hints (KDM for example uses double the height we
181 QSize size = _busyPopup->sizeHint();
182 QPixmap pixmap( 3 * size.width(), 3 * size.height() );
184 // Clear the pixmap with the widget's normal background color.
185 pixmap.fill( _busyPopup->paletteBackgroundColor() );
187 // Render the text - aligned top and left because otherwise it will of
188 // course be centered inside the pixmap which is usually much larger than
189 // the popup, thus the text would be cut off.
190 QPainter painter( &pixmap );
191 painter.drawText( pixmap.rect(), Qt::AlignLeft | Qt::AlignTop, _busyPopup->text() );
194 _busyPopup->setPaletteBackgroundPixmap( pixmap );
196 // If the application manages to render the true contents of the label we
197 // just misused so badly, the real label will interfere with the background
198 // pixmap with (maybe) a few pixels offset (bug #25647). Fast or
199 // multiprocessor machines tend to have this problem.
200 // So let's get rid of the label text and solely rely on the background
202 _busyPopup->setText( "" );
204 // Make sure the newly emptied text doesn't cause the busy dialog to be
205 // resized to nil (or a window manager dependent minimum size).
206 _busyPopup->setFixedSize( _busyPopup->size() );
210 YQPkgConflictDialog::~YQPkgConflictDialog()
217 YQPkgConflictDialog::sizeHint() const
219 return limitToScreenSize( this, 550, 450 );
224 YQPkgConflictDialog::solveAndShowConflicts()
228 y2debug( "Solving..." );
234 bool success = zypp::getZYpp()->resolver()->resolvePool();
236 _totalSolveTime += solveTime.elapsed() / 1000.0;
238 y2debug( "Solving done in %f s - average: %f s",
239 solveTime.elapsed() / 1000.0, averageSolveTime() );
241 return processSolverResult( success );
246 YQPkgConflictDialog::verifySystem()
250 y2debug( "Verifying system..." );
254 bool success = zypp::getZYpp()->resolver()->verifySystem( true ); // considerNewHardware
256 y2debug( "System verified in %f s", solveTime.elapsed() / 1000.0 );
258 return processSolverResult( success );
263 YQPkgConflictDialog::prepareSolving()
265 Q_CHECK_PTR( _conflictList );
266 YQUI::ui()->busyCursor();
270 // This is not only the starting point for all the dependency solving
271 // magic, it is also used internally when clicking the "OK - Try again"
272 // button. Thus, before doing anything else, check if the conflict list
273 // still contains anything, and if so, apply any conflict resolutions
274 // the user selected - but only if this dialog is already visible.
276 _conflictList->applyResolutions();
280 // Initialize for next round of solving.
281 _conflictList->clear();
283 if ( _solveCount++ == 0 || averageSolveTime() > SUPPRESS_BUSY_DIALOG_SECONDS )
285 YQDialog::center( _busyPopup, parentWidget() );
288 // No _busyPopup->repaint() - that doesn't help anyway: Qt doesn't do
289 // any actual painting until the window is mapped. We just rely on the
290 // background pixmap we provided in the constructor.
292 // Make sure show() gets processed - usually, a window manager catches
293 // the show() (XMap) events, positions and maybe resizes the window and
294 // only then sends off an event that makes the window appear. This
295 // event needs to be processed.
296 qApp->processEvents();
302 YQPkgConflictDialog::processSolverResult( bool success )
304 if ( _busyPopup->isVisible() )
307 // Package states may have changed: The solver may have set packages to
308 // autoInstall or autoUpdate. Make those changes known.
309 emit updatePackages();
311 YQUI::ui()->normalCursor();
312 int result = QDialog::Accepted;
314 if ( success ) // Solving went without any complaints?
316 result = QDialog::Accepted;
319 accept(); // Pop down the dialog.
321 else // There were solving problems.
323 y2debug( "Dependency conflict!" );
324 YQUI::ui()->busyCursor();
326 _conflictList->fill( zypp::getZYpp()->resolver()->problems() );
327 YQUI::ui()->normalCursor();
331 // Pop up the dialog and run a local event loop.
336 return result; // QDialog::Accepted or QDialog::Rejected
341 YQPkgConflictDialog::resetIgnoredDependencyProblems()
343 zypp::getZYpp()->resolver()->undo();
348 YQPkgConflictDialog::averageSolveTime() const
350 if ( _solveCount < 1 )
353 return _totalSolveTime / _solveCount;
358 YQPkgConflictDialog::askCreateSolverTestCase()
360 QString testCaseDir = "/var/log/YaST2/solverTestcase";
361 // Heading for popup dialog
362 QString heading = QString( "<h2>%1</h2>" ).arg( _( "Create Dependency Resolver Test Case" ) );
365 _( "<p>Use this to generate extensive logs to help tracking down bugs in the dependency resolver. "
366 "The logs will be stored in directory <br><tt>%1</tt></p>" ).arg( testCaseDir );
368 int button_no = QMessageBox::information( 0, // parent
369 _( "Solver Test Case" ), // caption
371 _( "C&ontinue" ), // button #0
372 _( "&Cancel" ) ); // button #1
374 if ( button_no == 1 ) // Cancel
377 y2milestone( "Generating solver test case START" );
378 bool success = zypp::getZYpp()->resolver()->createSolverTestcase( testCaseDir.ascii() );
379 y2milestone( "Generating solver test case END" );
384 _( "<p>Dependency resolver test case written to <br><tt>%1</tt></p>"
385 "<p>Prepare <tt>y2logs.tgz tar</tt> archive to attach to Bugzilla?</p>" ).arg( testCaseDir ),
386 button_no = QMessageBox::question( 0, // parent
387 _( "Success" ), // caption
389 QMessageBox::Yes | QMessageBox::Default,
391 QMessageBox::Cancel | QMessageBox::Escape );
393 if ( button_no & QMessageBox::Yes ) // really binary (not logical) '&' - QMessageBox::Default is still in there
394 YQUI::ui()->askSaveLogs();
398 QMessageBox::warning( 0, // parent
399 _( "Error" ), // caption
400 _( "<p><b>Error</b> creating dependency resolver test case</p>"
401 "<p>Please check disk space and permissions for <tt>%1</tt></p>" ).arg( testCaseDir ),
402 QMessageBox::Ok | QMessageBox::Default,
403 QMessageBox::NoButton,
404 QMessageBox::NoButton );
409 YQPkgConflictDialog::keyPressEvent( QKeyEvent * event )
411 if ( event && event->key() == Qt::Key_Print )
413 YQUI::ui()->makeScreenShot( "" );
416 QWidget::keyPressEvent( event );
421 #include "YQPkgConflictDialog.moc"