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 <qdatetime.h>
25 #include <qmessagebox.h>
27 #include <q3valuelist.h>
31 #define y2log_component "qt-pkg"
32 #include <ycp/y2log.h>
34 #include <zypp/ZYppFactory.h>
35 #include "YQPkgConflictList.h"
36 #include "YQPkgConflictDialog.h"
37 #include "YQIconPool.h"
39 #include "YQApplication.h"
48 #define LIST_SPLIT_THRESHOLD 8
50 #define RED QColor( 0xC0, 0, 0 )
51 #define BRIGHT_RED QColor( 0xFF, 0, 0 )
52 #define BLUE QColor( 0, 0, 0xC0 )
53 #define LIGHT_BLUE QColor( 0xE0, 0xE0, 0xF8 )
54 #define LIGHT_GREY QColor( 0xE0, 0xE0, 0xE0 )
55 #define MAGENTA Qt::magenta
56 #define DEEP_ORANGE QColor( 0xFF, 0x80, 0x20 )
57 #define LIGHT_ORANGE QColor( 0xFF, 0xC0, 0x50 )
60 YQPkgConflictList::YQPkgConflictList( QWidget * parent )
61 : QY2ListView( parent )
64 setHeaderLabel( _( "Dependency Conflict" ) );
65 setRootIsDecorated( true );
66 setSortByInsertionSequence( true );
70 YQPkgConflictList::~YQPkgConflictList()
77 YQPkgConflictList::fill( zypp::ResolverProblemList problemList )
83 zypp::ResolverProblemList::iterator it = problemList.begin();
85 while ( it != problemList.end() )
87 YQPkgConflict * conflict = new YQPkgConflict( this, *it );
88 Q_CHECK_PTR( conflict );
96 YQPkgConflictList::applyResolutions()
98 zypp::ProblemSolutionList userChoices;
101 QTreeWidgetItem * child;
103 while ( (child = topLevelItem(count)) )
105 YQPkgConflict * conflict = dynamic_cast<YQPkgConflict *> (child);
109 zypp::ProblemSolution_Ptr userChoice = conflict->userSelectedResolution();
112 userChoices.push_back( userChoice );
118 zypp::getZYpp()->resolver()->applySolutions( userChoices );
120 emit updatePackages();
125 YQPkgConflictList::askSaveToFile() const
127 QString filename = YQUI::ui()->askForSaveFileName( "conflicts.txt", // startsWith
129 _( "Save Conflicts List" ) );
130 if ( ! filename.isEmpty() )
131 saveToFile( filename, true );
136 YQPkgConflictList::saveToFile( const QString filename, bool interactive ) const
140 FILE * file = fopen( (const char *) filename, "w" );
144 y2error( "Can't open file %s", (const char *) filename );
150 QMessageBox::warning( 0, // parent
151 _( "Error" ), // caption
152 _( "Cannot open file %1" ).arg( filename ),
153 QMessageBox::Ok | QMessageBox::Default, // button0
154 QMessageBox::NoButton, // button1
155 QMessageBox::NoButton ); // button2
163 QString header = "#### YaST2 conflicts list - generated ";
164 header += QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" );
165 header += " ####\n\n";
167 fputs( (const char *) header, file );
170 // Recursively write all items
172 const QTreeWidgetItem * item;
174 while ( (item = topLevelItem(count)) )
176 saveItemToFile( file, item );
183 fprintf( file, "\n#### YaST2 conflicts list END ###\n" );
194 YQPkgConflictList::saveItemToFile( FILE * file,
195 const QTreeWidgetItem * item ) const
197 if ( ! item || ! file )
202 for ( int level = 0; level < item->depth(); level++ )
203 fprintf( file, " " );
208 const Q3CheckListItem * checkListItem = dynamic_cast<const Q3CheckListItem *> (item);
212 switch ( checkListItem->type() )
214 case Q3CheckListItem::CheckBox:
215 fprintf( file, "[%c] ", checkListItem->isOn() ? 'x' : ' ' );
217 case Q3CheckListItem::RadioButton:
218 fprintf( file, "(%c) ", checkListItem->isOn() ? 'x' : ' ' );
225 fprintf( file, "%s\n", (const char *) item->text(0) );
228 if ( item->isOpen() )
230 // Recursively write children
232 const QTreeWidgetItem * child = item->firstChild();
236 saveItemToFile( file, child );
237 child = child->nextSibling();
244 YQPkgConflictList::dumpList( QTreeWidgetItem * parent,
245 const QString & longText,
246 const QString & header,
251 y2error( "Null parent" );
255 if ( longText.isEmpty() )
258 if ( ! header.isEmpty() )
260 parent = new QY2ListViewItem( parent, header );
261 Q_CHECK_PTR( parent );
262 parent->setOpen( 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 );
303 YQPkgConflict::YQPkgConflict( YQPkgConflictList * parentList,
304 zypp::ResolverProblem_Ptr problem )
305 : QY2ListViewItem( parentList )
306 , _problem( problem )
307 , _resolutionsHeader( 0 )
309 setBackgroundColor( LIGHT_BLUE );
313 YQPkgConflictList::dumpList( this, fromUTF8( _problem->details() ) );
320 YQPkgConflict::formatHeading()
323 QPixmap icon = YQIconPool::normalPkgConflict();
324 setTextColor( BRIGHT_RED );
326 setText( 0, Qt::DisplayRole, fromUTF8( problem()->description() ) );
327 setData( 0, Qt::DecorationRole, icon );
332 YQPkgConflict::addSolutions()
334 _resolutionsHeader = new QY2CheckListItem( this,
335 // Heading for the choices
336 // how to resolve this conflict
337 _( "Conflict Resolution:" ) );
338 Q_CHECK_PTR( _resolutionsHeader );
339 _resolutionsHeader->setOpen( true );
340 _resolutionsHeader->setBackgroundColor( LIGHT_GREY );
342 zypp::ProblemSolutionList solutions = problem()->solutions();
343 zypp::ProblemSolutionList::iterator it = solutions.begin();
345 while ( it != solutions.end() )
347 new YQPkgConflictResolution( _resolutionsHeader, *it );
354 YQPkgConflict::paintCell( QPainter * painter,
355 const QColorGroup & colorGroup,
360 painter->setFont( YQUI::yqApp()->headingFont() );
361 QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
365 zypp::ProblemSolution_Ptr
366 YQPkgConflict::userSelectedResolution()
369 QTreeWidgetItem * item;
371 while ( item = _resolutionsHeader->topLevelItem(count) )
373 YQPkgConflictResolution * res = dynamic_cast<YQPkgConflictResolution *> (item);
375 if ( res && res->isOn() )
377 zypp::ProblemSolution_Ptr solution = res->solution();
379 y2milestone( "User selected resolution \"%s\" for problem \"%s\"",
380 solution->description().c_str(),
381 solution->problem()->description().c_str() );
388 return zypp::ProblemSolution_Ptr(); // Null pointer
396 YQPkgConflictResolution::YQPkgConflictResolution( QY2CheckListItem * parent,
397 zypp::ProblemSolution_Ptr solution )
398 : QY2CheckListItem( parent,
399 fromUTF8( solution->description() ),
400 /*Q3CheckListItem::RadioButton) */
401 , _solution( solution ))
403 YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
408 #include "YQPkgConflictList.moc"