From: Peter Penz Date: Wed, 20 Apr 2011 18:03:51 +0000 (+0200) Subject: Improve usability of Search Panel X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/ae488b13186a4cb5d0bc5d7f23b07467d6638979?ds=sidebyside Improve usability of Search Panel If the Search Panel is shown outside the context of the "Find" mode it will be always enabled and does a global search. Only if the user is in the "Find" mode and the searching is restricted to the current directory the Search Panel might get disabled if the current directory is not indexed. This solves the major usability issue that it was not clear for the users whether a global or restricted search is done. --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 07a3bc153..ed6d0f196 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -35,6 +35,7 @@ #include "panels/folders/folderspanel.h" #include "panels/places/placespanel.h" #include "panels/information/informationpanel.h" +#include "search/dolphinsearchbox.h" #include "search/dolphinsearchinformation.h" #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" @@ -821,6 +822,21 @@ void DolphinMainWindow::find() m_activeViewContainer->setSearchModeEnabled(true); } +void DolphinMainWindow::slotSearchLocationChanged() +{ + QDockWidget* searchDock = findChild("searchDock"); + if (!searchDock) { + return; + } + + SearchPanel* searchPanel = qobject_cast(searchDock->widget()); + if (searchPanel) { + searchPanel->setSearchMode(SearchSettings::location() == QLatin1String("FromHere") + ? SearchPanel::FromCurrentDir + : SearchPanel::Everywhere); + } +} + void DolphinMainWindow::updatePasteAction() { QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -1307,9 +1323,8 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) void DolphinMainWindow::slotSearchModeChanged(bool enabled) { #ifdef HAVE_NEPOMUK - const KUrl url = m_activeViewContainer->url(); const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); - if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) { + if (!searchInfo.isIndexingEnabled()) { return; } @@ -2066,6 +2081,10 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) connect(container, SIGNAL(searchModeChanged(bool)), this, SLOT(slotSearchModeChanged(bool))); + const DolphinSearchBox* searchBox = container->searchBox(); + connect(searchBox, SIGNAL(searchLocationChanged(SearchLocation)), + this, SLOT(slotSearchLocationChanged())); + DolphinView* view = container->view(); connect(view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(slotSelectionChanged(KFileItemList))); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4ba745125..9fb83bfa0 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -206,6 +206,13 @@ private slots: /** Replaces the URL navigator by a search box to find files. */ void find(); + /** + * Is invoked when the "Find" is active and the search location + * (From Here/Everywhere) has been changed. Updates the + * enabled state of the Search Panel. + */ + void slotSearchLocationChanged(); + /** * Updates the text of the paste action dependent on * the number of items which are in the clipboard. diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 6deb7b846..15eb7f644 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -177,6 +177,46 @@ bool DolphinViewContainer::isActive() const return m_view->isActive(); } +const DolphinStatusBar* DolphinViewContainer::statusBar() const +{ + return m_statusBar; +} + +DolphinStatusBar* DolphinViewContainer::statusBar() +{ + return m_statusBar; +} + +const KUrlNavigator* DolphinViewContainer::urlNavigator() const +{ + return m_urlNavigator; +} + +KUrlNavigator* DolphinViewContainer::urlNavigator() +{ + return m_urlNavigator; +} + +const DolphinView* DolphinViewContainer::view() const +{ + return m_view; +} + +DolphinView* DolphinViewContainer::view() +{ + return m_view; +} + +const DolphinSearchBox* DolphinViewContainer::searchBox() const +{ + return m_searchBox; +} + +DolphinSearchBox* DolphinViewContainer::searchBox() +{ + return m_searchBox; +} + void DolphinViewContainer::refresh() { GeneralSettings* settings = DolphinSettings::instance().generalSettings(); diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 82b105a4a..37b06b7d6 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -80,6 +80,9 @@ public: const DolphinView* view() const; DolphinView* view(); + const DolphinSearchBox* searchBox() const; + DolphinSearchBox* searchBox(); + /** * Refreshes the view container to get synchronized with the (updated) Dolphin settings. */ @@ -277,34 +280,4 @@ private: QElapsedTimer m_statusBarTimestamp; // Time in ms since last update }; -inline const DolphinStatusBar* DolphinViewContainer::statusBar() const -{ - return m_statusBar; -} - -inline DolphinStatusBar* DolphinViewContainer::statusBar() -{ - return m_statusBar; -} - -inline const KUrlNavigator* DolphinViewContainer::urlNavigator() const -{ - return m_urlNavigator; -} - -inline KUrlNavigator* DolphinViewContainer::urlNavigator() -{ - return m_urlNavigator; -} - -inline const DolphinView* DolphinViewContainer::view() const -{ - return m_view; -} - -inline DolphinView* DolphinViewContainer::view() -{ - return m_view; -} - #endif // DOLPHINVIEWCONTAINER_H diff --git a/src/panels/search/searchpanel.cpp b/src/panels/search/searchpanel.cpp index 38c78aacb..a7226154b 100644 --- a/src/panels/search/searchpanel.cpp +++ b/src/panels/search/searchpanel.cpp @@ -66,6 +66,9 @@ SearchPanel::~SearchPanel() void SearchPanel::setSearchMode(SearchMode mode) { m_searchMode = mode; + if (isVisible()) { + setEnabled(isFilteringPossible()); + } } SearchPanel::SearchMode SearchPanel::searchMode() const @@ -104,9 +107,7 @@ bool SearchPanel::urlChanged() setQuery(Nepomuk::Query::Query()); } - const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); - setEnabled(searchInfo.isIndexingEnabled() && - searchInfo.isPathIndexed(m_startedFromDir)); + setEnabled(isFilteringPossible()); } return true; @@ -167,9 +168,7 @@ void SearchPanel::showEvent(QShowEvent* event) m_initialized = true; } - const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); - setEnabled(searchInfo.isIndexingEnabled() && - searchInfo.isPathIndexed(url())); + setEnabled(isFilteringPossible()); Panel::showEvent(event); } @@ -190,9 +189,7 @@ void SearchPanel::slotSetUrlStatFinished(KJob* job) { m_lastSetUrlStatJob = 0; - const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); - setEnabled(searchInfo.isIndexingEnabled() && - searchInfo.isPathIndexed(m_startedFromDir)); + setEnabled(isFilteringPossible()); const KIO::UDSEntry uds = static_cast(job)->statResult(); const QString nepomukQueryStr = uds.stringValue(KIO::UDSEntry::UDS_NEPOMUK_QUERY); @@ -260,3 +257,10 @@ void SearchPanel::setQuery(const Nepomuk::Query::Query& query) m_facetWidget->setClientQuery(query); m_facetWidget->blockSignals(block); } + +bool SearchPanel::isFilteringPossible() const +{ + const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); + return searchInfo.isIndexingEnabled() + && ((m_searchMode == Everywhere) || searchInfo.isPathIndexed(m_startedFromDir)); +} diff --git a/src/panels/search/searchpanel.h b/src/panels/search/searchpanel.h index 700cfc84a..b92b692aa 100644 --- a/src/panels/search/searchpanel.h +++ b/src/panels/search/searchpanel.h @@ -79,6 +79,16 @@ private slots: private: void setQuery(const Nepomuk::Query::Query& query); + /** + * @return True if the facets can be applied to the given URL + * and hence a filtering of the content is possible. + * False is returned if the search-mode is set to + * SearchMode::FromCurrentDir and this directory is + * not indexed at all. Also if indexing is disabled + * false will be returned. + */ + bool isFilteringPossible() const; + private: bool m_initialized; SearchMode m_searchMode; diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index eb1b8dff8..c4270d383 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -196,8 +196,19 @@ void DolphinSearchBox::emitSearchSignal() emit search(m_searchInput->text()); } +void DolphinSearchBox::slotSearchLocationChanged() +{ + emit searchLocationChanged(m_fromHereButton->isChecked() ? SearchFromHere : SearchEverywhere); +} + +void DolphinSearchBox::slotSearchContextChanged() +{ + emit searchContextChanged(m_fileNameButton->isChecked() ? SearchFileName : SearchContent); +} + void DolphinSearchBox::slotConfigurationChanged() { + saveSettings(); if (m_startedSearching) { emitSearchSignal(); } @@ -220,7 +231,7 @@ void DolphinSearchBox::initButton(QPushButton* button) button->setAutoExclusive(true); button->setFlat(true); button->setCheckable(true); - connect(button, SIGNAL(toggled(bool)), this, SLOT(slotConfigurationChanged())); + connect(button, SIGNAL(clicked(bool)), this, SLOT(slotConfigurationChanged())); } void DolphinSearchBox::loadSettings() @@ -290,6 +301,8 @@ void DolphinSearchBox::init() QButtonGroup* searchWhatGroup = new QButtonGroup(this); searchWhatGroup->addButton(m_fileNameButton); searchWhatGroup->addButton(m_contentButton); + connect(m_fileNameButton, SIGNAL(clicked()), this, SLOT(slotSearchContextChanged())); + connect(m_contentButton, SIGNAL(clicked()), this, SLOT(slotSearchContextChanged())); m_separator = new KSeparator(Qt::Vertical, this); @@ -305,6 +318,8 @@ void DolphinSearchBox::init() QButtonGroup* searchLocationGroup = new QButtonGroup(this); searchLocationGroup->addButton(m_fromHereButton); searchLocationGroup->addButton(m_everywhereButton); + connect(m_fromHereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged())); + connect(m_everywhereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged())); // Apply layout for the options QHBoxLayout* optionsLayout = new QHBoxLayout(); diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index cb4806292..27561481d 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -46,6 +46,16 @@ class DolphinSearchBox : public QWidget { Q_OBJECT public: + enum SearchContext { + SearchFileName, + SearchContent + }; + + enum SearchLocation { + SearchFromHere, + SearchEverywhere + }; + explicit DolphinSearchBox(QWidget* parent = 0); virtual ~DolphinSearchBox(); @@ -105,6 +115,16 @@ signals: void returnPressed(const QString& text); + /** + * Is emitted if the search location has been changed by the user. + */ + void searchLocationChanged(SearchLocation location); + + /** + * Is emitted if the search context has been changed by the user. + */ + void searchContextChanged(SearchContext context); + /** * Emitted as soon as the search box should get closed. */ @@ -112,6 +132,8 @@ signals: private slots: void emitSearchSignal(); + void slotSearchLocationChanged(); + void slotSearchContextChanged(); void slotConfigurationChanged(); void slotSearchTextChanged(const QString& text); void slotReturnPressed(const QString& text);