]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve usability of Search Panel
authorPeter Penz <peter.penz19@gmail.com>
Wed, 20 Apr 2011 18:03:51 +0000 (20:03 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 20 Apr 2011 18:09:08 +0000 (20:09 +0200)
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.

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h
src/panels/search/searchpanel.cpp
src/panels/search/searchpanel.h
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h

index 07a3bc153188591d90bfcef246dc209e762d37b2..ed6d0f19626084d95d7a5fb98eafd912ce3b7855 100644 (file)
@@ -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<QDockWidget*>("searchDock");
+    if (!searchDock) {
+        return;
+    }
+
+    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(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)));
index 4ba7451258b96b92fdba4564d5b653d8206e34b4..9fb83bfa01b3dcdc111a257bab7078727a533d3b 100644 (file)
@@ -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.
index 6deb7b8464f0cd749f6b8efdddd2bcae8accf118..15eb7f64429343d03229b76b984c652d7f382efa 100644 (file)
@@ -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();
index 82b105a4a4f1e4a2b41d5e4e61b85428f59c068f..37b06b7d6e0efba49db66c2d303dea410ca605fd 100644 (file)
@@ -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
index 38c78aacbb4a098ea9f4ad1436fea92579702794..a7226154b033768850ab86a3a41eb1cc3e05d6bc 100644 (file)
@@ -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<KIO::StatJob*>(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));
+}
index 700cfc84a7ad7e81241cbecc5d87db6e02a7d8c5..b92b692aaecc3d7cf45c32c012afaaed387d5814 100644 (file)
@@ -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;
index eb1b8dff8284a943f2f0810ccba25158c07334a5..c4270d38312c95440b5d370e8cac64e3506f8e1c 100644 (file)
@@ -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();
index cb480629211109e0327c6b125117a015fefe64af..27561481d01756521ed2f4c3a75d2e3a37c0d97f 100644 (file)
@@ -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);