libyui-ncurses-pkg  2.48.9
NCPkgPatchSearch.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: NCPkgPatchSearch.cc
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 
42 #include "NCPkgPatchSearch.h"
43 
44 #include "NCTree.h"
45 #include "YMenuButton.h"
46 #include "YDialog.h"
47 #include "NCLayoutBox.h"
48 #include "NCSpacing.h"
49 #include "NCFrame.h"
50 
51 #include "NCPkgStrings.h"
52 #include "NCPackageSelector.h"
53 
54 #include "NCi18n.h"
55 
56 using std::endl;
57 
58 /*
59  Textdomain "ncurses-pkg"
60 */
61 
62 ///////////////////////////////////////////////////////////////////
63 //
64 //
65 // METHOD NAME : NCPkgPatchSearch::NCPkgPatchSearch
66 // METHOD TYPE : Constructor
67 //
68 // DESCRIPTION :
69 //
70 NCPkgPatchSearch::NCPkgPatchSearch( const wpos at, NCPackageSelector * pkger )
71  : NCPopup( at, false )
72  , searchExpr( 0 )
73  , packager( pkger )
74 {
75  createLayout( _( "Search for Patches" ) );
76 }
77 
78 ///////////////////////////////////////////////////////////////////
79 //
80 //
81 // METHOD NAME : NCPkgPatchSearch::~NCPkgPatchSearch
82 // METHOD TYPE : Destructor
83 //
84 // DESCRIPTION :
85 //
86 NCPkgPatchSearch::~NCPkgPatchSearch()
87 {
88 }
89 
90 ///////////////////////////////////////////////////////////////////
91 //
92 //
93 // METHOD NAME : NCPkgPatchSearch::createLayout
94 // METHOD TYPE : void
95 //
96 // DESCRIPTION :
97 //
98 void NCPkgPatchSearch::createLayout( const std::string & headline )
99 {
100  // vertical split is the (only) child of the dialog
101  NCLayoutBox * vSplit = new NCLayoutBox( this, YD_VERT );
102 
103  new NCSpacing( vSplit, YD_VERT, false, 0.8 ); // stretchable = false
104 
105  new NCLabel( vSplit, headline, true, false ); // isHeading = true
106 
107  new NCSpacing( vSplit, YD_VERT, false, 0.6 );
108 
109  NCFrame * frame0 = new NCFrame( vSplit, "" );
110 
111  // add the input field (a editable combo box)
112  searchExpr = new NCComboBox( frame0,
113  NCPkgStrings::SearchPhrase(),
114  true ); // editable = true
115 
116  searchExpr->setStretchable( YD_HORIZ, true );
117 
118  searchExpr->addItem( new YTableItem() );
119 
120  new NCSpacing( vSplit, YD_VERT, false, 0.6 );
121 
122  NCMultiSelectionBox * settings = new NCMultiSelectionBox( vSplit, NCPkgStrings::SearchIn() );
123  YItemCollection items;
124  searchName = new YItem ( _( "Name of the Patch" ), true);
125  items.push_back( searchName );
126  searchSum = new YItem ( _( "Summary" ), true);
127  items.push_back( searchSum );
128  settings->addItems( items );
129 
130  new NCSpacing( vSplit, YD_VERT, false, 0.6 );
131  NCLayoutBox * hSplit3 = new NCLayoutBox( vSplit, YD_HORIZ );
132  new NCSpacing( hSplit3, YD_HORIZ, true, 0.2 );
133 
134  // add the cancel and the ok button
135  okButton = new NCPushButton( hSplit3, NCPkgStrings::OKLabel() );
136  okButton->setFunctionKey( 10 );
137 
138  new NCSpacing( hSplit3, YD_HORIZ, true, 0.4 );
139 
140  cancelButton = new NCPushButton( hSplit3, NCPkgStrings::CancelLabel() );
141  cancelButton->setFunctionKey( 9 );
142 
143  new NCSpacing( hSplit3, YD_HORIZ, true, 0.2 );
144  new NCSpacing( vSplit, YD_VERT, false, 0.6 );
145 }
146 
147 ///////////////////////////////////////////////////////////////////
148 //
149 //
150 // METHOD NAME : NCPkgPatchSearch::showSearchPopup
151 // METHOD TYPE : void
152 //
153 // DESCRIPTION :
154 //
155 NCursesEvent & NCPkgPatchSearch::showSearchPopup( )
156 {
157  postevent = NCursesEvent();
158  do {
159  popupDialog();
160  if ( searchExpr )
161  {
162  searchExpr->setKeyboardFocus();
163  }
164  } while ( postAgain() );
165 
166  popdownDialog();
167 
168  return postevent;
169 }
170 
171 ///////////////////////////////////////////////////////////////////
172 //
173 // DESCRIPTION :
174 //
175 std::string NCPkgPatchSearch::getSearchExpression() const
176 {
177  std::string value;
178 
179  if ( searchExpr )
180  {
181  // get the expression and store it in combo box list
182  // value = searchExpr->getValue();
183 
184  value = searchExpr->text();
185  searchExpr->getListSize();
186 
187  searchExpr->addItem( value, true );
188  }
189 
190  return value;
191 }
192 
193 ///////////////////////////////////////////////////////////////////
194 //
195 //
196 // METHOD NAME : NCPkgPatchSearch::preferredWidth
197 // METHOD TYPE : int
198 //
199 int NCPkgPatchSearch::preferredWidth()
200 {
201  return NCurses::cols()/2;
202 }
203 
204 ///////////////////////////////////////////////////////////////////
205 //
206 //
207 // METHOD NAME : NCPkgPatchSearch::preferredHeight
208 // METHOD TYPE : int
209 //
210 int NCPkgPatchSearch::preferredHeight()
211 {
212  return 16;
213 }
214 
215 ///////////////////////////////////////////////////////////////////
216 //
217 //
218 // METHOD NAME : NCPopup::wHandleInput
219 // METHOD TYPE : NCursesEvent
220 //
221 // DESCRIPTION :
222 //
223 NCursesEvent NCPkgPatchSearch::wHandleInput( wint_t ch )
224 {
225  if ( ch == 27 ) // ESC
226  return NCursesEvent::cancel;
227 
228  // start package search if Return is pressed
229  if ( ch == KEY_RETURN )
230  return NCursesEvent::button;
231 
232  return NCDialog::wHandleInput( ch );
233 }
234 
235 ///////////////////////////////////////////////////////////////////
236 //
237 //
238 // METHOD NAME : NCPkgPatchSearch::postAgain
239 // METHOD TYPE : bool
240 //
241 // DESCRIPTION :
242 //
243 bool NCPkgPatchSearch::postAgain()
244 {
245  if ( ! postevent.widget )
246  return false;
247 
248  postevent.result = "";
249 
250  if ( postevent.widget == cancelButton )
251  {
252  postevent = NCursesEvent::cancel;
253  }
254  else if ( postevent == NCursesEvent::button )
255  {
256  // get the search expression
257  postevent.result = getSearchExpression();
258 
259  std::string filter = postevent.result;
260  bool checkName = searchName->selected();
261  bool checkSum = searchSum->selected();
262  packager->fillPatchSearchList( filter, checkName, checkSum );
263 
264  }
265 
266  if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
267  {
268  // return false means: close the popup dialog
269  return false;
270  }
271  return true;
272 }
bool fillPatchSearchList(const std::string &expr, bool checkName, bool checkSum)
Fills the package table with packages matching the search expression.
static const std::string CancelLabel()
The label of the Cancel button.
static const std::string OKLabel()
The label of the OK button.