gui: Introduce PreviewGeneratorOdt for basic previews of .odt files

This commit is contained in:
Albert S. 2022-07-24 11:42:29 +02:00
父節點 20d42a66a6
當前提交 1aa5ae0ccc
共有 4 個檔案被更改,包括 52 行新增1 行删除

查看文件

@ -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

查看文件

@ -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)
{

查看文件

@ -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
查看文件

@ -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