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 : QFrame( (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() );
70 _pkgConflictDialog = new YQPkgConflictDialog( this );
71 Q_CHECK_PTR( _pkgConflictDialog );
73 QString label = _( "Reset &Ignored Dependency Conflicts" );
74 _actionResetIgnoredDependencyProblems = new QAction( label, this);
75 _actionResetIgnoredDependencyProblems->setShortcut((QKeySequence) 0);
76 //_actionResetIgnoredDependencyProblems->setMenuRole(QAction::TextHeuristicRole);
77 Q_CHECK_PTR( _actionResetIgnoredDependencyProblems );
79 connect( _actionResetIgnoredDependencyProblems, SIGNAL( activated() ),
80 this, SLOT ( resetIgnoredDependencyProblems() ) );
82 zyppPool().saveState<zypp::Package >();
83 zyppPool().saveState<zypp::Pattern >();
84 zyppPool().saveState<zypp::Selection>();
85 zyppPool().saveState<zypp::Language >();
86 zyppPool().saveState<zypp::Patch >();
89 // Install event handler to handle WM_CLOSE like "Cancel"
90 topLevelWidget()->installEventFilter( this );
92 y2milestone( "PackageSelectorBase init done" );
96 YQPackageSelectorBase::~YQPackageSelectorBase()
98 y2milestone( "Destroying PackageSelector" );
103 YQPackageSelectorBase::resolveDependencies()
105 if ( ! _pkgConflictDialog )
107 y2error( "No package conflict dialog existing" );
108 return QDialog::Accepted;
112 YQUI::ui()->busyCursor();
113 emit resolvingStarted();
115 int result = _pkgConflictDialog->solveAndShowConflicts();
117 emit resolvingFinished();
118 YQUI::ui()->normalCursor();
125 YQPackageSelectorBase::verifySystem()
127 if ( ! _pkgConflictDialog )
129 y2error( "No package conflict dialog existing" );
130 return QDialog::Accepted;
134 YQUI::ui()->busyCursor();
135 int result = _pkgConflictDialog->verifySystem();
136 YQUI::ui()->normalCursor();
138 if ( result == QDialog::Accepted )
140 QMessageBox::information( this, "",
141 _( "System dependencies verify OK." ),
150 YQPackageSelectorBase::checkDiskUsage()
152 if ( ! _diskUsageList )
154 return QDialog::Accepted;
157 if ( ! _diskUsageList->overflowWarning.inRange() )
158 return QDialog::Accepted;
161 // Translators: RichText ( HTML-like ) format
162 "<p><b>" + _( "Error: Out of disk space!" ) + "</b></p>"
164 "You can choose to install anyway if you know what you are doing, "
165 "but you risk getting a corrupted system that requires manual repairs. "
166 "If you are not absolutely sure how to handle such a case, "
167 "press <b>Cancel</b> now and deselect some packages."
170 return YQPkgDiskUsageWarningDialog::diskUsageWarning( msg,
171 100, _( "C&ontinue Anyway" ), _( "&Cancel" ) );
178 YQPackageSelectorBase::showAutoPkgList()
180 resolveDependencies();
182 // Show which packages are installed/deleted automatically
186 + _( "Automatic Changes" )
188 // Detailed explanation ( automatic word wrap! )
190 + _( "In addition to your manual selections, the following packages"
191 " have been changed to resolve dependencies:" )
194 YQPkgChangesDialog::showChangesDialog( msg,
196 QString::null, // rejectButtonLabel
197 true ); // showIfEmpty
203 YQPackageSelectorBase::reject()
206 zyppPool().diffState<zypp::Package >() ||
207 zyppPool().diffState<zypp::Pattern >() ||
208 zyppPool().diffState<zypp::Selection>() ||
209 zyppPool().diffState<zypp::Language >() ||
210 zyppPool().diffState<zypp::Patch >();
214 if ( zyppPool().diffState<zypp::Package>() )
215 y2milestone( "diffState() reports changed packages" );
217 if ( zyppPool().diffState<zypp::Pattern>() )
218 y2milestone( "diffState() reports changed patterns" );
220 if ( zyppPool().diffState<zypp::Selection>() )
221 y2milestone( "diffState() reports changed selections" );
223 if ( zyppPool().diffState<zypp::Language>() )
224 y2milestone( "diffState() reports changed languages" );
226 if ( zyppPool().diffState<zypp::Patch>() )
227 y2milestone( "diffState() reports changed patches" );
231 ( QMessageBox::warning( this, "",
232 _( "Abandon all changes?" ),
233 _( "&OK" ), _( "&Cancel" ), "",
234 1, // defaultButtonNumber (from 0)
235 1 ) // escapeButtonNumber
236 == 0 ) // Proceed upon button #0 ( OK )
239 zyppPool().restoreState<zypp::Package >();
240 zyppPool().restoreState<zypp::Pattern >();
241 zyppPool().restoreState<zypp::Selection>();
242 zyppPool().restoreState<zypp::Language >();
243 zyppPool().restoreState<zypp::Patch >();
245 y2milestone( "Closing PackageSelector with \"Cancel\"" );
246 YQUI::ui()->sendEvent( new YCancelEvent() );
252 YQPackageSelectorBase::accept()
254 bool confirmedAllLicenses;
258 // Force final dependency resolving
259 if ( resolveDependencies() == QDialog::Rejected )
262 confirmedAllLicenses = showPendingLicenseAgreements();
264 } while ( ! confirmedAllLicenses ); // Some packages will be set to S_TABOO - need another solver run
266 if ( _showChangesDialog )
268 // Show which packages are installed/deleted automatically
272 + _( "Automatic Changes" )
274 // Detailed explanation ( automatic word wrap! )
276 + _( "In addition to your manual selections, the following packages"
277 " have been changed to resolve dependencies:" )
280 if ( YQPkgChangesDialog::showChangesDialog( msg, _( "C&ontinue" ), _( "&Cancel" ) )
281 == QDialog::Rejected )
286 if ( checkDiskUsage() == QDialog::Rejected )
289 y2milestone( "Closing PackageSelector with \"Accept\"" );
290 YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "accept" ) ) );
295 YQPackageSelectorBase::showPendingLicenseAgreements()
297 y2milestone( "Showing all pending license agreements" );
299 bool allConfirmed = true;
301 if ( onlineUpdateMode() )
302 allConfirmed = showPendingLicenseAgreements( zyppPatchesBegin(), zyppPatchesEnd() );
304 allConfirmed = showPendingLicenseAgreements( zyppPkgBegin(), zyppPkgEnd() ) && allConfirmed;
311 YQPackageSelectorBase::showPendingLicenseAgreements( ZyppPoolIterator begin, ZyppPoolIterator end )
313 bool allConfirmed = true;
315 for ( ZyppPoolIterator it = begin; it != end; ++it )
319 switch ( sel->status() )
326 if ( sel->candidateObj() )
328 string licenseText = sel->candidateObj()->licenseToConfirm();
330 if ( ! licenseText.empty() )
332 y2milestone( "Resolvable %s has a license agreement", sel->name().c_str() );
334 if( ! sel->hasLicenceConfirmed() )
336 y2debug( "Showing license agreement for resolvable %s", sel->name().c_str() );
337 allConfirmed = YQPkgObjListItem::showLicenseAgreement( sel ) && allConfirmed;
341 y2milestone( "Resolvable %s's license is already confirmed", sel->name().c_str() );
357 YQPackageSelectorBase::notImplemented()
359 QMessageBox::information( this, "",
360 _( "Not implemented yet. Sorry." ),
366 YQPackageSelectorBase::resetIgnoredDependencyProblems()
368 YQPkgConflictDialog::resetIgnoredDependencyProblems();
373 YQPackageSelectorBase::keyPressEvent( QKeyEvent * event )
377 Qt::KeyboardModifiers special_combo = ( Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier );
379 if ( ( event->modifiers() & special_combo ) == special_combo )
381 if ( event->key() == Qt::Key_A )
390 QWidget::keyPressEvent( event );
394 bool YQPackageSelectorBase::eventFilter( QObject * obj, QEvent * event )
396 if ( event->type() == QEvent::Close )
398 // Handle WM_CLOSE like "Cancel"
401 return true; // Stop processing this event
404 return false; // Don't stop processing this event
408 int YQPackageSelectorBase::preferredWidth()
410 return max( 640, sizeHint().width() );
414 int YQPackageSelectorBase::preferredHeight()
416 return max( 480, sizeHint().height() );
421 YQPackageSelectorBase::setSize( int newWidth, int newHeight )
423 resize( newWidth, newHeight );
428 YQPackageSelectorBase::setEnabling( bool enabled )
430 QWidget::setEnabled( enabled );
435 YQPackageSelectorBase::setKeyboardFocus()
443 #include "YQPackageSelectorBase.moc"