mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-04-29 16:39:37 -05:00
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.
This commit is contained in:
@@ -57,3 +57,11 @@ QByteArray removeBom(QByteArray& data)
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList toStringList(const QList<QByteArray> list) {
|
||||
QStringList strings;
|
||||
for (const QByteArray &item : list) {
|
||||
strings.append(QString::fromUtf8(item));
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ bool startsWithBom(const QByteArray& data);
|
||||
// with a BOM an empty byte array is returned and the original data is not modified.
|
||||
QByteArray removeBom(QByteArray& data);
|
||||
|
||||
QStringList toStringList(const QList<QByteArray> list);
|
||||
|
||||
#endif
|
||||
|
||||
+9
-3
@@ -25,6 +25,7 @@
|
||||
#include "RemoteDock.h"
|
||||
#include "RemoteDatabase.h"
|
||||
#include "FindReplaceDialog.h"
|
||||
#include "Data.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
@@ -2773,15 +2774,20 @@ void MainWindow::browseDataSetTableEncoding(bool forAllTables)
|
||||
// Ask the user for a new encoding
|
||||
bool ok;
|
||||
QString question;
|
||||
QStringList availableCodecs = toStringList(QTextCodec::availableCodecs());
|
||||
availableCodecs.removeDuplicates();
|
||||
int currentItem = availableCodecs.indexOf(encoding);
|
||||
|
||||
if(forAllTables)
|
||||
question = tr("Please choose a new encoding for all tables.");
|
||||
else
|
||||
question = tr("Please choose a new encoding for this table.");
|
||||
encoding = QInputDialog::getText(this,
|
||||
encoding = QInputDialog::getItem(this,
|
||||
tr("Set encoding"),
|
||||
tr("%1\nLeave the field empty for using the database encoding.").arg(question),
|
||||
QLineEdit::Normal,
|
||||
encoding,
|
||||
availableCodecs,
|
||||
currentItem,
|
||||
true, // editable
|
||||
&ok);
|
||||
|
||||
// Only set the new encoding if the user clicked the OK button
|
||||
|
||||
Reference in New Issue
Block a user