libyui-ncurses-pkg  2.50.10
NCPackageSelectorPluginImpl.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 Linux AG |
34 \----------------------------------------------------------------------/
35 
36  File: NCPackageSelectorPluginImpl.cc
37 
38  Author: Hedgehog Painter <kmachalkova@suse.cz>
39 
40 /-*/
41 
42 #include "NCPackageSelectorPluginImpl.h"
43 #include "NCPackageSelectorStart.h"
44 
45 #include <YTableHeader.h>
46 
47 #define YUILogComponent "ncurses-pkg"
48 #include <YUILog.h>
49 
50 using std::endl;
51 
52 ///////////////////////////////////////////////////////////////////
53 //
54 //
55 // METHOD NAME : NCPackageSelectorPluginStub::createPackageSelector
56 // METHOD TYPE : YWidget
57 //
58 // DESCRIPTION : Create NCPackageSelectorStart which reads the layout
59 // term of the package selection dialog, creates the widget
60 // tree and creates the NCPackageSelector.
61 //
63 
64 YPackageSelector *
65 NCPackageSelectorPluginImpl::createPackageSelector( YWidget * parent,
66  long modeFlags )
67 {
68  YWidget * w = 0;
69 
70  try
71  {
72  w = new NCPackageSelectorStart ( parent, modeFlags, YD_HORIZ );
73  }
74  catch (const std::exception & e)
75  {
76  yuiError() << "Caught a std::exception: " << e.what() << endl;
77  }
78  catch (...)
79  {
80  yuiError() << "Caught an unspecified exception" << endl;
81  }
82 
83  yuiMilestone() << "Package selector created: " << w << endl;
84 
85  return (YPackageSelector *)(w);
86 }
87 
88 
89 ///////////////////////////////////////////////////////////////////
90 //
91 //
92 // METHOD NAME : NCPackageSelectorPluign::createPkgSpecial
93 // METHOD TYPE : YWidget
94 //
95 // DESCRIPTION : creates special widgets used for the package selection
96 // dialog (which do not have a corresponding widget in qt-ui)
97 //
98 YWidget *
99 NCPackageSelectorPluginImpl::createPkgSpecial( YWidget *parent, const std::string &subwidget )
100 {
101  YWidget * w = 0;
102  YTableHeader * tableHeader = new YTableHeader();
103 
104  if ( subwidget == "pkgTable" )
105  {
106  yuiDebug() << "Creating a NCPkgTable" << endl;
107  try
108  {
109  // yuiError() << "Tady taky nic neni " << endl;
110  w = new NCPkgTable( parent, tableHeader );
111  }
112  catch (const std::exception & e)
113  {
114  yuiError() << "Caught a std::exception: " << e.what() << endl;
115  }
116  catch (...)
117  {
118  yuiError() << "Caught an unspecified exception" << endl;
119  }
120  }
121  else
122  {
123  yuiError() << "PkgSpecial( " << subwidget << " ) not found - take default `Label" << endl;
124  w = new NCLabel( parent, subwidget, false, false );
125  }
126 
127  return w;
128 }
129 
130 
131 ///////////////////////////////////////////////////////////////////
132 //
133 //
134 // METHOD NAME : NCPackageSelectorPLugin::runPkgSelection
135 // METHOD TYPE : YEvent *
136 //
137 // DESCRIPTION : Implementation of UI builtin RunPkgSelection() which
138 // has to be called after OpenDialog( `PackageSelector() ).
139 //
140 YEvent *
141 NCPackageSelectorPluginImpl::runPkgSelection( YDialog * dialog,
142  YWidget * selector )
143 {
144  NCPackageSelectorStart * ncSelector = 0;
145 
146  yuiMilestone() << "Calling runPkgSelection()" << endl;
147 
148  if ( !dialog )
149  {
150  yuiError() << "ERROR package selection: No dialog existing." << endl;
151  return 0;
152  }
153  if ( !selector )
154  {
155  yuiError() << "ERROR package selection: No package selector existing." << endl;
156  return 0;
157  }
158 
159  ncSelector = dynamic_cast<NCPackageSelectorStart *>( selector );
160 
161  bool result = true;
162 
163  // start event loop
164  NCursesEvent event = NCursesEvent::cancel;
165  NCDialog * ncd = static_cast<NCDialog *>( dialog );
166 
167  if ( ncSelector && ncd )
168  {
169  try
170  {
171  ncSelector->showDefaultList();
172  ncd->setStatusLine(); // show function keys
173  yuiMilestone() << "NCDialog: " << ncd << endl;
174  do
175  {
176  event = ncd->userInput();
177  result = ncSelector->handleEvent( event );
178  // reset to function keys of the main dialog
179  ncd->setStatusLine();
180  // yuiMilestone() << "Result of handleEvent: " << (result?"true":"false") << endl;
181  }
182  while ( event != NCursesEvent::cancel && result == true );
183  }
184  catch (const std::exception & e)
185  {
186  yuiError() << "Caught a std::exception: " << e.what() << endl;
187  }
188  catch (...)
189  {
190  yuiError() << "Caught an unspecified exception" << endl;
191  }
192  }
193  else
194  {
195  yuiError() << "No NCPackageSelectorStart existing" << endl;
196  }
197 
198  if ( event.result != "" )
199  {
200  // Before returning some value to the YCP client,
201  // we must delete (==close) any leftover dialogs,
202  // Wizard will not do it for us (#354712)
203  while( YDialog::topmostDialog() != dialog )
204  YDialog::deleteTopmostDialog();
205 
206  yuiMilestone() << "Return value: " << event.result << endl;
207  return new YMenuEvent( event.result );
208  }
209  else
210  return new YCancelEvent();
211 }
212 
NCPackageSelectorStart::handleEvent
bool handleEvent(const NCursesEvent &event)
Pass the event to the handleEvent method of the member variable NCPackageSelector packager.
Definition: NCPackageSelectorStart.cc:174
NCPackageSelectorStart::showDefaultList
void showDefaultList()
Fills the package table with packages belonging to the default filter (the filter which is selected w...
Definition: NCPackageSelectorStart.cc:141
NCPackageSelectorPluginImpl
Definition: NCPackageSelectorPluginImpl.h:49
NCPackageSelectorStart
the package selector widget
Definition: NCPackageSelectorStart.h:62
NCPkgTable
The package table class.
Definition: NCPkgTable.h:234