quick/preview_main.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "QuickNetworkDenial.h" | ||
| 2 | #include "../../tests/quick/PreviewFixture.h" | ||
| 3 | #include <QGuiApplication> | ||
| 4 | #include <QCommandLineParser> | ||
| 5 | #include <QTranslator> | ||
| 6 | #include "presentation/WorkspacePersistence.h" | ||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | ✗ | int main(int argc, char **argv) { | |
| 10 | ✗ | QGuiApplication app(argc, argv); | |
| 11 | ✗ | QCoreApplication::setApplicationName(QStringLiteral("mailjd-quick-preview")); | |
| 12 | ✗ | QCoreApplication::setOrganizationName(QStringLiteral("MailJD-Design")); | |
| 13 | ✗ | Q_INIT_RESOURCE(precision_ui); | |
| 14 | ✗ | QCommandLineParser parser; | |
| 15 | ✗ | parser.setApplicationDescription(QStringLiteral("Interactive design preview with fictional data; no accounts or network.")); | |
| 16 | ✗ | parser.addHelpOption(); | |
| 17 | ✗ | parser.addOption({QStringLiteral("dark"), QStringLiteral("Start with the dark theme")}); | |
| 18 | ✗ | parser.addOption({QStringLiteral("wide"), QStringLiteral("Start with the wide layout")}); | |
| 19 | ✗ | parser.addOption({QStringLiteral("state-directory"), QStringLiteral("Opt-in isolated directory for local preview preferences and tabs"), QStringLiteral("directory")}); | |
| 20 | ✗ | parser.addOption({QStringLiteral("language"), QStringLiteral("Interface language: en or de"), QStringLiteral("language"), QStringLiteral("en")}); | |
| 21 | ✗ | parser.process(app); | |
| 22 | ✗ | QTranslator translator; | |
| 23 | ✗ | if (parser.value(QStringLiteral("language")) == "de") { | |
| 24 | ✗ | if (!translator.load(QStringLiteral(":/translations/mailjd_de.qm"))) return 2; | |
| 25 | ✗ | app.installTranslator(&translator); | |
| 26 | } | ||
| 27 | ✗ | std::unique_ptr<WorkspacePersistence> persistence; | |
| 28 | ✗ | bool restored = true; | |
| 29 | ✗ | PreviewFixture fixture([&](WorkspaceState &workspace, DesignTokens &tokens) { | |
| 30 | ✗ | if (parser.isSet(QStringLiteral("state-directory"))) { | |
| 31 | ✗ | persistence = std::make_unique<WorkspacePersistence>(parser.value(QStringLiteral("state-directory")), workspace, tokens); | |
| 32 | ✗ | restored = persistence->load({}, [](const MailId &id) { | |
| 33 | ✗ | return id.accountId == "preview@example.test" && id.folderId == 17 && | |
| 34 | ✗ | id.uid >= 9007199254740993LL && id.uid < 9007199254741025LL; | |
| 35 | }); | ||
| 36 | ✗ | if (!restored) qCritical().noquote() << persistence->error(); | |
| 37 | ✗ | QObject::connect(persistence.get(), &WorkspacePersistence::saveFailed, &app, | |
| 38 | ✗ | [](const QString &error) { qWarning().noquote() << error; }); | |
| 39 | } | ||
| 40 | ✗ | if (parser.isSet(QStringLiteral("dark"))) tokens.setTheme(QStringLiteral("dark")); | |
| 41 | ✗ | if (parser.isSet(QStringLiteral("wide"))) workspace.setLayout(QStringLiteral("wide")); | |
| 42 | ✗ | }); | |
| 43 | ✗ | if (!restored) return 3; | |
| 44 | ✗ | if (!fixture.window) return 1; | |
| 45 | ✗ | const int result = app.exec(); | |
| 46 | ✗ | const bool saved = !persistence || persistence->flush(); | |
| 47 | ✗ | persistence.reset(); | |
| 48 | ✗ | return saved ? result : 3; | |
| 49 | ✗ | } | |
| 50 |