Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Synchronize std{in,out,err} encoding with Terminal
Browse files Browse the repository at this point in the history
See #11234 #11234
Spin off from #11168 #11168
  • Loading branch information
execjosh authored and ariya committed Apr 29, 2013
1 parent b159144 commit 39bec1c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class Encoding
QString getName() const;
void setEncoding(const QString &encoding);

QTextCodec *getCodec() const;

static const Encoding UTF8;

private:
QTextCodec *getCodec() const;

QTextCodec *m_codec;
static const QByteArray DEFAULT_CODEC_NAME;
};
Expand Down
24 changes: 23 additions & 1 deletion src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QTextCodec>

#include "../env.h"
#include "terminal.h"

System::System(QObject *parent) :
QObject(parent)
Expand Down Expand Up @@ -124,6 +125,8 @@ System::System(QObject *parent) :
m_os.insert("name", "unknown");
m_os.insert("version", "unknown");
#endif

connect(Terminal::instance(), SIGNAL(encodingChanged(QString)), this, SLOT(_onTerminalEncodingChanged(QString)));
}

System::~System()
Expand Down Expand Up @@ -203,10 +206,29 @@ QObject *System::_stdin() {
return m_stdin;
}

// private slots:

void System::_onTerminalEncodingChanged(const QString &encoding)
{
if ((File *)NULL != m_stdin) {
m_stdin->setEncoding(encoding);
}

if ((File *)NULL != m_stdout) {
m_stdout->setEncoding(encoding);
}

if ((File *)NULL != m_stderr) {
m_stderr->setEncoding(encoding);
}
}

// private:

File *System::createFileInstance(QFile *f)
{
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
// Get the Encoding used by the Terminal at this point in time
Encoding e(Terminal::instance()->getEncoding());
QTextCodec *codec = e.getCodec();
return new File(f, codec, this);
}
3 changes: 3 additions & 0 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class System : public QObject
// system.stdin
QObject *_stdin();

private slots:
void _onTerminalEncodingChanged(const QString &encoding);

private:
File *createFileInstance(QFile *f);

Expand Down

0 comments on commit 39bec1c

Please sign in to comment.