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, " " );
207 const Q3CheckListItem * checkListItem = dynamic_cast<const Q3CheckListItem *> (item);
211 switch ( checkListItem->type() )
213 case Q3CheckListItem::CheckBox:
214 fprintf( file, "[%c] ", checkListItem->isOn() ? 'x' : ' ' );
216 case Q3CheckListItem::RadioButton:
217 fprintf( file, "(%c) ", checkListItem->isOn() ? 'x' : ' ' );
224 fprintf( file, "%s\n", (const char *) item->text(0) );
227 if ( item->isOpen() )
229 // Recursively write children
231 const QTreeWidgetItem * child = item->firstChild();
235 saveItemToFile( file, child );
236 child = child->nextSibling();
244 YQPkgConflictList::dumpList( QTreeWidgetItem * parent,
245 const QString & longText,
246 const QString & header,
251 y2error( "Null parent" );
255 if ( longText.isEmpty() )
259 if ( ! header.isEmpty() )
261 parent = new QY2ListViewItem( parent, header );
262 Q_CHECK_PTR( parent );
263 parent->setOpen( true );
266 QStringList lines = QStringList::split( '\n', longText,
267 true ); // allowEmptyEntries
268 QList<QString>::const_iterator it = lines.begin();
270 bool doSplit = splitThreshold > 1 && lines.size() > splitThreshold + 3;
271 bool didSplit = false;
275 while ( it != lines.end() )
277 if ( doSplit && ! didSplit && ++count > splitThreshold )
281 int more = lines.size() - count + 1;
282 QString text = ( _( "%1 more..." ) ).arg( more );
283 QY2ListViewItem * sublist = new QY2ListViewItem( parent, text );
288 sublist->setBackgroundColor( LIGHT_ORANGE );
293 new QY2ListViewItem( parent, *it );
305 YQPkgConflict::YQPkgConflict( YQPkgConflictList * parentList,
306 zypp::ResolverProblem_Ptr problem )
307 : QY2ListViewItem( parentList )
308 , _problem( problem )
309 , _resolutionsHeader( 0 )
311 setBackgroundColor( LIGHT_BLUE );
317 YQPkgConflictList::dumpList( this, fromUTF8( _problem->details() ) );
324 YQPkgConflict::formatHeading()
327 QPixmap icon = YQIconPool::normalPkgConflict();
328 setTextColor( BRIGHT_RED );
331 setText( 0, Qt::DisplayRole, fromUTF8( problem()->description() ) );
333 setData( 0, Qt::DecorationRole, icon );
338 YQPkgConflict::addSolutions()
340 _resolutionsHeader = new QY2CheckListItem( this,
341 // Heading for the choices
342 // how to resolve this conflict
343 _( "Conflict Resolution:" ) );
344 Q_CHECK_PTR( _resolutionsHeader );
346 _resolutionsHeader->setOpen( true );
348 _resolutionsHeader->setBackgroundColor( LIGHT_GREY );
350 zypp::ProblemSolutionList solutions = problem()->solutions();
351 zypp::ProblemSolutionList::iterator it = solutions.begin();
353 while ( it != solutions.end() )
355 YQPkgConflictResolution * solution = new YQPkgConflictResolution( _resolutionsHeader, *it );
356 Q_CHECK_PTR( solution );
357 //FIXME solution->setOpen(true);
365 YQPkgConflict::paintCell( QPainter * painter,
366 const QColorGroup & colorGroup,
371 painter->setFont( YQUI::yqApp()->headingFont() );
373 QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
378 zypp::ProblemSolution_Ptr
379 YQPkgConflict::userSelectedResolution()
382 QTreeWidgetItem * item;
385 while ( item = _resolutionsHeader->topLevelItem(count) )
387 YQPkgConflictResolution * res = dynamic_cast<YQPkgConflictResolution *> (item);
389 if ( res && res->isOn() )
391 zypp::ProblemSolution_Ptr solution = res->solution();
393 y2milestone( "User selected resolution \"%s\" for problem \"%s\"",
394 solution->description().c_str(),
395 solution->problem()->description().c_str() );
403 return zypp::ProblemSolution_Ptr(); // Null pointer
411 YQPkgConflictResolution::YQPkgConflictResolution( QY2CheckListItem * parent,
412 zypp::ProblemSolution_Ptr solution )
413 : QY2CheckListItem( parent,
414 fromUTF8( solution->description() ) )
415 /*, Q3CheckListItem::RadioButton) */
417 _solution = solution;
418 YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
423 #include "YQPkgConflictList.moc"