46 #include <QPushButton>
47 #include <QRadioButton>
49 #include <QProgressDialog>
52 #include <QMessageBox>
54 #include <zypp/PoolQuery.h>
56 #define YUILogComponent "qt-pkg"
59 #include "YQPackageSelector.h"
60 #include "YQPkgSearchFilterView.h"
61 #include "QY2LayoutUtils.h"
64 #include "YQApplication.h"
73 QVBoxLayout * layout =
new QVBoxLayout;
74 YUI_CHECK_NEW( layout );
79 QHBoxLayout * hbox =
new QHBoxLayout();
80 YUI_CHECK_NEW( hbox );
81 layout->addLayout(hbox);
84 _searchText =
new QComboBox(
this );
85 YUI_CHECK_NEW( _searchText );
86 _searchText->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
88 hbox->addWidget(_searchText);
89 _searchText->setEditable(
true );
92 _searchButton =
new QPushButton( _(
"&Search" ),
this );
93 YUI_CHECK_NEW( _searchButton );
94 hbox->addWidget(_searchButton);
96 connect( _searchButton, SIGNAL( clicked() ),
105 QGroupBox * gbox =
new QGroupBox( _(
"Search in" ),
this );
106 YUI_CHECK_NEW( gbox );
107 layout->addWidget( gbox );
108 QVBoxLayout *vLayout =
new QVBoxLayout;
109 gbox->setLayout( vLayout );
111 _searchInName =
new QCheckBox( _(
"Nam&e" ), gbox ); YUI_CHECK_NEW( _searchInName );
112 vLayout->addWidget(_searchInName);
113 _searchInKeywords =
new QCheckBox( _(
"&Keywords" ), gbox ); YUI_CHECK_NEW( _searchInKeywords );
114 vLayout->addWidget(_searchInKeywords);
115 _searchInSummary =
new QCheckBox( _(
"Su&mmary" ), gbox ); YUI_CHECK_NEW( _searchInSummary );
116 vLayout->addWidget(_searchInSummary);
117 _searchInDescription =
new QCheckBox( _(
"Descr&iption" ), gbox ); YUI_CHECK_NEW( _searchInDescription );
118 vLayout->addWidget(_searchInDescription);
120 vLayout->addStretch();
122 _searchInProvides =
new QCheckBox( _(
"RPM \"P&rovides\""), gbox ); YUI_CHECK_NEW( _searchInProvides );
123 vLayout->addWidget(_searchInProvides);
124 _searchInRequires =
new QCheckBox( _(
"RPM \"Re&quires\""), gbox ); YUI_CHECK_NEW( _searchInRequires );
125 vLayout->addWidget(_searchInRequires);
127 _searchInFileList =
new QCheckBox( _(
"File list" ), gbox ); YUI_CHECK_NEW( _searchInFileList );
128 vLayout->addWidget(_searchInFileList);
131 _searchInName->setChecked(
true );
132 _searchInKeywords->setChecked(
true );
133 _searchInSummary->setChecked(
true );
135 layout->addStretch();
142 QLabel * label =
new QLabel( _(
"Search &Mode:" ),
this );
143 YUI_CHECK_NEW( label );
144 layout->addWidget( label );
146 _searchMode =
new QComboBox(
this );
147 YUI_CHECK_NEW( _searchMode );
148 layout->addWidget( _searchMode );
150 _searchMode->setEditable(
false );
152 label->setBuddy( _searchMode );
155 _searchMode->addItem( _(
"Contains" ) );
156 _searchMode->addItem( _(
"Begins with" ) );
157 _searchMode->addItem( _(
"Exact Match" ) );
158 _searchMode->addItem( _(
"Use Wild Cards" ) );
159 _searchMode->addItem( _(
"Use Regular Expression" ) );
161 _searchMode->setCurrentIndex( Contains );
164 layout->addStretch();
166 _caseSensitive =
new QCheckBox( _(
"Case Sensiti&ve" ),
this );
167 YUI_CHECK_NEW( _caseSensitive );
168 layout->addWidget(_caseSensitive);
170 for (
int i=0; i < 6; i++ )
171 layout->addStretch();
186 if ( event->modifiers() == Qt::NoModifier ||
187 event->modifiers() == Qt::KeypadModifier )
189 if ( event->key() == Qt::Key_Return ||
190 event->key() == Qt::Key_Enter )
192 _searchButton->animateClick();
199 QWidget::keyPressEvent( event );
206 _searchText->setFocus();
213 return QSize( 0, 0 );
233 if ( ! _searchText->currentText().isEmpty() )
239 zypp::PoolQuery query;
240 query.addKind(zypp::ResKind::package);
242 string searchtext = _searchText->currentText().toUtf8().data();
244 QProgressDialog progress( _(
"Searching..." ),
250 progress.setWindowTitle(
"" );
251 progress.setMinimumDuration( 1500 );
254 parentWidget()->parentWidget()->setCursor(Qt::WaitCursor);
255 progress.setCursor(Qt::ArrowCursor);
258 query.setCaseSensitive( _caseSensitive->isChecked() );
260 switch ( _searchMode->currentIndex() )
263 query.setMatchSubstring();
266 query.setMatchRegex();
267 searchtext =
"^" + searchtext;
270 query.setMatchExact();
273 query.setMatchGlob();
276 query.setMatchRegex();
282 query.addString( searchtext );
284 if ( _searchInName->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::name );
285 if ( _searchInDescription->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::description );
286 if ( _searchInSummary->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::summary );
287 if ( _searchInRequires->isChecked() ) query.addAttribute( zypp::sat::SolvAttr(
"solvable:requires") );
288 if ( _searchInProvides->isChecked() ) query.addAttribute( zypp::sat::SolvAttr(
"solvable:provides") );
289 if ( _searchInFileList->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::filelist );
290 if ( _searchInKeywords->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::keywords );
292 _searchText->setEnabled(
false);
293 _searchButton->setEnabled(
false);
299 for ( zypp::PoolQuery::Selectable_iterator it = query.selectableBegin();
300 it != query.selectableEnd() && ! progress.wasCanceled();
303 ZyppSel selectable = *it;
304 ZyppPkg zyppPkg = tryCastToZyppPkg( selectable->theObj() );
312 if ( progress.wasCanceled() )
315 progress.setValue( count++ );
317 if ( timer.elapsed() > 300 )
324 qApp->processEvents();
329 if ( _matchCount == 0 )
330 emit
message( _(
"No Results." ) );
333 catch (
const std::exception & exception )
335 yuiWarning() <<
"CAUGHT zypp exception: " << exception.what() << std::endl;
345 QString heading = _(
"Query Error" );
347 if ( heading.length() < 25 )
350 blanks.fill(
' ', 50 - heading.length() );
354 msgBox.setText( heading );
355 msgBox.setIcon( QMessageBox::Warning );
356 msgBox.setInformativeText( fromUTF8( exception.what() ) );
360 _searchText->setEnabled(
true);
361 _searchButton->setEnabled(
true);
362 parentWidget()->parentWidget()->setCursor(Qt::ArrowCursor);
372 QRegExp regexp( _searchText->currentText() );
373 regexp.setCaseSensitivity( _caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
374 regexp.setPatternSyntax( (_searchMode->currentIndex() == UseWildcards) ? QRegExp::Wildcard : QRegExp::RegExp);
375 return check( selectable, zyppObj, regexp );
382 const QRegExp & regexp )
388 ( _searchInName->isChecked() &&
check( zyppObj->name(), regexp ) ) ||
389 ( _searchInSummary->isChecked() &&
check( zyppObj->summary(), regexp ) ) ||
390 ( _searchInDescription->isChecked() &&
check( zyppObj->description(), regexp ) ) ||
391 ( _searchInProvides->isChecked() &&
check( zyppObj->dep( zypp::Dep::PROVIDES ), regexp ) ) ||
392 ( _searchInRequires->isChecked() &&
check( zyppObj->dep( zypp::Dep::REQUIRES ), regexp ) );
396 ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
411 const QRegExp & regexp )
413 QString att = fromUTF8( attribute );
414 QString searchText = _searchText->currentText();
417 switch ( _searchMode->currentIndex() )
420 match = att.contains( searchText, _caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
424 match = att.startsWith( searchText );
428 match = ( att == searchText );
434 match = att.contains( regexp );
447 for ( zypp::Capabilities::const_iterator it = capSet.begin();
451 zypp::CapDetail cap( *it );
453 if ( cap.isSimple() &&
check( cap.name().asString(), regexp ) )
463 #include "YQPkgSearchFilterView.moc"