Commit a1c1f2bd authored by Nicolás Alvarez's avatar Nicolás Alvarez
Browse files

Remove the Okular plugin.

It has been moved to the Okular repository.
parent 6a20a2dc
......@@ -5,9 +5,6 @@ include(KDE4Defaults)
include(MacroLibrary)
include(MacroOptionalAddSubdirectory)
find_package(Okular)
macro_log_feature(OKULAR_FOUND "okular" "Provides an Okular backend for Mobipocket documents" "http://okular.kde.org/" FALSE "" "")
find_package(Strigi)
macro_log_feature(STRIGI_FOUND "strigi libraries" "Provide a strigi analyzer for Mobipocket documents" "" FALSE "" "")
......@@ -17,9 +14,6 @@ include_directories(${KDE4_INCLUDES})
add_subdirectory(lib)
macro_optional_add_subdirectory(thumbnailers)
if(OKULAR_FOUND)
macro_optional_add_subdirectory(okular)
endif()
if(STRIGI_FOUND)
macro_optional_add_subdirectory(strigi)
endif()
......
include_directories(
${OKULAR_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/lib
)
########### next target ###############
set(okularGenerator_mobi_PART_SRCS
mobidocument.cpp
generator_mobi.cpp
converter.cpp
)
kde4_add_plugin(okularGenerator_mobi ${okularGenerator_mobi_PART_SRCS})
target_link_libraries(okularGenerator_mobi ${OKULAR_CORE_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} qmobipocket)
install(TARGETS okularGenerator_mobi DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES libokularGenerator_mobi.desktop okularMobi.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install( PROGRAMS okularApplication_mobi.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
#!/bin/sh
$XGETTEXT *.cpp -o $podir/okular_mobi.pot
/***************************************************************************
* 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 "converter.h"
#include <QtGui/QAbstractTextDocumentLayout>
#include <QtGui/QTextDocument>
#include <QtGui/QTextBlock>
#include <QtGui/QTextFrame>
#include <QtGui/QTextDocumentFragment>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include "mobipocket.h"
#include <klocale.h>
#include <okular/core/action.h>
using namespace Mobi;
Converter::Converter()
{
}
Converter::~Converter()
{
}
void Converter::handleMetadata(const QMap<Mobipocket::Document::MetaKey,QString> metadata)
{
QMapIterator<Mobipocket::Document::MetaKey,QString> it(metadata);
while (it.hasNext()) {
it.next();
switch (it.key()) {
case Mobipocket::Document::Title: addMetaData(Okular::DocumentInfo::Title, it.value()); break;
case Mobipocket::Document::Author: addMetaData(Okular::DocumentInfo::Author, it.value()); break;
case Mobipocket::Document::Description: addMetaData(Okular::DocumentInfo::Description, it.value()); break;
case Mobipocket::Document::Subject: addMetaData(Okular::DocumentInfo::Subject, it.value()); break;
case Mobipocket::Document::Copyright: addMetaData(Okular::DocumentInfo::Copyright, it.value()); break;
}
}
}
QTextDocument* Converter::convert( const QString &fileName )
{
MobiDocument* newDocument=new MobiDocument(fileName);
if (!newDocument->mobi()->isValid()) {
emit error(i18n("Error while opening the Mobipocket document."), -1);
delete newDocument;
return NULL;
}
if (newDocument->mobi()->hasDRM()) {
emit error(i18n("This book is protected by DRM and can be displayed only on designated device"), -1);
delete newDocument;
return NULL;
}
handleMetadata(newDocument->mobi()->metadata());
newDocument->setPageSize(QSizeF(600, 800));
QTextFrameFormat frameFormat;
frameFormat.setMargin( 20 );
QTextFrame *rootFrame = newDocument->rootFrame();
rootFrame->setFrameFormat( frameFormat );
QMap<QString,QPair<int,int> > links;
QMap<QString,QTextBlock> targets;
// go over whole document and add all <a> tags to links or targets map
for (QTextBlock it = newDocument->begin(); it != newDocument->end(); it = it.next())
for (QTextBlock::iterator fit=it.begin(); !fit.atEnd(); ++fit) {
QTextFragment frag=fit.fragment();
QTextCharFormat format=frag.charFormat();
if (!format.isAnchor()) continue;
//link
if (!format.anchorHref().isEmpty()) links[format.anchorHref()]=
QPair<int,int>(frag.position(), frag.position()+frag.length());
if (!format.anchorNames().isEmpty()) {
// link targets
Q_FOREACH(const QString& name, format.anchorNames())
targets['#'+name]=it;
}
}
// create link actions
QMapIterator<QString,QPair<int,int> > it(links);
while (it.hasNext()) {
it.next();
QUrl u(it.key());
// external or internal link
if (!u.isRelative()) emit addAction(new Okular::BrowseAction(it.key()), it.value().first, it.value().second);
else {
// is there valid target?
if (!targets.contains( it.key() ) || !targets[it.key()].isValid()) continue;
emit addAction(new Okular::GotoAction(QString(), calculateViewport( newDocument, targets[it.key()] )),
it.value().first, it.value().second);
}
}
return newDocument;
}
/***************************************************************************
* 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 MOBI_CONVERTER_H
#define MOBI_CONVERTER_H
#include <okular/core/textdocumentgenerator.h>
#include <okular/core/document.h>
#include "mobidocument.h"
#include "mobipocket.h"
namespace Mobi {
class Converter : public Okular::TextDocumentConverter
{
public:
Converter();
~Converter();
virtual QTextDocument *convert( const QString &fileName );
private:
void handleMetadata(const QMap<Mobipocket::Document::MetaKey, QString> metadata);
};
}
#endif
/***************************************************************************
* Copyright (C) 2008 by Ely Levy <elylevy@cs.huji.ac.il> *
* *
* 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 "generator_mobi.h"
#include "converter.h"
#include <kaboutdata.h>
#include <kconfigdialog.h>
static KAboutData createAboutData()
{
KAboutData aboutData(
"okular_mobi",
"okular_mobi",
ki18n("Mobipocket Backend"),
"0.1",
ki18n("A mobipocket backend"),
KAboutData::License_GPL,
ki18n("© 2008-2009 Jakub Stachowski")
);
aboutData.addAuthor(ki18n("Jakub Stachowski"), KLocalizedString(),
"qbast@go2.pl");
return aboutData;
}
OKULAR_EXPORT_PLUGIN( MobiGenerator, createAboutData() )
MobiGenerator::MobiGenerator( QObject *parent, const QVariantList &args )
: Okular::TextDocumentGenerator( new Mobi::Converter, "okular_mobi_generator_settings", parent, args )
{
}
void MobiGenerator::addPages( KConfigDialog* dlg )
{
Okular::TextDocumentSettingsWidget *widget = new Okular::TextDocumentSettingsWidget();
dlg->addPage( widget, generalSettings(), i18n("Mobipocket"), "application-x-mobipocket-ebook", i18n("Mobipocket Backend Configuration") );
}
/***************************************************************************
* Copyright (C) 2008 by Ely Levy <elylevy@cs.huji.ac.il> *
* *
* 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 OKULAR_GENERATOR_MOBI_H
#define OKULAR_GENERATOR_MOBI_H
#include <okular/core/textdocumentgenerator.h>
class MobiGenerator : public Okular::TextDocumentGenerator
{
public:
MobiGenerator( QObject *parent, const QVariantList &args );
~MobiGenerator() {}
// [INHERITED] reparse configuration
void addPages( KConfigDialog* dlg );
};
#endif
[Desktop Entry]
Type=Service
Name=Mobipocket document
Name[ar]=مستند Mobipocket
Name[ast]=Documentu Mobipocket
Name[bg]=Документ Mobipocket
Name[bs]=Mobipocket dokument
Name[ca]=Document Mobipocket
Name[ca@valencia]=Document Mobipocket
Name[cs]=Mobipocket dokument
Name[da]=Mobipocket-dokument
Name[de]=Mobipocket-Dokument
Name[el]=Έγγραφο Mobipocket
Name[en_GB]=Mobipocket document
Name[es]=Documento Mobipocket
Name[et]=Mobipocketi dokument
Name[eu]=Mobipocket dokumentua
Name[fi]=Mobipocket-asiakirja
Name[fr]=Document « Mobipocket »
Name[ga]=Cáipéis Mobipocket
Name[gl]=Documento Mobipocket
Name[hr]=Dokument oblika Mobipocket
Name[hu]=Mobipocket-dokumentum
Name[ia]=Documento de Mobipocket
Name[is]=Mobipocket skjal
Name[it]=Documento Mobipocket
Name[ja]=Mobipocket 文書
Name[kk]=Mobipocket құжаты
Name[km]=ឯកសារ Mobipocket
Name[ko]=Mobipocket 문서
Name[lt]=Mobipocket dokumentas
Name[lv]=Mobipocket dokuments
Name[mr]=मोबीपॉकेट दस्तऐवज
Name[nb]=Mobipocket-dokument
Name[nds]=Mobipocket-Dokment
Name[nl]=Mobipocket-document
Name[nn]=Mobipocket-dokument
Name[pa]=ਮੋਬੀਪਾਕਟ ਡੌਕੂਮੈਂਟ
Name[pl]=Dokument Mobipocket
Name[pt]=Documento do Mobipocket
Name[pt_BR]=Documento Mobipocket
Name[ro]=Document Mobipocket
Name[ru]=Документ Mobipocket
Name[sk]=Mobipocket dokument
Name[sl]=Dokument Mobipocket
Name[sq]=Dokument Mobipocket
Name[sr]=Мобипокет
Name[sr@ijekavian]=Мобипокет
Name[sr@ijekavianlatin]=Mobipocket
Name[sr@latin]=Mobipocket
Name[sv]=Mobipocket-dokument
Name[th]=เอกสาร Mobipocket
Name[tr]=Mobipocket belgesi
Name[ug]=Mobipocket پۈتۈكى
Name[uk]=Документ Mobipocket
Name[x-test]=xxMobipocket documentxx
Name[zh_CN]=Mobipocket 文档
Name[zh_TW]=Mobipocket 文件
Comment=Mobipocket backend for Okular
Comment[ar]=خلفية Mobipocket لأوكلار
Comment[ast]=Motor Mobipocket pa Okular
Comment[bg]=Ядро на Okular за Mobipocket
Comment[bs]=Pozadina Mobipocketa za Okular
Comment[ca]=Dorsal de Mobipocket per a l'Okular
Comment[ca@valencia]=Dorsal de Mobipocket per a l'Okular
Comment[cs]= Implementace Mobipocket pro Okular
Comment[da]=Mobipocket-motor til Okular
Comment[de]=Ein Anzeigemodul für Mobipocket-Dateien in Okular
Comment[el]=Σύστημα υποστήριξης Mobipocket για το Okular
Comment[en_GB]=Mobipocket backend for Okular
Comment[es]=Motor Mobipocket para Okular
Comment[et]=Okulari Mobipocketi taustaprogramm
Comment[eu]=Okular-en Mobipocket motorra
Comment[fi]=Mobipocket-taustaosa Okular-lukijalle
Comment[fr]=Moteur Mobipocket pour Okular
Comment[ga]=Inneall Mobipocket le haghaidh Okular
Comment[gl]=Infraestrutura de Mobipocket para Okular
Comment[hr]=Podrška za Mobipocket za Okular
Comment[hu]=Mobipocket-bővítmény az Okularhoz
Comment[ia]=Retro-administration de Mobipocket pro Okular
Comment[is]=Mobipocket stuðningur fyrir Okular
Comment[it]=Backend Mobipocket per Okular
Comment[ja]=Okular の Mobipocket 用バックエンド
Comment[kk]=Okular-дың Mobipocket тетігі
Comment[km]=កម្មវិធី​ខាងក្រោយ​សម្រាប់ Mobipocket សម្រាប់ Okular
Comment[ko]=Okular의 Mobipocket 백엔드
Comment[lt]=Mobipocket programinė sąsaja, skirta Okular
Comment[lv]=Mobipocket Okular aizmugure
Comment[mr]=ओक्युलर करिता मोबीपॉकेट बॅकएन्ड
Comment[nb]=Mobipocket-motor for okular
Comment[nds]=Mobipocket-Hülppropgramm för Okular
Comment[nl]=Mobipocket-backend voor Okular
Comment[nn]=Mobipocket-motor for Okular
Comment[pa]=ਓਕੁਲਾਰ ਲਈ ਮੋਬੀਪਾਕਟ ਬੈਕਐਂਡ
Comment[pl]=Obsługa formatu Mobipocket dla Okulara
Comment[pt]=Infra-estrutura do Mobipocket para o Okular
Comment[pt_BR]=Infraestrutura Mobipocket para o Okular
Comment[ro]=Platformă Mobipocket pentru Okular
Comment[ru]=Модуль поддержки формата Mobipocket для Okular
Comment[sk]=Backend Mobipocket pre Okular
Comment[sl]=Zaledje Mobipocket za Okular
Comment[sq]=Mbështetje Mobipocket për Okular
Comment[sr]=Позадина Мобипокета за Окулар
Comment[sr@ijekavian]=Позадина Мобипокета за Окулар
Comment[sr@ijekavianlatin]=Pozadina Mobipocketa za Okular
Comment[sr@latin]=Pozadina Mobipocketa za Okular
Comment[sv]=Mobipocket-gränssnitt för Okular
Comment[th]=แบ็กเอนด์แฟ้มแบบ Mobipocket สำหรับโอกูลาร์
Comment[tr]=Okular için Mobipocket arka ucu
Comment[ug]=Okular نىڭ Mobipocket ئارقائۇچى
Comment[uk]=Модуль Mobipocket для Okular
Comment[x-test]=xxMobipocket backend for Okularxx
Comment[zh_CN]=Okular 的 Mobipocket 格式后端
Comment[zh_TW]=Okular 的 Mobipocket 後端介面
X-KDE-ServiceTypes=okular/Generator
MimeType=application/x-mobipocket-ebook;
X-KDE-Library=okularGenerator_mobi
X-KDE-Priority=1
X-KDE-okularAPIVersion=1
X-KDE-okularHasInternalSettings=true
/***************************************************************************
* 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 "mobidocument.h"
#include "mobipocket.h"
#include "qfilestream.h"
#include <QtGui/QColor>
#include <QtCore/QFile>
#include <QtCore/QRegExp>
#include <kdebug.h>
using namespace Mobi;
MobiDocument::MobiDocument(const QString &fileName) : QTextDocument()
{
file = new Mobipocket::QFileStream(fileName);
doc = new Mobipocket::Document(file);
if (doc->isValid()) {
QString text=doc->text();
QString header=text.left(1024);
if (header.contains("<html>") || header.contains("<HTML>")) setHtml(fixMobiMarkup(text));
else setPlainText(text);
}
}
MobiDocument::~MobiDocument()
{
delete doc;
delete file;
}
QVariant MobiDocument::loadResource(int type, const QUrl &name)
{
if (type!=QTextDocument::ImageResource || name.scheme()!=QString("pdbrec")) return QVariant();
bool ok;
quint16 recnum=name.path().mid(1).toUShort(&ok);
if (!ok || recnum>=doc->imageCount()) return QVariant();
QVariant resource;
resource.setValue(doc->getImage(recnum-1));
addResource(type, name, resource);
return resource;
}
// starting from 'pos', find position in the string that is not inside a tag
int outsideTag(const QString& data, int pos)
{
for (int i=pos-1;i>=0;i--) {
if (data[i]=='>') return pos;
if (data[i]=='<') return i;
}
return pos;
}
QString MobiDocument::fixMobiMarkup(const QString& data)
{
QString ret=data;
QMap<int,QString> anchorPositions;
static QRegExp anchors("<a(?: href=\"[^\"]*\"){0,1}[\\s]+filepos=['\"]{0,1}([\\d]+)[\"']{0,1}", Qt::CaseInsensitive);
int pos=0;
// find all link destinations
while ( (pos=anchors.indexIn( data, pos ))!=-1) {
int filepos=anchors.cap( 1 ).toUInt( );
if (filepos) anchorPositions[filepos]=anchors.cap(1);
pos+=anchors.matchedLength();
}
// put HTML anchors in all link destinations
int offset=0;
QMapIterator<int,QString> it(anchorPositions);
while (it.hasNext()) {
it.next();
// link pointing outside the document, ignore
if ( (it.key()+offset) >= ret.size()) continue;
int fixedpos=outsideTag(ret, it.key()+offset);
ret.insert(fixedpos,QString("<a name=\"")+it.value()+QString("\">&nbsp;</a>"));
// inserting anchor shifts all offsets after the anchor
offset+=21+it.value().size();
}
// replace links referencing filepos with normal internal links
ret.replace(anchors,"<a href=\"#\\1\"");
// Mobipocket uses strange variang of IMG tags: <img recindex="3232"> where recindex is number of
// record containing image
static QRegExp imgs("<img.*recindex=\"([\\d]*)\".*>", Qt::CaseInsensitive);
imgs.setMinimal(true);
ret.replace(imgs,"<img src=\"pdbrec:/\\1\">");
ret.replace("<mbp:pagebreak/>","<p style=\"page-break-after:always\"></p>");
return ret;
}
/***************************************************************************
* 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 MOBI_DOCUMENT_H
#define MOBI_DOCUMENT_H
#include <QTextDocument>
#include <QUrl>
#include <QVariant>
class QFile;
namespace Mobipocket {
class Document;
class QFileStream;
}
namespace Mobi {
class MobiDocument : public QTextDocument {
public:
MobiDocument(const QString &fileName);
~MobiDocument();
Mobipocket::Document* mobi() const { return doc; }
protected:
virtual QVariant loadResource(int type, const QUrl &name);
private:
QString fixMobiMarkup(const QString& data);
Mobipocket::Document *doc;
Mobipocket::QFileStream* file;
};
}
#endif
[Desktop Entry]
MimeType=application/x-mobipocket-ebook;
Terminal=false
Name=Okular
Name[ar]=اوكلار
Name[ast]=Okular
Name[bg]=Okular
Name[bs]=Okular
Name[ca]=Okular
Name[ca@valencia]=Okular
Name[cs]=Okular
Name[da]=Okular
Name[de]=Okular
Name[el]=Okular
Name[en_GB]=Okular
Name[eo]=Okular
Name[es]=Okular
Name[et]=Okular
Name[eu]=Okular
Name[fi]=Okular
Name[fr]=Okular
Name[ga]=Okular
Name[gl]=Okular
Name[hne]=ओकुलर
Name[hr]=Okular
Name[hu]=Okular
Name[ia]=Okular
Name[is]=Okular
Name[it]=Okular
Name[ja]=Okular
Name[kk]=Okular
Name[km]=Okular
Name[ko]=Okular
Name[ku]=Okular
Name[lt]=Okular
Name[lv]=Okular
Name[mr]=ओक्युलर
Name[nb]=Okular
Name[nds]=Okular
Name[nl]=Okular
Name[nn]=Okular
Name[pa]=ਓਕੁਲਾਰ
Name[pl]=Okular
Name[pt]=Okular
Name[pt_BR]=Okular
Name[ro]=Okular
Name[ru]=Okular
Name[si]=Okular
Name[sk]=Okular
Name[sl]=Okular
Name[sq]=Okular
Name[sr]=Окулар
Name[sr@ijekavian]=Окулар
Name[sr@ijekavianlatin]=Okular
Name[sr@latin]=Okular
Name[sv]=Okular
Name[th]=โอกูลาร์
Name[tr]=Okular
Name[ug]=Okular
Name[uk]=Okular
Name[x-test]=xxOkularxx
Name[zh_CN]=Okular
Name[zh_TW]=Okular
GenericName=Document Viewer
GenericName[ar]=عارض المستندات
GenericName[ast]=Visor de documentos
GenericName[bg]=Преглед на документи
GenericName[bs]=Prikazivač dokumenata
GenericName[ca]=Visualitzador de documents
GenericName[ca@valencia]=Visualitzador de documents
GenericName[cs]=Prohlížeč dokumentů
GenericName[da]=Dokumentfremviser
GenericName[de]=Dokumentenbetrachter
GenericName[el]=Προβολέας εγγράφων
GenericName[en_GB]=Document Viewer
GenericName[eo]=Dokumenta rigardilo
GenericName[es]=Visor de documentos
GenericName[et]=Dokumendinäitaja
GenericName[eu]=Dokumentu ikustailea
GenericName[fa]=مشاهده‌گر سند
GenericName[fi]=Asiakirjan näyttöohjelma
GenericName[fr]=Afficheur de documents
GenericName[ga]=Amharcán Cáipéisí
GenericName[gl]=Visor de documentos
GenericName[hi]=दस्तावेज़ प्रदर्शक
GenericName[hne]=कागद प्रदर्सक
GenericName[hr]=Preglednik dokumenata
GenericName[hu]=Dokumentumnézegető
GenericName[ia]=Visor de documento
GenericName[is]=Skjalaskoðari
GenericName[it]=Visore di documenti
GenericName[ja]=文書ビューア
GenericName[kk]=Құжатты қарау құралы
GenericName[km]=កម្មវិធី​មើល​ឯកសារ
GenericName[ko]=문서 뷰어
GenericName[ku]=Nîşanderê Belgeyan
GenericName[lt]=Dokumentų žiūryklė
GenericName[lv]=Dokumentu skatītājs
GenericName[mr]=दस्तऐवज प्रदर्शक
GenericName[nb]=Dokumentviser
GenericName[nds]=Dokmentkieker