1 /* This file is part of the KDE project
2 Copyright (C) 2004 David Faure <faure@kde.org>
3 2007 Jos van den Oever <jos@vandenoever.info>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
20 #define STRIGI_IMPORT_API
21 #include <strigi/streamthroughanalyzer.h>
22 #include <strigi/analyzerplugin.h>
23 #include <strigi/fieldtypes.h>
24 #include <strigi/analysisresult.h>
25 #include "trashimpl.h"
27 using namespace Strigi
;
30 class TrashThroughAnalyzerFactory
;
31 class TrashThroughAnalyzer
: public StreamThroughAnalyzer
{
32 const TrashThroughAnalyzerFactory
* factory
;
35 void setIndexable(AnalysisResult
*i
) {
38 InputStream
*connectInputStream(InputStream
*in
);
39 bool isReadyWithStream() { return true; }
40 const char* name() const {
41 return "TrashThroughAnalyzer";
44 TrashThroughAnalyzer(const TrashThroughAnalyzerFactory
* f
) :factory(f
) {}
46 //define all the available analyzers in this plugin
47 class TrashThroughAnalyzerFactory
: public StreamThroughAnalyzerFactory
{
49 const char* name() const {
50 return "TrashThroughAnalyzer";
52 StreamThroughAnalyzer
* newInstance() const {
53 return new TrashThroughAnalyzer(this);
55 void registerFields(FieldRegister
&);
56 static const string originalpathFieldName
;
57 static const string dateofdeletionFieldName
;
59 const RegisteredField
* originalpathField
;
60 const RegisteredField
* dateofdeletionField
;
63 InputStream
* TrashThroughAnalyzer::connectInputStream(InputStream
* in
) {
64 const string
& path
= idx
->path();
65 if (strncmp(path
.c_str(), "system:/trash", 13)
66 || strncmp(path
.c_str(), "trash:/", 7)) {
69 KUrl
url(path
.c_str());
71 if ( url
.protocol()=="system"
72 && url
.path().startsWith("/trash") )
74 QString path
= url
.path();
76 url
.setProtocol("trash");
80 //kDebug() << info.url();
81 if ( url
.protocol() != "trash" )
87 if ( !TrashImpl::parseURL( url
, trashId
, fileId
, relativePath
) ) {
91 TrashImpl::TrashedFileInfo trashInfo
;
92 if ( !impl
.infoForFile( trashId
, fileId
, trashInfo
) ) {
96 idx
->addValue(factory
->originalpathField
,
97 (const char*)trashInfo
.origPath
.toUtf8());
98 idx
->addValue(factory
->dateofdeletionField
,
99 (uint32_t)trashInfo
.deletionDate
.toTime_t());
104 TrashThroughAnalyzerFactory::registerFields(FieldRegister
& reg
) {
105 originalpathField
= reg
.registerField("trash.original_location",
106 FieldRegister::stringType
, 1, 0);
107 dateofdeletionField
= reg
.registerField("trash.deletion_time",
108 FieldRegister::integerType
, 1, 0);
111 class Factory
: public AnalyzerFactoryFactory
{
113 list
<StreamThroughAnalyzerFactory
*>
114 streamThroughAnalyzerFactories() const {
115 list
<StreamThroughAnalyzerFactory
*> af
;
116 af
.push_back(new TrashThroughAnalyzerFactory());
121 STRIGI_ANALYZER_FACTORY(Factory
)