diff options
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 39 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.h | 6 | ||||
| -rw-r--r-- | src/search/dolphinsearchinformation.cpp | 99 | ||||
| -rw-r--r-- | src/search/dolphinsearchinformation.h | 57 |
4 files changed, 159 insertions, 42 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 039c16ded..f9a7a0cf2 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -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 diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 1ca97ea9c..053726123 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -108,12 +108,6 @@ private: 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. */ KUrl nepomukUrlForSearching() const; diff --git a/src/search/dolphinsearchinformation.cpp b/src/search/dolphinsearchinformation.cpp new file mode 100644 index 000000000..2cba5a147 --- /dev/null +++ b/src/search/dolphinsearchinformation.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2011 by Peter Penz <[email protected]> * + * * + * 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 index 000000000..6fb1947ca --- /dev/null +++ b/src/search/dolphinsearchinformation.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2011 by Peter Penz <[email protected]> * + * * + * 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 + |
