summaryrefslogtreecommitdiffstats
path: root/examples/tools/codecs
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/tools/codecs
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/tools/codecs')
-rw-r--r--examples/tools/codecs/codecs.pro13
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-1.txt6
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-15.txt8
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16.txtbin0 -> 162 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16be.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16le.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-8.txt6
-rw-r--r--examples/tools/codecs/main.cpp51
-rw-r--r--examples/tools/codecs/mainwindow.cpp202
-rw-r--r--examples/tools/codecs/mainwindow.h87
-rw-r--r--examples/tools/codecs/previewform.cpp101
-rw-r--r--examples/tools/codecs/previewform.h79
12 files changed, 553 insertions, 0 deletions
diff --git a/examples/tools/codecs/codecs.pro b/examples/tools/codecs/codecs.pro
new file mode 100644
index 0000000000..097601fa0b
--- /dev/null
+++ b/examples/tools/codecs/codecs.pro
@@ -0,0 +1,13 @@
+HEADERS += mainwindow.h \
+ previewform.h
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ previewform.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/codecs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS encodedfiles codecs.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/codecs
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-1.txt b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
new file mode 100644
index 0000000000..d7fcacae66
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
@@ -0,0 +1,6 @@
+Paulo Coelho: O Gênio e as Rosas
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Walter Moers: Die 13½ Leben des Käpt'n Blaubär
+Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-15.txt b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
new file mode 100644
index 0000000000..be2d83c98d
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
@@ -0,0 +1,8 @@
+Paulo Coelho: O Gênio e as Rosas
+Jean-Pierre Coffe: À table en famille avec 15 ¤ par jour
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Helena Lehecková: T¨ekkiä suomalaisille
+Arthur Rimbaud: ¼uvres complètes
+Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/utf-16.txt b/examples/tools/codecs/encodedfiles/utf-16.txt
new file mode 100644
index 0000000000..371f06f7fa
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16be.txt b/examples/tools/codecs/encodedfiles/utf-16be.txt
new file mode 100644
index 0000000000..d8ae6428bc
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16be.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16le.txt b/examples/tools/codecs/encodedfiles/utf-16le.txt
new file mode 100644
index 0000000000..3779264c7c
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16le.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-8.txt b/examples/tools/codecs/encodedfiles/utf-8.txt
new file mode 100644
index 0000000000..a5e4ae6fa7
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-8.txt
@@ -0,0 +1,6 @@
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: РуÑÑкий
+언어 : 한국어
+言語: 日本語
+Langage : Français
diff --git a/examples/tools/codecs/main.cpp b/examples/tools/codecs/main.cpp
new file mode 100644
index 0000000000..923c1f8514
--- /dev/null
+++ b/examples/tools/codecs/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/tools/codecs/mainwindow.cpp b/examples/tools/codecs/mainwindow.cpp
new file mode 100644
index 0000000000..25eda1d2ba
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "previewform.h"
+
+MainWindow::MainWindow()
+{
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ setCentralWidget(textEdit);
+
+ findCodecs();
+
+ previewForm = new PreviewForm(this);
+ previewForm->setCodecList(codecs);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Codecs"));
+ resize(500, 400);
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot read file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QByteArray data = file.readAll();
+
+ previewForm->setEncodedData(data);
+ if (previewForm->exec())
+ textEdit->setPlainText(previewForm->decodedString());
+ }
+}
+
+void MainWindow::save()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot write file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QAction *action = qobject_cast<QAction *>(sender());
+ QByteArray codecName = action->data().toByteArray();
+
+ QTextStream out(&file);
+ out.setCodec(codecName);
+ out << textEdit->toPlainText();
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Codecs"),
+ tr("The <b>Codecs</b> example demonstrates how to read and write "
+ "files using various encodings."));
+}
+
+void MainWindow::aboutToShowSaveAsMenu()
+{
+ QString currentText = textEdit->toPlainText();
+
+ foreach (QAction *action, saveAsActs) {
+ QByteArray codecName = action->data().toByteArray();
+ QTextCodec *codec = QTextCodec::codecForName(codecName);
+ action->setVisible(codec && codec->canEncode(currentText));
+ }
+}
+
+void MainWindow::findCodecs()
+{
+ QMap<QString, QTextCodec *> codecMap;
+ QRegExp iso8859RegExp("ISO[- ]8859-([0-9]+).*");
+
+ foreach (int mib, QTextCodec::availableMibs()) {
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QString sortKey = codec->name().toUpper();
+ int rank;
+
+ if (sortKey.startsWith("UTF-8")) {
+ rank = 1;
+ } else if (sortKey.startsWith("UTF-16")) {
+ rank = 2;
+ } else if (iso8859RegExp.exactMatch(sortKey)) {
+ if (iso8859RegExp.cap(1).size() == 1)
+ rank = 3;
+ else
+ rank = 4;
+ } else {
+ rank = 5;
+ }
+ sortKey.prepend(QChar('0' + rank));
+
+ codecMap.insert(sortKey, codec);
+ }
+ codecs = codecMap.values();
+}
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ foreach (QTextCodec *codec, codecs) {
+ QString text = tr("%1...").arg(QString(codec->name()));
+
+ QAction *action = new QAction(text, this);
+ action->setData(codec->name());
+ connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ saveAsActs.append(action);
+ }
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ saveAsMenu = new QMenu(tr("&Save As"), this);
+ foreach (QAction *action, saveAsActs)
+ saveAsMenu->addAction(action);
+ connect(saveAsMenu, SIGNAL(aboutToShow()),
+ this, SLOT(aboutToShowSaveAsMenu()));
+
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addMenu(saveAsMenu);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addSeparator();
+ menuBar()->addMenu(helpMenu);
+}
diff --git a/examples/tools/codecs/mainwindow.h b/examples/tools/codecs/mainwindow.h
new file mode 100644
index 0000000000..9a59e27310
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+class PreviewForm;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ void save();
+ void about();
+ void aboutToShowSaveAsMenu();
+
+private:
+ void findCodecs();
+ void createActions();
+ void createMenus();
+
+ QTextEdit *textEdit;
+ PreviewForm *previewForm;
+ QList<QTextCodec *> codecs;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QMenu *saveAsMenu;
+ QAction *openAct;
+ QList<QAction *> saveAsActs;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/tools/codecs/previewform.cpp b/examples/tools/codecs/previewform.cpp
new file mode 100644
index 0000000000..523be6cb0f
--- /dev/null
+++ b/examples/tools/codecs/previewform.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "previewform.h"
+
+PreviewForm::PreviewForm(QWidget *parent)
+ : QDialog(parent)
+{
+ encodingComboBox = new QComboBox;
+
+ encodingLabel = new QLabel(tr("&Encoding:"));
+ encodingLabel->setBuddy(encodingComboBox);
+
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ textEdit->setReadOnly(true);
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(encodingComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateTextEdit()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(encodingLabel, 0, 0);
+ mainLayout->addWidget(encodingComboBox, 0, 1);
+ mainLayout->addWidget(textEdit, 1, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Choose Encoding"));
+ resize(400, 300);
+}
+
+void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
+{
+ encodingComboBox->clear();
+ foreach (QTextCodec *codec, list)
+ encodingComboBox->addItem(codec->name(), codec->mibEnum());
+}
+
+void PreviewForm::setEncodedData(const QByteArray &data)
+{
+ encodedData = data;
+ updateTextEdit();
+}
+
+void PreviewForm::updateTextEdit()
+{
+ int mib = encodingComboBox->itemData(
+ encodingComboBox->currentIndex()).toInt();
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QTextStream in(&encodedData);
+ in.setAutoDetectUnicode(false);
+ in.setCodec(codec);
+ decodedStr = in.readAll();
+
+ textEdit->setPlainText(decodedStr);
+}
diff --git a/examples/tools/codecs/previewform.h b/examples/tools/codecs/previewform.h
new file mode 100644
index 0000000000..21a2e13722
--- /dev/null
+++ b/examples/tools/codecs/previewform.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PREVIEWFORM_H
+#define PREVIEWFORM_H
+
+#include <QDialog>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QLabel;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class PreviewForm : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PreviewForm(QWidget *parent = 0);
+
+ void setCodecList(const QList<QTextCodec *> &list);
+ void setEncodedData(const QByteArray &data);
+ QString decodedString() const { return decodedStr; }
+
+private slots:
+ void updateTextEdit();
+
+private:
+ QByteArray encodedData;
+ QString decodedStr;
+
+ QComboBox *encodingComboBox;
+ QLabel *encodingLabel;
+ QTextEdit *textEdit;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif