libyui-ncurses-pkg  2.50.8
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  {
160  popupDialog();
161  if ( searchExpr )
162  {
163  searchExpr->setKeyboardFocus();
164  }
165  } while ( postAgain() );
166 
167  popdownDialog();
168 
169  return postevent;
170 }
171 
172 ///////////////////////////////////////////////////////////////////
173 //
174 // DESCRIPTION :
175 //
176 std::string NCPkgPatchSearch::getSearchExpression() const
177 {
178  std::string value;
179 
180  if ( searchExpr )
181  {
182  // get the expression and store it in combo box list
183  // value = searchExpr->getValue();
184 
185  value = searchExpr->text();
186  searchExpr->getListSize();
187 
188  searchExpr->addItem( value, true );
189  }
190 
191  return value;
192 }
193 
194 ///////////////////////////////////////////////////////////////////
195 //
196 //
197 // METHOD NAME : NCPkgPatchSearch::preferredWidth
198 // METHOD TYPE : int
199 //
200 int NCPkgPatchSearch::preferredWidth()
201 {
202  return NCurses::cols()/2;
203 }
204 
205 ///////////////////////////////////////////////////////////////////
206 //
207 //
208 // METHOD NAME : NCPkgPatchSearch::preferredHeight
209 // METHOD TYPE : int
210 //
211 int NCPkgPatchSearch::preferredHeight()
212 {
213  return 16;
214 }
215 
216 ///////////////////////////////////////////////////////////////////
217 //
218 //
219 // METHOD NAME : NCPopup::wHandleInput
220 // METHOD TYPE : NCursesEvent
221 //
222 // DESCRIPTION :
223 //
224 NCursesEvent NCPkgPatchSearch::wHandleInput( wint_t ch )
225 {
226  if ( ch == 27 ) // ESC
227  return NCursesEvent::cancel;
228 
229  // start package search if Return is pressed
230  if ( ch == KEY_RETURN )
231  return NCursesEvent::button;
232 
233  return NCDialog::wHandleInput( ch );
234 }
235 
236 ///////////////////////////////////////////////////////////////////
237 //
238 //
239 // METHOD NAME : NCPkgPatchSearch::postAgain
240 // METHOD TYPE : bool
241 //
242 // DESCRIPTION :
243 //
244 bool NCPkgPatchSearch::postAgain()
245 {
246  if ( ! postevent.widget )
247  return false;
248 
249  postevent.result = "";
250 
251  if ( postevent.widget == cancelButton )
252  {
253  postevent = NCursesEvent::cancel;
254  }
255  else if ( postevent == NCursesEvent::button )
256  {
257  // get the search expression
258  postevent.result = getSearchExpression();
259 
260  std::string filter = postevent.result;
261  bool checkName = searchName->selected();
262  bool checkSum = searchSum->selected();
263  packager->fillPatchSearchList( filter, checkName, checkSum );
264 
265  }
266 
267  if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
268  {
269  // return false means: close the popup dialog
270  return false;
271  }
272  return true;
273 }
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.