41 #define YUILogComponent "ncurses-pkg"
45 #include <boost/format.hpp>
47 #include "NCPkgFilterSearch.h"
49 #include "NCAlignment.h"
51 #include "YMenuButton.h"
53 #include "NCLayoutBox.h"
54 #include "NCSpacing.h"
57 #include "NCPkgStrings.h"
58 #include "NCPackageSelector.h"
59 #include "NCPkgSearchSettings.h"
60 #include "NCPopupInfo.h"
78 NCPkgFilterSearch::NCPkgFilterSearch( YWidget *parent, YUIDimension dim,
NCPackageSelector *pkger )
79 : NCLayoutBox( parent, dim )
95 NCPkgFilterSearch::~NCPkgFilterSearch()
107 void NCPkgFilterSearch::createLayout( YWidget *parent )
110 NCFrame * frame0 =
new NCFrame(
this,
"" );
113 NCLayoutBox * vSplit =
new NCLayoutBox ( frame0, YD_VERT);
116 searchExpr =
new NCInputField( vSplit, NCPkgStrings::SearchPhrase() );
117 searchExpr->setStretchable( YD_HORIZ,
true );
121 if ( !packager->isYouMode() )
124 NCAlignment *left1 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
126 ignoreCase =
new NCCheckBox( left1, _(
"&Ignore Case" ),
true );
127 new NCSpacing( vSplit, YD_VERT,
true, 0.5 );
131 NCAlignment *left2 =
new NCAlignment( vSplit, YAlignBegin, YAlignUnchanged );
132 searchMode =
new NCComboBox (left2, _(
"Search &Mode" ),
false);
134 searchMode->addItem( _(
"Contains" ),
false);
135 searchMode->addItem( _(
"Begins with" ),
false);
136 searchMode->addItem( _(
"Exact Match" ),
false);
137 searchMode->addItem( _(
"Use Wildcards" ),
false);
138 searchMode->addItem( _(
"Use RegExp" ),
false);
140 new NCSpacing( vSplit, YD_VERT,
true, 0.5 );
148 std::string NCPkgFilterSearch::getSearchExpression()
const
157 value = searchExpr->value();
164 bool NCPkgFilterSearch::match( std::string s1, std::string s2,
bool ignoreCase )
166 std::string::iterator pos;
170 pos = search( s1.begin(), s1.end(),
171 s2.begin(), s2.end(),
176 pos = search( s1.begin(), s1.end(),
177 s2.begin(), s2.end() );
180 return ( pos != s1.end() );
184 bool NCPkgFilterSearch::fillSearchList( std::string & expr,
187 NCPkgTable * packageList = packager->PackageList();
200 switch ( searchMode->getCurrentItem() )
203 q.setMatchSubstring();
221 q.addKind( zypp::ResKind::package );
224 q.setCaseSensitive();
225 if ( settings->doCheckName() )
226 q.addAttribute( zypp::sat::SolvAttr::name );
227 if ( settings->doCheckSummary() )
228 q.addAttribute( zypp::sat::SolvAttr::summary );
229 if ( settings->doCheckKeywords() )
230 q.addAttribute( zypp::sat::SolvAttr::keywords );
231 if ( settings->doCheckDescr() )
232 q.addAttribute( zypp::sat::SolvAttr::description );
233 if ( settings->doCheckProvides() )
234 q.addAttribute( zypp::sat::SolvAttr::provides );
235 if ( settings->doCheckRequires() )
237 q.addAttribute( zypp::sat::SolvAttr::requires );
239 NCPopupInfo * info =
new NCPopupInfo( wpos( (NCurses::lines()-4)/2, (NCurses::cols()-18)/2 ),
243 info->setPreferredSize( 18, 4 );
248 for( zypp::PoolQuery::Selectable_iterator it = q.selectableBegin();
249 it != q.selectableEnd(); it++)
251 ZyppPkg pkg = tryCastToZyppPkg( (*it)->theObj() );
255 catch (
const std::exception & e)
257 NCPopupInfo * info =
new NCPopupInfo ( wpos( NCurses::lines()/10,
259 NCPkgStrings::ErrorLabel(),
262 _(
"Query Error:" ) + (
"<br>") + e.what(),
264 info->setPreferredSize( 50, 10 );
265 info->showInfoPopup();
266 YDialog::deleteTopmostDialog();
267 yuiError() <<
"Caught a std::exception: " << e.what () << endl;
271 YDialog::deleteTopmostDialog();
274 std::ostringstream s;
275 s << boost::format( _(
"%d packages found" )) % found_pkgs;
276 packager->PatternLabel()->setText( s.str() );
281 if ( found_pkgs > 0 )
283 packageList->setCurrentItem( 0 );
285 packageList->setKeyboardFocus();
288 packager->clearInfoArea();
302 bool NCPkgFilterSearch::showSearchResultPackages()
304 std::string filter = getSearchExpression();
306 if ( !packager->isYouMode() )
309 fillSearchList( filter, getCheckBoxValue( ignoreCase ) );
315 bool NCPkgFilterSearch::getCheckBoxValue( NCCheckBox * checkBox )
317 YCheckBoxState value = YCheckBox_off;
321 value = checkBox->value();
323 return ( value == YCheckBox_on ?
true :
false );