/** * @RDE_HEADER@ * Main entry for thp viewer * $Id$ * $HeadURL$ * $Author$ */ #include #include #include #include #include #include #include #include "thp_viewer.h" #include #include #ifdef Q_OS_WIN # include #endif class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser { public: CmdLineParser() : LtsCommandLineParser(ProvideCommandLineParameterOptions::None) { addOption({{QStringLiteral("l"), QStringLiteral("lang")}, QStringLiteral("Language iso code to use (de_DE, en_GB, en_US)"), QStringLiteral("") }); addOption({{QStringLiteral("t"), QStringLiteral("alwaysontop")}, QStringLiteral("Set as always on top window") }); } bool useAsAlwaysOnTop() const { return isSet(QStringLiteral("t")); } QString langIsoCode() const { return value(QStringLiteral("l")); } }; int main(int argc, char **argv) { QNetworkProxy::setApplicationProxy(QNetworkProxy()); NGLSingleApplication app(argc, argv); app.createLogger("THP", "log4cxx_thp_viewer.props"); app.setOrganizationName(QStringLiteral("RME")); app.setApplicationName(QStringLiteral("thp_viewer")); app.setAttribute(Qt::AA_UseHighDpiPixmaps); QDir::setSearchPaths(QLatin1String("icon"), QStringList(QLatin1String(":/style/"))); Q_INIT_RESOURCE(rme_light_style); // Parse Options CmdLineParser options; if (!options.init()) return -1; // Set Translation QString langIsoCode = options.langIsoCode(); if (langIsoCode.isEmpty()) langIsoCode = QLocale::system().name(); NGL::setTranslationLocale(langIsoCode.toLatin1()); //check for optional alyways on top flag bool alwaysOnTop = options.useAsAlwaysOnTop(); QString index; const QStringList args = options.positionalArguments(); // QString searchDir = QCoreApplication::applicationDirPath(); QString searchDir(QDir::currentPath()); if (args.count() == 1) { QFileInfo fi(args.first()); if (fi.isDir()) searchDir = fi.absolutePath(); else index = fi.absoluteFilePath(); } if (index.isEmpty()) { const auto indexFiles = { QStringLiteral("index_%1.html").arg(langIsoCode), QStringLiteral("index.html") }; for (const QString &indexFile : indexFiles) { QDir d(searchDir); index = d.absoluteFilePath(indexFile); while (!d.exists(index)) { if (!d.cdUp()) break; index = d.absoluteFilePath(indexFile); } if (d.exists(index)) break; } } QFileInfo fi(index); QString basePath = fi.path() + QLatin1Char('/'); if (!fi.exists() || !fi.isFile()) { fprintf(stderr, "%s basePath=%s\n", argv[0], basePath.toStdString().c_str()); QMessageBox::critical(nullptr, QObject::tr("File missing"), QObject::tr("Could not find a valid index.html - aborting")); return -1; } index = fi.absoluteFilePath(); if (app.sendMessage(index)) return 0; int ret = 1; { QString splashfile = basePath; static const auto extension = {QStringLiteral("gif"), QStringLiteral("jpg"), QStringLiteral("png")}; for (const auto &ext : extension) { const QString fn = splashfile + QStringLiteral("/wappen.") + ext; if (!QFile::exists(fn)) continue; splashfile = fn; break; } const QPixmap splashPixmap(splashfile); QSplashScreen splash((splashPixmap)); if (!splashPixmap.isNull()) splash.show(); #ifdef BUILD_STATIC_LIBRARIES Q_INIT_RESOURCE(libsymbol); Q_INIT_RESOURCE(nglresources); #endif NGL::ThpViewer view(QUrl::fromLocalFile(index)); if (alwaysOnTop) { view.setWindowFlag(Qt::WindowStaysOnTopHint, true); view.setWindowFlag(Qt::WindowMinimizeButtonHint, false); } if (!view.init()) return ret; view.center(); QObject::connect(&app, &NGLSingleApplication::messageReceived, &view, &NGL::ThpViewer::onNewThp); view.show(); splash.finish(&view); ret = app.exec(); } return ret; }