libyui-ncurses-pkg  2.50.8
NCPkgMenuConfig.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: NCPkgMenuConfig.cc
37 
38  Author: Hedgehog Painter <kmachalkova@suse.cz>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "NCPkgMenuConfig.h"
45 #include "NCPackageSelector.h"
46 
47 #define CHECK_BOX "[ ] "
48 
49 using std::endl;
50 
51 /*
52  Textdomain "ncurses-pkg"
53 */
54 
55 
56 NCPkgMenuConfig::NCPkgMenuConfig (YWidget *parent, std::string label, NCPackageSelector *pkger)
57  : NCMenuButton( parent, label)
58  , pkg( pkger )
59 {
60  createLayout();
61 }
62 
63 NCPkgMenuConfig::~NCPkgMenuConfig()
64 {
65 
66 }
67 
68 void NCPkgMenuConfig::setSelected( YMenuItem *item, bool selected)
69 {
70  std::string oldLabel = item->label();
71 
72  std::string newLabel = oldLabel.replace(1, 1, 1, selected ? 'x' : ' ');
73 
74  item->setLabel( newLabel);
75 }
76 
77 void NCPkgMenuConfig::createLayout()
78 {
79  exitAction = pkg->ActionAtExit();
80 
81  repoManager = new YMenuItem( _( "Launch &Repository Manager") );
82  onlineUpdate = new YMenuItem( _( "Launch &Online Update Configuration" ) );
83  actionOnExit = new YMenuItem( _( "&Action after Package Installation" ) );
84 
85  items.push_back( repoManager );
86  items.push_back( onlineUpdate );
87 
88  if (! exitAction.empty())
89  {
90  items.push_back( actionOnExit );
91 
92  restart = new YMenuItem( actionOnExit, CHECK_BOX + _( "&Restart Package Manager" ) );
93  close = new YMenuItem( actionOnExit, CHECK_BOX + _( "&Close Package Manager" ) );
94  showSummary = new YMenuItem( actionOnExit, CHECK_BOX + _( "&Show Summary" ) );
95 
96  idToItemPtr["restart"] = restart;
97  idToItemPtr["close"] = close;
98  idToItemPtr["summary"] = showSummary;
99 
100  setSelected( idToItemPtr[ exitAction ], true);
101  }
102 
103  addItems( items );
104 
105 }
106 
107 bool NCPkgMenuConfig::handleEvent( const NCursesEvent & event)
108 {
109  if (!event.selection)
110  return false;
111 
112  if ( event.selection == repoManager )
113  {
114  // return `repo_mgr symbol to YCP module (FaTE #302517)
115  const_cast<NCursesEvent &>(event).result = "repo_mgr";
116  yuiMilestone() << "Launching repository manager " << endl;
117 
118  // and close the main loop
119  return false;
120  }
121  else if ( event.selection == onlineUpdate )
122  {
123  // the same as above, return `online_update_config
124  const_cast<NCursesEvent &>(event).result = "online_update_configuration";
125  yuiMilestone() << "Launching YOU configuration " << endl;
126 
127  return false;
128  }
129  else
130  {
131  std::string old = exitAction;
132 
133  if ( event.selection == restart )
134  {
135  exitAction = "restart";
136  }
137  else if ( event.selection == close )
138  {
139  exitAction = "close";
140  }
141  else if ( event.selection == showSummary )
142  {
143  exitAction = "summary";
144  }
145 
146  setSelected(idToItemPtr[old], false);
147  setSelected(idToItemPtr[exitAction], true);
148  pkg->setActionAtExit( exitAction );
149  }
150 
151  return true;
152 }
153