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