1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinsearchinformation.h"
22 #include <config-nepomuk.h>
25 #include <KConfigGroup>
26 #include <Nepomuk2/ResourceManager>
34 struct DolphinSearchInformationSingleton
36 DolphinSearchInformation instance
;
38 K_GLOBAL_STATIC(DolphinSearchInformationSingleton
, s_dolphinSearchInformation
)
41 DolphinSearchInformation
& DolphinSearchInformation::instance()
43 return s_dolphinSearchInformation
->instance
;
46 DolphinSearchInformation::~DolphinSearchInformation()
50 bool DolphinSearchInformation::isIndexingEnabled() const
52 return m_indexingEnabled
;
56 /// recursively check if a folder is hidden
57 bool isDirHidden( QDir
& dir
) {
58 if (QFileInfo(dir
.path()).isHidden()) {
60 } else if (dir
.cdUp()) {
61 return isDirHidden(dir
);
67 bool isDirHidden(const QString
& path
) {
69 return isDirHidden(dir
);
73 bool DolphinSearchInformation::isPathIndexed(const KUrl
& url
) const
76 const KConfig
strigiConfig("nepomukstrigirc");
77 const QStringList indexedFolders
= strigiConfig
.group("General").readPathEntry("folders", QStringList());
79 // Nepomuk does not index hidden folders
80 if (isDirHidden(url
.toLocalFile())) {
84 // Check whether the path is part of an indexed folder
85 bool isIndexed
= false;
86 foreach (const QString
& indexedFolder
, indexedFolders
) {
87 const KUrl
indexedPath(indexedFolder
);
88 if (indexedPath
.isParentOf(url
)) {
95 // The path is part of an indexed folder. Check whether no
96 // excluded folder is part of the path.
97 const QStringList excludedFolders
= strigiConfig
.group("General").readPathEntry("exclude folders", QStringList());
98 foreach (const QString
& excludedFolder
, excludedFolders
) {
99 const KUrl
excludedPath(excludedFolder
);
100 if (excludedPath
.isParentOf(url
)) {
114 DolphinSearchInformation::DolphinSearchInformation() :
115 m_indexingEnabled(false)
118 if (Nepomuk2::ResourceManager::instance()->initialized()) {
119 KConfig
config("nepomukserverrc");
120 m_indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", true);