Commit 55c67162 authored by Gustavo Carneiro's avatar Gustavo Carneiro Committed by Tomaz Canabrava
Browse files

Remove profile dependency in decoders.

parent 3afa3482
......@@ -113,7 +113,7 @@ void SaveHistoryTask::execute()
if (((dialog->selectedNameFilter()).contains(QLatin1String("html"), Qt::CaseInsensitive)) ||
((dialog->selectedFiles()).at(0).endsWith(QLatin1String("html"), Qt::CaseInsensitive))) {
Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
jobInfo.decoder = new HTMLDecoder(profile);
jobInfo.decoder = new HTMLDecoder(profile->colorScheme(), profile->font());
} else {
jobInfo.decoder = new PlainTextDecoder();
}
......
......@@ -13,26 +13,30 @@
// Qt
#include <QTextStream>
#include <QFont>
using namespace Konsole;
HTMLDecoder::HTMLDecoder(const QExplicitlySharedDataPointer<Profile> &profile) :
_output(nullptr)
, _profile(profile)
HTMLDecoder::HTMLDecoder(const QString &colorSchemeName, const QFont &profileFont)
: _output(nullptr)
, _colorSchemeName(colorSchemeName)
, _profileFont(profileFont)
, _innerSpanOpen(false)
, _lastRendition(DEFAULT_RENDITION)
, _lastForeColor(CharacterColor())
, _lastBackColor(CharacterColor())
, _validProfile(false)
{
const ColorScheme *colorScheme = nullptr;
if (profile) {
colorScheme = ColorSchemeManager::instance()->findColorScheme(profile->colorScheme());
if (!colorSchemeName.isEmpty()) {
colorScheme = ColorSchemeManager::instance()->findColorScheme(colorSchemeName);
if (colorScheme == nullptr) {
colorScheme = ColorSchemeManager::instance()->defaultColorScheme();
}
_validProfile = true;
}
if (colorScheme != nullptr) {
......@@ -49,17 +53,16 @@ void HTMLDecoder::begin(QTextStream* output)
_output = output;
if (_profile) {
if (_validProfile) {
QString style;
QFont font = _profile->font();
style.append(QStringLiteral("font-family:'%1',monospace;").arg(font.family()));
style.append(QStringLiteral("font-family:'%1',monospace;").arg(_profileFont.family()));
// Prefer point size if set
if (font.pointSizeF() > 0) {
style.append(QStringLiteral("font-size:%1pt;").arg(font.pointSizeF()));
if (_profileFont.pointSizeF() > 0) {
style.append(QStringLiteral("font-size:%1pt;").arg(_profileFont.pointSizeF()));
} else {
style.append(QStringLiteral("font-size:%1px;").arg(font.pixelSize()));
style.append(QStringLiteral("font-size:%1px;").arg(_profileFont.pixelSize()));
}
......@@ -78,7 +81,7 @@ void HTMLDecoder::end()
{
Q_ASSERT(_output);
if (_profile) {
if (_validProfile) {
*_output << QStringLiteral("</body>");
} else {
QString text;
......@@ -90,8 +93,7 @@ void HTMLDecoder::end()
}
//TODO: Support for LineProperty (mainly double width , double height)
void HTMLDecoder::decodeLine(const Character* const characters, int count, LineProperty /*properties*/
)
void HTMLDecoder::decodeLine(const Character* const characters, int count, LineProperty /*properties*/)
{
Q_ASSERT(_output);
......@@ -180,6 +182,7 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
*_output << text;
}
void HTMLDecoder::openSpan(QString& text , const QString& style)
{
text.append(QStringLiteral("<span style=\"%1\">").arg(style));
......
......@@ -10,7 +10,8 @@
// Konsole
#include "TerminalCharacterDecoder.h"
#include "profile/Profile.h"
#include <QFont>
class QString;
namespace Konsole
{
......@@ -23,7 +24,7 @@ namespace Konsole
/**
* Constructs an HTML decoder using a default black-on-white color scheme.
*/
explicit HTMLDecoder(const Profile::Ptr &profile = Profile::Ptr());
explicit HTMLDecoder(const QString &colorSchemeName = QString(), const QFont &profileFont = QFont());
void decodeLine(const Character * const characters, int count,
LineProperty properties) override;
......@@ -36,12 +37,14 @@ namespace Konsole
void closeSpan(QString &text);
QTextStream *_output;
Profile::Ptr _profile;
QString _colorSchemeName;
QFont _profileFont;
ColorEntry _colorTable[TABLE_COLORS];
bool _innerSpanOpen;
RenditionFlags _lastRendition;
CharacterColor _lastForeColor;
CharacterColor _lastBackColor;
bool _validProfile;
};
}
......
......@@ -9,7 +9,7 @@
#include "konsoleprivate_export.h"
#include "../decoders/TerminalCharacterDecoder.h"
#include "TerminalCharacterDecoder.h"
class QTextStream;
template<typename> class QList;
......
......@@ -18,7 +18,6 @@
class QTextStream;
namespace Konsole {
class Profile;
/**
* Base class for terminal character decoders
......
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