From 6f4845c62180e779dae6db41b599407203bd9ea2 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 15 Jul 2021 22:57:12 +0200 Subject: [PATCH] main: Move some generic initialization out of MixxxMainWindow --- src/main.cpp | 16 ++++++++++++++-- src/mixxxmainwindow.cpp | 18 ++++-------------- src/mixxxmainwindow.h | 7 ++++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0840fd58c657..5324afe89002 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,8 +23,20 @@ constexpr int kFatalErrorOnStartupExitCode = 1; constexpr int kParseCmdlineArgsErrorExitCode = 2; int runMixxx(MixxxApplication* app, const CmdlineArgs& args) { - auto coreServices = std::make_shared(args); - MixxxMainWindow mainWindow(app, coreServices); + const auto pCoreServices = std::make_shared(args); + pCoreServices->initializeSettings(); + pCoreServices->initializeKeyboard(); + + MixxxMainWindow mainWindow(app, pCoreServices); + app->installEventFilter(&mainWindow); + + QObject::connect(pCoreServices.get(), + &mixxx::CoreServices::initializationProgressUpdate, + &mainWindow, + &MixxxMainWindow::initializationProgressUpdate); + pCoreServices->initialize(app); + mainWindow.initialize(); + // If startup produced a fatal error, then don't even start the // Qt event loop. if (ErrorDialogHandler::instance()->checkError()) { diff --git a/src/mixxxmainwindow.cpp b/src/mixxxmainwindow.cpp index 320d9a0a45cd..ecd32d1642f9 100644 --- a/src/mixxxmainwindow.cpp +++ b/src/mixxxmainwindow.cpp @@ -103,8 +103,6 @@ MixxxMainWindow::MixxxMainWindow( m_toolTipsCfg(mixxx::TooltipsPreference::TOOLTIPS_ON) { DEBUG_ASSERT(pApp); DEBUG_ASSERT(pCoreServices); - m_pCoreServices->initializeSettings(); - m_pCoreServices->initializeKeyboard(); // These depend on the settings createMenuBar(); m_pMenuBar->hide(); @@ -120,14 +118,9 @@ MixxxMainWindow::MixxxMainWindow( show(); pApp->processEvents(); - connect( - m_pCoreServices.get(), - &mixxx::CoreServices::initializationProgressUpdate, - this, - &MixxxMainWindow::initializationProgressUpdate); - - m_pCoreServices->initialize(pApp); +} +void MixxxMainWindow::initialize() { UserSettingsPointer pConfig = m_pCoreServices->getSettings(); // Set the visibility of tooltips, default "1" = ON @@ -161,6 +154,8 @@ MixxxMainWindow::MixxxMainWindow( initializationProgressUpdate(65, tr("skin")); + // Install an event filter to catch certain QT events, such as tooltips. + // This allows us to turn off tooltips. installEventFilter(m_pCoreServices->getKeyboardEventFilter().get()); DEBUG_ASSERT(m_pCoreServices->getPlayerManager()); @@ -269,11 +264,6 @@ MixxxMainWindow::MixxxMainWindow( checkDirectRendering(); } - // Install an event filter to catch certain QT events, such as tooltips. - // This allows us to turn off tooltips. - pApp->installEventFilter(this); // The eventfilter is located in this - // Mixxx class as a callback. - // Try open player device If that fails, the preference panel is opened. bool retryClicked; do { diff --git a/src/mixxxmainwindow.h b/src/mixxxmainwindow.h index 9d94f34de18b..86d6669ae449 100644 --- a/src/mixxxmainwindow.h +++ b/src/mixxxmainwindow.h @@ -48,6 +48,8 @@ class MixxxMainWindow : public QMainWindow { MixxxMainWindow(QApplication* app, std::shared_ptr pCoreServices); ~MixxxMainWindow() override; + /// Initialize main window after creation. Should only be called once. + void initialize(); /// creates the menu_bar and inserts the file Menu void createMenuBar(); void connectMenuBar(); @@ -78,6 +80,8 @@ class MixxxMainWindow : public QMainWindow { void slotNoDeckPassthroughInputConfigured(); void slotNoVinylControlInputConfigured(); + void initializationProgressUpdate(int progress, const QString& serviceName); + private slots: void slotTooltipModeChanged(mixxx::TooltipsPreference tt); @@ -93,9 +97,6 @@ class MixxxMainWindow : public QMainWindow { bool eventFilter(QObject *obj, QEvent *event) override; void closeEvent(QCloseEvent *event) override; - private slots: - void initializationProgressUpdate(int progress, const QString& serviceName); - private: void initializeWindow(); void checkDirectRendering();