From: Peter Penz Date: Fri, 13 Nov 2009 21:03:19 +0000 (+0000) Subject: search finetuning: X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/bd30bb6ca98374b37db20d14a41542c21acdd5e0 search finetuning: * trigger progress information when starting a search * let the information panel hide the meta data for the search string * get the search string from the configurator svn path=/trunk/KDE/kdebase/apps/; revision=1048721 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ee5994955..10275ce8c 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1003,15 +1003,20 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can canDecode = KUrl::List::canDecode(event->mimeData()); } -void DolphinMainWindow::searchItems(const KUrl& url) +void DolphinMainWindow::searchItems() { - m_activeViewContainer->setUrl(url); + const QString searchOptions = m_searchOptionsConfigurator->options(); - // The Nepomuk IO-slave does not provide any progress information. Give - // an immediate hint to the user that a searching is done: - DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); - statusBar->setProgressText(i18nc("@info", "Searching...")); - statusBar->setProgress(-1); + QString searchString = m_searchBox->text(); + if (!searchString.isEmpty() && !searchOptions.isEmpty()) { + searchString += ' ' + searchOptions; + } else if (!searchOptions.isEmpty()) { + searchString += searchOptions; + } + + if (!searchString.isEmpty()) { + m_activeViewContainer->setUrl(KUrl("nepomuksearch:/" + searchString)); + } } void DolphinMainWindow::slotTabMoved(int from, int to) @@ -1070,6 +1075,8 @@ void DolphinMainWindow::init() #ifdef HAVE_NEPOMUK m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this); m_searchOptionsConfigurator->hide(); + connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged(QString)), + this, SLOT(searchItems())); #endif m_tabBar = new KTabBar(this); @@ -1346,7 +1353,7 @@ void DolphinMainWindow::setupActions() // 'Search' toolbar m_searchBox = new DolphinSearchBox(this); - connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl))); + connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems())); KAction* search = new KAction(this); actionCollection()->addAction("search_bar", search); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index f87e70dc4..e9332194f 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -388,10 +388,10 @@ private slots: void slotTestCanDecode(const QDragMoveEvent* event, bool& accept); /** - * Is connected with the Dolphin search box and searchs items that - * match to the text entered in the search bar. + * Is connected with the Dolphin search box and the search configurator + * and triggers a Nepomuk search. */ - void searchItems(const KUrl& url); + void searchItems(); /** * Is connected to the QTabBar signal tabMoved(int from, int to). diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 7bb4b7bec..bdeaab258 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -112,6 +112,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, m_proxyModel->setSourceModel(m_dolphinModel); m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + connect(m_dirLister, SIGNAL(started(KUrl)), + this, SLOT(initializeProgress())); connect(m_dirLister, SIGNAL(clear()), this, SLOT(delayedStatusBarUpdate())); connect(m_dirLister, SIGNAL(percent(int)), @@ -266,7 +268,7 @@ void DolphinViewContainer::updateStatusBar() // - shows already the item count information or // - shows only a not very important information // - if any progress is given don't show the item count info at all - const QString msg(m_statusBar->message()); + const QString msg = m_statusBar->message(); const bool updateStatusBarMsg = (msg.isEmpty() || (msg == m_statusBar->defaultText()) || (m_statusBar->type() == DolphinStatusBar::Information)) @@ -280,6 +282,16 @@ void DolphinViewContainer::updateStatusBar() } } +void DolphinViewContainer::initializeProgress() +{ + if (m_view->url().protocol() == "nepomuksearch") { + // The Nepomuk IO-slave does not provide any progress information. Give + // an immediate hint to the user that a searching is done: + m_statusBar->setProgressText(i18nc("@info", "Searching...")); + m_statusBar->setProgress(-1); + } + } + void DolphinViewContainer::updateProgress(int percent) { if (m_statusBar->progressText().isEmpty()) { @@ -418,7 +430,7 @@ void DolphinViewContainer::restoreView(const KUrl& url) "Protocol not supported by Dolphin, Konqueror has been launched")); } - QString secureUrl = KShell::quoteArg(url.pathOrUrl()); + const QString secureUrl = KShell::quoteArg(url.pathOrUrl()); const QString command = app + ' ' + secureUrl; KRun::runCommand(command, app, app, this); } else { diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index a691b278f..6d4b9b1a4 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -141,6 +141,8 @@ private slots: */ void updateStatusBar(); + void initializeProgress(); + void updateProgress(int percent); /** diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 828783e67..16876e302 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -146,37 +146,54 @@ void InformationPanelContent::showItem(const KFileItem& item) m_pendingPreview = false; const KUrl itemUrl = item.url(); + const bool isNepomukSearchUrl = (itemUrl.protocol() == "nepomuksearch") && item.nepomukUri().isEmpty(); if (!applyPlace(itemUrl)) { - // try to get a preview pixmap from the item... - m_pendingPreview = true; - - // Mark the currently shown preview as outdated. This is done - // with a small delay to prevent a flickering when the next preview - // can be shown within a short timeframe. This timer is not started - // for directories, as directory previews might fail and return the - // same icon. - if (!item.isDir()) { - m_outdatedPreviewTimer->start(); - } + if (isNepomukSearchUrl) { + // in the case of a Nepomuk query-URL the URL is not readable for humans + // (at least not useful to show in the Information Panel) + KIconLoader iconLoader; + QPixmap icon = iconLoader.loadIcon("nepomuk", + KIconLoader::NoGroup, + KIconLoader::SizeEnormous); + m_preview->setPixmap(icon); + setNameLabelText(QString()); + } else { + // try to get a preview pixmap from the item... + m_pendingPreview = true; + + // Mark the currently shown preview as outdated. This is done + // with a small delay to prevent a flickering when the next preview + // can be shown within a short timeframe. This timer is not started + // for directories, as directory previews might fail and return the + // same icon. + if (!item.isDir()) { + m_outdatedPreviewTimer->start(); + } - KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, - m_preview->width(), - m_preview->height(), - 0, - 0, - false, - true); + KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, + m_preview->width(), + m_preview->height(), + 0, + 0, + false, + true); - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(showPreview(const KFileItem&, const QPixmap&))); - connect(job, SIGNAL(failed(const KFileItem&)), - this, SLOT(showIcon(const KFileItem&))); + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(showPreview(const KFileItem&, const QPixmap&))); + connect(job, SIGNAL(failed(const KFileItem&)), + this, SLOT(showIcon(const KFileItem&))); - setNameLabelText(itemUrl.fileName()); + setNameLabelText(itemUrl.fileName()); + } } if (m_metaDataWidget != 0) { - m_metaDataWidget->setItem(item); + if (isNepomukSearchUrl) { + m_metaDataWidget->hide(); + } else { + m_metaDataWidget->show(); + m_metaDataWidget->setItem(item); + } } if (InformationPanelSettings::showPreview()) { diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 9f228140b..4375974a4 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -256,6 +256,11 @@ DolphinSearchBox::~DolphinSearchBox() { } +QString DolphinSearchBox::text() const +{ + return m_searchInput->text(); +} + bool DolphinSearchBox::event(QEvent* event) { if (event->type() == QEvent::Polish) { @@ -286,7 +291,7 @@ bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event) void DolphinSearchBox::emitSearchSignal() { - emit search(KUrl("nepomuksearch:/" + m_searchInput->text())); + emit search(m_searchInput->text()); } #include "dolphinsearchbox.moc" diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index fea7129b1..36bcb0e10 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -69,6 +69,12 @@ public: DolphinSearchBox(QWidget* parent = 0); virtual ~DolphinSearchBox(); + /** + * Returns the text that should be used as input + * for searching. + */ + QString text() const; + protected: virtual bool event(QEvent* event); virtual bool eventFilter(QObject* watched, QEvent* event); @@ -76,11 +82,17 @@ protected: signals: /** * Is emitted when the user pressed Return or Enter - * and provides the Nepomuk URL that should be used + * and provides the text that should be used as input * for searching. */ - void search(const KUrl& url); + void search(const QString& text); + /** + * Is emitted if the search box gets the focus and + * requests the need for a UI that allows to adjust + * search options. It is up to the application to ignore + * this request. + */ void requestSearchOptions(); private slots: @@ -88,7 +100,6 @@ private slots: private: KLineEdit* m_searchInput; - DolphinSearchCompleter* m_completer; }; diff --git a/src/search/dolphinsearchoptionsconfigurator.cpp b/src/search/dolphinsearchoptionsconfigurator.cpp index d0b7cace2..db51f2c42 100644 --- a/src/search/dolphinsearchoptionsconfigurator.cpp +++ b/src/search/dolphinsearchoptionsconfigurator.cpp @@ -35,8 +35,6 @@ #include #include -#include - DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) : QWidget(parent), m_initialized(false), @@ -69,6 +67,7 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare searchButton->setIcon(KIcon("edit-find")); searchButton->setText(i18nc("@action:button", "Search")); searchButton->setToolTip(i18nc("@info", "Start searching")); + connect(searchButton, SIGNAL(clicked()), this, SLOT(emitSearchOptionsChanged())); // add button "Save" QPushButton* saveButton = new QPushButton(this); @@ -115,6 +114,21 @@ DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator() { } +QString DolphinSearchOptionsConfigurator::options() const +{ + QString searchOptions; + foreach (const SearchCriterionSelector* criterion, m_criterions) { + const QString criterionString = criterion->toString(); + if (!criterionString.isEmpty()) { + if (!searchOptions.isEmpty()) { + searchOptions += ' '; + } + searchOptions += criterionString; + } + } + return searchOptions; +} + void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event) { if (!event->spontaneous() && !m_initialized) { @@ -143,14 +157,9 @@ void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked() addCriterion(selector); } -void DolphinSearchOptionsConfigurator::slotCriterionChanged() +void DolphinSearchOptionsConfigurator::emitSearchOptionsChanged() { - QString searchOptions; - foreach (const SearchCriterionSelector* criterion, m_criterions) { - searchOptions += criterion->queryString() + ' '; - } - kDebug() << "Search option string:" << searchOptions; - emit searchOptionsChanged(searchOptions); + emit searchOptionsChanged(options()); } void DolphinSearchOptionsConfigurator::removeCriterion() @@ -201,8 +210,12 @@ void DolphinSearchOptionsConfigurator::saveQuery() void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion) { - connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); - connect(criterion, SIGNAL(criterionChanged()), this, SLOT(slotCriterionChanged())); + connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); + // TODO: It is unclear yet whether changing a criterion should also result in triggering + // a searchOptionsChanged() signal. This mainly depends on the performance achievable with + // Nepomuk. Currently the searchOptionsChanged() signal is only emitted when the search-button + // has been triggered by the user. + // connect(criterion, SIGNAL(criterionChanged()), this, SLOT(emitSearchOptionsChanged())); // insert the new selector before the lastLineLayout and the KSeparator at the bottom const int index = m_vBoxLayout->count() - 2; diff --git a/src/search/dolphinsearchoptionsconfigurator.h b/src/search/dolphinsearchoptionsconfigurator.h index 46950e422..5bceaceea 100644 --- a/src/search/dolphinsearchoptionsconfigurator.h +++ b/src/search/dolphinsearchoptionsconfigurator.h @@ -39,6 +39,12 @@ public: DolphinSearchOptionsConfigurator(QWidget* parent = 0); virtual ~DolphinSearchOptionsConfigurator(); + /** + * Returns the configured options as compliant + * string that may be used as input for a nepomuk:/-URI. + */ + QString options() const; + signals: void searchOptionsChanged(const QString& options); @@ -48,7 +54,7 @@ protected: private slots: void slotAddSelectorButtonClicked(); - void slotCriterionChanged(); + void emitSearchOptionsChanged(); void removeCriterion(); diff --git a/src/search/searchcriterionselector.cpp b/src/search/searchcriterionselector.cpp index f685e50fc..4b6112b9c 100644 --- a/src/search/searchcriterionselector.cpp +++ b/src/search/searchcriterionselector.cpp @@ -74,7 +74,7 @@ SearchCriterionSelector::~SearchCriterionSelector() { } -QString SearchCriterionSelector::queryString() const +QString SearchCriterionSelector::toString() const { if (m_valueWidget == 0) { return QString(); @@ -85,9 +85,15 @@ QString SearchCriterionSelector::queryString() const const int compIndex = m_comparatorBox->currentIndex(); const SearchCriterionDescription::Comparator& comp = descr.comparators()[compIndex]; + if (comp.operation.isEmpty()) { + return QString(); + } - return comp.prefix + descr.identifier() + comp.operation + - '"' + m_valueWidget->value() + '"'; + QString criterion = comp.prefix + descr.identifier() + comp.operation; + if (!m_valueWidget->value().isEmpty()) { + criterion += '"' + m_valueWidget->value() + '"'; + } + return criterion; } void SearchCriterionSelector::slotDescriptionChanged(int index) diff --git a/src/search/searchcriterionselector.h b/src/search/searchcriterionselector.h index c6c3b22e0..27cbb2e46 100644 --- a/src/search/searchcriterionselector.h +++ b/src/search/searchcriterionselector.h @@ -50,7 +50,11 @@ public: SearchCriterionSelector(Type type, QWidget* parent = 0); virtual ~SearchCriterionSelector(); - QString queryString() const; + /** + * Converts the string representation of the criterion. + * The string is conform to get added to a nepomuk:/-URI. + */ + QString toString() const; signals: /**