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) {}
94 std::map<YItem *, std::string> detailsMap;
97 virtual NCursesEvent wHandleInput( wint_t ch );
102 : NCMultiSelectionBox( parent, label)
103 , depsPopup (aDepsPopup) {}
106 void saveDetails( YItem * item, std::string details ) { detailsMap[item] = details; }
119 : NCPopup( at, false )
141 NCPkgPopupDeps::~NCPkgPopupDeps()
153 void NCPkgPopupDeps::createLayout( )
157 NCLayoutBox * vSplit =
new NCLayoutBox(
this, YD_VERT );
159 vSplit->setNotify(
true );
161 new NCSpacing( vSplit, YD_VERT,
false, 1 );
163 head =
new NCLabel( vSplit,
"",
true );
166 if ( this->preferredHeight() > 25 )
167 new NCSpacing( vSplit, YD_VERT,
false, 1 );
169 NCAlignment * left =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
170 left->setWeight(YD_VERT, 30 );
174 problemw->setStretchable( YD_HORIZ,
true );
176 NCAlignment * left1 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
177 left1->setWeight(YD_VERT, 10 );
180 details =
new NCLabel ( left1,
"",
false,
true );
181 details->setStretchable( YD_HORIZ,
true );
183 if ( this->preferredHeight() > 25 )
184 new NCSpacing( vSplit, YD_VERT,
false, 0.5 );
186 NCAlignment * left2 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
187 left2->setWeight( YD_VERT, 30 );
192 if ( this->preferredHeight() > 25 )
193 new NCSpacing( vSplit, YD_VERT,
false, 1 );
195 NCAlignment * left3 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
196 left3->setWeight( YD_VERT, 30 );
199 solDetails =
new NCRichText ( left3,
"",
true );
201 if ( this->preferredHeight() > 25 )
202 new NCSpacing( vSplit, YD_VERT,
false, 1 );
204 NCLayoutBox * hSplit =
new NCLayoutBox( vSplit, YD_HORIZ );
208 solveButton->setFunctionKey( 10 );
210 new NCSpacing( hSplit, YD_HORIZ,
true, 0.2 );
214 cancelButton->setFunctionKey( 9 );
216 if ( this->preferredHeight() > 25 )
217 new NCSpacing( vSplit, YD_VERT,
false, 0.5 );
225 bool NCPkgPopupDeps::showDependencies( NCPkgSolverAction action,
bool * ok )
238 bool success = solve (problemw, action );
244 showSolutions( problemw->getCurrentItem() );
245 NCursesEvent input = showDependencyPopup( action );
247 if ( input == NCursesEvent::cancel
248 && input.detail != NCursesEvent::USERDEF )
252 problemw->setKeyboardFocus();
259 bool NCPkgPopupDeps::solve( NCSelectionBox * problemw, NCPkgSolverAction action )
264 yuiDebug() <<
"Solving..." << endl;
266 NCPopupInfo * info =
new NCPopupInfo( wpos( (NCurses::lines()-4)/2, (NCurses::cols()-18)/2 ),
268 NCPkgStrings::Solving(),
271 info->setPreferredSize( 18, 4 );
274 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
276 bool success =
false;
280 success = resolver->resolvePool();
283 success = resolver->verifySystem( );
286 yuiError() <<
"Unknown action for resolve" << endl;
291 YDialog::deleteTopmostDialog();
298 problemw->deleteAllItems ();
300 zypp::ResolverProblemList rproblems = resolver->problems ();
301 zypp::ResolverProblemList::iterator
302 b = rproblems.begin (),
303 e = rproblems.end (),
307 for (i = b, idx = 0; i != e; ++i, ++idx)
309 yuiMilestone() <<
"Problem: " << (*i)->description () << endl;
310 yuiMilestone() <<
"Details: " << (*i)->details () << endl;
313 problems.push_back (std::make_pair (*i, zypp::ProblemSolution_Ptr ()));
315 problemw->addItem( (*i)->description(), false );
321 bool NCPkgPopupDeps::showSolutions(
int index )
326 unsigned int size = problems.size ();
328 if ( index < 0 || (
unsigned int)index >= size )
331 solutionw->startMultipleChanges();
332 solutionw->deleteAllItems();
334 zypp::ResolverProblem_Ptr problem = problems[index].first;
335 zypp::ProblemSolution_Ptr user_solution = problems[index].second;
337 details->setText( problem->details() );
339 zypp::ProblemSolutionList solutions = problem->solutions ();
340 zypp::ProblemSolutionList::iterator
341 bb = solutions.begin (),
342 ee = solutions.end (),
345 bool showDetails =
true;;
346 std::string description;
348 for (ii = bb; ii != ee; ++ii) {
349 yuiMilestone() <<
"Solution: " << (*ii)->description () << endl;
350 yuiMilestone() <<
"Details: " << (*ii)->details () << endl;
351 yuiMilestone() <<
"User decision: " << user_solution << endl;
353 description = (*ii)->description();
355 if ( !((*ii)->details().empty()) )
357 description += _(
" see below" );
361 showSolutionDetails( (*ii)->details() );
365 YItem *newItem =
new YItem ( description,
366 (user_solution == *ii) );
368 solutionw->addItem( newItem );
369 solutionw->saveDetails( newItem, (*ii)->details() );
371 yuiDebug() <<
"Solution: " << (*ii) << endl;
374 solutionw->doneMultipleChanges();
388 NCursesEvent NCPkgPopupDeps::showDependencyPopup( NCPkgSolverAction action )
390 postevent = NCursesEvent();
394 }
while ( postAgain( action ) );
409 int NCPkgPopupDeps::preferredWidth()
411 return NCurses::cols()-8;
422 int NCPkgPopupDeps::preferredHeight()
424 return NCurses::lines()-5;
435 NCursesEvent NCPkgPopupDeps::wHandleInput( wint_t ch )
438 return NCursesEvent::cancel;
440 return NCDialog::wHandleInput( ch );
451 bool NCPkgPopupDeps::postAgain( NCPkgSolverAction action )
453 if ( ! postevent.widget )
456 if ( postevent.widget == cancelButton )
459 postevent = NCursesEvent::cancel;
461 else if ( postevent.widget == solveButton )
464 zypp::Resolver_Ptr resolver = zypp::getZYpp()->resolver();
465 ProblemSolutionCorrespondence::iterator
466 b = problems.begin (),
469 zypp::ProblemSolutionList solutions;
470 for (i = b; i != e; ++i)
476 solutions.push_back (i->second);
479 resolver->applySolutions (solutions);
482 bool success = solve (problemw, action );
486 problemw->setKeyboardFocus();
487 showSolutions( problemw->getCurrentItem() );
492 postevent = NCursesEvent::cancel;
496 if ( postevent == NCursesEvent::cancel )
513 void NCPkgPopupDeps::setSolution (
int index)
517 int prob_num = problemw->getCurrentItem ();
518 zypp::ResolverProblem_Ptr problem = problems[prob_num].first;
519 zypp::ProblemSolution_Ptr sol = zypp::ProblemSolution_Ptr ();
521 zypp::ProblemSolutionList solutions = problem->solutions ();
522 zypp::ProblemSolutionList::iterator
523 bb = solutions.begin (),
524 ee = solutions.end (),
527 for (ii = bb, idx = 0; ii != ee && idx < index; ++ii, ++idx) {
533 problems[prob_num] = std::make_pair (problem, sol);
536 void NCPkgPopupDeps::showSolutionDetails( std::string details )
539 if ( details.empty() )
542 text = _(
"No further solution details available" );
547 solDetails->setText( text );
559 NCursesEvent NCProblemSelectionBox::wHandleInput( wint_t key )
561 NCursesEvent ret = NCursesEvent::none;
575 depsPopup->showSolutions (getCurrentItem ());
576 ret = NCursesEvent::handled;
597 NCursesEvent NCSolutionSelectionBox::wHandleInput( wint_t key )
599 NCursesEvent ret = NCMultiSelectionBox::wHandleInput( key );
607 YItem *cur = currentItem ();
608 bool on = isItemSelected( cur );
612 selectItem (cur,
true);
613 depsPopup->setSolution ( cur->index() );
620 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.