Commit daa7341c authored by Luigi Toscano's avatar Luigi Toscano
Browse files

Remove Strigi references

parent 5cf97d4d
......@@ -27,15 +27,6 @@ add_subdirectory(lib)
ecm_optional_add_subdirectory(thumbnailers)
find_package(Strigi)
set_package_properties(Strigi PROPERTIES DESCRIPTION "Provide a strigi analyser for Mobipocket documents"
URL "http://strigi.sourceforge.net"
TYPE OPTIONAL
)
if(STRIGI_STREAMS_LIBRARY)
ecm_optional_add_subdirectory(strigi)
endif()
set(CMAKECONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/QMobipocket")
ecm_configure_package_config_file(
......
......@@ -23,7 +23,8 @@ namespace Mobipocket {
/**
Minimalistic stream abstraction. It is supposed to allow mobipocket document classes to be
used with both QIODevice (for Okular generator) and InputStream for Strigi analyzer.
used with QIODevice (for Okular generator), and previously also with InputStream for Strigi
analyzer.
*/
class QMOBIPOCKET_EXPORT Stream {
public:
......
include_directories(${STRIGI_INCLUDE_DIR})
########### next target ###############
set(mobianalyzer_SRCS
mobiendanalyzer.cpp
)
add_library(mobi MODULE ${mobianalyzer_SRCS})
target_link_libraries(mobi ${STRIGI_STREAMS_LIBRARY} ${STRIGI_STREAMANALYZER_LIBRARY}
Qt5::Core Qt5::Gui qmobipocket)
# install the module in the right directory so it is picked up
set_target_properties(mobi PROPERTIES PREFIX strigila_)
########### install files ###############
install(TARGETS mobi LIBRARY DESTINATION ${LIB_INSTALL_DIR}/strigi)
/***************************************************************************
* Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "mobiendanalyzer.h"
#define STRIGI_IMPORT_API
#include <strigi/strigiconfig.h>
#include <strigi/analysisresult.h>
#include <strigi/fieldtypes.h>
#include <strigi/streamendanalyzer.h>
#include <strigi/analyzerplugin.h>
#include <list>
#include "mobipocket.h"
using namespace Strigi;
class StrigiStream : public Mobipocket::Stream
{
public:
StrigiStream(InputStream* str) : d(str) {}
int read(char* buf, int len) {
const char* b2;
int l=d->read(b2, len,len);
if (l>0) memcpy(buf,b2,l);
return l;
}
bool seek(int pos) { d->reset(pos); return (pos==d->position()); }
private:
InputStream *d;
};
void
MobiEndAnalyzerFactory::registerFields(FieldRegister& reg) {
subjectField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#subject");
titleField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#title");
authorField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#author");
descriptionField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#description");
copyrightField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#copyright");
encryptedField = reg.registerField(
"http://freedesktop.org/standards/xesam/1.0/core#isContentEncrypted");
// typeField = reg.typeField;
//FIXME: check other fields - for example encryption
/* add the fields to the internal list of fields */
addField(subjectField);
addField(titleField);
addField(authorField);
addField(descriptionField);
addField(copyrightField);
addField(encryptedField);
// addField(typeField);
}
MobiEndAnalyzer::MobiEndAnalyzer(const MobiEndAnalyzerFactory* f) :factory(f) {
}
bool
MobiEndAnalyzer::checkHeader(const char* header, int32_t headersize) const { //krazy:exclude=typedefs
static const char magic1[] = "TEXtREAd";
static const char magic2[] = "BOOKMOBI";
return headersize >= 67 && (!memcmp(header+60, magic1, 8) || !memcmp(header+60, magic2, 8));
}
signed char
MobiEndAnalyzer::analyze(AnalysisResult& as, InputStream* in) {
StrigiStream str(in);
Mobipocket::Document doc(&str);
if (!doc.isValid()) return -1;
// as.addValue(factory->typeField, "http://freedesktop.org/standards/xesam/1.0/core#Document");
as.addValue(factory->encryptedField, doc.hasDRM());
QMapIterator<Mobipocket::Document::MetaKey,QString> it(doc.metadata());
while (it.hasNext()) {
it.next();
switch (it.key()) {
case Mobipocket::Document::Title: as.addValue(factory->titleField, it.value().toUtf8().data() ); break;
case Mobipocket::Document::Author: as.addValue(factory->authorField, it.value().toUtf8().data() ); break;
case Mobipocket::Document::Description: as.addValue(factory->descriptionField, it.value().toUtf8().data() ); break;
case Mobipocket::Document::Subject: as.addValue(factory->subjectField, it.value().toUtf8().data() ); break;
case Mobipocket::Document::Copyright: as.addValue(factory->copyrightField, it.value().toUtf8().data() ); break;
}
}
if (!doc.hasDRM()) {
QByteArray text=doc.text(20480).toUtf8();
as.addText(text.data(), text.size());
}
return 0;
}
class Factory : public AnalyzerFactoryFactory
{
public:
std::list<StreamEndAnalyzerFactory*>
streamEndAnalyzerFactories() const {
std::list<StreamEndAnalyzerFactory*> af;
af.push_back(new MobiEndAnalyzerFactory());
return af;
}
};
STRIGI_ANALYZER_FACTORY(Factory)
/***************************************************************************
* Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef MOBIENDANALYZER
#define MOBIENDANALYZER
#include <strigi/streamendanalyzer.h>
#include <strigi/streambase.h>
class MobiEndAnalyzerFactory;
class MobiEndAnalyzer : public Strigi::StreamEndAnalyzer {
private:
const MobiEndAnalyzerFactory* factory;
bool checkHeader(const char* header, int32_t headersize) const; //krazy:exclude=typedefs
signed char analyze(Strigi::AnalysisResult& idx, Strigi::InputStream* in);
const char* name() const { return "MobiEndAnalyzer"; }
public:
MobiEndAnalyzer(const MobiEndAnalyzerFactory* f);
};
class MobiEndAnalyzerFactory : public Strigi::StreamEndAnalyzerFactory {
friend class MobiEndAnalyzer;
private:
const Strigi::RegisteredField* titleField;
const Strigi::RegisteredField* authorField;
const Strigi::RegisteredField* copyrightField;
const Strigi::RegisteredField* subjectField;
const Strigi::RegisteredField* descriptionField;
const Strigi::RegisteredField* encryptedField;
// const Strigi::RegisteredField* typeField;
const char* name() const {
return "MobiEndAnalyzer";
}
Strigi::StreamEndAnalyzer* newInstance() const {
return new MobiEndAnalyzer(this);
}
void registerFields(Strigi::FieldRegister&);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment