libyui-ncurses-pkg  2.48.5
NCPkgTable.cc
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgTable.cc
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 #include <YDialog.h>
44 
45 #include "NCurses.h"
46 #include "NCPkgTable.h"
47 #include "NCTable.h"
48 #include "NCPopupInfo.h"
49 #include "NCPkgStrings.h"
50 #include "NCi18n.h"
51 #include "NCPkgPopupDiskspace.h"
52 #include "NCPackageSelector.h"
53 #include <zypp/ui/Selectable.h>
54 #include "NCZypp.h"
55 
56 using std::endl;
57 
58 /*
59  Textdomain "ncurses-pkg"
60 */
61 
62 ///////////////////////////////////////////////////////////////////
63 //
64 //
65 // METHOD NAME : NCPkgTableTag::NCPkgTableTag
66 // METHOD TYPE : Constructor
67 //
68 // DESCRIPTION :
69 //
70 NCPkgTableTag::NCPkgTableTag( ZyppObj objPtr, ZyppSel selPtr,
71  ZyppStatus stat )
72  : YTableCell( " " )
73  , status ( stat )
74  , dataPointer( objPtr )
75  , selPointer( selPtr )
76 {
77  setLabel( statusToString(stat) );
78 }
79 
80 std::string NCPkgTableTag::statusToString( ZyppStatus stat ) const
81 {
82  // convert ZyppStatus to std::string
83  switch ( stat )
84  {
85  case S_NoInst: // Is not installed and will not be installed
86  return " ";
87  case S_KeepInstalled: // Is installed - keep this version
88  return " i ";
89  case S_Install: // Will be installed
90  return " + ";
91  case S_Del: // Will be deleted
92  return " - ";
93  case S_Update: // Will be updated
94  return " > ";
95  case S_AutoInstall: // Will be automatically installed
96  return " a+ ";
97  case S_AutoDel: // Will be automatically deleted
98  return " a- ";
99  case S_AutoUpdate: // Will be automatically updated
100  return " a> ";
101  case S_Taboo: // Never install this
102  return " ---";
103  case S_Protected: // always keep installed version
104  return " -i-";
105  default:
106  return "####";
107  }
108 
109  return " ";
110 }
111 
112 ///////////////////////////////////////////////////////////////////
113 //
114 //
115 // METHOD NAME : NCPkgTable::NCPkgTable
116 // METHOD TYPE : Constructor
117 //
118 // DESCRIPTION :
119 //
120 NCPkgTable::NCPkgTable( YWidget * parent, YTableHeader * tableHeader )
121  : NCTable( parent, tableHeader )
122  , packager ( 0 )
123  , statusStrategy( new PackageStatStrategy ) // default strategy: packages
124  , tableType ( T_Packages ) // default type: packages
125  , haveInstalledVersion ( false )
126  , visibleInfo( I_Technical )
127 {
128  yuiDebug() << "NCPkgTable created" << endl;
129 }
130 
131 
132 ///////////////////////////////////////////////////////////////////
133 //
134 //
135 // METHOD NAME : NCPkgTable::~NCPkgTable
136 // METHOD TYPE : Destructor
137 //
138 // DESCRIPTION :
139 //
140 NCPkgTable::~NCPkgTable()
141 {
142  delete statusStrategy;
143  yuiDebug() << endl;
144 }
145 
146 
147 
148 ///////////////////////////////////////////////////////////////////
149 //
150 //
151 // METHOD NAME : NCPkgTable::addLine
152 // METHOD TYPE : void
153 //
154 // DESCRIPTION :
155 //
156 void NCPkgTable::addLine( ZyppStatus stat,
157  const std::vector<std::string> & elements,
158  ZyppObj objPtr,
159  ZyppSel slbPtr )
160 {
161  YTableItem *tabItem = new YTableItem();
162 
163  // fill first column (containing the status information and the package pointers)
164  tabItem->addCell( new NCPkgTableTag( objPtr, slbPtr, stat ));
165 
166 
167  for ( unsigned i = 1; i < elements.size()+1; ++i ) {
168  tabItem->addCell( elements[i-1] );
169  }
170 
171  // use all-at-once insertion mode - DrawPad() is called only after the loop
172  addItem(tabItem, true);
173 
174 }
175 
176 ///////////////////////////////////////////////////////////////////
177 //
178 //
179 // METHOD NAME : NCPkgTable::deleteAllItems
180 // METHOD TYPE : void
181 //
182 // DESCRIPTION :
183 //
185 {
186  return NCTable::deleteAllItems();
187 }
188 
189 
190 ///////////////////////////////////////////////////////////////////
191 //
192 //
193 // METHOD NAME : NCPkgTable::cellChanged
194 // METHOD TYPE : void
195 //
196 // DESCRIPTION :
197 //
198 void NCPkgTable::cellChanged( int index, int colnum, const std::string & newtext )
199 {
200  return NCTable::cellChanged( index, colnum, newtext );
201 }
202 
203 ///////////////////////////////////////////////////////////////////
204 //
205 //
206 // METHOD NAME : NCPkgTable::changeStatus
207 // METHOD TYPE : bool
208 //
209 // DESCRIPTION : sets the new status in first column of the package table
210 // and informs the package manager
211 //
212 bool NCPkgTable::changeStatus( ZyppStatus newstatus,
213  const ZyppSel & slbPtr,
214  // objPtr is candidatePtr or what the user selected instead of it.
215  ZyppObj objPtr,
216  bool singleChange )
217 {
218  if ( !packager || !slbPtr )
219  return false;
220 
221  std::string notify;
222  std::string license;
223  bool license_confirmed = true;
224  ZyppPkg pkgPtr = NULL;
225  std::string header;
226  bool ok = true;
227  int cols = NCurses::cols();
228  int lines = NCurses::lines();
229 
230  switch ( newstatus )
231  {
232  case S_Del:
233  case S_NoInst:
234  case S_Taboo:
235  if ( objPtr )
236  {
237  notify = objPtr->delnotify();
238  yuiMilestone() << "DELETE message: " << notify << endl;
239  header = NCPkgStrings::WarningLabel();
240  }
241  break;
242  //display notify msg only if we mark pkg for installation
243  //disregard update, to be consistent with Qt (#308410)
244  case S_Install:
245  if ( objPtr )
246  {
247  notify = objPtr->insnotify();
248  yuiMilestone() << "NOTIFY message: " << notify << endl;
249  header = NCPkgStrings::NotifyLabel();
250  }
251  case S_Update:
252  case S_AutoInstall:
253  case S_AutoUpdate:
254  if ( objPtr )
255  {
256  // check license of packages and patches in case of S_Install/S_Update/S_AutoInstall/S_AutoUpdate
257  license = objPtr->licenseToConfirm();
258  license_confirmed = slbPtr->hasLicenceConfirmed();
259  }
260  break;
261 
262  default: break;
263  }
264 
265  std::string pkgName = slbPtr->name();
266 
267  if ( !license.empty() )
268  {
269  if ( !license_confirmed )
270  {
271  license_confirmed = packager->showLicensePopup( pkgName, license);
272  }
273 
274  if ( !license_confirmed )
275  {
276  // make sure the package won't be installed
277  switch ( newstatus )
278  {
279  case S_Install:
280  case S_AutoInstall:
281  newstatus = S_Taboo;
282  break;
283 
284  case S_Update:
285  case S_AutoUpdate:
286  newstatus = S_Protected;
287  break;
288 
289  default:
290  break;
291  }
292 
293  ok = false;
294  } else {
295  yuiMilestone() << "User confirmed license agreement for " << pkgName << endl;
296  slbPtr->setLicenceConfirmed (true);
297  }
298  }
299 
300  if ( ok && !notify.empty() )
301  {
302  std::string html_text = packager->InfoText()->createHtmlText( notify );
303  NCPopupInfo * info = new NCPopupInfo( wpos( (lines * 35)/100, (cols * 25)/100),
304  header,
305  "<i>" + pkgName + "</i><br><br>" + html_text
306  );
307  info->setPreferredSize( (NCurses::cols() * 50)/100, (NCurses::lines() * 30)/100);
308  info->showInfoPopup( );
309 
310  YDialog::deleteTopmostDialog();
311  }
312 
313  // inform the package manager
314  ok = statusStrategy->setObjectStatus( newstatus, slbPtr, objPtr );
315 
316  if ( ok && singleChange )
317  {
318  switch ( tableType )
319  {
320  case T_Packages:
321  case T_PatchPkgs:
322  case T_Update:
323  // check/show dependencies of packages
324  packager->showPackageDependencies( false ); // only check if automatic check is ON
325  // show the required diskspace
326  packager->showDiskSpace();
327  break;
328  case T_Availables:
329  // check/show dependencies of packages
330  packager->showPackageDependencies( false );
331  // don't show diskspace (type T_Availables is also used in YOU mode)
332  break;
333  case T_Selections:
334  // check/show dependencies of selections
335  packager->showSelectionDependencies();
336  packager->showDiskSpace();
337  break;
338 
339  case T_Patches:
340  // show the download size for all selected patches
341  packager->showDownloadSize();
342  packager->showPackageDependencies( false );
343  break;
344 
345  default:
346  break;
347  }
348  // update this list to show the status changes
349  updateTable();
350 
351  if ( tableType == T_Availables || tableType == T_MultiVersion )
352  {
353  // additionally update the package list
354  packager->updatePackageList();
355  }
356  }
357 
358  return ok;
359 }
360 
361 ///////////////////////////////////////////////////////////////////
362 //
363 //
364 // METHOD NAME : NCPkgTable::updateTable
365 // METHOD TYPE : bool
366 //
367 // DESCRIPTION : set the new status info if status has changed
368 //
370 {
371  unsigned int size = getNumLines();
372  unsigned int index = 0;
373  bool ret = true;
374 
375  while ( index < size )
376  {
377  // get the table line
378  NCTableLine * cl = myPad()->ModifyLine( index );
379  if ( !cl )
380  {
381  ret = false;
382  break;
383  }
384 
385  // get first column (the column containing the status info)
386  YTableItem *it = dynamic_cast<YTableItem*> (cl->origItem() );
387  YTableCell *tcell = it->cell(0);
388  NCPkgTableTag * cc = static_cast<NCPkgTableTag*>( tcell );
389  // get the object pointer
390  ZyppSel slbPtr = getSelPointer( index );
391  ZyppObj objPtr = getDataPointer( index );
392 
393  if ( !cc )
394  {
395  ret = false;
396  break;
397  }
398 
399  ZyppStatus newstatus = S_NoInst;
400  if ( slbPtr && objPtr)
401  {
402  if ( tableType == T_Availables && !slbPtr->multiversionInstall() )
403  {
404  std::string isCandidate = " ";
405  if ( objPtr == slbPtr->candidateObj() )
406  isCandidate = " x ";
407 
408  cl->AddCol( 2, new NCTableCol( isCandidate ) );
409  }
410  else
411  {
412  // get the new status and replace old status
413  newstatus = statusStrategy->getPackageStatus( slbPtr, objPtr );
414 
415  // set new status (if status has changed)
416  if ( getStatus(index) != newstatus )
417  {
418  cc->setStatus( newstatus );
419  cellChanged( index, 0, cc->statusToString (newstatus) );
420  }
421  }
422  }
423  index++;
424  }
425 
426  DrawPad();
427 
428  return ret;
429 }
430 
431 ///////////////////////////////////////////////////////////////////
432 //
433 // slbHasInstalledObj
434 //
435 // a helper to call a method
436 //
437 static bool slbHasInstalledObj (const ZyppSel & slb)
438 {
439  return ! slb->installedEmpty ();
440 }
441 
442 ///////////////////////////////////////////////////////////////////
443 //
444 // fillHeader
445 //
446 // Fillup the column headers of the package table
447 //
449 {
450  std::vector<std::string> header;
451 
452  switch ( tableType )
453  {
454  case T_Packages:
455  case T_Update: {
456  bool haveInstalledPkgs = find_if (zyppPkgBegin (), zyppPkgEnd (),
457  slbHasInstalledObj) != zyppPkgEnd ();
458 
459  header.reserve(7);
460  header.push_back( "L" + NCPkgStrings::PkgStatus() );
461  header.push_back( "L" + NCPkgStrings::PkgName() );
462  header.push_back( "L" + NCPkgStrings::PkgSummary() );
463  if ( haveInstalledPkgs > 0 )
464  {
465  header.push_back( "L" + NCPkgStrings::PkgVersionNew() );
466  header.push_back( "L" + NCPkgStrings::PkgVersionInst() );
467  haveInstalledVersion = true;
468  }
469  else
470  {
471  header.push_back( "L" + NCPkgStrings::PkgVersion() );
472  }
473  header.push_back( "L" + NCPkgStrings::PkgSize() );
474 // installation of source rpms is not possible
475 #ifdef FIXME
476  header.push_back( "L" + NCPkgStrings::PkgSource() );
477 #endif
478  break;
479  }
480  case T_PatchPkgs: {
481  header.reserve(7);
482  header.push_back( "L" + NCPkgStrings::PkgStatus() );
483  header.push_back( "L" + NCPkgStrings::PkgName() );
484  header.push_back( "L" + NCPkgStrings::PkgVersionNew() );
485  header.push_back( "L" + NCPkgStrings::PkgVersionInst() );
486  header.push_back( "L" + NCPkgStrings::PkgSummary() );
487  header.push_back( "L" + NCPkgStrings::PkgSize() );
488  break;
489  }
490  case T_Patches: {
491  header.reserve(6);
492  header.push_back( "L" + NCPkgStrings::PkgStatus() );
493  header.push_back( "L" + NCPkgStrings::PkgName() );
494  header.push_back( "L" + NCPkgStrings::PatchKind() );
495  header.push_back( "L" + NCPkgStrings::PkgSummary() );
496  header.push_back( "L" + NCPkgStrings::PkgVersion() );
497  // header.push_back( "L" + NCPkgStrings::PkgSize() );
498  break;
499  }
500  case T_Selections: {
501  header.reserve(3);
502  header.push_back( "L" + NCPkgStrings::PkgStatus() );
503  header.push_back( "L" + NCPkgStrings::PatternsLabel() );
504  break;
505  }
506  case T_Languages: {
507  header.reserve(4);
508  header.push_back( "L" + NCPkgStrings::PkgStatus() );
509  header.push_back( "L" + NCPkgStrings::LangCode() );
510  header.push_back( "L" + NCPkgStrings::LangName() );
511  break;
512  }
513  case T_Availables: {
514  header.reserve(6);
515  header.push_back( "L" + NCPkgStrings::PkgStatus() );
516  header.push_back( "L" + NCPkgStrings::PkgName() );
517  header.push_back( "L" + NCPkgStrings::PkgStatus() );
518  header.push_back( "L" + NCPkgStrings::PkgVersion() );
519  header.push_back( "L" + NCPkgStrings::PkgInstSource() );
520  header.push_back( "L" + NCPkgStrings::PkgSize() );
521  header.push_back( "L" + NCPkgStrings::PkgArch() );
522  break;
523  }
524  case T_MultiVersion: {
525  header.reserve(5);
526  header.push_back( "L" + NCPkgStrings::PkgStatus() );
527  header.push_back( "L" + NCPkgStrings::PkgName() );
528  header.push_back( "L" + NCPkgStrings::PkgVersion() );
529  header.push_back( "L" + NCPkgStrings::PkgInstSource() );
530  header.push_back( "L" + NCPkgStrings::PkgSize() );
531  header.push_back( "L" + NCPkgStrings::PkgArch() );
532  break;
533  }
534  default: {
535  header.reserve(4);
536  header.push_back( "L" + NCPkgStrings::PkgStatus() );
537  header.push_back( "L" + NCPkgStrings::PkgName() );
538  header.push_back( "L" + NCPkgStrings::PkgSummary() );
539  break;
540  }
541  }
542  setHeader( header );
543 }
544 
545 ///////////////////////////////////////////////////////////////////
546 //
547 // createListEntry
548 //
549 //
550 bool NCPkgTable::createListEntry ( ZyppPkg pkgPtr, ZyppSel slbPtr )
551 {
552  std::vector<std::string> pkgLine;
553  pkgLine.reserve(6);
554 
555  if ( !pkgPtr || !slbPtr )
556  {
557  yuiError() << "No valid package available" << endl;
558  return false;
559  }
560 
561  // add the package name
562  pkgLine.push_back( slbPtr->name() );
563 
564  std::string instVersion = "";
565  std::string version = "";
566  ZyppStatus status;
567 
568  switch( tableType )
569  {
570  case T_PatchPkgs: {
571  // if the package is installed, get the installed version
572  if ( ! slbPtr->installedEmpty() )
573  {
574  instVersion = slbPtr->installedObj()->edition().asString();
575  }
576  // if a candidate is available, get the candidate version
577  if ( slbPtr->hasCandidateObj() )
578  {
579  version = slbPtr->candidateObj()->edition().asString();
580  }
581  else
582  {
583  version = pkgPtr->edition().asString();
584  }
585  pkgLine.push_back( version );
586 
587  // in case of YOU there are always installed packages
588  // => always add installed version (or empty column)
589  pkgLine.push_back( instVersion );
590 
591  pkgLine.push_back( pkgPtr->summary() ); // short description
592 
593  status = slbPtr->status(); // the package status
594  yuiMilestone() << "Status of " << slbPtr->name() << ": " << status << endl;
595  zypp::ByteCount size = pkgPtr->installSize(); // installed size
596  pkgLine.push_back( size.asString( 8 ) ); // format size
597 
598  break;
599  }
600  case T_Availables: {
601  std::string isCandidate = " ";
602  if ( pkgPtr == slbPtr->candidateObj() )
603  isCandidate = " x ";
604  pkgLine.push_back( isCandidate );
605 
606  version = pkgPtr->edition().asString();
607  pkgLine.push_back( version );
608  // show the name of the repository (the installation source)
609  pkgLine.push_back( pkgPtr->repository().info().name() );
610 
611  // set package status either to S_NoInst or S_KeepInstalled
612  status = S_NoInst;
613  zypp::ui::Selectable::installed_iterator it = slbPtr->installedBegin();
614 
615  while ( it != slbPtr->installedEnd() )
616  {
617  if ( pkgPtr->edition() == (*it)->edition() &&
618  pkgPtr->arch() == (*it)->arch() &&
619  pkgPtr->vendor() == (*it)->vendor() )
620  {
621  status = S_KeepInstalled;
622  }
623  ++it;
624  }
625 
626  zypp::ByteCount size = pkgPtr->installSize(); // installed size
627  pkgLine.push_back( size.asString( 8 ) ); // format size
628  pkgLine.push_back( pkgPtr->arch().asString()); // architecture
629 
630  break;
631  }
632  case T_MultiVersion: {
633  version = pkgPtr->edition().asString();
634  pkgLine.push_back( version );
635  // show the name of the repository (the installation source)
636  pkgLine.push_back( pkgPtr->repository().info().name() );
637 
638  zypp::PoolItem itemPtr( pkgPtr->satSolvable() );
639  status = slbPtr->pickStatus( itemPtr );
640  yuiMilestone() << "Multi version: status of " << version << ": " << status << endl;
641 
642  zypp::ByteCount size = pkgPtr->installSize(); // installed size
643  pkgLine.push_back( size.asString( 8 ) ); // format size
644  pkgLine.push_back( pkgPtr->arch().asString()); // architecture
645  break;
646  }
647  default: {
648  // if the package is installed, get the installed version
649  pkgLine.push_back( pkgPtr->summary() ); // short description
650  if ( ! slbPtr->installedEmpty() )
651  {
652  instVersion = slbPtr->installedObj()->edition().version();
653 
654  // if a candidate is available, get the candidate version
655  if ( slbPtr->hasCandidateObj() )
656  {
657  version = slbPtr->candidateObj()->edition().version();
658  }
659  }
660  else
661  {
662  version = pkgPtr->edition().version();
663  }
664  pkgLine.push_back( version ); // the available version (the candidate)
665 
666  if ( haveInstalledVersion )
667  {
668  pkgLine.push_back( instVersion ); // installed version
669  }
670 
671  status = slbPtr->status(); // the package status
672 
673  zypp::ByteCount size = pkgPtr->installSize(); // installed size
674  pkgLine.push_back( size.asString( 8 ) ); // format size
675 
676 // Selectable does not have source_install
677 #ifdef FIXME
678  if ( slbPtr->source_install() )
679  {
680  pkgLine.push_back( " x " );
681  }
682  else
683 #endif
684  {
685  pkgLine.push_back( " " );
686  }
687  }
688  }
689 
690  addLine( status, // the package status
691  pkgLine, // the package data
692  pkgPtr, // the corresponding package pointer
693  slbPtr
694  );
695 
696  return true;
697 }
698 
699 ///////////////////////////////////////////////////////////////////
700 //
701 // createInfoEntry
702 //
703 //
704 bool NCPkgTable::createInfoEntry ( std::string text )
705 {
706  std::vector<std::string> pkgLine;
707  pkgLine.reserve(2);
708 
709  pkgLine.push_back( text );
710  addLine( S_NoInst, // use status NoInst
711  pkgLine,
712  ZyppObj(),
713  ZyppSel()); // null pointer
714 
715  return true;
716 }
717 
718 ///////////////////////////////////////////////////////////////////
719 //
720 // createPatchEntry
721 //
722 //
723 bool NCPkgTable::createPatchEntry ( ZyppPatch patchPtr, ZyppSel slb )
724 {
725  std::vector<std::string> pkgLine;
726  pkgLine.reserve(5);
727 
728  if ( !patchPtr || !slb )
729  {
730  yuiError() << "No valid patch available" << endl;
731  return false;
732  }
733 
734  pkgLine.push_back( slb->name() ); // show the patch name
735 
736  pkgLine.push_back( patchPtr->category() ); // patch kind
737 
738  if ( !patchPtr->summary().empty() )
739  pkgLine.push_back( patchPtr->summary() ); // short description
740  else
741  pkgLine.push_back( slb->name() ); // name
742 
743  pkgLine.push_back( patchPtr->edition().asString() ); // patch version
744 
745  // zypp::ByteCount size = patchPtr->size();
746  // pkgLine.push_back( size.asString( 8 ) );
747 
748 
749  addLine( slb->status(), // get the status
750  pkgLine,
751  patchPtr,
752  slb ); // the corresponding pointer
753 
754  return true;
755 }
756 
757 ///////////////////////////////////////////////////////////////////
758 //
759 // showInformation
760 //
761 //
763 {
764  ZyppObj objPtr = getDataPointer( getCurrentItem() );
765  ZyppSel slbPtr = getSelPointer( getCurrentItem() );
766 
767  if ( !packager || !objPtr || !slbPtr )
768  return false;
769 
770  yuiMilestone() << "show information for " << slbPtr->name() << endl;
771 
772  switch ( tableType )
773  {
774  case T_Packages:
775  case T_Update:
776  // show the required package info
777  updateInfo( objPtr, slbPtr, VisibleInfo() );
778  packager->PackageLabel()->setLabel( slbPtr->name() );
779  break;
780  case T_Patches:
781  // show the patch info
782  updateInfo( objPtr, slbPtr, VisibleInfo() );
783  break;
784  default:
785  break;
786  }
787 
788  return true;
789 }
790 
791 
792 ///////////////////////////////////////////////////////////////////
793 //
794 //
795 // METHOD NAME : NCPkgTable::wHandleInput
796 // METHOD TYPE : NCursesEvent
797 //
798 // DESCRIPTION :
799 //
800 NCursesEvent NCPkgTable::wHandleInput( wint_t key )
801 {
802  NCursesEvent ret = NCursesEvent::none;
803 
804  // call handleInput of NCPad
805  handleInput( key );
806 
807  if ( packager->isTestMode() )
808  {
809  if ( packager->diskSpacePopup() )
810  packager->diskSpacePopup()->setDiskSpace( key );
811  return ret;
812  }
813 
814  switch ( key )
815  {
816  case KEY_UP:
817  case KEY_DOWN:
818  case KEY_NPAGE:
819  case KEY_PPAGE:
820  case KEY_END:
821  case KEY_HOME: {
822  // show the corresponding information
823  showInformation( );
824  break;
825  }
826  case KEY_SPACE:
827  case KEY_RETURN: {
828  // toggle status
829  toggleObjStatus( );
830  break;
831  }
832  //from the parent class, to enable sorting
833  case CTRL('o'): {
834  NCTable::wHandleInput( key);
835  break;
836  }
837  case '-':
838  case '+':
839  case '>':
840  case '<':
841  case '!':
842  case '*': {
843  // set the new status
844  changeObjStatus( key );
845  }
846  default: {
847  break;
848  }
849  }
850 
851  NCDialog * currentDialog = static_cast<NCDialog *>(YDialog::topmostDialog());
852  if ( currentDialog )
853  currentDialog->setStatusLine();
854 
855  return NCursesEvent::handled;
856 }
857 
858 ///////////////////////////////////////////////////////////////////
859 //
860 // NCPkgTable::getStatus()
861 //
862 // Gets the status of the package of selected line
863 //
864 ZyppStatus NCPkgTable::getStatus( int index )
865 {
866  // get the tag
867  NCPkgTableTag * cc = getTag( index);
868  if ( !cc )
869  return S_NoInst;
870 
871  return cc->getStatus();
872 }
873 
874 ZyppObj NCPkgTable::getDataPointer( int index )
875 {
876  // get the tag
877  NCPkgTableTag *cc = getTag( index );
878  if ( !cc )
879  return ZyppObj( );
880 
881  return cc->getDataPointer();
882 }
883 
884 ZyppSel NCPkgTable::getSelPointer( int index )
885 {
886  // get the tag
887  NCPkgTableTag *cc = getTag( index );
888  if ( !cc )
889  return ZyppSel( );
890 
891  return cc->getSelPointer();
892 }
893 
894 NCPkgTableTag * NCPkgTable::getTag( const int & index )
895 {
896  // get the table line
897  NCTableLine * cl = myPad()->ModifyLine( index );
898  if ( !cl )
899  return 0;
900 
901  // get first column (the column containing the status info)
902  YTableItem *it = dynamic_cast<YTableItem*> (cl->origItem() );
903  YTableCell *tcell = it->cell(0);
904  NCPkgTableTag * cc = static_cast<NCPkgTableTag *>( tcell );
905 
906  return cc;
907 }
908 
909 #ifdef FIXME
910 ///////////////////////////////////////////////////////////////////
911 //
912 // NCPkgTable::SourceInstall()
913 //
914 //
915 bool NCPkgTable::SourceInstall( bool install )
916 {
917  int index = getCurrentItem();
918  ZyppObj objPtr = getDataPointer( index );
919  bool ok;
920 
921  if ( !objPtr )
922  {
923  yuiError() << "Invalid Pointer" << endl;
924  return false;
925  }
926  ZyppSel selPtr = objPtr->getSelectable();
927  NCTableLine * currentLine = myPad()->ModifyLine( index );
928 
929  if ( !selPtr || !currentLine )
930  {
931  yuiError() << "Invalid Selectable" << endl;
932  return false;
933  }
934 
935  NCTableCol * currentCol = currentLine->GetCol( currentLine->Cols()-1 );
936 
937  if ( install && selPtr->providesSources() )
938  {
939  ok = selPtr->set_source_install( true );
940  yuiMilestone() << "Set source install returns: " << (ok?"true":"false") << endl;
941  if ( currentCol )
942  currentCol->SetLabel( NClabel( " x " ) );
943  }
944  else if ( !install && selPtr->source_install() )
945  {
946  ok = selPtr->set_source_install( false );
947  yuiMilestone() << "ReSet source install returns: " << (ok?"true":"false") << endl;
948  if ( currentCol )
949  currentCol->SetLabel( NClabel( " " ) );
950  }
951 
952  return true;
953 }
954 #endif
955 
956 ///////////////////////////////////////////////////////////////////
957 //
958 // NCPkgTable::toggleObjStatus()
959 //
960 //
961 bool NCPkgTable::toggleObjStatus( )
962 {
963  ZyppSel slbPtr = getSelPointer( getCurrentItem() );
964  ZyppObj objPtr = getDataPointer( getCurrentItem() );
965 
966  if ( !slbPtr )
967  return false;
968 
969  ZyppStatus newStatus;
970 
971  bool ok = statusStrategy->toggleStatus( slbPtr, objPtr, newStatus );
972 
973  if ( ok )
974  {
975  changeStatus( newStatus, slbPtr, objPtr, true );
976  }
977 
978  return true;
979 }
980 
981 ///////////////////////////////////////////////////////////////////
982 //
983 // NCPkgTable::changeObjStatus()
984 //
985 //
986 bool NCPkgTable::changeObjStatus( int key )
987 {
988  ZyppSel slbPtr = getSelPointer( getCurrentItem() );
989  ZyppObj objPtr = getDataPointer( getCurrentItem() );
990 
991  if ( !slbPtr )
992  {
993  return false;
994  }
995  ZyppStatus newStatus;
996 
997  bool ok = statusStrategy->keyToStatus( key, slbPtr, objPtr, newStatus );
998 
999  if ( ok )
1000  {
1001  changeStatus( newStatus, slbPtr, objPtr, true );
1002  }
1003  return true;
1004 }
1005 
1006 ///////////////////////////////////////////////////////////////////
1007 //
1008 // NCPkgTable::changeListObjStatus()
1009 //
1010 //
1011 bool NCPkgTable::changeListObjStatus( NCPkgTableListAction type )
1012 {
1013  ZyppStatus newStatus;
1014  unsigned int size = getNumLines();
1015  unsigned int index = 0;
1016 
1017  while ( index < size )
1018  {
1019  // get the object pointer
1020  ZyppSel slbPtr = getSelPointer( index );
1021  ZyppObj objPtr = getDataPointer( index );
1022  bool ok = false;
1023 
1024  if ( slbPtr )
1025  {
1026  switch ( type ) {
1027  case A_Install: {
1028  if ( slbPtr->status() == S_NoInst )
1029  ok = statusStrategy->keyToStatus( '+', slbPtr, objPtr, newStatus );
1030  break;
1031  }
1032  case A_Delete: {
1033  if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
1034  ok = statusStrategy->keyToStatus( '-', slbPtr, objPtr, newStatus );
1035  break;
1036  }
1037  case A_UpdateNewer: {
1038  // set status to update respecting "vendor change" settings
1039  if ( slbPtr->installedObj() && slbPtr->status() != S_Protected && slbPtr->updateCandidateObj() )
1040  {
1041  slbPtr->setOnSystem( slbPtr->updateCandidateObj() );
1042  ok = statusStrategy->keyToStatus( '>', slbPtr, objPtr, newStatus );
1043  }
1044  break;
1045  }
1046  case A_Update: {
1047  if ( slbPtr->installedObj() && slbPtr->status() != S_Protected )
1048  ok = statusStrategy->keyToStatus( '>', slbPtr, objPtr, newStatus );
1049  break;
1050  }
1051  case A_Keep: {
1052  if ( slbPtr->status() == S_Install
1053  || slbPtr->status() == S_AutoInstall
1054  || slbPtr->status() == S_Update
1055  || slbPtr->status() == S_AutoUpdate )
1056  ok = statusStrategy->keyToStatus( '<', slbPtr, objPtr, newStatus );
1057  else if ( slbPtr->status() == S_Del
1058  || slbPtr->status() == S_AutoDel )
1059  ok = statusStrategy->keyToStatus( '+', slbPtr, objPtr, newStatus );
1060  break;
1061  }
1062  default:
1063  yuiError() << "Unknown list action" << endl;
1064  }
1065 
1066  if ( ok )
1067  {
1068  changeStatus( newStatus,
1069  slbPtr,
1070  objPtr,
1071  false ); // do not do the updates with every change
1072  }
1073  }
1074 
1075  index++;
1076  }
1077 
1078  // do the updates now
1079  packager->showPackageDependencies( false );
1080  packager->showDiskSpace();
1081 
1082  updateTable();
1083 
1084  return true;
1085 }
1086 
1087 bool NCPkgTable::fillAvailableList ( ZyppSel slb )
1088 {
1089  if ( !slb )
1090  {
1091  yuiError() << "Package pointer not valid" << endl;
1092  return false;
1093  }
1094 
1095  // clear the package table
1096  itemsCleared ();
1097 
1098  NCPkgStatusStrategy * strategy;
1099  NCPkgTableType type;
1100 
1101  if ( slb->multiversionInstall() || slb->installedSize() > 1 )
1102  {
1103  // Either the selectable has at least one multiversion
1104  // package or there are more than one installed package
1105  // instances.
1106  // The last case can also happens by an previous package
1107  // installation error.
1108  type = T_MultiVersion;
1109  strategy = new MultiVersionStatStrategy();
1110  yuiMilestone() << "Multi version package " << slb->name() << endl;
1111  }
1112  else
1113  {
1114  type = T_Availables;
1115  strategy = new AvailableStatStrategy();
1116  }
1117 
1118  setTableType( type, strategy );
1119  this->fillHeader();
1120 
1121  // pick list contains installed and available packages (valid for single and multi version)
1122  zypp::ui::Selectable::picklist_iterator it = slb->picklistBegin();
1123  while ( it != slb->picklistEnd() )
1124  {
1125  createListEntry( tryCastToZyppPkg(*it), slb );
1126  ++it;
1127  }
1128 
1129 #if 0
1130  // show installed packages
1131  {
1132  zypp::ui::Selectable::installed_iterator it = slb->installedBegin();
1133  while ( it != slb->installedEnd() )
1134  {
1135  createListEntry( tryCastToZyppPkg(*it), slb );
1136  ++it;
1137  }
1138  }
1139  // and all availables
1140  {
1141  zypp::ui::Selectable::available_iterator it = slb->availableBegin();
1142  while ( it != slb->availableEnd() )
1143  {
1144  createListEntry( tryCastToZyppPkg(*it), slb );
1145  ++it;
1146  }
1147  }
1148 #endif
1149 
1150  // show the package list
1151  drawList();
1152 
1153  if ( getNumLines() > 0 )
1154  {
1155  setCurrentItem( 0 );
1156  }
1157  return true;
1158 
1159 }
1160 
1161 bool NCPkgTable::fillSummaryList( NCPkgTable::NCPkgTableListType type )
1162 {
1163  // clear the package table
1164  itemsCleared ();
1165 
1166  // get the package list and sort it
1167  std::list<ZyppSel> pkgList( zyppPkgBegin (), zyppPkgEnd () );
1168  pkgList.sort( sortByName );
1169 
1170  // fill the package table
1171  std::list<ZyppSel>::iterator listIt;
1172  ZyppPkg pkgPtr;
1173 
1174  // If the dependency check is off, the dependencies will not be solved for
1175  // the installation summary.
1176  // This is not necessary because the dependencies will be solved and the
1177  // "Automatic Changes" list will be shown if the OK button is pressed.
1178  //if ( !autoCheck )
1179  //{
1180  // showPackageDependencies( true );
1181  //}
1182 
1183  for ( listIt = pkgList.begin(); listIt != pkgList.end(); ++listIt )
1184  {
1185  ZyppSel selectable = *listIt;
1186  ZyppPkg pkg = tryCastToZyppPkg (selectable->theObj ());
1187  // show all matching packages
1188  switch ( type )
1189  {
1190  case NCPkgTable::L_Changes: {
1191  if ( selectable->status() != S_NoInst
1192  && selectable->status() != S_KeepInstalled )
1193  {
1194  createListEntry( pkg, selectable );
1195  }
1196  break;
1197  }
1198  case NCPkgTable::L_Installed: {
1199  if ( selectable->status() == S_KeepInstalled )
1200  {
1201  createListEntry( pkg, selectable );
1202  }
1203  break;
1204  }
1205  default:
1206  break;
1207  }
1208  }
1209 
1210  // show the package list
1211  drawList();
1212 
1213  return true;
1214 }
1215 
1216 void NCPkgTable::updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode )
1217 {
1218  switch (mode)
1219  {
1220  case I_Descr:
1221  if ( packager->InfoText() )
1222  packager->InfoText()->longDescription( pkgPtr );
1223  break;
1224  case I_Technical:
1225  if ( packager->InfoText() )
1226  packager->InfoText()->technicalData( pkgPtr, slbPtr );
1227  break;
1228  case I_Files:
1229  if ( packager->InfoText() )
1230  packager->InfoText()->fileList( slbPtr );
1231  break;
1232  case I_Deps:
1233  if ( packager->InfoText() )
1234  packager->InfoText()->dependencyList( pkgPtr, slbPtr );
1235  break;
1236  case I_Versions:
1237  if ( packager->VersionsList() )
1238  packager->VersionsList()->fillAvailableList( slbPtr );
1239  break;
1240  case I_PatchDescr:
1241  if ( packager->InfoText() )
1242  packager->InfoText()->patchDescription( pkgPtr, slbPtr );
1243  break;
1244  case I_PatchPkgs:
1245  if ( packager->PatchPkgs() )
1246  {
1247  packager->fillPatchPackages( packager->PatchPkgs(), pkgPtr );
1248  }
1249  break;
1250  // Intentionally omitting 'default' branch so the compiler can
1251  // catch unhandled enum states
1252  }
1253 }
virtual NCursesEvent wHandleInput(wint_t key)
Handles the events concerning the package table (e.g.
Definition: NCPkgTable.cc:800
bool showInformation()
Show the corresponding information (e.g.
Definition: NCPkgTable.cc:762
virtual bool keyToStatus(const int &key, ZyppSel slbPtr, ZyppObj objPtr, ZyppStatus &newStat)
Returns the new status to the given key (respecting the old status of th eobject).
bool createPatchEntry(ZyppPatch pkgPtr, ZyppSel slbPtr)
Creates a line in the YOU patch table.
Definition: NCPkgTable.cc:723
void showDiskSpace()
Calls the package mananager (updateDu()) and shows the required disk space.
void showSelectionDependencies()
Checks and shows the selectiondependencies.
virtual bool toggleStatus(ZyppSel slbPtr, ZyppObj objPtr, ZyppStatus &newStat)
Toggles the package status (e.g.
virtual void cellChanged(int index, int colnum, const std::string &newtext)
Changes the contents of a certain cell in table.
Definition: NCPkgTable.cc:198
virtual void addLine(ZyppStatus status, const std::vector< std::string > &elements, ZyppObj objPtr, ZyppSel slbPtr)
This method is called to add a line to the package list.
Definition: NCPkgTable.cc:156
virtual bool setObjectStatus(ZyppStatus newstatus, ZyppSel slbPtr, ZyppObj objPtr)
Informs the package manager about the new status.
ZyppObj getDataPointer(int index)
Gets the data pointer of a certain package.
Definition: NCPkgTable.cc:874
void showDownloadSize()
Shows the total download size.
void updatePackageList()
Updates the status in list of packages.
void fillHeader()
Fills the header of the table.
Definition: NCPkgTable.cc:448
bool fillPatchPackages(NCPkgTable *pkgTable, ZyppObj youPatch)
Fills the list of packages belonging to the youPatch.
bool showLicensePopup(std::string pkgName, std::string license)
Shows &#39;End User License Agreement&#39; popup with license text.
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:550
This class is used for the first column of the package table which contains the status information of...
Definition: NCPkgTable.h:68
bool createInfoEntry(std::string text)
Creates a line in the table shwing an info text.
Definition: NCPkgTable.cc:704
ZyppStatus getStatus(int index)
Gets the currently displayed package status.
Definition: NCPkgTable.cc:864
ZyppSel getSelPointer(int index)
Gets the selectable pointer of a certain package.
Definition: NCPkgTable.cc:884
bool updateTable()
Set the status information if status has changed.
Definition: NCPkgTable.cc:369
bool setTableType(NCPkgTableType type, NCPkgStatusStrategy *strategy)
Sets the type of the table and the status strategy (which means call particular methods to set/get th...
Definition: NCPkgTable.h:384
unsigned int getNumLines()
Returns the number of lines in the table (the table size)
Definition: NCPkgTable.h:415
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:184
virtual ZyppStatus getPackageStatus(ZyppSel slbPtr, ZyppObj objPtr)
Gets the status information from the package manager.
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:295
bool changeStatus(ZyppStatus newstat, const ZyppSel &slbPtr, ZyppObj objPtr, bool singleChange)
Informs the package manager about the status change of the currently selected package and updates the...
Definition: NCPkgTable.cc:212
bool showPackageDependencies(bool doit)
Checks and shows the dependencies.