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