Skip to content

Commit

Permalink
Fix Text Encoding to work correctly
Browse files Browse the repository at this point in the history
Issue: 891

Store the name of the codec in the action so when the action is
activated the name can be correctly retrieved.  Storing the offset
requires that the same list be obtained which can introduce bugs such
as this one where the menu was enhanced to be sorted while the offset
was used against the unsorted list.
  • Loading branch information
icefox committed Jul 15, 2010
1 parent 72eb2a7 commit 28d4ad2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/browsermainwindow.cpp
Expand Up @@ -903,7 +903,7 @@ void BrowserMainWindow::aboutToShowTextEncodingMenu()
currentCodec = codecs.indexOf(defaultTextEncoding);

QAction *defaultEncoding = m_viewTextEncodingMenu->addAction(tr("Default"));
defaultEncoding->setData(-1);
defaultEncoding->setData(QString());
defaultEncoding->setCheckable(true);
if (currentCodec == -1)
defaultEncoding->setChecked(true);
Expand All @@ -912,8 +912,8 @@ void BrowserMainWindow::aboutToShowTextEncodingMenu()
for (int i = 0; i < codecs.count(); ++i) {
const QString &codec = codecs.at(i);
QAction *action = m_viewTextEncodingMenu->addAction(codec);
action->setData(i);
action->setCheckable(true);
action->setData(codec);
action->setCheckable(true);
if (currentCodec == i)
action->setChecked(true);
}
Expand All @@ -925,12 +925,11 @@ void BrowserMainWindow::viewTextEncoding(QAction *action)
Q_UNUSED(action);
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
Q_ASSERT(action);
QList<QByteArray> codecs = QTextCodec::availableCodecs();
int offset = action->data().toInt();
if (offset < 0 || offset >= codecs.count())
QWebSettings::globalSettings()->setDefaultTextEncoding(QString());
QString codec = action->data().toString();
if (codec.isEmpty())
QWebSettings::globalSettings()->setDefaultTextEncoding(QString());
else
QWebSettings::globalSettings()->setDefaultTextEncoding(QLatin1String(codecs[offset]));
QWebSettings::globalSettings()->setDefaultTextEncoding(codec);
#endif
}

Expand Down

0 comments on commit 28d4ad2

Please sign in to comment.