]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchinformation.cpp
Provide additional default groups for the Places Panel
[dolphin.git] / src / search / dolphinsearchinformation.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphinsearchinformation.h"
21
22 #include <config-nepomuk.h>
23 #ifdef HAVE_NEPOMUK
24 #include <KConfig>
25 #include <KConfigGroup>
26 #include <Nepomuk/ResourceManager>
27 #endif
28
29 #include <KGlobal>
30 #include <KUrl>
31
32 struct DolphinSearchInformationSingleton
33 {
34 DolphinSearchInformation instance;
35 };
36 K_GLOBAL_STATIC(DolphinSearchInformationSingleton, s_dolphinSearchInformation)
37
38
39 DolphinSearchInformation& DolphinSearchInformation::instance()
40 {
41 return s_dolphinSearchInformation->instance;
42 }
43
44 DolphinSearchInformation::~DolphinSearchInformation()
45 {
46 }
47
48 bool DolphinSearchInformation::isIndexingEnabled() const
49 {
50 return m_indexingEnabled;
51 }
52
53 bool DolphinSearchInformation::isPathIndexed(const KUrl& url) const
54 {
55 #ifdef HAVE_NEPOMUK
56 const KConfig strigiConfig("nepomukstrigirc");
57 const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
58
59 // Check whether the path is part of an indexed folder
60 bool isIndexed = false;
61 foreach (const QString& indexedFolder, indexedFolders) {
62 const KUrl indexedPath(indexedFolder);
63 if (indexedPath.isParentOf(url)) {
64 isIndexed = true;
65 break;
66 }
67 }
68
69 if (isIndexed) {
70 // The path is part of an indexed folder. Check whether no
71 // excluded folder is part of the path.
72 const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
73 foreach (const QString& excludedFolder, excludedFolders) {
74 const KUrl excludedPath(excludedFolder);
75 if (excludedPath.isParentOf(url)) {
76 isIndexed = false;
77 break;
78 }
79 }
80 }
81
82 return isIndexed;
83 #else
84 Q_UNUSED(url);
85 return false;
86 #endif
87 }
88
89 DolphinSearchInformation::DolphinSearchInformation() :
90 m_indexingEnabled(false)
91 {
92 #ifdef HAVE_NEPOMUK
93 if (Nepomuk::ResourceManager::instance()->initialized()) {
94 KConfig config("nepomukserverrc");
95 m_indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", false);
96 }
97 #endif
98 }
99