libyui-ncurses-pkg  2.48.2
 All Classes Functions
NCPkgFilterInstSummary.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: NCPkgFilterInstSummary.cc
37 
38  Author: Hedgehog Painter <kmachalkova@suse.cz>
39 
40 /-*/
41 
42 #include "NCPkgFilterInstSummary.h"
43 
44 using std::endl;
45 
46 /*
47  Textdomain "ncurses-pkg"
48 */
49 
50 NCPkgFilterInstSummary::NCPkgFilterInstSummary ( YWidget *parent, std::string label, NCPackageSelector *pkger)
51  : NCMultiSelectionBox ( parent, label)
52  , pkg( pkger )
53 {
54  //setNotify(true);
55  createLayout();
56 }
57 
58 NCPkgFilterInstSummary::~NCPkgFilterInstSummary()
59 {
60 
61 }
62 
63 void NCPkgFilterInstSummary::createLayout()
64 {
65  del = new YItem ( _( "Delete" ), true);
66  items.push_back (del);
67  inst = new YItem ( _( "Install" ), true);
68  items.push_back (inst);
69  update = new YItem ( _( "Update" ), true);
70  items.push_back (update);
71  taboo = new YItem ( _( "Taboo" ), true);
72  items.push_back (taboo);
73  protect = new YItem ( _( "Protected" ), true);
74  items.push_back (protect);
75  keep = new YItem ( _( "Keep" ));
76  items.push_back (keep);
77  dontinstall = new YItem ( _( "Do not install" ));
78  items.push_back (dontinstall);
79 
80  addItems( items );
81 }
82 
83 bool NCPkgFilterInstSummary::check( ZyppObj opkg, ZyppSel slb )
84 {
85  if (!slb)
86  return false;
87 
88  bool show = false;
89 
90  switch ( slb->status() )
91  {
92  //group these two together, due to lack of space
93  case S_Del:
94  case S_AutoDel: show = del->selected(); break;
95  case S_Install:
96  case S_AutoInstall: show = inst->selected(); break;
97  case S_KeepInstalled: show = keep->selected(); break;
98  case S_NoInst: show = dontinstall->selected(); break;
99  case S_Protected: show = protect->selected(); break;
100  case S_Taboo: show = taboo->selected(); break;
101  case S_Update:
102  case S_AutoUpdate: show = update->selected(); break;
103  }
104 
105  if ( show )
106  {
107  ZyppPkg pkg = tryCastToZyppPkg (opkg);
108 
109  if ( !pkg )
110  return false;
111  }
112 
113  return show;
114 }
115 
116 bool NCPkgFilterInstSummary::showInstSummaryPackages()
117 {
118 
119  NCPkgTable * packageList = pkg->PackageList();
120 
121  if ( !packageList )
122  {
123  yuiError() << "No valid NCPkgTable widget" << endl;
124  return false;
125  }
126 
127  // clear the package table
128  packageList->itemsCleared ();
129 
130 
131  for_( listIt, zyppPkgBegin(), zyppPkgEnd() )
132  {
133  ZyppSel selectable = *listIt;
134  ZyppObj obj = selectable->candidateObj();
135 
136  if (!obj)
137  {
138  // If there is neither an installed nor a candidate package, check
139  // any other instance.
140  ( selectable->installedObj() ) ? (obj = selectable->installedObj())
141  : ( obj = selectable->theObj() );
142  }
143 
144  if( check( obj, selectable ) )
145  {
146  ZyppPkg pkg = tryCastToZyppPkg (obj);
147  packageList->createListEntry( pkg, selectable);
148  }
149 
150  }
151 
152  // show the package list
153  packageList->setCurrentItem( 0 );
154  packageList->drawList();
155  packageList->showInformation();
156 
157  yuiMilestone() << "Fill package list" << endl;
158 
159  return true;
160 
161 }
162 
163 NCursesEvent NCPkgFilterInstSummary::wHandleInput( wint_t ch )
164 {
165  NCursesEvent ret = NCursesEvent::none;
166 
167  //treat this like any other MultiSelBox input ...
168  NCMultiSelectionBox::wHandleInput( ch ) ;
169  switch ( ch )
170  {
171  //special case for toggling item status
172  case KEY_SPACE:
173  case KEY_RETURN: {
174  showInstSummaryPackages();
175  }
176  }
177 
178  //... but do not return to the main loop
179  ret = NCursesEvent::handled;
180 
181  return ret;
182 }
183 
bool showInformation()
Show the corresponding information (e.g.
Definition: NCPkgTable.cc:762
The package table class.
Definition: NCPkgTable.h:175
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:550
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:184
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:263