42 #define YUILogComponent "ncurses-pkg" 45 #include "NCPkgPopupDeps.h" 47 #include "NCAlignment.h" 50 #include "NCLayoutBox.h" 51 #include "NCSpacing.h" 52 #include "NCPkgStrings.h" 53 #include "NCSelectionBox.h" 54 #include "NCMultiSelectionBox.h" 55 #include "NCPushButton.h" 56 #include "NCPopupInfo.h" 57 #include "NCInputField.h" 76 virtual NCursesEvent wHandleInput( wint_t ch );
81 : NCSelectionBox( parent, label),
82 depsPopup( aDepsPopup )
95 std::map<YItem *, std::string> detailsMap;
98 virtual NCursesEvent wHandleInput( wint_t ch );
103 : NCMultiSelectionBox( parent, label)
104 , depsPopup( aDepsPopup )
109 void saveDetails( YItem * item, std::string details )
111 detailsMap[item] = details;
125 : NCPopup( at, false )
147 NCPkgPopupDeps::~NCPkgPopupDeps()
159 void NCPkgPopupDeps::createLayout()
163 NCLayoutBox * vSplit =
new NCLayoutBox(
this, YD_VERT );
165 vSplit->setNotify(
true );
167 new NCSpacing( vSplit, YD_VERT,
false, 1 );
169 head =
new NCLabel( vSplit,
"",
true );
172 if ( this->preferredHeight() > 25 )
173 new NCSpacing( vSplit, YD_VERT,
false, 1 );
175 NCAlignment * left =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
176 left->setWeight(YD_VERT, 30 );
180 problemw->setStretchable( YD_HORIZ,
true );
182 NCAlignment * left1 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
183 left1->setWeight(YD_VERT, 10 );
186 details =
new NCLabel ( left1,
"",
false,
true );
187 details->setStretchable( YD_HORIZ,
true );
189 if ( this->preferredHeight() > 25 )
190 new NCSpacing( vSplit, YD_VERT,
false, 0.5 );
192 NCAlignment * left2 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
193 left2->setWeight( YD_VERT, 30 );
198 if ( this->preferredHeight() > 25 )
199 new NCSpacing( vSplit, YD_VERT,
false, 1 );
201 NCAlignment * left3 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
202 left3->setWeight( YD_VERT, 30 );
205 solDetails =
new NCRichText ( left3,
"",
true );
207 if ( this->preferredHeight() > 25 )
208 new NCSpacing( vSplit, YD_VERT,
false, 1 );
210 NCLayoutBox * hSplit =
new NCLayoutBox( vSplit, YD_HORIZ );
214 solveButton->setFunctionKey( 10 );
216 new NCSpacing( hSplit, YD_HORIZ,
true, 0.2 );
220 cancelButton->setFunctionKey( 9 );
222 if ( this->preferredHeight() > 25 )
223 new NCSpacing( vSplit, YD_VERT,
false, 0.5 );
231 bool NCPkgPopupDeps::showDependencies( NCPkgSolverAction action,
bool * ok )
244 bool success = solve (problemw, action );
250 showSolutions( problemw->getCurrentItem() );
251 NCursesEvent input = showDependencyPopup( action );
253 if ( input == NCursesEvent::cancel
254 && input.detail != NCursesEvent::USERDEF )
258 problemw->setKeyboardFocus();
265 bool NCPkgPopupDeps::solve( NCSelectionBox * problemw, NCPkgSolverAction action )
270 yuiDebug() <<
"Solving..." << endl;
272 NCPopupInfo * info =
new NCPopupInfo( wpos( (NCurses::lines()-4)/2, (NCurses::cols()-18)/2 ),
274 NCPkgStrings::Solving(),
277 info->setPreferredSize( 18, 4 );
280 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
282 bool success =
false;
286 success = resolver->resolvePool();
289 success = resolver->verifySystem();
292 yuiError() <<
"Unknown action for resolve" << endl;
297 YDialog::deleteTopmostDialog();
304 problemw->deleteAllItems();
306 zypp::ResolverProblemList rproblems = resolver->problems();
307 zypp::ResolverProblemList::iterator
308 b = rproblems.begin(),
313 for (i = b, idx = 0; i != e; ++i, ++idx)
315 yuiMilestone() <<
"Problem: " << (*i)->description() << endl;
316 yuiMilestone() <<
"Details: " << (*i)->details() << endl;
319 problems.push_back (std::make_pair (*i, zypp::ProblemSolution_Ptr()));
321 problemw->addItem( (*i)->description(), false );
327 bool NCPkgPopupDeps::showSolutions(
int index )
332 unsigned int size = problems.size();
334 if ( index < 0 || (
unsigned int)index >= size )
337 solutionw->startMultipleChanges();
338 solutionw->deleteAllItems();
340 zypp::ResolverProblem_Ptr problem = problems[index].first;
341 zypp::ProblemSolution_Ptr user_solution = problems[index].second;
343 details->setText( problem->details() );
345 zypp::ProblemSolutionList solutions = problem->solutions();
346 zypp::ProblemSolutionList::iterator
347 bb = solutions.begin(),
348 ee = solutions.end(),
351 bool showDetails =
true;;
352 std::string description;
354 for ( ii = bb; ii != ee; ++ii)
356 yuiMilestone() <<
"Solution: " << (*ii)->description() << endl;
357 yuiMilestone() <<
"Details: " << (*ii)->details() << endl;
358 yuiMilestone() <<
"User decision: " << user_solution << endl;
360 description = (*ii)->description();
362 if ( !((*ii)->details().empty()) )
364 description += _(
" see below" );
368 showSolutionDetails( (*ii)->details() );
372 YItem *newItem =
new YItem ( description,
373 (user_solution == *ii) );
375 solutionw->addItem( newItem );
376 solutionw->saveDetails( newItem, (*ii)->details() );
378 yuiDebug() <<
"Solution: " << (*ii) << endl;
381 solutionw->doneMultipleChanges();
395 NCursesEvent NCPkgPopupDeps::showDependencyPopup( NCPkgSolverAction action )
397 postevent = NCursesEvent();
402 }
while ( postAgain( action ) );
417 int NCPkgPopupDeps::preferredWidth()
419 return NCurses::cols()-8;
430 int NCPkgPopupDeps::preferredHeight()
432 return NCurses::lines()-5;
443 NCursesEvent NCPkgPopupDeps::wHandleInput( wint_t ch )
446 return NCursesEvent::cancel;
448 return NCDialog::wHandleInput( ch );
459 bool NCPkgPopupDeps::postAgain( NCPkgSolverAction action )
461 if ( ! postevent.widget )
464 if ( postevent.widget == cancelButton )
467 postevent = NCursesEvent::cancel;
469 else if ( postevent.widget == solveButton )
472 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
473 ProblemSolutionCorrespondence::iterator
474 b = problems.begin(),
477 zypp::ProblemSolutionList solutions;
478 for (i = b; i != e; ++i)
484 solutions.push_back (i->second);
487 resolver->applySolutions (solutions);
490 bool success = solve (problemw, action );
494 problemw->setKeyboardFocus();
495 showSolutions( problemw->getCurrentItem() );
500 postevent = NCursesEvent::cancel;
504 if ( postevent == NCursesEvent::cancel )
521 void NCPkgPopupDeps::setSolution (
int index)
525 int prob_num = problemw->getCurrentItem();
526 zypp::ResolverProblem_Ptr problem = problems[prob_num].first;
527 zypp::ProblemSolution_Ptr sol = zypp::ProblemSolution_Ptr();
529 zypp::ProblemSolutionList solutions = problem->solutions();
530 zypp::ProblemSolutionList::iterator
531 bb = solutions.begin(),
532 ee = solutions.end(),
536 for (ii = bb, idx = 0; ii != ee && idx < index; ++ii, ++idx)
544 problems[prob_num] = std::make_pair (problem, sol);
547 void NCPkgPopupDeps::showSolutionDetails( std::string details )
550 if ( details.empty() )
553 text = _(
"No further solution details available" );
558 solDetails->setText( text );
570 NCursesEvent NCProblemSelectionBox::wHandleInput( wint_t key )
572 NCursesEvent ret = NCursesEvent::none;
586 depsPopup->showSolutions (getCurrentItem());
587 ret = NCursesEvent::handled;
605 NCursesEvent NCSolutionSelectionBox::wHandleInput( wint_t key )
607 NCursesEvent ret = NCMultiSelectionBox::wHandleInput( key );
616 YItem *cur = currentItem();
617 bool on = isItemSelected( cur );
621 selectItem (cur,
true);
622 depsPopup->setSolution ( cur->index() );
630 depsPopup->showSolutionDetails( detailsMap[currentItem()] );
static const std::string SolveLabel()
The label of the Solve button.
static const std::string PackageDeps()
The headline of the dependency popup.
static const std::string CancelLabel()
The label of the Cancel button.
static const std::string OKLabel()
The label of the OK button.