Remove GUI bootstraping from core/ (#5513)

This commit is contained in:
louib 2020-10-08 22:48:45 -04:00 committed by GitHub
parent fb87b1c794
commit 48d9fb3e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 83 additions and 82 deletions

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -32,6 +32,7 @@
#include "Utils.h" #include "Utils.h"
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Bootstrap.h" #include "core/Bootstrap.h"
#include "core/Metadata.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -19,7 +19,6 @@
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Translator.h" #include "core/Translator.h"
#include "gui/MessageBox.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <aclapi.h> // for createWindowsDACL() #include <aclapi.h> // for createWindowsDACL()
@ -73,59 +72,8 @@ namespace Bootstrap
setupSearchPaths(); setupSearchPaths();
applyEarlyQNetworkAccessManagerWorkaround(); 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(); 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 // LCOV_EXCL_START

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -18,13 +18,9 @@
#ifndef KEEPASSXC_BOOTSTRAP_H #ifndef KEEPASSXC_BOOTSTRAP_H
#define KEEPASSXC_BOOTSTRAP_H #define KEEPASSXC_BOOTSTRAP_H
#include "gui/MainWindow.h"
namespace Bootstrap namespace Bootstrap
{ {
void bootstrap(); void bootstrap();
void bootstrapApplication();
void restoreMainWindowState(MainWindow& mainWindow);
void disableCoreDumps(); void disableCoreDumps();
bool createWindowsDACL(); bool createWindowsDACL();
void setupSearchPaths(); void setupSearchPaths();

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2012 Tobias Tangemann * Copyright (C) 2012 Tobias Tangemann
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -20,9 +20,11 @@
#include "Application.h" #include "Application.h"
#include "autotype/AutoType.h" #include "autotype/AutoType.h"
#include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Global.h" #include "core/Global.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include "gui/MessageBox.h"
#include "gui/osutils/OSUtils.h" #include "gui/osutils/OSUtils.h"
#include "gui/styles/dark/DarkStyle.h" #include "gui/styles/dark/DarkStyle.h"
#include "gui/styles/light/LightStyle.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() void Application::applyTheme()
{ {
auto appTheme = config()->get(Config::GUI_ApplicationTheme).toString(); auto appTheme = config()->get(Config::GUI_ApplicationTheme).toString();

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2012 Tobias Tangemann * Copyright (C) 2012 Tobias Tangemann
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -41,6 +41,8 @@ public:
Application(int& argc, char** argv); Application(int& argc, char** argv);
~Application() override; ~Application() override;
static void bootstrap();
void applyTheme(); void applyTheme();
bool event(QEvent* event) override; bool event(QEvent* event) override;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de> * 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 * 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 * 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); config()->set(Config::Messages_Qt55CompatibilityWarning, true);
} }
#endif #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() 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*> MainWindow::getOpenDatabases()
{ {
QList<DatabaseWidget*> dbWidgets; QList<DatabaseWidget*> dbWidgets;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -49,6 +49,7 @@ public:
~MainWindow(); ~MainWindow();
QList<DatabaseWidget*> getOpenDatabases(); QList<DatabaseWidget*> getOpenDatabases();
void restoreConfigState();
enum StackedWidgetIndex enum StackedWidgetIndex
{ {

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -22,7 +22,6 @@
#include "cli/Utils.h" #include "cli/Utils.h"
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "crypto/Crypto.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")); QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop"));
#endif #endif
Bootstrap::bootstrapApplication(); Application::bootstrap();
if (!Crypto::init()) { if (!Crypto::init()) {
QString error = QObject::tr("Fatal error while testing the cryptographic functions."); QString error = QObject::tr("Fatal error while testing the cryptographic functions.");
@ -132,12 +131,6 @@ int main(int argc, char** argv)
} }
MainWindow mainWindow; 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); const bool pwstdin = parser.isSet(pwstdinOption);
for (const QString& filename : fileNames) { for (const QString& filename : fileNames) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019 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 * 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 * it under the terms of the GNU General Public License as published by
@ -20,7 +20,10 @@
#include "config-keepassx-tests.h" #include "config-keepassx-tests.h"
#include "core/Bootstrap.h" #include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Entry.h"
#include "core/Global.h" #include "core/Global.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
#include "keys/drivers/YubiKey.h" #include "keys/drivers/YubiKey.h"
@ -65,7 +68,7 @@ void TestCli::initTestCase()
QVERIFY(Crypto::init()); QVERIFY(Crypto::init());
Config::createTempFileInstance(); Config::createTempFileInstance();
Bootstrap::bootstrapApplication(); Bootstrap::bootstrap();
auto fd = new QFile(); auto fd = new QFile();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -39,7 +39,6 @@
#include <QToolButton> #include <QToolButton>
#include "config-keepassx-tests.h" #include "config-keepassx-tests.h"
#include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Database.h" #include "core/Database.h"
#include "core/Entry.h" #include "core/Entry.h"
@ -118,7 +117,7 @@ void TestGui::initTestCase()
// Disable the update check first time alert // Disable the update check first time alert
config()->set(Config::UpdateCheckMessageShown, true); config()->set(Config::UpdateCheckMessageShown, true);
Bootstrap::bootstrapApplication(); Application::bootstrap();
m_mainWindow.reset(new MainWindow()); m_mainWindow.reset(new MainWindow());
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de> * Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2019 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 * 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 * it under the terms of the GNU General Public License as published by
@ -33,7 +33,6 @@
#include "browser/BrowserService.h" #include "browser/BrowserService.h"
#include "config-keepassx-tests.h" #include "config-keepassx-tests.h"
#include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Database.h" #include "core/Database.h"
#include "core/Entry.h" #include "core/Entry.h"
@ -81,7 +80,6 @@ void TestGuiBrowser::initTestCase()
config()->set(Config::UpdateCheckMessageShown, true); config()->set(Config::UpdateCheckMessageShown, true);
m_mainWindow.reset(new MainWindow()); m_mainWindow.reset(new MainWindow());
Bootstrap::restoreMainWindowState(*m_mainWindow);
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
m_mainWindow->show(); m_mainWindow->show();
} }

View File

@ -29,13 +29,14 @@
#include "TestGlobal.h" #include "TestGlobal.h"
#include "config-keepassx-tests.h" #include "config-keepassx-tests.h"
#include "core/Bootstrap.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
#include "gui/Application.h"
#include "gui/DatabaseTabWidget.h" #include "gui/DatabaseTabWidget.h"
#include "gui/DatabaseWidget.h" #include "gui/DatabaseWidget.h"
#include "gui/FileDialog.h" #include "gui/FileDialog.h"
#include "gui/MainWindow.h"
#include "gui/MessageBox.h" #include "gui/MessageBox.h"
#include "gui/wizard/NewDatabaseWizard.h" #include "gui/wizard/NewDatabaseWizard.h"
#include "util/TemporaryFile.h" #include "util/TemporaryFile.h"
@ -195,7 +196,7 @@ void TestGuiFdoSecrets::initTestCase()
// activate within individual tests // activate within individual tests
FdoSecrets::settings()->setShowNotification(false); FdoSecrets::settings()->setShowNotification(false);
Bootstrap::bootstrapApplication(); Application::bootstrap();
m_mainWindow.reset(new MainWindow()); m_mainWindow.reset(new MainWindow());
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");