1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPackageSelectorBase.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #include <QMessageBox>
24 #define y2log_component "qt-pkg"
25 #include <ycp/y2log.h>
28 #include <QVBoxLayout>
29 #include <QHBoxLayout>
30 #include "QY2LayoutUtils.h"
32 #include "YQPackageSelectorBase.h"
33 #include "YQPkgChangesDialog.h"
34 #include "YQPkgConflictDialog.h"
35 #include "YQPkgDiskUsageList.h"
36 #include "YQPkgDiskUsageWarningDialog.h"
37 #include "YQPkgTextDialog.h"
38 #include "YQPkgObjList.h"
42 #include "YQApplication.h"
52 YQPackageSelectorBase::YQPackageSelectorBase( YWidget * parent,
54 : QWidget( (QWidget *) parent->widgetRep() )
55 , YPackageSelector( parent, modeFlags )
59 // QHBoxLayout *layout = new QHBoxLayout(this);
62 _showChangesDialog = false;
63 _pkgConflictDialog = 0;
65 _pkgConflictDialog = 0;
67 YQUI::setTextdomain( "packages-qt" );
68 setFont( YQUI::yqApp()->currentFont() );
69 YQUI::ui()->blockWmClose(); // Automatically undone after UI::RunPkgSelection()
71 _pkgConflictDialog = new YQPkgConflictDialog( this );
72 Q_CHECK_PTR( _pkgConflictDialog );
74 QString label = _( "Reset &Ignored Dependency Conflicts" );
75 _actionResetIgnoredDependencyProblems = new QAction( label, this);
76 _actionResetIgnoredDependencyProblems->setShortcut((QKeySequence) 0);
77 //_actionResetIgnoredDependencyProblems->setMenuRole(QAction::TextHeuristicRole);
78 Q_CHECK_PTR( _actionResetIgnoredDependencyProblems );
80 connect( _actionResetIgnoredDependencyProblems, SIGNAL( activated() ),
81 this, SLOT ( resetIgnoredDependencyProblems() ) );
83 zyppPool().saveState<zypp::Package >();
84 zyppPool().saveState<zypp::Pattern >();
85 zyppPool().saveState<zypp::Selection>();
86 zyppPool().saveState<zypp::Language >();
87 zyppPool().saveState<zypp::Patch >();
91 // Handle WM_CLOSE like "Cancel"
94 connect( YQUI::ui(), SIGNAL( wmClose() ),
95 this, SLOT ( reject() ) );
97 y2milestone( "PackageSelectorBase init done" );
101 YQPackageSelectorBase::~YQPackageSelectorBase()
103 y2milestone( "Destroying PackageSelector" );
108 YQPackageSelectorBase::resolveDependencies()
110 if ( ! _pkgConflictDialog )
112 y2error( "No package conflict dialog existing" );
113 return QDialog::Accepted;
117 YQUI::ui()->busyCursor();
118 emit resolvingStarted();
120 int result = _pkgConflictDialog->solveAndShowConflicts();
122 emit resolvingFinished();
123 YQUI::ui()->normalCursor();
130 YQPackageSelectorBase::verifySystem()
132 if ( ! _pkgConflictDialog )
134 y2error( "No package conflict dialog existing" );
135 return QDialog::Accepted;
139 YQUI::ui()->busyCursor();
140 int result = _pkgConflictDialog->verifySystem();
141 YQUI::ui()->normalCursor();
143 if ( result == QDialog::Accepted )
145 QMessageBox::information( this, "",
146 _( "System dependencies verify OK." ),
155 YQPackageSelectorBase::checkDiskUsage()
157 if ( ! _diskUsageList )
159 return QDialog::Accepted;
162 if ( ! _diskUsageList->overflowWarning.inRange() )
163 return QDialog::Accepted;
166 // Translators: RichText ( HTML-like ) format
167 "<p><b>" + _( "Error: Out of disk space!" ) + "</b></p>"
169 "You can choose to install anyway if you know what you are doing, "
170 "but you risk getting a corrupted system that requires manual repairs. "
171 "If you are not absolutely sure how to handle such a case, "
172 "press <b>Cancel</b> now and deselect some packages."
175 return YQPkgDiskUsageWarningDialog::diskUsageWarning( msg,
176 100, _( "C&ontinue Anyway" ), _( "&Cancel" ) );
183 YQPackageSelectorBase::showAutoPkgList()
185 resolveDependencies();
187 // Show which packages are installed/deleted automatically
191 + _( "Automatic Changes" )
193 // Detailed explanation ( automatic word wrap! )
195 + _( "In addition to your manual selections, the following packages"
196 " have been changed to resolve dependencies:" )
199 YQPkgChangesDialog::showChangesDialog( msg,
201 QString::null, // rejectButtonLabel
202 true ); // showIfEmpty
208 YQPackageSelectorBase::reject()
211 zyppPool().diffState<zypp::Package >() ||
212 zyppPool().diffState<zypp::Pattern >() ||
213 zyppPool().diffState<zypp::Selection>() ||
214 zyppPool().diffState<zypp::Language >() ||
215 zyppPool().diffState<zypp::Patch >();
219 if ( zyppPool().diffState<zypp::Package>() )
220 y2milestone( "diffState() reports changed packages" );
222 if ( zyppPool().diffState<zypp::Pattern>() )
223 y2milestone( "diffState() reports changed patterns" );
225 if ( zyppPool().diffState<zypp::Selection>() )
226 y2milestone( "diffState() reports changed selections" );
228 if ( zyppPool().diffState<zypp::Language>() )
229 y2milestone( "diffState() reports changed languages" );
231 if ( zyppPool().diffState<zypp::Patch>() )
232 y2milestone( "diffState() reports changed patches" );
236 ( QMessageBox::warning( this, "",
237 _( "Abandon all changes?" ),
238 _( "&OK" ), _( "&Cancel" ), "",
239 1, // defaultButtonNumber (from 0)
240 1 ) // escapeButtonNumber
241 == 0 ) // Proceed upon button #0 ( OK )
244 zyppPool().restoreState<zypp::Package >();
245 zyppPool().restoreState<zypp::Pattern >();
246 zyppPool().restoreState<zypp::Selection>();
247 zyppPool().restoreState<zypp::Language >();
248 zyppPool().restoreState<zypp::Patch >();
250 y2milestone( "Closing PackageSelector with \"Cancel\"" );
251 YQUI::ui()->sendEvent( new YCancelEvent() );
257 YQPackageSelectorBase::accept()
259 bool confirmedAllLicenses;
263 // Force final dependency resolving
264 if ( resolveDependencies() == QDialog::Rejected )
267 confirmedAllLicenses = showPendingLicenseAgreements();
269 } while ( ! confirmedAllLicenses ); // Some packages will be set to S_TABOO - need another solver run
271 if ( _showChangesDialog )
273 // Show which packages are installed/deleted automatically
277 + _( "Automatic Changes" )
279 // Detailed explanation ( automatic word wrap! )
281 + _( "In addition to your manual selections, the following packages"
282 " have been changed to resolve dependencies:" )
285 if ( YQPkgChangesDialog::showChangesDialog( msg, _( "C&ontinue" ), _( "&Cancel" ) )
286 == QDialog::Rejected )
291 if ( checkDiskUsage() == QDialog::Rejected )
294 y2milestone( "Closing PackageSelector with \"Accept\"" );
295 YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "accept" ) ) );
300 YQPackageSelectorBase::showPendingLicenseAgreements()
302 y2milestone( "Showing all pending license agreements" );
304 bool allConfirmed = true;
306 if ( onlineUpdateMode() )
307 allConfirmed = showPendingLicenseAgreements( zyppPatchesBegin(), zyppPatchesEnd() );
309 allConfirmed = showPendingLicenseAgreements( zyppPkgBegin(), zyppPkgEnd() ) && allConfirmed;
316 YQPackageSelectorBase::showPendingLicenseAgreements( ZyppPoolIterator begin, ZyppPoolIterator end )
318 bool allConfirmed = true;
320 for ( ZyppPoolIterator it = begin; it != end; ++it )
324 switch ( sel->status() )
331 if ( sel->candidateObj() )
333 string licenseText = sel->candidateObj()->licenseToConfirm();
335 if ( ! licenseText.empty() )
337 y2milestone( "Resolvable %s has a license agreement", sel->name().c_str() );
339 if( ! sel->hasLicenceConfirmed() )
341 y2debug( "Showing license agreement for resolvable %s", sel->name().c_str() );
342 allConfirmed = YQPkgObjListItem::showLicenseAgreement( sel ) && allConfirmed;
346 y2milestone( "Resolvable %s's license is already confirmed", sel->name().c_str() );
362 YQPackageSelectorBase::notImplemented()
364 QMessageBox::information( this, "",
365 _( "Not implemented yet. Sorry." ),
371 YQPackageSelectorBase::resetIgnoredDependencyProblems()
373 YQPkgConflictDialog::resetIgnoredDependencyProblems();
378 YQPackageSelectorBase::keyPressEvent( QKeyEvent * event )
382 unsigned special_combo = ( Qt::ControlButton | Qt::ShiftButton | Qt::AltButton );
384 if ( ( event->state() & special_combo ) == special_combo )
386 if ( event->key() == Qt::Key_A )
393 else if ( event->key() == Qt::Key_F5 ) // No matter if Ctrl/Alt/Shift pressed
395 YQUI::ui()->easterEgg();
400 QWidget::keyPressEvent( event );
404 int YQPackageSelectorBase::preferredWidth()
406 return max( 640, sizeHint().width() );
410 int YQPackageSelectorBase::preferredHeight()
412 return max( 480, sizeHint().height() );
417 YQPackageSelectorBase::setSize( int newWidth, int newHeight )
419 resize( newWidth, newHeight );
424 YQPackageSelectorBase::setEnabling( bool enabled )
426 QWidget::setEnabled( enabled );
431 YQPackageSelectorBase::setKeyboardFocus()
439 #include "YQPackageSelectorBase.moc"