45 #include <QMessageBox> 46 #include <QRadioButton> 50 #include <QVBoxLayout> 54 #define YUILogComponent "qt-pkg" 57 #include <zypp/ZYppFactory.h> 58 #include "YQPkgConflictList.h" 59 #include "YQPkgConflictDialog.h" 60 #include "YQIconPool.h" 62 #include "YQApplication.h" 71 #define LIST_SPLIT_THRESHOLD 8 73 #define RED QColor( 0xC0, 0, 0 ) 74 #define BRIGHT_RED QColor( 0xFF, 0, 0 ) 75 #define BLUE QColor( 0, 0, 0xC0 ) 76 #define LIGHT_BLUE QColor( 0xE0, 0xE0, 0xF8 ) 77 #define LIGHT_GREY QColor( 0xE0, 0xE0, 0xE0 ) 78 #define MAGENTA Qt::magenta 79 #define DEEP_ORANGE QColor( 0xFF, 0x80, 0x20 ) 80 #define LIGHT_ORANGE QColor( 0xFF, 0xC0, 0x50 ) 84 : QScrollArea( parent ), _layout( 0 )
86 setWidget(
new QFrame(
this ) );
87 _layout =
new QVBoxLayout;
88 widget()->setLayout( _layout );
91 widget()->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
101 YQPkgConflictList::clear()
105 foreach( conflict, _conflicts )
107 _layout->removeWidget( conflict );
113 delete _layout->takeAt( 0 );
122 zypp::ResolverProblemList::iterator it = problemList.begin();
124 while ( it != problemList.end() )
127 Q_CHECK_PTR( conflict );
129 connect( conflict, SIGNAL( expanded() ),
130 SLOT( relayout() ) );
131 _layout->addWidget( conflict );
132 _conflicts.push_back( conflict );
135 _layout->addStretch( 1 );
139 void YQPkgConflictList::relayout()
143 QSize minSize = QSize( _layout->margin() * 2, _layout->margin() * 2 );
147 foreach( conflict, _conflicts )
149 minSize = minSize.expandedTo( conflict->minimumSizeHint() );
150 minSize.rheight() += conflict->minimumSizeHint().height() + _layout->spacing();
153 widget()->resize( minSize );
159 zypp::ProblemSolutionList userChoices;
162 foreach( conflict, _conflicts )
167 userChoices.push_back( userChoice );
170 zypp::getZYpp()->resolver()->applySolutions( userChoices );
178 QString filename = YQApplication::askForSaveFileName(
"conflicts.txt",
180 _(
"Save Conflicts List" ) );
181 if ( ! filename.isEmpty() )
190 QFile file(filename);
192 if ( ! file.open(QIODevice::WriteOnly) )
194 yuiError() <<
"Can't open file " << filename << std::endl;
200 QMessageBox::warning( 0,
202 _(
"Cannot open file %1" ).arg( filename ),
203 QMessageBox::Ok | QMessageBox::Default,
204 QMessageBox::NoButton,
205 QMessageBox::NoButton );
213 QString header =
"#### YaST2 conflicts list - generated ";
214 header += QDateTime::currentDateTime().toString(
"yyyy-MM-dd hh:mm:ss" );
215 header +=
" ####\n\n";
217 file.write(header.toUtf8());
221 foreach( conflict, _conflicts )
229 file.write(
"\n#### YaST2 conflicts list END ###\n" );
244 zypp::ResolverProblem_Ptr problem )
246 , _problem( problem )
247 , _resolutionsHeader( 0 )
249 _layout =
new QVBoxLayout(
this );
250 _layout->setSpacing( 0 );
251 _layout->setMargin( 0 );
255 QLabel * detailsLabel =
new QLabel( fromUTF8 ( _problem->details() ),
this );
256 _layout->addWidget( detailsLabel );
258 setProperty(
"class",
"conflict" );
260 setMinimumSize( _layout->minimumSize() );
261 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
268 QFrame * frame =
new QFrame(
this );
269 frame->setProperty(
"class",
"conflict-frame" );
271 QHBoxLayout * hbox =
new QHBoxLayout( frame );
273 QLabel * pix =
new QLabel(
this );
274 pix->setPixmap( YQIconPool::normalPkgConflict() );
275 hbox->addWidget( pix );
277 QString text = fromUTF8(
problem()->description() );
278 QLabel * heading =
new QLabel( text,
this );
279 heading->setProperty(
"class",
"conflict-heading" );
280 heading->setStyleSheet(
"font-size: +2; font: bold;" );
281 hbox->addWidget( heading );
283 hbox->addStretch( 1 );
285 _layout->addWidget( frame );
292 _resolutionsHeader =
new QLabel( _(
"Conflict Resolution:" ),
this );
293 _layout->addWidget( _resolutionsHeader );
295 QHBoxLayout *hbox =
new QHBoxLayout();
296 hbox->addSpacing( 20 );
298 QVBoxLayout *vbox =
new QVBoxLayout();
299 hbox->addLayout( vbox );
300 _layout->addLayout( hbox );
302 zypp::ProblemSolutionList solutions =
problem()->solutions();
303 zypp::ProblemSolutionList::iterator it = solutions.begin();
307 while ( it != solutions.end() )
310 QString shortcut =
"" + QString( (n<10)?
"&":
"" ) + QString::number(n) +
": ";
312 QRadioButton * solutionButton =
new QRadioButton( shortcut + fromUTF8( ( *it )->description() ),
this );
313 vbox->addWidget( solutionButton );
314 _solutions[ solutionButton ] = *it;
316 QString details = fromUTF8( ( *it )->details() );
318 if ( ! details.isEmpty() )
320 QStringList lines = details.split(
"\n" );
322 if ( lines.count() > 7 )
326 for (
int i = 0; i < 4; i++ )
327 details += lines[i] +
"<br>\n";
329 details += _(
"<a href='/'>%1 more...</a>" ).arg( lines.count() - 4 );
332 QLabel * detailsLabel =
new QLabel( details,
this );
334 connect( detailsLabel, SIGNAL( linkActivated (
const QString & ) ),
335 this, SLOT ( detailsExpanded() ) );
337 connect( detailsLabel, SIGNAL( linkHovered (
const QString & ) ),
338 this, SLOT ( detailsTooltip() ) );
340 QHBoxLayout * hbox =
new QHBoxLayout();
341 hbox->addSpacing( 15 );
342 hbox->addWidget( detailsLabel );
343 vbox->addLayout( hbox );
344 _details[ detailsLabel ] = *it;
352 YQPkgConflict::detailsExpanded()
354 QLabel * obj = qobject_cast<QLabel*>( sender() );
356 if ( !obj || ! _details.contains( obj ) )
359 QSize _size = size();
360 int oldHeight = obj->height();
361 obj->setText( fromUTF8( _details[obj]->details() ) );
363 resize( _size.width(), _size.height() + ( obj->minimumSizeHint().height() - oldHeight ) );
368 zypp::ProblemSolution_Ptr
371 QMap<QRadioButton*, zypp::ProblemSolution_Ptr>::iterator it;
373 for ( it = _solutions.begin(); it != _solutions.end(); ++it )
375 QRadioButton *button = it.key();
376 if ( !button->isChecked() )
378 zypp::ProblemSolution_Ptr solution = it.value();
380 yuiMilestone() <<
"User selected resolution \""<< solution->description()
385 return zypp::ProblemSolution_Ptr();
392 if ( ! file.isOpen() )
397 QMap<QRadioButton*, zypp::ProblemSolution_Ptr>::const_iterator it;
399 file.write(
problem()->description().c_str() );
401 file.write(
problem()->details().c_str() );
406 for ( it = _solutions.begin(); it != _solutions.end(); ++it )
408 QRadioButton *button = it.key();
409 zypp::ProblemSolution_Ptr solution = it.value();
410 buffer.sprintf(
" [%c] %s\n", button->isChecked() ?
'x' :
' ', qPrintable( fromUTF8( solution->description() ) ) );
411 buffer += fromUTF8( solution->details() );
413 file.write( buffer.toUtf8() );
416 file.write(
"\n\n" );
419 #include "YQPkgConflictList.moc" void saveToFile(const QString filename, bool interactive) const
Save the conflict list in its current state to a file.
YQPkgConflictList(QWidget *parent)
Constructor.
void applyResolutions()
Apply the choices the user made.
zypp::ResolverProblem_Ptr problem() const
Returns the corresponding ResolverProblem.
void askSaveToFile() const
Ask for a file name and save the current conflict list to file.
zypp::ProblemSolution_Ptr userSelectedResolution()
Returns the resolution the user selected or 0 if he didn't select one.
void saveToFile(QFile &file) const
save one item to file.
void formatHeading()
Format the text heading line for this item.
virtual ~YQPkgConflictList()
Destructor.
void fill(zypp::ResolverProblemList problemList)
Fill the list with the specified problems.
YQPkgConflict(QWidget *parent, zypp::ResolverProblem_Ptr problem)
Constructor.
Root item for each individual conflict.
void updatePackages()
Update package states - they may have changed.
void addSolutions()
Add suggestions how to resolve this conflict.