libyui-ncurses-pkg  2.48.5
NCPkgMenuAction.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: NCPkgMenuAction.cc
37 
38  Author: Hedgehog Painter <kmachalkova@suse.cz>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "NCPkgMenuAction.h"
45 #include "NCPackageSelector.h"
46 
47 using std::endl;
48 
49 /*
50  Textdomain "ncurses-pkg"
51 */
52 
53 NCPkgMenuAction::NCPkgMenuAction (YWidget *parent, std::string label, NCPackageSelector *pkger)
54  : NCMenuButton( parent, label)
55  ,pkg( pkger )
56 {
57  createLayout();
58 }
59 
60 NCPkgMenuAction::~NCPkgMenuAction()
61 {
62 
63 }
64 
65 void NCPkgMenuAction::createLayout()
66 {
67  if ( !pkg->isYouMode() )
68  {
69  // Please note: add an appropriate number of whitespaces to get a well
70  // formated menu (the [ ]s should be in one column) and use unique hotkeys until end:
71  // begin: Actions menu, toggle the status of a package, e.g. change from installed to delete
72  toggleItem = new YMenuItem( _( "&Toggle [SPACE]" ) );
73  installItem = new YMenuItem( _( "&Install [+]" ) );
74  deleteItem = new YMenuItem( _( "&Delete [-]" ) );
75  updateItem = new YMenuItem( _( "&Update [>]" ) );
76  tabooItem = new YMenuItem( _( "Ta&boo [!]" ) );
77  lockItem = new YMenuItem( _( "&Lock [*]" ) );
78  // end: Actions menu, set status of all packages (title of a submenu)
79  allItem = new YMenuItem( _( "&All Listed Packages" ) );
80 
81  items.push_back( toggleItem );
82  items.push_back( installItem );
83  items.push_back( deleteItem );
84  items.push_back( updateItem );
85  items.push_back( tabooItem );
86  items.push_back( lockItem );
87  items.push_back( allItem );
88 
89  // begin: submenu items actions concerning all packages
90  installAllItem = new YMenuItem( allItem, _( "&Install All" ) );
91  deleteAllItem = new YMenuItem( allItem, _( "&Delete All" ) );
92  keepAllItem = new YMenuItem( allItem, _( "&Keep All" ) );
93  updateAllItem = new YMenuItem( allItem, _( "U&pdate All Unconditionally" ) );
94  // end: submenu items: actions concerning all packages
95  updateNewerItem = new YMenuItem( allItem, _( "&Update If Newer Version Available" ) );
96 
97  addItems( items );
98  }
99  else // YOU mode
100  { // Please note: add an appropriate number of whitespaces to get a well
101  // formated menu (the [ ]s should be in one column) and use unique hotkeys until end:
102  // begin: Online Update Actions menu
103  toggleItem = new YMenuItem( _( "&Toggle [SPACE]" ) );
104  installItem = new YMenuItem( _( "&Install [+]" ) );
105  deleteItem = new YMenuItem( _( "&Do Not Install [-]" ) );
106  tabooItem = new YMenuItem( _( "&Lock or Taboo [!]" ) );
107  // end: Update Actions menu
108 
109  // update and delete aren't supported for patches
110 
111  items.push_back( toggleItem );
112  items.push_back( installItem );
113  items.push_back( deleteItem );
114  items.push_back( tabooItem );
115 
116  addItems( items );
117  }
118 }
119 
120 bool NCPkgMenuAction::handleEvent ( const NCursesEvent & event)
121 {
122  NCPkgTable *pkgList = pkg->PackageList();
123  if ( !pkgList || !event.selection)
124  return false;
125 
126  if ( pkgList->getNumLines() == 0)
127  return true;
128 
129  if (event.selection == toggleItem)
130  {
131  pkgList->toggleObjStatus();
132  }
133  else if (event.selection == installItem)
134  {
135  pkgList->changeObjStatus( '+' );
136  }
137  else if (event.selection == deleteItem )
138  {
139  pkgList->changeObjStatus( '-' );
140  }
141  else if (event.selection == updateItem )
142  {
143  pkgList->changeObjStatus( '>' );
144  }
145  else if (event.selection == tabooItem )
146  {
147  pkgList->changeObjStatus( '!' );
148  }
149  else if (event.selection == lockItem )
150  {
151  pkgList->changeObjStatus( '*' );
152  }
153  else if (event.selection == installAllItem )
154  {
155  pkgList->changeListObjStatus( NCPkgTable::A_Install );
156  }
157  else if (event.selection == deleteAllItem )
158  {
159  pkgList->changeListObjStatus( NCPkgTable::A_Delete );
160  }
161  else if (event.selection == keepAllItem )
162  {
163  pkgList->changeListObjStatus( NCPkgTable::A_Keep );
164  }
165  else if ( event.selection == updateNewerItem )
166  {
167  pkgList->changeListObjStatus( NCPkgTable::A_UpdateNewer );
168  }
169  else if (event.selection == updateAllItem )
170  {
171  pkgList->changeListObjStatus( NCPkgTable::A_Update );
172  }
173  else
174  yuiError() << "zatim nic" << endl;
175 
176  if ( pkg->VersionsList() )
177  pkg->VersionsList()->updateTable();
178 
179  return true;
180 
181 }
The package table class.
Definition: NCPkgTable.h:207
bool updateTable()
Set the status information if status has changed.
Definition: NCPkgTable.cc:369
unsigned int getNumLines()
Returns the number of lines in the table (the table size)
Definition: NCPkgTable.h:415