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" 71 : QScrollArea( parent )
73 QWidget * content =
new QWidget;
74 QVBoxLayout * layout =
new QVBoxLayout;
75 YUI_CHECK_NEW( layout );
76 content->setLayout( layout );
80 QHBoxLayout * hbox =
new QHBoxLayout();
81 YUI_CHECK_NEW( hbox );
82 layout->addLayout(hbox);
85 _searchText =
new QComboBox( content );
86 YUI_CHECK_NEW( _searchText );
87 _searchText->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
89 hbox->addWidget(_searchText);
90 _searchText->setEditable(
true );
93 _searchButton =
new QPushButton( _(
"&Search" ), content );
94 YUI_CHECK_NEW( _searchButton );
95 hbox->addWidget(_searchButton);
97 connect( _searchButton, SIGNAL( clicked() ),
100 layout->addStretch();
106 QGroupBox * gbox =
new QGroupBox( _(
"Search in" ), content );
107 YUI_CHECK_NEW( gbox );
108 layout->addWidget( gbox );
109 QVBoxLayout *vLayout =
new QVBoxLayout;
110 gbox->setLayout( vLayout );
112 _searchInName =
new QCheckBox( _(
"Nam&e" ), gbox ); YUI_CHECK_NEW( _searchInName );
113 vLayout->addWidget(_searchInName);
114 _searchInKeywords =
new QCheckBox( _(
"&Keywords" ), gbox ); YUI_CHECK_NEW( _searchInKeywords );
115 vLayout->addWidget(_searchInKeywords);
116 _searchInSummary =
new QCheckBox( _(
"Su&mmary" ), gbox ); YUI_CHECK_NEW( _searchInSummary );
117 vLayout->addWidget(_searchInSummary);
118 _searchInDescription =
new QCheckBox( _(
"Descr&iption" ), gbox ); YUI_CHECK_NEW( _searchInDescription );
119 vLayout->addWidget(_searchInDescription);
121 vLayout->addStretch();
123 _searchInProvides =
new QCheckBox( _(
"RPM \"P&rovides\""), gbox ); YUI_CHECK_NEW( _searchInProvides );
124 vLayout->addWidget(_searchInProvides);
125 _searchInRequires =
new QCheckBox( _(
"RPM \"Re&quires\""), gbox ); YUI_CHECK_NEW( _searchInRequires );
126 vLayout->addWidget(_searchInRequires);
128 _searchInFileList =
new QCheckBox( _(
"File list" ), gbox ); YUI_CHECK_NEW( _searchInFileList );
129 vLayout->addWidget(_searchInFileList);
132 _searchInName->setChecked(
true );
133 _searchInKeywords->setChecked(
true );
134 _searchInSummary->setChecked(
true );
136 layout->addStretch();
143 QLabel * label =
new QLabel( _(
"Search &Mode:" ), content );
144 YUI_CHECK_NEW( label );
145 layout->addWidget( label );
147 _searchMode =
new QComboBox( content );
148 YUI_CHECK_NEW( _searchMode );
149 layout->addWidget( _searchMode );
151 _searchMode->setEditable(
false );
153 label->setBuddy( _searchMode );
156 _searchMode->addItem( _(
"Contains" ) );
157 _searchMode->addItem( _(
"Begins with" ) );
158 _searchMode->addItem( _(
"Exact Match" ) );
159 _searchMode->addItem( _(
"Use Wild Cards" ) );
160 _searchMode->addItem( _(
"Use Regular Expression" ) );
162 _searchMode->setCurrentIndex( Contains );
165 layout->addStretch();
167 _caseSensitive =
new QCheckBox( _(
"Case Sensiti&ve" ), content );
168 YUI_CHECK_NEW( _caseSensitive );
169 layout->addWidget(_caseSensitive);
171 for (
int i=0; i < 6; i++ )
172 layout->addStretch();
174 setWidgetResizable(
true);
190 if ( event->modifiers() == Qt::NoModifier ||
191 event->modifiers() == Qt::KeypadModifier )
193 if ( event->key() == Qt::Key_Return ||
194 event->key() == Qt::Key_Enter )
196 _searchButton->animateClick();
203 QWidget::keyPressEvent( event );
210 _searchText->setFocus();
217 return QSize( 0, 0 );
237 if ( ! _searchText->currentText().isEmpty() )
243 zypp::PoolQuery query;
244 query.addKind(zypp::ResKind::package);
246 string searchtext = _searchText->currentText().toUtf8().data();
248 QProgressDialog progress( _(
"Searching..." ),
254 progress.setWindowTitle(
"" );
255 progress.setMinimumDuration( 1500 );
258 parentWidget()->parentWidget()->setCursor(Qt::WaitCursor);
259 progress.setCursor(Qt::ArrowCursor);
262 query.setCaseSensitive( _caseSensitive->isChecked() );
264 switch ( _searchMode->currentIndex() )
267 query.setMatchSubstring();
270 query.setMatchRegex();
271 searchtext =
"^" + searchtext;
274 query.setMatchExact();
277 query.setMatchGlob();
280 query.setMatchRegex();
286 query.addString( searchtext );
288 if ( _searchInName->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::name );
289 if ( _searchInDescription->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::description );
290 if ( _searchInSummary->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::summary );
291 if ( _searchInRequires->isChecked() ) query.addAttribute( zypp::sat::SolvAttr(
"solvable:requires") );
292 if ( _searchInProvides->isChecked() ) query.addAttribute( zypp::sat::SolvAttr(
"solvable:provides") );
293 if ( _searchInFileList->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::filelist );
294 if ( _searchInKeywords->isChecked() ) query.addAttribute( zypp::sat::SolvAttr::keywords );
296 _searchText->setEnabled(
false);
297 _searchButton->setEnabled(
false);
303 for ( zypp::PoolQuery::Selectable_iterator it = query.selectableBegin();
304 it != query.selectableEnd() && ! progress.wasCanceled();
307 ZyppSel selectable = *it;
308 ZyppPkg zyppPkg = tryCastToZyppPkg( selectable->theObj() );
316 if ( progress.wasCanceled() )
319 progress.setValue( count++ );
321 if ( timer.elapsed() > 300 )
328 qApp->processEvents();
333 if ( _matchCount == 0 )
334 emit
message( _(
"No Results." ) );
337 catch (
const std::exception & exception )
339 yuiWarning() <<
"CAUGHT zypp exception: " << exception.what() << std::endl;
349 QString heading = _(
"Query Error" );
351 if ( heading.length() < 25 )
354 blanks.fill(
' ', 50 - heading.length() );
358 msgBox.setText( heading );
359 msgBox.setIcon( QMessageBox::Warning );
360 msgBox.setInformativeText( fromUTF8( exception.what() ) );
364 _searchText->setEnabled(
true);
365 _searchButton->setEnabled(
true);
366 parentWidget()->parentWidget()->setCursor(Qt::ArrowCursor);
376 QRegExp regexp( _searchText->currentText() );
377 regexp.setCaseSensitivity( _caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive );
378 regexp.setPatternSyntax( (_searchMode->currentIndex() == UseWildcards) ? QRegExp::Wildcard : QRegExp::RegExp);
379 return check( selectable, zyppObj, regexp );
386 const QRegExp & regexp )
392 ( _searchInName->isChecked() &&
check( zyppObj->name(), regexp ) ) ||
393 ( _searchInSummary->isChecked() &&
check( zyppObj->summary(), regexp ) ) ||
394 ( _searchInDescription->isChecked() &&
check( zyppObj->description(), regexp ) ) ||
395 ( _searchInProvides->isChecked() &&
check( zyppObj->dep( zypp::Dep::PROVIDES ), regexp ) ) ||
396 ( _searchInRequires->isChecked() &&
check( zyppObj->dep( zypp::Dep::REQUIRES ), regexp ) );
400 ZyppPkg zyppPkg = tryCastToZyppPkg( zyppObj );
415 const QRegExp & regexp )
417 QString att = fromUTF8( attribute );
418 QString searchText = _searchText->currentText();
421 switch ( _searchMode->currentIndex() )
424 match = att.contains( searchText, _caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
428 match = att.startsWith( searchText );
432 match = ( att == searchText );
438 match = att.contains( regexp );
451 for ( zypp::Capabilities::const_iterator it = capSet.begin();
455 zypp::CapDetail cap( *it );
457 if ( cap.isSimple() &&
check( cap.name().asString(), regexp ) )
467 #include "YQPkgSearchFilterView.moc" void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
bool check(ZyppSel selectable, ZyppObj zyppObj)
Check one ResObject against the currently selected values.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
YQPkgSearchFilterView(QWidget *parent)
Constructor.
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
void message(const QString &text)
Send a short message about unsuccessful searches.
void filterFinished()
Emitted when filtering is finished.
virtual ~YQPkgSearchFilterView()
Destructor.
virtual void keyPressEvent(QKeyEvent *event)
Key press event: Execute search upon 'Return' Reimplemented from QVBox / QWidget. ...
void filterStart()
Emitted when the filtering starts.
void setFocus()
Set the keyboard focus into this view's input field.
void filter()
Filter according to the view's rules and current selection.