1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgConflictList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
24 #include <QMessageBox>
29 #define y2log_component "qt-pkg"
30 #include <ycp/y2log.h>
32 #include <zypp/ZYppFactory.h>
33 #include "YQPkgConflictList.h"
34 #include "YQPkgConflictDialog.h"
35 #include "YQIconPool.h"
37 #include "YQApplication.h"
46 #define LIST_SPLIT_THRESHOLD 8
48 #define RED QColor( 0xC0, 0, 0 )
49 #define BRIGHT_RED QColor( 0xFF, 0, 0 )
50 #define BLUE QColor( 0, 0, 0xC0 )
51 #define LIGHT_BLUE QColor( 0xE0, 0xE0, 0xF8 )
52 #define LIGHT_GREY QColor( 0xE0, 0xE0, 0xE0 )
53 #define MAGENTA Qt::magenta
54 #define DEEP_ORANGE QColor( 0xFF, 0x80, 0x20 )
55 #define LIGHT_ORANGE QColor( 0xFF, 0xC0, 0x50 )
58 YQPkgConflictList::YQPkgConflictList( QWidget * parent )
59 : QY2ListView( parent )
62 setHeaderLabel( _( "Dependency Conflict" ) );
63 setRootIsDecorated( true );
64 setSortByInsertionSequence( true );
68 YQPkgConflictList::~YQPkgConflictList()
75 YQPkgConflictList::fill( zypp::ResolverProblemList problemList )
81 zypp::ResolverProblemList::iterator it = problemList.begin();
83 while ( it != problemList.end() )
85 YQPkgConflict * conflict = new YQPkgConflict( this, *it );
86 Q_CHECK_PTR( conflict );
94 YQPkgConflictList::applyResolutions()
96 zypp::ProblemSolutionList userChoices;
99 QTreeWidgetItem * child;
101 while ( (child = topLevelItem(count)) )
103 YQPkgConflict * conflict = dynamic_cast<YQPkgConflict *> (child);
107 zypp::ProblemSolution_Ptr userChoice = conflict->userSelectedResolution();
110 userChoices.push_back( userChoice );
116 zypp::getZYpp()->resolver()->applySolutions( userChoices );
118 emit updatePackages();
123 YQPkgConflictList::askSaveToFile() const
125 QString filename = YQUI::ui()->askForSaveFileName( "conflicts.txt", // startsWith
127 _( "Save Conflicts List" ) );
128 if ( ! filename.isEmpty() )
129 saveToFile( filename, true );
134 YQPkgConflictList::saveToFile( const QString filename, bool interactive ) const
137 QFile file(filename);
139 if ( ! file.open(QIODevice::WriteOnly) )
141 y2error( "Can't open file %s", qPrintable(filename) );
147 QMessageBox::warning( 0, // parent
148 _( "Error" ), // caption
149 _( "Cannot open file %1" ).arg( filename ),
150 QMessageBox::Ok | QMessageBox::Default, // button0
151 QMessageBox::NoButton, // button1
152 QMessageBox::NoButton ); // button2
160 QString header = "#### YaST2 conflicts list - generated ";
161 header += QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" );
162 header += " ####\n\n";
164 file.write(header.toUtf8());
167 // Recursively write all items
169 const QTreeWidgetItem * item;
171 while ( (item = topLevelItem(count)) )
173 saveItemToFile( file, item );
180 file.write("\n#### YaST2 conflicts list END ###\n" );
191 YQPkgConflictList::saveItemToFile( QFile &file,
192 const QTreeWidgetItem * item ) const
195 if ( ! item || ! file.isOpen() )
199 for ( int level = 0; level < item->depth(); level++ )
204 const QTreeWidgetItem * checkListItem = dynamic_cast<const QTreeWidgetItem *> (item);
208 switch ( checkListItem->type() )
211 case Q3CheckListItem::CheckBox:
212 buffer.sprintf( "[%c] ", checkListItem->( checkState(0) == Qt::Checked ) ? 'x' : ' ' );
214 case Q3CheckListItem::RadioButton:
215 sbuffer.sprintf( "(%c) ", checkListItem->( checkState(0) == Qt::Checked ) ? 'x' : ' ' );
220 file.write(buffer.toUtf8());
223 buffer.sprintf("%s\n", qPrintable(item->text(0)) );
224 file.write(buffer.toUtf8());
226 if ( item->isExpanded() )
228 // Recursively write children
230 const QTreeWidgetItem * child = item->firstChild();
234 saveItemToFile( file, child );
235 child = child->nextSibling();
243 YQPkgConflictList::dumpList( QTreeWidgetItem * parent,
244 const QString & longText,
245 const QString & header,
250 y2error( "Null parent" );
254 if ( longText.isEmpty() )
258 if ( ! header.isEmpty() )
260 parent = new QY2ListViewItem( parent, header );
261 Q_CHECK_PTR( parent );
262 parent->setExpanded( true );
265 QStringList lines = QStringList::split( '\n', longText,
266 true ); // allowEmptyEntries
267 QList<QString>::const_iterator it = lines.begin();
269 bool doSplit = splitThreshold > 1 && lines.size() > splitThreshold + 3;
270 bool didSplit = false;
274 while ( it != lines.end() )
276 if ( doSplit && ! didSplit && ++count > splitThreshold )
280 int more = lines.size() - count + 1;
281 QString text = ( _( "%1 more..." ) ).arg( more );
282 QY2ListViewItem * sublist = new QY2ListViewItem( parent, text );
287 sublist->setBackgroundColor( LIGHT_ORANGE );
292 new QY2ListViewItem( parent, *it );
304 YQPkgConflict::YQPkgConflict( YQPkgConflictList * parentList,
305 zypp::ResolverProblem_Ptr problem )
306 : QY2ListViewItem( parentList )
307 , _problem( problem )
308 , _resolutionsHeader( 0 )
310 setBackgroundColor( LIGHT_BLUE );
316 YQPkgConflictList::dumpList( this, fromUTF8( _problem->details() ) );
323 YQPkgConflict::formatHeading()
326 QPixmap icon = YQIconPool::normalPkgConflict();
327 setTextColor( BRIGHT_RED );
330 setText( 0, Qt::DisplayRole, fromUTF8( problem()->description() ) );
332 setData( 0, Qt::DecorationRole, icon );
337 YQPkgConflict::addSolutions()
339 _resolutionsHeader = new QY2CheckListItem( this,
340 // Heading for the choices
341 // how to resolve this conflict
342 _( "Conflict Resolution:" ) );
343 Q_CHECK_PTR( _resolutionsHeader );
345 _resolutionsHeader->setExpanded( true );
347 _resolutionsHeader->setBackgroundColor( LIGHT_GREY );
349 zypp::ProblemSolutionList solutions = problem()->solutions();
350 zypp::ProblemSolutionList::iterator it = solutions.begin();
352 while ( it != solutions.end() )
354 YQPkgConflictResolution * solution = new YQPkgConflictResolution( _resolutionsHeader, *it );
355 Q_CHECK_PTR( solution );
356 //FIXME solution->setExpanded(true);
364 // YQPkgConflict::paintCell( QPainter * painter,
365 // const QColorGroup & colorGroup,
370 // painter->setFont( YQUI::yqApp()->headingFont() );
372 // QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
377 zypp::ProblemSolution_Ptr
378 YQPkgConflict::userSelectedResolution()
381 QTreeWidgetItem * item;
384 while ( item = _resolutionsHeader->topLevelItem(count) )
386 YQPkgConflictResolution * res = dynamic_cast<YQPkgConflictResolution *> (item);
388 if ( res && res->( checkState(0) == Qt::Checked ) )
390 zypp::ProblemSolution_Ptr solution = res->solution();
392 y2milestone( "User selected resolution \"%s\" for problem \"%s\"",
393 solution->description().c_str(),
394 solution->problem()->description().c_str() );
402 return zypp::ProblemSolution_Ptr(); // Null pointer
410 YQPkgConflictResolution::YQPkgConflictResolution( QY2CheckListItem * parent,
411 zypp::ProblemSolution_Ptr solution )
412 : QY2CheckListItem( parent,
413 fromUTF8( solution->description() ) )
414 /*, Q3CheckListItem::RadioButton) */
416 _solution = solution;
417 YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
422 #include "YQPkgConflictList.moc"