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