Commit 62d7a693 authored by Albert Astals Cid's avatar Albert Astals Cid

Remove the ooo plugin

As mentioned on the Akademy meeting, just use the calligra okular plugins if you want to open an odt/odp in Okular
parent 493e0610
Pipeline #36743 passed with stage
in 13 minutes and 12 seconds
......@@ -129,8 +129,6 @@ endif(TIFF_FOUND)
add_subdirectory(xps)
add_subdirectory(ooo)
add_subdirectory(fictionbook)
add_subdirectory(comicbook)
......
remove_definitions(-DTRANSLATION_DOMAIN="okular")
add_definitions(-DTRANSLATION_DOMAIN="okular_ooo")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../..
)
find_package(Qca-qt5 2.2.0)
set_package_properties(Qca-qt5 PROPERTIES DESCRIPTION "Support for encryption"
URL "https://download.kde.org/stable/qca-qt5/"
TYPE RECOMMENDED)
if ( Qca-qt5_FOUND )
add_definitions( -DQCA2 )
endif()
########### next target ###############
set(okularGenerator_ooo_PART_SRCS
converter.cpp
document.cpp
formatproperty.cpp
generator_ooo.cpp
manifest.cpp
styleinformation.cpp
styleparser.cpp
)
okular_add_generator(okularGenerator_ooo ${okularGenerator_ooo_PART_SRCS})
target_link_libraries(okularGenerator_ooo okularcore KF5::KIOCore KF5::Archive KF5::I18n ${MATH_LIB} Qt5::Xml)
if (Qca-qt5_FOUND)
target_link_libraries(okularGenerator_ooo qca-qt5)
endif ()
if (KF5Wallet_FOUND)
target_link_libraries(okularGenerator_ooo KF5::Wallet)
endif ()
########### install files ###############
install( FILES okularOoo.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install( PROGRAMS okularApplication_ooo.desktop org.kde.mobile.okular_ooo.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
install( FILES org.kde.okular-ooo.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} )
#!/bin/sh
$XGETTEXT $(find . -name "*.cpp" -o -name "*.h") -o $podir/okular_ooo.pot
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 OOO_CONVERTER_H
#define OOO_CONVERTER_H
#include <QDomDocument>
#include <QTextCharFormat>
#include <core/textdocumentgenerator.h>
#include "styleinformation.h"
class QDomElement;
class QDomText;
namespace OOO
{
class Converter : public Okular::TextDocumentConverter
{
Q_OBJECT
public:
Converter();
~Converter() override;
Okular::Document::OpenResult convertWithPassword(const QString &fileName, const QString &password) override;
private:
bool convertBody(const QDomElement &element);
bool convertText(const QDomElement &element);
bool convertHeader(QTextCursor *cursor, const QDomElement &element);
bool convertParagraph(QTextCursor *cursor, const QDomElement &element, const QTextBlockFormat &format = QTextBlockFormat(), bool merge = false);
bool convertTextNode(QTextCursor *cursor, const QDomText &element, const QTextCharFormat &format);
bool convertSpan(QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format);
bool convertLink(QTextCursor *cursor, const QDomElement &element, const QTextCharFormat &format);
bool convertList(QTextCursor *cursor, const QDomElement &element);
bool convertTable(const QDomElement &element);
bool convertFrame(const QDomElement &element);
bool convertAnnotation(QTextCursor *cursor, const QDomElement &element);
QTextDocument *mTextDocument;
QTextCursor *mCursor;
StyleInformation *mStyleInformation;
};
}
#endif
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 "document.h"
#include <KLocalizedString>
#include <kzip.h>
using namespace OOO;
Document::Document(const QString &fileName)
: mFileName(fileName)
, mManifest(nullptr)
, mAnyEncrypted(false)
{
}
bool Document::open(const QString &password)
{
mContent.clear();
mStyles.clear();
KZip zip(mFileName);
if (!zip.open(QIODevice::ReadOnly)) {
setError(i18n("Document is not a valid ZIP archive"));
return false;
}
const KArchiveDirectory *directory = zip.directory();
if (!directory) {
setError(i18n("Invalid document structure (main directory is missing)"));
return false;
}
const QStringList entries = directory->entries();
if (!entries.contains(QStringLiteral("META-INF"))) {
setError(i18n("Invalid document structure (META-INF directory is missing)"));
return false;
}
const KArchiveDirectory *metaInfDirectory = static_cast<const KArchiveDirectory *>(directory->entry(QStringLiteral("META-INF")));
if (!(metaInfDirectory->entries().contains(QStringLiteral("manifest.xml")))) {
setError(i18n("Invalid document structure (META-INF/manifest.xml is missing)"));
return false;
}
const KArchiveFile *file = static_cast<const KArchiveFile *>(metaInfDirectory->entry(QStringLiteral("manifest.xml")));
mManifest = new Manifest(mFileName, file->data(), password);
// we should really get the file names from the manifest, but for now, we only care
// if the manifest says the files are encrypted.
if (!entries.contains(QStringLiteral("content.xml"))) {
setError(i18n("Invalid document structure (content.xml is missing)"));
return false;
}
file = static_cast<const KArchiveFile *>(directory->entry(QStringLiteral("content.xml")));
if (mManifest->testIfEncrypted(QStringLiteral("content.xml"))) {
mAnyEncrypted = true;
mContent = mManifest->decryptFile(QStringLiteral("content.xml"), file->data());
} else {
mContent = file->data();
}
if (entries.contains(QStringLiteral("styles.xml"))) {
file = static_cast<const KArchiveFile *>(directory->entry(QStringLiteral("styles.xml")));
if (mManifest->testIfEncrypted(QStringLiteral("styles.xml"))) {
mAnyEncrypted = true;
mStyles = mManifest->decryptFile(QStringLiteral("styles.xml"), file->data());
} else {
mStyles = file->data();
}
}
if (entries.contains(QStringLiteral("meta.xml"))) {
file = static_cast<const KArchiveFile *>(directory->entry(QStringLiteral("meta.xml")));
if (mManifest->testIfEncrypted(QStringLiteral("meta.xml"))) {
mAnyEncrypted = true;
mMeta = mManifest->decryptFile(QStringLiteral("meta.xml"), file->data());
} else {
mMeta = file->data();
}
}
if (entries.contains(QStringLiteral("Pictures"))) {
const KArchiveDirectory *imagesDirectory = static_cast<const KArchiveDirectory *>(directory->entry(QStringLiteral("Pictures")));
const QStringList imagesEntries = imagesDirectory->entries();
for (int i = 0; i < imagesEntries.count(); ++i) {
file = static_cast<const KArchiveFile *>(imagesDirectory->entry(imagesEntries[i]));
QString fullPath = QStringLiteral("Pictures/%1").arg(imagesEntries[i]);
if (mManifest->testIfEncrypted(fullPath)) {
mAnyEncrypted = true;
mImages.insert(fullPath, mManifest->decryptFile(fullPath, file->data()));
} else {
mImages.insert(fullPath, file->data());
}
}
}
zip.close();
return true;
}
Document::~Document()
{
delete mManifest;
}
QString Document::lastErrorString() const
{
return mErrorString;
}
QByteArray Document::content() const
{
return mContent;
}
QByteArray Document::meta() const
{
return mMeta;
}
QByteArray Document::styles() const
{
return mStyles;
}
QMap<QString, QByteArray> Document::images() const
{
return mImages;
}
bool Document::anyFileEncrypted() const
{
return mAnyEncrypted;
}
void Document::setError(const QString &error)
{
mErrorString = error;
}
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 OOO_DOCUMENT_H
#define OOO_DOCUMENT_H
#include <QByteArray>
#include <QMap>
#include <QString>
#include "manifest.h"
namespace OOO
{
class Document
{
public:
explicit Document(const QString &fileName);
~Document();
Document(const Document &) = delete;
Document &operator=(const Document &) = delete;
bool open(const QString &password);
QString lastErrorString() const;
QByteArray content() const;
QByteArray meta() const;
QByteArray styles() const;
QMap<QString, QByteArray> images() const;
bool anyFileEncrypted() const;
private:
void setError(const QString &);
QString mFileName;
QByteArray mContent;
QByteArray mMeta;
QByteArray mStyles;
QMap<QString, QByteArray> mImages;
Manifest *mManifest;
QString mErrorString;
bool mAnyEncrypted;
};
}
#endif
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 "formatproperty.h"
#include <QTextFormat>
#include "styleinformation.h"
using namespace OOO;
FontFormatProperty::FontFormatProperty()
: mFamily(QStringLiteral("Nimbus Sans L"))
{
}
void FontFormatProperty::apply(QTextFormat *format) const
{
format->setProperty(QTextFormat::FontFamily, mFamily);
}
void FontFormatProperty::setFamily(const QString &name)
{
mFamily = name;
}
ParagraphFormatProperty::ParagraphFormatProperty()
: mPageNumber(0)
, mWritingMode(LRTB)
, mAlignment(Qt::AlignLeft)
, mHasAlignment(false)
{
}
void ParagraphFormatProperty::apply(QTextFormat *format) const
{
if (mWritingMode == LRTB || mWritingMode == TBLR || mWritingMode == LR || mWritingMode == TB)
format->setLayoutDirection(Qt::LeftToRight);
else
format->setLayoutDirection(Qt::RightToLeft);
if (mHasAlignment) {
static_cast<QTextBlockFormat *>(format)->setAlignment(mAlignment);
}
format->setProperty(QTextFormat::FrameWidth, 595);
static_cast<QTextBlockFormat *>(format)->setLeftMargin(mLeftMargin);
if (mBackgroundColor.isValid())
format->setBackground(mBackgroundColor);
}
void ParagraphFormatProperty::setPageNumber(int number)
{
mPageNumber = number;
}
void ParagraphFormatProperty::setWritingMode(WritingMode mode)
{
mWritingMode = mode;
}
bool ParagraphFormatProperty::writingModeIsRightToLeft() const
{
return ((mWritingMode == RLTB) || (mWritingMode == TBRL) || (mWritingMode == RL));
}
void ParagraphFormatProperty::setTextAlignment(Qt::Alignment alignment)
{
mHasAlignment = true;
mAlignment = alignment;
}
void ParagraphFormatProperty::setBackgroundColor(const QColor &color)
{
mBackgroundColor = color;
}
void ParagraphFormatProperty::setLeftMargin(const qreal margin)
{
mLeftMargin = margin;
}
TextFormatProperty::TextFormatProperty()
: mStyleInformation(nullptr)
, mHasFontSize(false)
, mFontWeight(-1)
, mFontStyle(-1)
, mTextPosition(0)
{
}
TextFormatProperty::TextFormatProperty(const StyleInformation *information)
: mStyleInformation(information)
, mHasFontSize(false)
, mFontWeight(-1)
, mFontStyle(-1)
, mTextPosition(0)
{
}
void TextFormatProperty::apply(QTextCharFormat *format) const
{
if (!mFontName.isEmpty()) {
if (mStyleInformation) {
const FontFormatProperty property = mStyleInformation->fontProperty(mFontName);
property.apply(format);
}
}
if (mFontWeight != -1) {
QFont font = format->font();
font.setWeight(mFontWeight);
format->setFont(font);
}
if (mHasFontSize) {
QFont font = format->font();
font.setPointSize(mFontSize);
format->setFont(font);
}
if (mFontStyle != -1) {
QFont font = format->font();
font.setStyle((QFont::Style)mFontStyle);
format->setFont(font);
}
if (mColor.isValid())
format->setForeground(mColor);
if (mBackgroundColor.isValid())
format->setBackground(mBackgroundColor);
// TODO: get FontFormatProperty and apply it
// TODO: how to set the base line?!?
}
void TextFormatProperty::setFontSize(int size)
{
mHasFontSize = true;
mFontSize = size;
}
void TextFormatProperty::setFontName(const QString &name)
{
mFontName = name;
}
void TextFormatProperty::setFontWeight(int weight)
{
mFontWeight = weight;
}
void TextFormatProperty::setFontStyle(int style)
{
mFontStyle = style;
}
void TextFormatProperty::setTextPosition(int position)
{
mTextPosition = position;
}
void TextFormatProperty::setColor(const QColor &color)
{
mColor = color;
}
void TextFormatProperty::setBackgroundColor(const QColor &color)
{
mBackgroundColor = color;
}
StyleFormatProperty::StyleFormatProperty()
: mStyleInformation(nullptr)
, mDefaultStyle(false)
{
}
StyleFormatProperty::StyleFormatProperty(const StyleInformation *information)
: mStyleInformation(information)
, mDefaultStyle(false)
{
}
void StyleFormatProperty::applyBlock(QTextBlockFormat *format) const
{
if (!mDefaultStyle && !mFamily.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mFamily);
property.applyBlock(format);
}
if (!mParentStyleName.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mParentStyleName);
property.applyBlock(format);
}
mParagraphFormat.apply(format);
}
void StyleFormatProperty::applyText(QTextCharFormat *format) const
{
if (!mDefaultStyle && !mFamily.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mFamily);
property.applyText(format);
}
if (!mParentStyleName.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mParentStyleName);
property.applyText(format);
}
mTextFormat.apply(format);
}
void StyleFormatProperty::applyTableColumn(QTextTableFormat *format) const
{
if (!mDefaultStyle && !mFamily.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mFamily);
property.applyTableColumn(format);
}
if (!mParentStyleName.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mParentStyleName);
property.applyTableColumn(format);
}
mTableColumnFormat.apply(format);
}
void StyleFormatProperty::applyTableCell(QTextBlockFormat *format) const
{
if (!mDefaultStyle && !mFamily.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mFamily);
property.applyTableCell(format);
}
if (!mParentStyleName.isEmpty() && mStyleInformation) {
const StyleFormatProperty property = mStyleInformation->styleProperty(mParentStyleName);
property.applyTableCell(format);
}
mTableCellFormat.apply(format);
}
void StyleFormatProperty::setParentStyleName(const QString &parentStyleName)
{
mParentStyleName = parentStyleName;
}
QString StyleFormatProperty::parentStyleName() const
{
return mParentStyleName;
}
void StyleFormatProperty::setFamily(const QString &family)
{
mFamily = family;
}
void StyleFormatProperty::setDefaultStyle(bool defaultStyle)
{
mDefaultStyle = defaultStyle;
}
void StyleFormatProperty::setMasterPageName(const QString &masterPageName)
{
mMasterPageName = masterPageName;
}
void StyleFormatProperty::setParagraphFormat(const ParagraphFormatProperty &format)
{
mParagraphFormat = format;
}
void StyleFormatProperty::setTextFormat(const TextFormatProperty &format)
{
mTextFormat = format;
}