delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / trash / trashthroughanalyzer.cpp
blob31f9d04a1d850641cb0e5833d0ee44ca1ec17cb0
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"
26 #include <KUrl>
27 using namespace Strigi;
28 using namespace std;
30 class TrashThroughAnalyzerFactory;
31 class TrashThroughAnalyzer : public StreamThroughAnalyzer {
32 const TrashThroughAnalyzerFactory* factory;
33 TrashImpl impl;
34 AnalysisResult* idx;
35 void setIndexable(AnalysisResult*i) {
36 idx = i;
38 InputStream *connectInputStream(InputStream *in);
39 bool isReadyWithStream() { return true; }
40 const char* name() const {
41 return "TrashThroughAnalyzer";
43 public:
44 TrashThroughAnalyzer(const TrashThroughAnalyzerFactory* f) :factory(f) {}
46 //define all the available analyzers in this plugin
47 class TrashThroughAnalyzerFactory : public StreamThroughAnalyzerFactory {
48 private:
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;
58 public:
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)) {
67 return in;
69 KUrl url(path.c_str());
71 if ( url.protocol()=="system"
72 && url.path().startsWith("/trash") )
74 QString path = url.path();
75 path.remove(0, 6);
76 url.setProtocol("trash");
77 url.setPath(path);
80 //kDebug() << info.url();
81 if ( url.protocol() != "trash" )
82 return in;
84 int trashId;
85 QString fileId;
86 QString relativePath;
87 if ( !TrashImpl::parseURL( url, trashId, fileId, relativePath ) ) {
88 return in;
91 TrashImpl::TrashedFileInfo trashInfo;
92 if ( !impl.infoForFile( trashId, fileId, trashInfo ) ) {
93 return in;
96 idx->addValue(factory->originalpathField,
97 (const char*)trashInfo.origPath.toUtf8());
98 idx->addValue(factory->dateofdeletionField,
99 (uint32_t)trashInfo.deletionDate.toTime_t());
100 return in;
103 void
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 {
112 public:
113 list<StreamThroughAnalyzerFactory*>
114 streamThroughAnalyzerFactories() const {
115 list<StreamThroughAnalyzerFactory*> af;
116 af.push_back(new TrashThroughAnalyzerFactory());
117 return af;
121 STRIGI_ANALYZER_FACTORY(Factory)