-
Notifications
You must be signed in to change notification settings - Fork 15
Port to Qt 6 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Port to Qt 6 #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,5 @@ | |
| /qtads.pro.user* | ||
| /qrc_resources.cpp | ||
| /.qmake.stash | ||
| .cache | ||
| compile_commands.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| #include "confdialog.h" | ||
|
|
||
| #include "globals.h" | ||
| #include "qstringconverter_base.h" | ||
| #include "settings.h" | ||
| #include "sysframe.h" | ||
| #include "syswingroup.h" | ||
|
|
@@ -10,7 +11,9 @@ | |
| #include <QCheckBox> | ||
| #include <QColorDialog> | ||
| #include <QPushButton> | ||
| #include <QTextCodec> | ||
| #include <QStringConverter> | ||
| #include <QStringDecoder> | ||
| #include <QStringEncoder> | ||
| #include <algorithm> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -40,27 +43,20 @@ ConfDialog::ConfDialog(CHtmlSysWinGroupQt* const parent) | |
| ui->linkClickedColorButton->setFixedSize(macSize); | ||
| #endif | ||
|
|
||
| const auto aliases = QTextCodec::availableCodecs(); | ||
| std::vector<QByteArray> codecs; | ||
| for (const auto& alias : aliases) { | ||
| auto codecName = QTextCodec::codecForName(alias)->name(); | ||
| // Only allow some of the possible sets, otherwise we would get a big | ||
| // list with most of the encodings being irrelevant. The only Unicode | ||
| // encoding we allow is UTF-8, since it's a single-byte character set | ||
| // and therefore can be used by TADS 2 games (though I'm not aware of | ||
| // any that actually use UTF-8.) | ||
| if (codecName == "UTF-8" or codecName.startsWith("windows-") or codecName.startsWith("ISO-") | ||
| or codecName.startsWith("KOI8-") or codecName.startsWith("IBM") | ||
| or codecName.startsWith("EUC-") or codecName.startsWith("jisx020") | ||
| or codecName.startsWith("cp949")) | ||
| { | ||
| codecs.emplace_back(std::move(codecName)); | ||
| } | ||
| } | ||
| std::sort(codecs.begin(), codecs.end()); | ||
| const QStringConverter::Encoding codecs[9]{ | ||
| QStringConverter::Encoding::System, QStringConverter::Encoding::Latin1, | ||
| QStringConverter::Encoding::Utf16, QStringConverter::Encoding::Utf16BE, | ||
| QStringConverter::Encoding::Utf16LE, QStringConverter::Encoding::Utf32, | ||
| QStringConverter::Encoding::Utf32BE, QStringConverter::Encoding::Utf32LE, | ||
| QStringConverter::Encoding::Utf8, | ||
| }; | ||
| for (const auto& codec : codecs) { | ||
| if (ui->encodingComboBox->findText(QString::fromLatin1(codec)) == -1) { | ||
| ui->encodingComboBox->addItem(QString::fromLatin1(codec)); | ||
| if (ui->encodingComboBox->findText( | ||
| QString::fromLatin1(QStringConverter::nameForEncoding(codec))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to ( |
||
| == -1) | ||
| { | ||
| ui->encodingComboBox->addItem( | ||
| QString::fromLatin1(QStringConverter::nameForEncoding(codec))); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,29 +21,63 @@ | |
| auto main(int argc, char** argv) -> int | ||
| { | ||
| CHtmlResType::add_basic_types(); | ||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
| // No need to enable High Dpi scaling because it's always on | ||
| #elif QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
| QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||
| #endif | ||
| CHtmlSysFrameQt* app = new CHtmlSysFrameQt( | ||
| argc, argv, "QTads", QTADS_VERSION, "Nikos Chantziaras", {}); | ||
| CHtmlSysFrameQt* app = | ||
| new CHtmlSysFrameQt(argc, argv, "QTads", QTADS_VERSION, "Nikos Chantziaras", {}); | ||
| #if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0) | ||
| QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); | ||
| #endif | ||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) | ||
| QApplication::setDesktopFileName("nikos.chantziaras.qtads"); | ||
| #endif | ||
|
|
||
| // Filename of the game to run. | ||
| QString gameFileName; | ||
| bool embed = false; | ||
|
|
||
| const QStringList& args = app->arguments(); | ||
| if (args.size() == 2) { | ||
| if (QFile::exists(args.at(1))) { | ||
| gameFileName = args.at(1); | ||
| } else if (QFile::exists(args.at(1) + ".gam")) { | ||
| gameFileName = args.at(1) + ".gam"; | ||
| } else if (QFile::exists(args.at(1) + ".t3")) { | ||
| gameFileName = args.at(1) + ".t3"; | ||
| } else { | ||
| qWarning() << "File" << args.at(1) << "not found."; | ||
| if (args.size() >= 1) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Replace all of this tedious manual command-line parsing with, #include <QCommandLineParser>
// ...
auto main(int argc, char** argv) -> int {
QString gameFileName;
bool embedOption = false;
// ...
QCommandLineParser parser;
parser.setApplicationDescription("QTads: Interpreter for TADS 2 and 3 game files");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("FILE", "Game file to load");
parser.addOptions({
{{"e", "embed"},
"Print the QTads window ID to stdout on startup (for embedding)"},
});
parser.process(app);
const QStringList args = parser.positionalArguments();
embedOption = parser.isSet("embed");
if (args.length() > 0) {
gameFileName = checkFileName(args.at(0));
if (gameFileName.isEmpty()) {
qWarning() << "File" << args.at(0) << "not found.";
}
}(And a helper auto checkFileName(const QString& input) -> QString {
QStringList fileExtensions;
fileExtensions << QLatin1String("")
<< QStringLiteral(".gam")
<< QStringLiteral(".t3");
for (auto& ext : fileExtensions) {
QString name = input + ext;
if (QFile::exists(name)) {
return name;
}
}
return nullptr;
}Qt will handle processing of $ qtads --help
Usage: qtads [options] FILE
QTads: Interpreter for TADS 2 and 3 game files
Options:
-h, --help Displays help on commandline options.
--help-all Displays help including Qt specific options.
-v, --version Displays version information.
-e, --embed Print the QTads window ID to stdout on startup (for embedding)
Arguments:
FILE Game file to loadThe Windows version will even show the help in a window, if QTads is launched from a script or desktop shortcut with a bad argument, instead of in a shell. |
||
| bool prevNonFlagArgument = false; | ||
|
|
||
| for (int i = 1; i < args.size(); ++i) { | ||
| const auto& arg = args.at(i); | ||
|
|
||
| if (!arg.startsWith("-")) { | ||
| if (prevNonFlagArgument) { | ||
| qWarning() << "It looks like you specified more than one non-flag command-line" | ||
| << "argument at" << arg | ||
| << "but QTADS can only accept one game file, so only the" | ||
| << "first non flag argument will be used."; | ||
| } else if (gameFileName.isNull()) { | ||
| if (QFile::exists(arg)) { | ||
| gameFileName = arg; | ||
| } else if (QFile::exists(arg + ".gam")) { | ||
| gameFileName = arg + ".gam"; | ||
| } else if (QFile::exists(arg + ".t3")) { | ||
| gameFileName = arg + ".t3"; | ||
| } else { | ||
| qWarning() << "File" << arg << "not found."; | ||
| } | ||
| } | ||
|
|
||
| prevNonFlagArgument = true; | ||
| } else if (arg == "--help" || arg == "-h") { | ||
| qInfo() << "qtads [OPTIONS] [FILE]\n" | ||
| << "\t--help\t\tThis help message\n" | ||
| << "\t--embed\t\tPrint out the window id on startup so that qtads can be " | ||
| "embedded\n" | ||
| << "\t-h\t\tSame as --help\n" | ||
| << "\t-e\t\tSame as --embed"; | ||
| } else if (arg == "--embed" || arg == "-e") { | ||
| embed = true; | ||
| } else { | ||
| qWarning() << "Unrecognized command line argument " << arg << "."; | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -60,7 +94,8 @@ auto main(int argc, char** argv) -> int | |
| } | ||
| #endif | ||
|
|
||
| QTimer::singleShot(0, app, [app, gameFileName] { app->entryPoint(gameFileName); }); | ||
| QTimer::singleShot( | ||
| 0, app, [app, embed, gameFileName] { app->entryPoint(gameFileName, embed); }); | ||
| int ret = CHtmlSysFrameQt::exec(); | ||
|
|
||
| delete app; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this list actually makes much sense. As the comment in the removed code said, in the original set only UTF-8 was included (despite even that not being common in practice) because at least TADS 2 has a one-byte-per-character format. So UTF16 is unlikely-to-impossible, and I don't think I've ever seen UTF32-encoded... anything. Anywhere. Ever.
On my (Fedora Linux) system, presumably thanks to the ICU library,
QStringConverter::availableCodecs()produces a list of 233 codecs, pretty much a drop-in replacement forQTextCodec::availableCodecs(). Filtering that list by the same criteria as the old code leaves these 78:That's probably excessive, but OTOH some legacy codecs like
windows-1250,windows-1252,ISO-8859-15, etc. were extremely common in older files, and still come up fairly often even today.