libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
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  // end: Update Actions menu
107  // update isn't supported for patches
108 
109  items.push_back( toggleItem );
110  items.push_back( installItem );
111  items.push_back( deleteItem );
112 
113  addItems( items );
114  }
115 }
116 
117 bool NCPkgMenuAction::handleEvent ( const NCursesEvent & event)
118 {
119  NCPkgTable *pkgList = pkg->PackageList();
120  if ( !pkgList || !event.selection)
121  return false;
122 
123  if ( pkgList->getNumLines() == 0)
124  return true;
125 
126  if (event.selection == toggleItem)
127  {
128  pkgList->toggleObjStatus();
129  }
130  else if (event.selection == installItem)
131  {
132  pkgList->changeObjStatus( '+' );
133  }
134  else if (event.selection == deleteItem )
135  {
136  pkgList->changeObjStatus( '-' );
137  }
138  else if (event.selection == updateItem )
139  {
140  pkgList->changeObjStatus( '>' );
141  }
142  else if (event.selection == tabooItem )
143  {
144  pkgList->changeObjStatus( '!' );
145  }
146  else if (event.selection == lockItem )
147  {
148  pkgList->changeObjStatus( '*' );
149  }
150  else if (event.selection == installAllItem )
151  {
152  pkgList->changeListObjStatus( NCPkgTable::A_Install );
153  }
154  else if (event.selection == deleteAllItem )
155  {
156  pkgList->changeListObjStatus( NCPkgTable::A_Delete );
157  }
158  else if (event.selection == keepAllItem )
159  {
160  pkgList->changeListObjStatus( NCPkgTable::A_Keep );
161  }
162  else if ( event.selection == updateNewerItem )
163  {
164  pkgList->changeListObjStatus( NCPkgTable::A_UpdateNewer );
165  }
166  else if (event.selection == updateAllItem )
167  {
168  pkgList->changeListObjStatus( NCPkgTable::A_Update );
169  }
170  else
171  yuiError() << "zatim nic" << endl;
172 
173  if ( pkg->VersionsList() )
174  pkg->VersionsList()->updateTable();
175 
176  return true;
177 
178 }