2
* This file is part of the KDE Baloo Project
3
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) version 3, or any
9
* later version accepted by the membership of KDE e.V. (or its
10
* successor approved by the membership of KDE e.V.), which shall
11
* act as a proxy defined in Section 6 of version 3 of the license.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#include "basicindexingjob.h"
25
#include "xapiandocument.h"
26
#include "lib/baloo_xattr_p.h"
30
#include <QStringList>
32
#include <kfilemetadata/typeinfo.h>
35
using namespace Baloo;
37
BasicIndexingJob::BasicIndexingJob(QSqlDatabase* db, const FileMapping& file, const QString& mimetype)
40
, m_mimetype(mimetype)
45
BasicIndexingJob::~BasicIndexingJob()
49
bool BasicIndexingJob::index()
51
if (m_file.id() == 0) {
52
if (!m_file.create(*m_sqlDb)) {
53
kError() << "Cannot create fileMapping for" << m_file.url();
58
QFileInfo fileInfo(m_file.url());
61
doc.addTerm(m_mimetype, "M");
62
doc.indexText(fileInfo.fileName(), 1000);
63
doc.indexText(fileInfo.fileName(), "F", 1000);
66
QDateTime mod = fileInfo.lastModified();
67
const QString dtm = mod.toString(Qt::ISODate);
69
doc.addBoolTerm(dtm, "DT_M");
70
doc.addBoolTerm(mod.date().year(), "DT_MY");
71
doc.addBoolTerm(mod.date().month(), "DT_MM");
72
doc.addBoolTerm(mod.date().day(), "DT_MD");
74
const QString timeTStr = QString::number(mod.toTime_t());
75
doc.addValue(0, timeTStr);
76
doc.addValue(1, QString::number(mod.date().toJulianDay()));
79
QVector<KFileMetaData::Type::Type> tList = typesForMimeType(m_mimetype);
80
Q_FOREACH (KFileMetaData::Type::Type type, tList) {
81
QString tstr = KFileMetaData::TypeInfo(type).name().toLower();
82
doc.addBoolTerm(tstr, "T");
84
doc.addBoolTerm("file", "T");
86
if (fileInfo.isDir()) {
87
doc.addBoolTerm("folder", "T");
89
// This is an optimization for folders. They do not need to go through
90
// file indexing, so there are no indexers for folders
91
doc.addBoolTerm("Z2");
94
doc.addBoolTerm("Z1");
102
baloo_getxattr(m_file.url(), QLatin1String("user.xdg.tags"), &val);
103
if (!val.isEmpty()) {
104
QStringList tags = val.split(QLatin1Char(','), QString::SkipEmptyParts);
105
Q_FOREACH (const QString& tag, tags) {
106
doc.indexText(tag, QLatin1String("TA"));
107
doc.addBoolTerm(QLatin1String("TAG-") + tag);
112
baloo_getxattr(m_file.url(), QLatin1String("user.baloo.rating"), &val);
113
if (!val.isEmpty()) {
114
doc.addBoolTerm(val, QLatin1String("R"));
118
baloo_getxattr(m_file.url(), QLatin1String("user.xdg.comment"), &val);
119
if (!val.isEmpty()) {
120
doc.indexText(val, QLatin1String("C"));
128
QVector<KFileMetaData::Type::Type> BasicIndexingJob::typesForMimeType(const QString& mimeType) const
130
using namespace KFileMetaData;
131
QVector<Type::Type> types;
134
if (mimeType.contains(QLatin1String("audio")))
135
types << Type::Audio;
136
if (mimeType.contains(QLatin1String("video")))
137
types << Type::Video;
138
if (mimeType.contains(QLatin1String("image")))
139
types << Type::Image;
140
if (mimeType.contains(QLatin1String("document")))
141
types << Type::Document;
142
if (mimeType.contains(QLatin1String("text")))
144
//if (mimeType.contains(QLatin1String("font")))
147
if (mimeType.contains(QLatin1String("powerpoint"))) {
148
types << Type::Presentation;
149
types << Type::Document;
151
if (mimeType.contains(QLatin1String("excel"))) {
152
types << Type::Spreadsheet;
153
types << Type::Document;
155
//if (mimeType.contains(QLatin1String("text/html")))
158
static QMultiHash<QString, Type::Type> typeMapper;
159
if (typeMapper.isEmpty()) {
161
typeMapper.insert(QLatin1String("text/plain"), Type::Document);
162
typeMapper.insert(QLatin1String("application/msword"), Type::Document);
163
typeMapper.insert(QLatin1String("application/vnd.ms-powerpoint"), Type::Document);
164
typeMapper.insert(QLatin1String("application/vnd.ms-powerpoint"), Type::Presentation);
165
typeMapper.insert(QLatin1String("application/vnd.ms-excel"), Type::Document);
166
typeMapper.insert(QLatin1String("application/vnd.ms-excel"), Type::Spreadsheet);
169
typeMapper.insert(QLatin1String("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
171
typeMapper.insert(QLatin1String("application/vnd.openxmlformats-officedocument.presentationml.presentation"),
173
typeMapper.insert(QLatin1String("application/vnd.openxmlformats-officedocument.presentationml.presentation"),
175
typeMapper.insert(QLatin1String("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
177
typeMapper.insert(QLatin1String("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
180
// Open document formats - http://en.wikipedia.org/wiki/OpenDocument_technical_specification
181
typeMapper.insert(QLatin1String("application/vnd.oasis.opendocument.text"), Type::Document);
182
typeMapper.insert(QLatin1String("application/vnd.oasis.opendocument.presentation"), Type::Document);
183
typeMapper.insert(QLatin1String("application/vnd.oasis.opendocument.presentation"), Type::Presentation);
184
typeMapper.insert(QLatin1String("application/vnd.oasis.opendocument.spreadsheet"), Type::Document);
185
typeMapper.insert(QLatin1String("application/vnd.oasis.opendocument.spreadsheet"), Type::Spreadsheet);
188
typeMapper.insert(QLatin1String("application/pdf"), Type::Document);
189
typeMapper.insert(QLatin1String("application/postscript"), Type::Document);
190
typeMapper.insert(QLatin1String("application/x-dvi"), Type::Document);
191
typeMapper.insert(QLatin1String("application/rtf"), Type::Document);
194
typeMapper.insert(QLatin1String("application/epub+zip"), Type::Document);
195
typeMapper.insert(QLatin1String("application/x-mobipocket-ebook"), Type::Document);
197
// Archives - http://en.wikipedia.org/wiki/List_of_archive_formats
198
typeMapper.insert(QLatin1String("application/x-tar"), Type::Archive);
199
typeMapper.insert(QLatin1String("application/x-bzip2"), Type::Archive);
200
typeMapper.insert(QLatin1String("application/x-gzip"), Type::Archive);
201
typeMapper.insert(QLatin1String("application/x-lzip"), Type::Archive);
202
typeMapper.insert(QLatin1String("application/x-lzma"), Type::Archive);
203
typeMapper.insert(QLatin1String("application/x-lzop"), Type::Archive);
204
typeMapper.insert(QLatin1String("application/x-compress"), Type::Archive);
205
typeMapper.insert(QLatin1String("application/x-7z-compressed"), Type::Archive);
206
typeMapper.insert(QLatin1String("application/x-ace-compressed"), Type::Archive);
207
typeMapper.insert(QLatin1String("application/x-astrotite-afa"), Type::Archive);
208
typeMapper.insert(QLatin1String("application/x-alz-compressed"), Type::Archive);
209
typeMapper.insert(QLatin1String("application/vnd.android.package-archive"), Type::Archive);
210
typeMapper.insert(QLatin1String("application/x-arj"), Type::Archive);
211
typeMapper.insert(QLatin1String("application/vnd.ms-cab-compressed"), Type::Archive);
212
typeMapper.insert(QLatin1String("application/x-cfs-compressed"), Type::Archive);
213
typeMapper.insert(QLatin1String("application/x-dar"), Type::Archive);
214
typeMapper.insert(QLatin1String("application/x-lzh"), Type::Archive);
215
typeMapper.insert(QLatin1String("application/x-lzx"), Type::Archive);
216
typeMapper.insert(QLatin1String("application/x-rar-compressed"), Type::Archive);
217
typeMapper.insert(QLatin1String("application/x-stuffit"), Type::Archive);
218
typeMapper.insert(QLatin1String("application/x-stuffitx"), Type::Archive);
219
typeMapper.insert(QLatin1String("application/x-gtar"), Type::Archive);
220
typeMapper.insert(QLatin1String("application/zip"), Type::Archive);
224
typeMapper.insert(QLatin1String("image/vnd.microsoft.icon"), "Icon");
225
typeMapper.insert(QLatin1String("image/svg+xml"), "Image");
228
typeMapper.insert(QLatin1String("application/vnd.ms-fontobject"), "Font");
229
typeMapper.insert(QLatin1String("application/vnd.ms-opentype"), "Font");
233
types << typeMapper.values(mimeType).toVector();