diff options
author | louib <code@louib.net> | 2020-10-09 05:48:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 05:48:45 +0300 |
commit | 48d9fb3e796af368f2cf611136b3ab6fbc2bcae4 (patch) | |
tree | 0cbabcb8e0730ad3f5e1e8a9d235e0d8b309874e /src | |
parent | fb87b1c794f7e297ed42111514a0347d3f30151a (diff) |
Remove GUI bootstraping from core/ (#5513)
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/keepassxc-cli.cpp | 3 | ||||
-rw-r--r-- | src/core/Bootstrap.cpp | 54 | ||||
-rw-r--r-- | src/core/Bootstrap.h | 6 | ||||
-rw-r--r-- | src/gui/Application.cpp | 28 | ||||
-rw-r--r-- | src/gui/Application.h | 4 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 35 | ||||
-rw-r--r-- | src/gui/MainWindow.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 11 |
8 files changed, 72 insertions, 72 deletions
diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 2f8294446..e55766eaa 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ #include "Utils.h" #include "config-keepassx.h" #include "core/Bootstrap.h" +#include "core/Metadata.h" #include "core/Tools.h" #include "crypto/Crypto.h" diff --git a/src/core/Bootstrap.cpp b/src/core/Bootstrap.cpp index cdf5e334a..4845ef0b1 100644 --- a/src/core/Bootstrap.cpp +++ b/src/core/Bootstrap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ #include "config-keepassx.h" #include "core/Config.h" #include "core/Translator.h" -#include "gui/MessageBox.h" #ifdef Q_OS_WIN #include <aclapi.h> // for createWindowsDACL() @@ -73,59 +72,8 @@ namespace Bootstrap setupSearchPaths(); applyEarlyQNetworkAccessManagerWorkaround(); - } - /** - * Perform early application bootstrapping such as setting up search paths, - * configuration OS security properties, and loading translators. - * A QApplication object has to be instantiated before calling this function. - */ - void bootstrapApplication() - { - bootstrap(); Translator::installTranslators(); - -#ifdef Q_OS_WIN - // Qt on Windows uses "MS Shell Dlg 2" as the default font for many widgets, which resolves - // to Tahoma 8pt, whereas the correct font would be "Segoe UI" 9pt. - // Apparently, some widgets are already using the correct font. Thanks, MuseScore for this neat fix! - QApplication::setFont(QApplication::font("QMessageBox")); -#endif - - MessageBox::initializeButtonDefs(); - -#ifdef Q_OS_MACOS - // Don't show menu icons on OSX - QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); -#endif - } - - /** - * Restore the main window's state after launch - * - * @param mainWindow the main window whose state to restore - */ - void restoreMainWindowState(MainWindow& mainWindow) - { - // start minimized if configured - if (config()->get(Config::GUI_MinimizeOnStartup).toBool()) { - mainWindow.hideWindow(); - } else { - mainWindow.bringToFront(); - } - - if (config()->get(Config::OpenPreviousDatabasesOnStartup).toBool()) { - const QStringList fileNames = config()->get(Config::LastOpenedDatabases).toStringList(); - for (const QString& filename : fileNames) { - if (!filename.isEmpty() && QFile::exists(filename)) { - mainWindow.openDatabase(filename); - } - } - auto lastActiveFile = config()->get(Config::LastActiveDatabase).toString(); - if (!lastActiveFile.isEmpty()) { - mainWindow.openDatabase(lastActiveFile); - } - } } // LCOV_EXCL_START diff --git a/src/core/Bootstrap.h b/src/core/Bootstrap.h index de1a4d836..9ec0c5dc8 100644 --- a/src/core/Bootstrap.h +++ b/src/core/Bootstrap.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,13 +18,9 @@ #ifndef KEEPASSXC_BOOTSTRAP_H #define KEEPASSXC_BOOTSTRAP_H -#include "gui/MainWindow.h" - namespace Bootstrap { void bootstrap(); - void bootstrapApplication(); - void restoreMainWindowState(MainWindow& mainWindow); void disableCoreDumps(); bool createWindowsDACL(); void setupSearchPaths(); diff --git a/src/gui/Application.cpp b/src/gui/Application.cpp index 2d48ee741..060e86ee1 100644 --- a/src/gui/Application.cpp +++ b/src/gui/Application.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2012 Tobias Tangemann * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +20,11 @@ #include "Application.h" #include "autotype/AutoType.h" +#include "core/Bootstrap.h" #include "core/Config.h" #include "core/Global.h" #include "gui/MainWindow.h" +#include "gui/MessageBox.h" #include "gui/osutils/OSUtils.h" #include "gui/styles/dark/DarkStyle.h" #include "gui/styles/light/LightStyle.h" @@ -142,6 +144,30 @@ Application::~Application() } } +/** + * Perform early application bootstrapping such as setting up search paths, + * configuration OS security properties, and loading translators. + * A QApplication object has to be instantiated before calling this function. + */ +void Application::bootstrap() +{ + Bootstrap::bootstrap(); + +#ifdef Q_OS_WIN + // Qt on Windows uses "MS Shell Dlg 2" as the default font for many widgets, which resolves + // to Tahoma 8pt, whereas the correct font would be "Segoe UI" 9pt. + // Apparently, some widgets are already using the correct font. Thanks, MuseScore for this neat fix! + QApplication::setFont(QApplication::font("QMessageBox")); +#endif + + MessageBox::initializeButtonDefs(); + +#ifdef Q_OS_MACOS + // Don't show menu icons on OSX + QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); +#endif +} + void Application::applyTheme() { auto appTheme = config()->get(Config::GUI_ApplicationTheme).toString(); diff --git a/src/gui/Application.h b/src/gui/Application.h index 9f694f8c3..62095658e 100644 --- a/src/gui/Application.h +++ b/src/gui/Application.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2012 Tobias Tangemann * Copyright (C) 2012 Felix Geyer <debfx@fobos.de> - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,8 @@ public: Application(int& argc, char** argv); ~Application() override; + static void bootstrap(); + void applyTheme(); bool event(QEvent* event) override; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index bf6c1f1ae..e87cebce4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Felix Geyer <debfx@fobos.de> - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -597,12 +597,45 @@ MainWindow::MainWindow() config()->set(Config::Messages_Qt55CompatibilityWarning, true); } #endif + + QObject::connect(qApp, SIGNAL(anotherInstanceStarted()), this, SLOT(bringToFront())); + QObject::connect(qApp, SIGNAL(applicationActivated()), this, SLOT(bringToFront())); + QObject::connect(qApp, SIGNAL(openFile(QString)), this, SLOT(openDatabase(QString))); + QObject::connect(qApp, SIGNAL(quitSignalReceived()), this, SLOT(appExit()), Qt::DirectConnection); + + restoreConfigState(); } MainWindow::~MainWindow() { } +/** + * Restore the main window's state after launch + */ +void MainWindow::restoreConfigState() +{ + // start minimized if configured + if (config()->get(Config::GUI_MinimizeOnStartup).toBool()) { + hideWindow(); + } else { + bringToFront(); + } + + if (config()->get(Config::OpenPreviousDatabasesOnStartup).toBool()) { + const QStringList fileNames = config()->get(Config::LastOpenedDatabases).toStringList(); + for (const QString& filename : fileNames) { + if (!filename.isEmpty() && QFile::exists(filename)) { + openDatabase(filename); + } + } + auto lastActiveFile = config()->get(Config::LastActiveDatabase).toString(); + if (!lastActiveFile.isEmpty()) { + openDatabase(lastActiveFile); + } + } +} + QList<DatabaseWidget*> MainWindow::getOpenDatabases() { QList<DatabaseWidget*> dbWidgets; diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index a69fb5343..f09b0ea80 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Felix Geyer <debfx@fobos.de> - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +49,7 @@ public: ~MainWindow(); QList<DatabaseWidget*> getOpenDatabases(); + void restoreConfigState(); enum StackedWidgetIndex { diff --git a/src/main.cpp b/src/main.cpp index b88dc41e0..ebbd7dc22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Felix Geyer <debfx@fobos.de> - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2020 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,6 @@ #include "cli/Utils.h" #include "config-keepassx.h" -#include "core/Bootstrap.h" #include "core/Config.h" #include "core/Tools.h" #include "crypto/Crypto.h" @@ -112,7 +111,7 @@ int main(int argc, char** argv) QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop")); #endif - Bootstrap::bootstrapApplication(); + Application::bootstrap(); if (!Crypto::init()) { QString error = QObject::tr("Fatal error while testing the cryptographic functions."); @@ -132,12 +131,6 @@ int main(int argc, char** argv) } MainWindow mainWindow; - QObject::connect(&app, SIGNAL(anotherInstanceStarted()), &mainWindow, SLOT(bringToFront())); - QObject::connect(&app, SIGNAL(applicationActivated()), &mainWindow, SLOT(bringToFront())); - QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString))); - QObject::connect(&app, SIGNAL(quitSignalReceived()), &mainWindow, SLOT(appExit()), Qt::DirectConnection); - - Bootstrap::restoreMainWindowState(mainWindow); const bool pwstdin = parser.isSet(pwstdinOption); for (const QString& filename : fileNames) { |