gui: Introduce PreviewGeneratorOdt for basic previews of .odt files

This commit is contained in:
Albert S. 2022-07-24 11:42:29 +02:00
parent 20d42a66a6
commit 1aa5ae0ccc
4 changed files with 52 additions and 1 deletions

View File

@ -36,9 +36,11 @@ SOURCES += \
clicklabel.cpp \
previewgenerator.cpp \
previewgeneratormapfunctor.cpp \
previewgeneratorodt.cpp \
previewgeneratorpdf.cpp \
previewgeneratorplaintext.cpp \
previewresult.cpp \
previewresultodt.cpp \
previewresultpdf.cpp \
previewresultplaintext.cpp \
renderconfig.cpp \
@ -54,9 +56,11 @@ HEADERS += \
clicklabel.h \
previewgenerator.h \
previewgeneratormapfunctor.h \
previewgeneratorodt.h \
previewgeneratorpdf.h \
previewgeneratorplaintext.h \
previewresult.h \
previewresultodt.h \
previewresultpdf.h \
previewresultplaintext.h \
renderconfig.h \
@ -66,6 +70,7 @@ FORMS += \
mainwindow.ui
INCLUDEPATH += /usr/include/poppler/qt5/
INCLUDEPATH += /usr/include/quazip5
QT += widgets sql

View File

@ -2,13 +2,15 @@
#include "previewgenerator.h"
#include "previewgeneratorpdf.h"
#include "previewgeneratorplaintext.h"
#include "previewgeneratorodt.h"
static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText();
static QMap<QString, PreviewGenerator *> generators{
{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator}, {"md", plainTextGenerator},
{"py", plainTextGenerator}, {"java", plainTextGenerator}, {"js", plainTextGenerator},
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator}};
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator},
{"odt", new PreviewGeneratorOdt()}};
PreviewGenerator *PreviewGenerator::get(QFileInfo &info)
{

View File

@ -0,0 +1,32 @@
#include <quazip.h>
#include <quazipfile.h>
#include "previewgeneratorplaintext.h"
#include "previewgeneratorodt.h"
#include "previewresultodt.h"
#include "../shared/tagstripperprocessor.h"
QSharedPointer<PreviewResult> PreviewGeneratorOdt::generate(RenderConfig config, QString documentPath,
unsigned int page)
{
PreviewResultOdt *result = new PreviewResultOdt(documentPath, page);
QFileInfo info{documentPath};
QuaZipFile zipFile(documentPath);
zipFile.setFileName("content.xml");
if(!zipFile.open(QIODevice::ReadOnly))
{
return QSharedPointer<PreviewResult>(result);
}
QByteArray entireContent = zipFile.readAll();
if(entireContent.isEmpty())
{
throw LooqsGeneralException("Error while reading content.xml of " + documentPath);
}
TagStripperProcessor tsp;
QString content = tsp.process(entireContent).first().content;
PreviewGeneratorPlainText plainTextGenerator;
result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName()));
return QSharedPointer<PreviewResult>(result);
}

12
gui/previewgeneratorodt.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef PREVIEWGENERATORODT_H
#define PREVIEWGENERATORODT_H
#include "previewgenerator.h"
class PreviewGeneratorOdt : public PreviewGenerator
{
public:
using PreviewGenerator::PreviewGenerator;
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
};
#endif // PREVIEWGENERATORODT_H