Skip to content

Commit 588363b

Browse files
committed
Get the encoding name from a combo box in the "Set encoding" dialog
User can enter the encoding name with completion or select it from the list using the mouse. This will help users to discover available codecs and to find a suitable one in an easier way. This should help with encoding issues like #1453.
1 parent 98f4b88 commit 588363b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/Data.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ QByteArray removeBom(QByteArray& data)
5757
return QByteArray();
5858
}
5959
}
60+
61+
QStringList toStringList(const QList<QByteArray> list) {
62+
QStringList strings;
63+
for (const QByteArray &item : list) {
64+
strings.append(QString::fromUtf8(item));
65+
}
66+
return strings;
67+
}

src/Data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ bool startsWithBom(const QByteArray& data);
1717
// with a BOM an empty byte array is returned and the original data is not modified.
1818
QByteArray removeBom(QByteArray& data);
1919

20+
QStringList toStringList(const QList<QByteArray> list);
21+
2022
#endif

src/MainWindow.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "RemoteDock.h"
2626
#include "RemoteDatabase.h"
2727
#include "FindReplaceDialog.h"
28+
#include "Data.h"
2829

2930
#include <QFile>
3031
#include <QApplication>
@@ -2773,15 +2774,20 @@ void MainWindow::browseDataSetTableEncoding(bool forAllTables)
27732774
// Ask the user for a new encoding
27742775
bool ok;
27752776
QString question;
2777+
QStringList availableCodecs = toStringList(QTextCodec::availableCodecs());
2778+
availableCodecs.removeDuplicates();
2779+
int currentItem = availableCodecs.indexOf(encoding);
2780+
27762781
if(forAllTables)
27772782
question = tr("Please choose a new encoding for all tables.");
27782783
else
27792784
question = tr("Please choose a new encoding for this table.");
2780-
encoding = QInputDialog::getText(this,
2785+
encoding = QInputDialog::getItem(this,
27812786
tr("Set encoding"),
27822787
tr("%1\nLeave the field empty for using the database encoding.").arg(question),
2783-
QLineEdit::Normal,
2784-
encoding,
2788+
availableCodecs,
2789+
currentItem,
2790+
true, // editable
27852791
&ok);
27862792

27872793
// Only set the new encoding if the user clicked the OK button

0 commit comments

Comments
 (0)