2022-07-24 11:42:29 +02:00
|
|
|
#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;
|
2023-05-14 14:28:11 +02:00
|
|
|
QString content = tsp.process(entireContent).pages.constFirst().content;
|
2022-07-24 11:42:29 +02:00
|
|
|
|
|
|
|
PreviewGeneratorPlainText plainTextGenerator;
|
|
|
|
result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName()));
|
|
|
|
return QSharedPointer<PreviewResult>(result);
|
|
|
|
}
|