1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgConflictList.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
25 #include <qdatetime.h>
26 #include <qmessagebox.h>
28 #include <q3valuelist.h>
32 #define y2log_component "qt-pkg"
33 #include <ycp/y2log.h>
35 #include <zypp/ZYppFactory.h>
36 #include "YQPkgConflictList.h"
37 #include "YQPkgConflictDialog.h"
38 #include "YQIconPool.h"
40 #include "YQApplication.h"
49 #define LIST_SPLIT_THRESHOLD 8
51 #define RED QColor( 0xC0, 0, 0 )
52 #define BRIGHT_RED QColor( 0xFF, 0, 0 )
53 #define BLUE QColor( 0, 0, 0xC0 )
54 #define LIGHT_BLUE QColor( 0xE0, 0xE0, 0xF8 )
55 #define LIGHT_GREY QColor( 0xE0, 0xE0, 0xE0 )
56 #define MAGENTA Qt::magenta
57 #define DEEP_ORANGE QColor( 0xFF, 0x80, 0x20 )
58 #define LIGHT_ORANGE QColor( 0xFF, 0xC0, 0x50 )
61 YQPkgConflictList::YQPkgConflictList( QWidget * parent )
62 : QY2ListView( parent )
65 setHeaderLabel( _( "Dependency Conflict" ) );
66 setRootIsDecorated( true );
67 setSortByInsertionSequence( true );
71 YQPkgConflictList::~YQPkgConflictList()
78 YQPkgConflictList::fill( zypp::ResolverProblemList problemList )
84 zypp::ResolverProblemList::iterator it = problemList.begin();
86 while ( it != problemList.end() )
88 YQPkgConflict * conflict = new YQPkgConflict( this, *it );
89 Q_CHECK_PTR( conflict );
97 YQPkgConflictList::applyResolutions()
99 zypp::ProblemSolutionList userChoices;
102 QTreeWidgetItem * child;
104 while ( (child = topLevelItem(count)) )
106 YQPkgConflict * conflict = dynamic_cast<YQPkgConflict *> (child);
110 zypp::ProblemSolution_Ptr userChoice = conflict->userSelectedResolution();
113 userChoices.push_back( userChoice );
119 zypp::getZYpp()->resolver()->applySolutions( userChoices );
121 emit updatePackages();
126 YQPkgConflictList::askSaveToFile() const
128 QString filename = YQUI::ui()->askForSaveFileName( "conflicts.txt", // startsWith
130 _( "Save Conflicts List" ) );
131 if ( ! filename.isEmpty() )
132 saveToFile( filename, true );
137 YQPkgConflictList::saveToFile( const QString filename, bool interactive ) const
141 FILE * file = fopen( (const char *) filename, "w" );
145 y2error( "Can't open file %s", (const char *) filename );
151 QMessageBox::warning( 0, // parent
152 _( "Error" ), // caption
153 _( "Cannot open file %1" ).arg( filename ),
154 QMessageBox::Ok | QMessageBox::Default, // button0
155 QMessageBox::NoButton, // button1
156 QMessageBox::NoButton ); // button2
164 QString header = "#### YaST2 conflicts list - generated ";
165 header += QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" );
166 header += " ####\n\n";
168 fputs( (const char *) header, file );
171 // Recursively write all items
173 const QTreeWidgetItem * item;
175 while ( (item = topLevelItem(count)) )
177 saveItemToFile( file, item );
184 fprintf( file, "\n#### YaST2 conflicts list END ###\n" );
195 YQPkgConflictList::saveItemToFile( FILE * file,
196 const QTreeWidgetItem * item ) const
198 if ( ! item || ! file )
203 for ( int level = 0; level < item->depth(); level++ )
204 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();
245 YQPkgConflictList::dumpList( QTreeWidgetItem * parent,
246 const QString & longText,
247 const QString & header,
252 y2error( "Null parent" );
256 if ( longText.isEmpty() )
260 if ( ! header.isEmpty() )
262 parent = new QY2ListViewItem( parent, header );
263 Q_CHECK_PTR( parent );
264 parent->setOpen( true );
267 QStringList lines = QStringList::split( '\n', longText,
268 true ); // allowEmptyEntries
269 QList<QString>::const_iterator it = lines.begin();
271 bool doSplit = splitThreshold > 1 && lines.size() > splitThreshold + 3;
272 bool didSplit = false;
276 while ( it != lines.end() )
278 if ( doSplit && ! didSplit && ++count > splitThreshold )
282 int more = lines.size() - count + 1;
283 QString text = ( _( "%1 more..." ) ).arg( more );
284 QY2ListViewItem * sublist = new QY2ListViewItem( parent, text );
289 sublist->setBackgroundColor( LIGHT_ORANGE );
294 new QY2ListViewItem( parent, *it );
306 YQPkgConflict::YQPkgConflict( YQPkgConflictList * parentList,
307 zypp::ResolverProblem_Ptr problem )
308 : QY2ListViewItem( parentList )
309 , _problem( problem )
310 , _resolutionsHeader( 0 )
312 setBackgroundColor( LIGHT_BLUE );
318 YQPkgConflictList::dumpList( this, fromUTF8( _problem->details() ) );
325 YQPkgConflict::formatHeading()
328 QPixmap icon = YQIconPool::normalPkgConflict();
329 setTextColor( BRIGHT_RED );
332 setText( 0, Qt::DisplayRole, fromUTF8( problem()->description() ) );
334 setData( 0, Qt::DecorationRole, icon );
339 YQPkgConflict::addSolutions()
341 _resolutionsHeader = new QY2CheckListItem( this,
342 // Heading for the choices
343 // how to resolve this conflict
344 _( "Conflict Resolution:" ) );
345 Q_CHECK_PTR( _resolutionsHeader );
347 _resolutionsHeader->setOpen( true );
349 _resolutionsHeader->setBackgroundColor( LIGHT_GREY );
351 zypp::ProblemSolutionList solutions = problem()->solutions();
352 zypp::ProblemSolutionList::iterator it = solutions.begin();
354 while ( it != solutions.end() )
356 YQPkgConflictResolution * solution = new YQPkgConflictResolution( _resolutionsHeader, *it );
357 Q_CHECK_PTR( solution );
358 //FIXME solution->setOpen(true);
366 // YQPkgConflict::paintCell( QPainter * painter,
367 // const QColorGroup & colorGroup,
372 // painter->setFont( YQUI::yqApp()->headingFont() );
374 // QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
379 zypp::ProblemSolution_Ptr
380 YQPkgConflict::userSelectedResolution()
383 QTreeWidgetItem * item;
386 while ( item = _resolutionsHeader->topLevelItem(count) )
388 YQPkgConflictResolution * res = dynamic_cast<YQPkgConflictResolution *> (item);
390 if ( res && res->isOn() )
392 zypp::ProblemSolution_Ptr solution = res->solution();
394 y2milestone( "User selected resolution \"%s\" for problem \"%s\"",
395 solution->description().c_str(),
396 solution->problem()->description().c_str() );
404 return zypp::ProblemSolution_Ptr(); // Null pointer
412 YQPkgConflictResolution::YQPkgConflictResolution( QY2CheckListItem * parent,
413 zypp::ProblemSolution_Ptr solution )
414 : QY2CheckListItem( parent,
415 fromUTF8( solution->description() ) )
416 /*, Q3CheckListItem::RadioButton) */
418 _solution = solution;
419 YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
424 #include "YQPkgConflictList.moc"