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" );
270 frame->setStyleSheet(
"background-color: " +
271 QApplication::palette().color( QPalette::Active, QPalette::Base ).name() +
274 QHBoxLayout * hbox =
new QHBoxLayout( frame );
276 QLabel * pix =
new QLabel(
this );
277 pix->setPixmap( YQIconPool::normalPkgConflict() );
278 hbox->addWidget( pix );
280 QString text = fromUTF8(
problem()->description() );
281 QLabel * heading =
new QLabel( text,
this );
282 heading->setProperty(
"class",
"conflict-heading" );
283 heading->setStyleSheet(
"font-size: +2; color: red; font: bold;" );
284 hbox->addWidget( heading );
286 hbox->addStretch( 1 );
288 _layout->addWidget( frame );
295 _resolutionsHeader =
new QLabel( _(
"Conflict Resolution:" ),
this );
296 _layout->addWidget( _resolutionsHeader );
298 QHBoxLayout *hbox =
new QHBoxLayout();
299 hbox->addSpacing( 20 );
301 QVBoxLayout *vbox =
new QVBoxLayout();
302 hbox->addLayout( vbox );
303 _layout->addLayout( hbox );
305 zypp::ProblemSolutionList solutions =
problem()->solutions();
306 zypp::ProblemSolutionList::iterator it = solutions.begin();
310 while ( it != solutions.end() )
313 QString shortcut =
"" + QString( (n<10)?
"&":
"" ) + QString::number(n) +
": ";
315 QRadioButton * solutionButton =
new QRadioButton( shortcut + fromUTF8( ( *it )->description() ),
this );
316 vbox->addWidget( solutionButton );
317 _solutions[ solutionButton ] = *it;
319 QString details = fromUTF8( ( *it )->details() );
321 if ( ! details.isEmpty() )
323 QStringList lines = details.split(
"\n" );
325 if ( lines.count() > 7 )
329 for (
int i = 0; i < 4; i++ )
330 details += lines[i] +
"<br>\n";
332 details += _(
"<a href='/'>%1 more...</a>" ).arg( lines.count() - 4 );
335 QLabel * detailsLabel =
new QLabel( details,
this );
337 connect( detailsLabel, SIGNAL( linkActivated (
const QString & ) ),
338 this, SLOT ( detailsExpanded() ) );
340 connect( detailsLabel, SIGNAL( linkHovered (
const QString & ) ),
341 this, SLOT ( detailsTooltip() ) );
343 QHBoxLayout * hbox =
new QHBoxLayout();
344 hbox->addSpacing( 15 );
345 hbox->addWidget( detailsLabel );
346 vbox->addLayout( hbox );
347 _details[ detailsLabel ] = *it;
355 YQPkgConflict::detailsExpanded()
357 QLabel * obj = qobject_cast<QLabel*>( sender() );
359 if ( !obj || ! _details.contains( obj ) )
362 QSize _size = size();
363 int oldHeight = obj->height();
364 obj->setText( fromUTF8( _details[obj]->details() ) );
366 resize( _size.width(), _size.height() + ( obj->minimumSizeHint().height() - oldHeight ) );
371 zypp::ProblemSolution_Ptr
374 QMap<QRadioButton*, zypp::ProblemSolution_Ptr>::iterator it;
376 for ( it = _solutions.begin(); it != _solutions.end(); ++it )
378 QRadioButton *button = it.key();
379 if ( !button->isChecked() )
381 zypp::ProblemSolution_Ptr solution = it.value();
383 yuiMilestone() <<
"User selected resolution \""<< solution->description()
384 <<
"\" for problem \"" << solution->problem()->description()
389 return zypp::ProblemSolution_Ptr();
396 if ( ! file.isOpen() )
401 QMap<QRadioButton*, zypp::ProblemSolution_Ptr>::const_iterator it;
403 file.write(
problem()->description().c_str() );
405 file.write(
problem()->details().c_str() );
410 for ( it = _solutions.begin(); it != _solutions.end(); ++it )
412 QRadioButton *button = it.key();
413 zypp::ProblemSolution_Ptr solution = it.value();
414 buffer.sprintf(
" [%c] %s\n", button->isChecked() ?
'x' :
' ', qPrintable( fromUTF8( solution->description() ) ) );
415 buffer += fromUTF8( solution->details() );
417 file.write( buffer.toUtf8() );
420 file.write(
"\n\n" );
423 #include "YQPkgConflictList.moc"