Commit 3f1da4d8 authored by Alexander Semke's avatar Alexander Semke
Browse files

[R] parse the mime type 'image' before the type 'octet-stream' is parsed. This...

[R] parse the mime type 'image' before the type 'octet-stream' is parsed. This fixes the showing of PNG files for plot results.
parent 6eb2da85
Pipeline #122410 passed with stage
in 23 minutes and 56 seconds
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2018-2022 Alexander Semke <alexander.semke@web.de>
*/
#include "rexpression.h"
......@@ -11,17 +12,13 @@
#include "epsresult.h"
#include "rsession.h"
#include <QDebug>
#include <KLocalizedString>
#include <QMimeType>
#include <QMimeDatabase>
#include <QFile>
#include <QStringList>
#include <QTextDocument>
RExpression::RExpression( Cantor::Session* session, bool internal ) : Cantor::Expression(session, internal),
m_isHelpRequest(false)
RExpression::RExpression( Cantor::Session* session, bool internal ) : Cantor::Expression(session, internal)
{
}
......@@ -78,18 +75,21 @@ void RExpression::addInformation(const QString& information)
void RExpression::showFilesAsResult(const QStringList& files)
{
qDebug()<<"showing files: "<<files;
foreach(const QString& file, files)
for (const QString& file : files)
{
QMimeType type;
QMimeDatabase db;
type=db.mimeTypeForUrl(QUrl(file));
auto type = db.mimeTypeForUrl(QUrl(file));
qDebug()<<"MimeType: "<<type.name();
if(type.inherits(QLatin1String("application/postscript")))
{
qDebug()<<"it's PostScript";
setResult(new Cantor::EpsResult(QUrl::fromLocalFile(file)));
}
else if (type.name().contains(QLatin1String("image")))
{
setResult(new Cantor::ImageResult(QUrl::fromLocalFile(file)));
setStatus(Cantor::Expression::Done);
}
else if(type.inherits(QLatin1String("text/plain"))
|| type.inherits(QLatin1String("application/x-extension-html"))
||type.inherits(QLatin1String("application/octet-stream")) )
......@@ -125,15 +125,11 @@ void RExpression::showFilesAsResult(const QStringList& files)
else
setResult(new Cantor::TextResult(content));
setStatus(Cantor::Expression::Done);
}else if (type.name().contains(QLatin1String("image")))
{
setResult(new Cantor::ImageResult(QUrl::fromLocalFile(file)));
setStatus(Cantor::Expression::Done);
}
else
{
// File has unsupported mime type, but we suspect, that it is text, so will open the file in Cantor script editor
// Even if it don't text, the script editor can deals with it.
// File has unsupported mime type, but we suspect, that it is text, so we open the file in the script editor
// Even if it's not text, the script editor can deal with it.
setStatus(Cantor::Expression::Done);
const QString& editor = QStandardPaths::findExecutable(QLatin1String("cantor_scripteditor"));
int code = QProcess::execute(editor, QStringList(file));
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2018-2022 Alexander Semke <alexander.semke@web.de>
*/
#ifndef _REXPRESSION_H
......@@ -18,13 +19,14 @@ class RExpression : public Cantor::Expression
void evaluate() override;
void interrupt() override;
void parseOutput(const QString& text);
void parseError(const QString& text);
void showFilesAsResult(const QStringList& files);
void parseOutput(const QString&);
void parseError(const QString&);
void showFilesAsResult(const QStringList&);
void addInformation(const QString&) override;
private:
bool m_isHelpRequest;
bool m_isHelpRequest{false};
};
#endif /* _REXPRESSION_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment