mirror of https://github.com/vitalif/phantomjs
Make `Terminal` emit a signal upon encoding change
See #11234 https://github.com/ariya/phantomjs/pull/11234 Spin off from #11168 https://github.com/ariya/phantomjs/pull/111681.x
parent
c07a2efa33
commit
3d874d9e0d
|
@ -54,9 +54,33 @@ QString Terminal::getEncoding() const
|
||||||
return m_encoding.getName();
|
return m_encoding.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::setEncoding(const QString &encoding)
|
bool Terminal::setEncoding(const QString &encoding)
|
||||||
{
|
{
|
||||||
|
// Since there can be multiple names for the same codec (i.e., "utf8" and
|
||||||
|
// "utf-8"), we need to get the codec in the system first and use its
|
||||||
|
// canonical name
|
||||||
|
QTextCodec *codec = QTextCodec::codecForName(encoding.toAscii());
|
||||||
|
if ((QTextCodec *)NULL == codec) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether encoding actually needs to be changed
|
||||||
|
const QString encodingBeforeUpdate(m_encoding.getName());
|
||||||
|
if (0 == encodingBeforeUpdate.compare(QString(codec->name()), Qt::CaseInsensitive)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_encoding.setEncoding(encoding);
|
m_encoding.setEncoding(encoding);
|
||||||
|
|
||||||
|
// Emit the signal only if the encoding actually was changed
|
||||||
|
const QString encodingAfterUpdate(m_encoding.getName());
|
||||||
|
if (0 == encodingBeforeUpdate.compare(encodingAfterUpdate, Qt::CaseInsensitive)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit encodingChanged(encoding);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::cout(const QString &string, const bool newline) const
|
void Terminal::cout(const QString &string, const bool newline) const
|
||||||
|
|
|
@ -39,15 +39,20 @@
|
||||||
|
|
||||||
class Terminal: public QObject
|
class Terminal: public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Terminal *instance();
|
static Terminal *instance();
|
||||||
|
|
||||||
QString getEncoding() const;
|
QString getEncoding() const;
|
||||||
void setEncoding(const QString &encoding);
|
bool setEncoding(const QString &encoding);
|
||||||
|
|
||||||
void cout(const QString &string, const bool newline = true) const;
|
void cout(const QString &string, const bool newline = true) const;
|
||||||
void cerr(const QString &string, const bool newline = true) const;
|
void cerr(const QString &string, const bool newline = true) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void encodingChanged(const QString &encoding);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void output(std::ostream &out, const QString &string, const bool newline) const;
|
void output(std::ostream &out, const QString &string, const bool newline) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue