libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
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  webpinSearch = new YMenuItem( _("Search Packages on &Web") );
85 
86  items.push_back( repoManager );
87  items.push_back( onlineUpdate );
88 
89  if (! exitAction.empty())
90  {
91  items.push_back( actionOnExit );
92 
93  restart = new YMenuItem( actionOnExit, CHECK_BOX + _( "&Restart Package Manager" ) );
94  close = new YMenuItem( actionOnExit,CHECK_BOX + _( "&Close Package Manager" ) );
95  showSummary = new YMenuItem( actionOnExit, CHECK_BOX + _( "&Show Summary" ) );
96 
97  idToItemPtr["restart"] = restart;
98  idToItemPtr["close"] = close;
99  idToItemPtr["summary"] = showSummary;
100 
101  setSelected( idToItemPtr[ exitAction ], true);
102  }
103  items.push_back( webpinSearch );
104 
105  addItems( items );
106 
107 }
108 
109 bool NCPkgMenuConfig::handleEvent( const NCursesEvent & event)
110 {
111  if (!event.selection)
112  return false;
113 
114  if ( event.selection == repoManager )
115  {
116  //return `repo_mgr symbol to YCP module (FaTE #302517)
117  const_cast<NCursesEvent &>(event).result = "repo_mgr";
118  yuiMilestone() << "Launching repository manager " << endl;
119 
120  //and close the main loop
121  return false;
122  }
123  else if ( event.selection == onlineUpdate )
124  {
125  //the same as above, return `online_update_config
126  const_cast<NCursesEvent &>(event).result = "online_update_configuration";
127  yuiMilestone() << "Launching YOU configuration " << endl;
128 
129  return false;
130  }
131  else if ( event.selection == webpinSearch )
132  {
133  //the same as above, return `webpin
134  const_cast<NCursesEvent &>(event).result = "webpin";
135  yuiMilestone() << "Launching webpin search " << endl;
136 
137  //and close the main loop
138  return false;
139  }
140 
141  else
142  {
143  std::string old = exitAction;
144 
145  if ( event.selection == restart )
146  {
147  exitAction = "restart";
148  }
149  else if ( event.selection == close )
150  {
151  exitAction = "close";
152  }
153  else if ( event.selection == showSummary )
154  {
155  exitAction = "summary";
156  }
157 
158  setSelected(idToItemPtr[old], false);
159  setSelected(idToItemPtr[exitAction], true);
160  pkg->setActionAtExit( exitAction );
161  }
162 
163  return true;
164 }
165