]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchinformation.cpp
Set the Details View colummns width to the preferred column width, by double-clicking...
[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 <Nepomuk2/ResourceManager>
27 #endif
28
29 #include <KGlobal>
30 #include <KUrl>
31 #include <QFileInfo>
32 #include <QDir>
33
34 struct DolphinSearchInformationSingleton
35 {
36 DolphinSearchInformation instance;
37 };
38 K_GLOBAL_STATIC(DolphinSearchInformationSingleton, s_dolphinSearchInformation)
39
40
41 DolphinSearchInformation& DolphinSearchInformation::instance()
42 {
43 return s_dolphinSearchInformation->instance;
44 }
45
46 DolphinSearchInformation::~DolphinSearchInformation()
47 {
48 }
49
50 bool DolphinSearchInformation::isIndexingEnabled() const
51 {
52 return m_indexingEnabled;
53 }
54
55 namespace {
56 /// recursively check if a folder is hidden
57 bool isDirHidden( QDir& dir ) {
58 if (QFileInfo(dir.path()).isHidden()) {
59 return true;
60 } else if (dir.cdUp()) {
61 return isDirHidden(dir);
62 } else {
63 return false;
64 }
65 }
66
67 bool isDirHidden(const QString& path) {
68 QDir dir(path);
69 return isDirHidden(dir);
70 }
71 }
72
73 bool DolphinSearchInformation::isPathIndexed(const KUrl& url) const
74 {
75 #ifdef HAVE_NEPOMUK
76 const KConfig strigiConfig("nepomukstrigirc");
77 const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
78
79 // Nepomuk does not index hidden folders
80 if (isDirHidden(url.toLocalFile())) {
81 return false;
82 }
83
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)) {
89 isIndexed = true;
90 break;
91 }
92 }
93
94 if (isIndexed) {
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)) {
101 isIndexed = false;
102 break;
103 }
104 }
105 }
106
107 return isIndexed;
108 #else
109 Q_UNUSED(url);
110 return false;
111 #endif
112 }
113
114 DolphinSearchInformation::DolphinSearchInformation() :
115 m_indexingEnabled(false)
116 {
117 #ifdef HAVE_NEPOMUK
118 if (Nepomuk2::ResourceManager::instance()->initialized()) {
119 KConfig config("nepomukserverrc");
120 m_indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", true);
121 }
122 #endif
123 }
124