diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/main.cpp b/src/main.cpp index 7e340da4d..b88dc41e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,51 +56,47 @@ int main(int argc, char** argv) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif - Application app(argc, argv); - Application::setApplicationName("KeePassXC"); - Application::setApplicationVersion(KEEPASSXC_VERSION); - app.setProperty("KPXC_QUALIFIED_APPNAME", "org.keepassxc.KeePassXC"); - app.applyTheme(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop")); -#endif - - // don't set organizationName as that changes the return value of - // QStandardPaths::writableLocation(QDesktopServices::DataLocation) - Bootstrap::bootstrapApplication(); - QCommandLineParser parser; parser.setApplicationDescription(QObject::tr("KeePassXC - cross-platform password manager")); parser.addPositionalArgument( - "filename", QObject::tr("filenames of the password databases to open (*.kdbx)"), "[filename(s)]"); + "filename(s)", QObject::tr("filenames of the password databases to open (*.kdbx)"), "[filename(s)]"); QCommandLineOption configOption("config", QObject::tr("path to a custom config file"), "config"); + QCommandLineOption localConfigOption( + "localconfig", QObject::tr("path to a custom local config file"), "localconfig"); QCommandLineOption keyfileOption("keyfile", QObject::tr("key file of the database"), "keyfile"); QCommandLineOption pwstdinOption("pw-stdin", QObject::tr("read password of the database from stdin")); - // This is needed under Windows where clients send --parent-window parameter with Native Messaging connect method - QCommandLineOption parentWindowOption(QStringList() << "pw" - << "parent-window", - QObject::tr("Parent window handle"), - "handle"); QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption versionOption = parser.addVersionOption(); QCommandLineOption debugInfoOption(QStringList() << "debug-info", QObject::tr("Displays debugging information.")); parser.addOption(configOption); + parser.addOption(localConfigOption); parser.addOption(keyfileOption); parser.addOption(pwstdinOption); - parser.addOption(parentWindowOption); parser.addOption(debugInfoOption); + Application app(argc, argv); + // don't set organizationName as that changes the return value of + // QStandardPaths::writableLocation(QDesktopServices::DataLocation) + Application::setApplicationName("KeePassXC"); + Application::setApplicationVersion(KEEPASSXC_VERSION); + app.setProperty("KPXC_QUALIFIED_APPNAME", "org.keepassxc.KeePassXC"); + parser.process(app); - // Don't try and do anything with the application if we're only showing the help / version + // Exit early if we're only showing the help / version if (parser.isSet(versionOption) || parser.isSet(helpOption)) { return EXIT_SUCCESS; } - const QStringList fileNames = parser.positionalArguments(); + // Process config file options early + if (parser.isSet(configOption) || parser.isSet(localConfigOption)) { + Config::createConfigFromFile(parser.value(configOption), parser.value(localConfigOption)); + } + // Process single instance and early exit if already running + const QStringList fileNames = parser.positionalArguments(); if (app.isAlreadyRunning()) { if (!fileNames.isEmpty()) { app.sendFileNamesToRunningInstance(fileNames); @@ -109,7 +105,14 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } - QApplication::setQuitOnLastWindowClosed(false); + // Apply the configured theme before creating any GUI elements + app.applyTheme(); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) + QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop")); +#endif + + Bootstrap::bootstrapApplication(); if (!Crypto::init()) { QString error = QObject::tr("Fatal error while testing the cryptographic functions."); @@ -128,10 +131,6 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } - if (parser.isSet(configOption)) { - Config::createConfigFromFile(parser.value(configOption)); - } - MainWindow mainWindow; QObject::connect(&app, SIGNAL(anotherInstanceStarted()), &mainWindow, SLOT(bringToFront())); QObject::connect(&app, SIGNAL(applicationActivated()), &mainWindow, SLOT(bringToFront())); |