Skip to content

Commit

Permalink
main: Move some generic initialization out of MixxxMainWindow
Browse files Browse the repository at this point in the history
The `MixxxMainWindow` class should not be responsible for initializing
`CoreServices`. Mixxx should still be able to work when there is no
`MixxxMainWindow` (e.g. when we switch to a `QQmlApplication` for QML).
  • Loading branch information
Holzhaus committed Jul 22, 2021
1 parent 154df65 commit dc30c6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
16 changes: 14 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ constexpr int kFatalErrorOnStartupExitCode = 1;
constexpr int kParseCmdlineArgsErrorExitCode = 2;

int runMixxx(MixxxApplication* app, const CmdlineArgs& args) {
auto coreServices = std::make_shared<mixxx::CoreServices>(args);
MixxxMainWindow mainWindow(app, coreServices);
const auto pCoreServices = std::make_shared<mixxx::CoreServices>(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()) {
Expand Down
19 changes: 4 additions & 15 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -119,15 +117,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
Expand Down Expand Up @@ -161,6 +153,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());
Expand Down Expand Up @@ -269,11 +263,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 {
Expand Down
7 changes: 4 additions & 3 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class MixxxMainWindow : public QMainWindow {
MixxxMainWindow(QApplication* app, std::shared_ptr<mixxx::CoreServices> 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();
Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down

0 comments on commit dc30c6b

Please sign in to comment.