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 )
63 addColumn( _( "Dependency Conflict" ) );
64 setRootIsDecorated( true );
65 setSortByInsertionSequence( true );
69 YQPkgConflictList::~YQPkgConflictList()
76 YQPkgConflictList::fill( zypp::ResolverProblemList problemList )
82 zypp::ResolverProblemList::iterator it = problemList.begin();
84 while ( it != problemList.end() )
86 YQPkgConflict * conflict = new YQPkgConflict( this, *it );
87 Q_CHECK_PTR( conflict );
95 YQPkgConflictList::applyResolutions()
97 zypp::ProblemSolutionList userChoices;
99 Q3ListViewItem * child = firstChild();
103 YQPkgConflict * conflict = dynamic_cast<YQPkgConflict *> (child);
107 zypp::ProblemSolution_Ptr userChoice = conflict->userSelectedResolution();
110 userChoices.push_back( userChoice );
113 child = child->nextSibling();
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
138 FILE * file = fopen( (const char *) filename, "w" );
142 y2error( "Can't open file %s", (const char *) filename );
148 QMessageBox::warning( 0, // parent
149 _( "Error" ), // caption
150 _( "Cannot open file %1" ).arg( filename ),
151 QMessageBox::Ok | QMessageBox::Default, // button0
152 QMessageBox::NoButton, // button1
153 QMessageBox::NoButton ); // button2
161 QString header = "#### YaST2 conflicts list - generated ";
162 header += QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" );
163 header += " ####\n\n";
165 fputs( (const char *) header, file );
168 // Recursively write all items
170 const Q3ListViewItem * item = firstChild();
174 saveItemToFile( file, item );
175 item = item->nextSibling();
181 fprintf( file, "\n#### YaST2 conflicts list END ###\n" );
192 YQPkgConflictList::saveItemToFile( FILE * file,
193 const Q3ListViewItem * item ) const
195 if ( ! item || ! file )
200 for ( int level = 0; level < item->depth(); level++ )
201 fprintf( file, " " );
206 const Q3CheckListItem * checkListItem = dynamic_cast<const Q3CheckListItem *> (item);
210 switch ( checkListItem->type() )
212 case Q3CheckListItem::CheckBox:
213 fprintf( file, "[%c] ", checkListItem->isOn() ? 'x' : ' ' );
215 case Q3CheckListItem::RadioButton:
216 fprintf( file, "(%c) ", checkListItem->isOn() ? 'x' : ' ' );
223 fprintf( file, "%s\n", (const char *) item->text(0) );
226 if ( item->isOpen() )
228 // Recursively write children
230 const Q3ListViewItem * child = item->firstChild();
234 saveItemToFile( file, child );
235 child = child->nextSibling();
242 YQPkgConflictList::dumpList( Q3ListViewItem * parent,
243 const QString & longText,
244 const QString & header,
249 y2error( "Null parent" );
253 if ( longText.isEmpty() )
256 if ( ! header.isEmpty() )
258 parent = new QY2ListViewItem( parent, header );
259 Q_CHECK_PTR( parent );
260 parent->setOpen( true );
263 QStringList lines = QStringList::split( '\n', longText,
264 true ); // allowEmptyEntries
265 QList<QString>::const_iterator it = lines.begin();
267 bool doSplit = splitThreshold > 1 && lines.size() > splitThreshold + 3;
268 bool didSplit = false;
272 while ( it != lines.end() )
274 if ( doSplit && ! didSplit && ++count > splitThreshold )
278 int more = lines.size() - count + 1;
279 QString text = ( _( "%1 more..." ) ).arg( more );
280 QY2ListViewItem * sublist = new QY2ListViewItem( parent, text );
285 sublist->setBackgroundColor( LIGHT_ORANGE );
290 new QY2ListViewItem( parent, *it );
301 YQPkgConflict::YQPkgConflict( YQPkgConflictList * parentList,
302 zypp::ResolverProblem_Ptr problem )
303 : QY2ListViewItem( parentList )
304 , _problem( problem )
305 , _resolutionsHeader( 0 )
307 setBackgroundColor( LIGHT_BLUE );
311 YQPkgConflictList::dumpList( this, fromUTF8( _problem->details() ) );
318 YQPkgConflict::formatHeading()
321 QPixmap icon = YQIconPool::normalPkgConflict();
322 setTextColor( BRIGHT_RED );
324 setText( 0, fromUTF8( problem()->description() ) );
325 setPixmap( 0, icon );
330 YQPkgConflict::addSolutions()
332 _resolutionsHeader = new QY2CheckListItem( this,
333 // Heading for the choices
334 // how to resolve this conflict
335 _( "Conflict Resolution:" ),
336 Q3CheckListItem::Controller );
337 Q_CHECK_PTR( _resolutionsHeader );
338 _resolutionsHeader->setOpen( true );
339 _resolutionsHeader->setBackgroundColor( LIGHT_GREY );
341 zypp::ProblemSolutionList solutions = problem()->solutions();
342 zypp::ProblemSolutionList::iterator it = solutions.begin();
344 while ( it != solutions.end() )
346 new YQPkgConflictResolution( _resolutionsHeader, *it );
353 YQPkgConflict::paintCell( QPainter * painter,
354 const QColorGroup & colorGroup,
359 painter->setFont( YQUI::yqApp()->headingFont() );
360 QY2ListViewItem::paintCell( painter, colorGroup, column, width, alignment );
364 zypp::ProblemSolution_Ptr
365 YQPkgConflict::userSelectedResolution()
367 Q3ListViewItem * item = _resolutionsHeader->firstChild();
371 YQPkgConflictResolution * res = dynamic_cast<YQPkgConflictResolution *> (item);
373 if ( res && res->isOn() )
375 zypp::ProblemSolution_Ptr solution = res->solution();
377 y2milestone( "User selected resolution \"%s\" for problem \"%s\"",
378 solution->description().c_str(),
379 solution->problem()->description().c_str() );
383 item = item->nextSibling();
386 return zypp::ProblemSolution_Ptr(); // Null pointer
394 YQPkgConflictResolution::YQPkgConflictResolution( QY2CheckListItem * parent,
395 zypp::ProblemSolution_Ptr solution )
396 : QY2CheckListItem( parent,
397 fromUTF8( solution->description() ),
398 Q3CheckListItem::RadioButton )
399 , _solution( solution )
401 YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
406 #include "YQPkgConflictList.moc"