]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix visibility- and enabled-issues for the filter-panel
authorPeter Penz <peter.penz19@gmail.com>
Wed, 2 Feb 2011 18:36:08 +0000 (19:36 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 2 Feb 2011 18:36:08 +0000 (19:36 +0100)
The filter-panel should be disabled if the current folder is not indexed at all. Also when triggering a "Find" the filter-panel should stay invisible per default when the current folder is not indexed.

CCBUG: 264969

src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/panels/filter/filterpanel.cpp
src/panels/filter/filterpanel.h
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h
src/search/dolphinsearchinformation.cpp [new file with mode: 0644]
src/search/dolphinsearchinformation.h [new file with mode: 0644]

index e7ac06c63dd1879decb547597401c109f5f0051e..61caec60d081f953320f2e914f2f4e458d552ab3 100644 (file)
@@ -114,6 +114,7 @@ set(dolphin_SRCS
     panels/folders/folderspanel.cpp
     panels/folders/paneltreeview.cpp
     search/dolphinsearchbox.cpp
+    search/dolphinsearchinformation.cpp
     settings/general/behaviorsettingspage.cpp
     settings/general/contextmenusettingspage.cpp
     settings/general/generalsettingspage.cpp
index cd1810d37674c1450919560982dcf08c1a42e963..1c4a45bda5d868c9d6a0a660f94174f8e7bf92e4 100644 (file)
@@ -36,6 +36,7 @@
 #include "panels/folders/folderspanel.h"
 #include "panels/places/placespanel.h"
 #include "panels/information/informationpanel.h"
+#include "search/dolphinsearchinformation.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
 #include "statusbar/dolphinstatusbar.h"
@@ -1220,13 +1221,14 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
 {
 #ifdef HAVE_NEPOMUK
-    if (Nepomuk::ResourceManager::instance()->init() != 0) {
-        // Currently the Filter Panel only works with Nepomuk enabled
+    const KUrl url = m_activeViewContainer->url();
+    const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+    if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) {
         return;
     }
 
     QDockWidget* filterDock = findChild<QDockWidget*>("filterDock");
-    if ((filterDock == 0) || !filterDock->isEnabled()) {
+    if (filterDock == 0) {
         return;
     }
 
index 453c12729ff7d32e47082e3cf44768d53202b089..97389e08fd257b45c945b00bd0b34175cf074b55 100644 (file)
@@ -36,6 +36,8 @@
 #include <Nepomuk/Vocabulary/NMM>
 #include <Nepomuk/Vocabulary/NIE>
 
+#include <search/dolphinsearchinformation.h>
+
 #include <kfileitem.h>
 #include <kio/jobclasses.h>
 #include <kio/job.h>
 FilterPanel::FilterPanel(QWidget* parent) :
     Panel(parent),
     m_initialized(false),
-    m_nepomukEnabled(false),
     m_lastSetUrlStatJob(0),
     m_startedFromDir(),
     m_facetWidget(0),
     m_unfacetedRestQuery()
 {
+    setEnabled(false);
 }
 
 FilterPanel::~FilterPanel()
@@ -70,7 +72,7 @@ bool FilterPanel::urlChanged()
         m_startedFromDir = url();
     }
 
-    if (isVisible() && m_nepomukEnabled) {
+    if (isVisible() && DolphinSearchInformation::instance().isIndexingEnabled()) {
         setQuery(Nepomuk::Query::Query());
 
         delete m_lastSetUrlStatJob;
@@ -140,15 +142,25 @@ void FilterPanel::showEvent(QShowEvent* event)
         connect(m_facetWidget, SIGNAL(queryTermChanged(Nepomuk::Query::Term)),
                 this, SLOT(slotQueryTermChanged(Nepomuk::Query::Term)));
 
-        m_nepomukEnabled = (Nepomuk::ResourceManager::instance()->init() == 0);
-        m_facetWidget->setEnabled(m_nepomukEnabled);
-
         m_initialized = true;
     }
 
+    const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+    setEnabled(searchInfo.isIndexingEnabled() &&
+               searchInfo.isPathIndexed(m_startedFromDir));
+
     Panel::showEvent(event);
 }
 
+void FilterPanel::hideEvent(QHideEvent* event)
+{
+    if (!event->spontaneous()) {
+        setEnabled(false);
+    }
+
+    Panel::hideEvent(event);
+}
+
 void FilterPanel::contextMenuEvent(QContextMenuEvent* event)
 {
     Panel::contextMenuEvent(event);
@@ -218,7 +230,10 @@ void FilterPanel::setQuery(const Nepomuk::Query::Query& query)
 
         m_unfacetedRestQuery = m_facetWidget->extractFacetsFromQuery(query);
         m_facetWidget->setClientQuery(query);
-        setEnabled(true);
+
+        const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+        setEnabled(searchInfo.isIndexingEnabled() &&
+                   searchInfo.isPathIndexed(m_startedFromDir));
 
         m_facetWidget->blockSignals(block);
     } else {
index 20d4e9cbf14a3c0c35293ed377e43557687f91c4..8ccc62d6312dfb83f98e8600ec4f0fbae0731764 100644 (file)
@@ -52,6 +52,9 @@ protected:
     /** @see QWidget::showEvent() */
     virtual void showEvent(QShowEvent* event);
 
+    /** @see QWidget::hideEvent() */
+    virtual void hideEvent(QHideEvent* event);
+
     /** @see QWidget::contextMenuEvent() */
     virtual void contextMenuEvent(QContextMenuEvent* event);
 
@@ -64,7 +67,6 @@ private:
 
 private:
     bool m_initialized;
-    bool m_nepomukEnabled;
     KJob* m_lastSetUrlStatJob;
 
     KUrl m_startedFromDir;
index 039c16dedbc1ef2c48a2d2e26b3f7852a122df20..f9a7a0cf20f80ba0af59a5a11f68aa5072b070f2 100644 (file)
@@ -20,6 +20,7 @@
 #include "dolphinsearchbox.h"
 
 #include "dolphin_searchsettings.h"
+#include "dolphinsearchinformation.h"
 
 #include <kicon.h>
 #include <klineedit.h>
@@ -111,7 +112,8 @@ KUrl DolphinSearchBox::searchPath() const
 KUrl DolphinSearchBox::urlForSearching() const
 {
     KUrl url;
-    if (m_nepomukActivated && isSearchPathIndexed()) {
+    const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+    if (searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(url)) {
         url = nepomukUrlForSearching();
     } else {
         url.setProtocol("filenamesearch");
@@ -328,41 +330,6 @@ void DolphinSearchBox::init()
     connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal()));
 }
 
-bool DolphinSearchBox::isSearchPathIndexed() const
-{
-#ifdef HAVE_NEPOMUK
-    const QString path = m_searchPath.path();
-
-    const KConfig strigiConfig("nepomukstrigirc");
-    const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
-
-    // Check whether the current search path is part of an indexed folder
-    bool isIndexed = false;
-    foreach (const QString& indexedFolder, indexedFolders) {
-        if (path.startsWith(indexedFolder)) {
-            isIndexed = true;
-            break;
-        }
-    }
-
-    if (isIndexed) {
-        // The current search path is part of an indexed folder. Check whether no
-        // excluded folder is part of the search path.
-        const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
-        foreach (const QString& excludedFolder, excludedFolders) {
-            if (path.startsWith(excludedFolder)) {
-                isIndexed = false;
-                break;
-            }
-        }
-    }
-
-    return isIndexed;
-#else
-    return false;
-#endif
-}
-
 KUrl DolphinSearchBox::nepomukUrlForSearching() const
 {
 #ifdef HAVE_NEPOMUK
index 1ca97ea9cfe14cc0acd6a380a69ebc7d8446653f..05372612345e9ca980582383ee7aa2de8fe1e332 100644 (file)
@@ -107,12 +107,6 @@ private:
     void saveSettings();
     void init();
 
-    /**
-     * @return True, if the complete directory tree specified by m_searchPath
-     *         is indexed by Strigi.
-     */
-    bool isSearchPathIndexed() const;
-
     /**
      * @return URL that represents the Nepomuk query for starting the search.
      */
diff --git a/src/search/dolphinsearchinformation.cpp b/src/search/dolphinsearchinformation.cpp
new file mode 100644 (file)
index 0000000..2cba5a1
--- /dev/null
@@ -0,0 +1,99 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "dolphinsearchinformation.h"
+
+#include <config-nepomuk.h>
+#ifdef HAVE_NEPOMUK
+    #include <KConfig>
+    #include <KConfigGroup>
+    #include <Nepomuk/ResourceManager>
+#endif
+
+#include <KGlobal>
+#include <KUrl>
+
+struct DolphinSearchInformationSingleton
+{
+    DolphinSearchInformation instance;
+};
+K_GLOBAL_STATIC(DolphinSearchInformationSingleton, s_dolphinSearchInformation)
+
+
+DolphinSearchInformation& DolphinSearchInformation::instance()
+{
+    return s_dolphinSearchInformation->instance;
+}
+
+DolphinSearchInformation::~DolphinSearchInformation()
+{
+}
+
+bool DolphinSearchInformation::isIndexingEnabled() const
+{
+    return m_indexingEnabled;
+}
+
+bool DolphinSearchInformation::isPathIndexed(const KUrl& url) const
+{
+#ifdef HAVE_NEPOMUK
+    const QString path = url.path();
+
+    const KConfig strigiConfig("nepomukstrigirc");
+    const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
+
+    // Check whether the path is part of an indexed folder
+    bool isIndexed = false;
+    foreach (const QString& indexedFolder, indexedFolders) {
+        if (path.startsWith(indexedFolder)) {
+            isIndexed = true;
+            break;
+        }
+    }
+
+    if (isIndexed) {
+        // The path is part of an indexed folder. Check whether no
+        // excluded folder is part of the path.
+        const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
+        foreach (const QString& excludedFolder, excludedFolders) {
+            if (path.startsWith(excludedFolder)) {
+                isIndexed = false;
+                break;
+            }
+        }
+    }
+
+    return isIndexed;
+#else
+    Q_UNUSED(path);
+    return false;
+#endif
+}
+
+DolphinSearchInformation::DolphinSearchInformation() :
+    m_indexingEnabled(false)
+{
+#ifdef HAVE_NEPOMUK
+    if (Nepomuk::ResourceManager::instance()->init() == 0) {
+        KConfig config("nepomukserverrc");
+        m_indexingEnabled = config.group("Service-nepomukstrigiservice").readEntry("autostart", false);
+    }
+#endif
+}
+
diff --git a/src/search/dolphinsearchinformation.h b/src/search/dolphinsearchinformation.h
new file mode 100644 (file)
index 0000000..6fb1947
--- /dev/null
@@ -0,0 +1,57 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef DOLPHINSEARCHINFORMATION_H
+#define DOLPHINSEARCHINFORMATION_H
+
+class KUrl;
+
+/**
+ * @brief Allows to access search-engine related information.
+ */
+class DolphinSearchInformation
+{
+public:
+    static DolphinSearchInformation& instance();
+    virtual ~DolphinSearchInformation();
+
+    /**
+     * @return True if the Nepomuk indexer is enabled. If Nepomuk is
+     *         disabled, always false is returned.
+     */
+    bool isIndexingEnabled() const;
+
+    /**
+     * @return True if the complete directory tree specified by path
+     *         is indexed by the Nepomuk indexer. If Nepomuk is disabled,
+     *         always false is returned.
+     */
+    bool isPathIndexed(const KUrl& url) const;
+
+protected:
+    DolphinSearchInformation();
+
+private:
+    bool m_indexingEnabled;
+
+    friend class DolphinSearchInformationSingleton;
+};
+
+#endif
+