Skip to content

Commit

Permalink
Move to signal/slot
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Feb 10, 2025
1 parent 982c080 commit 045e506
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/GuiApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ class LMMS_EXPORT GuiApplication : public QObject
AutomationEditorWindow* automationEditor() { return m_automationEditor; }
ControllerRackView* getControllerRackView() { return m_controllerRackView; }

void sendInterrupt(int signal);

public slots:
void displayInitProgress(const QString &msg);

private slots:
void childDestroyed(QObject *obj);
void processInterrupt(int signal);

signals:
void interruptOccurred(int signal);

private:
static GuiApplication* s_instance;
Expand Down
11 changes: 8 additions & 3 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ void fpeHandler( int signum ) {
}
#endif

void interruptHandler(int unused) {
if(qApp != nullptr) qApp->exit(3);
exit(3);
void interruptHandler(int code) {
using namespace lmms::gui;

if(getGUI() != nullptr) {
getGUI()->sendInterrupt(code);
} else {
exit(3);
}
}

static inline QString baseName( const QString & file )
Expand Down
17 changes: 17 additions & 0 deletions src/gui/GuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <QLabel>
#include <QMessageBox>
#include <QSplashScreen>
#include <csignal>

#ifdef LMMS_BUILD_WIN32
#include <windows.h>
Expand Down Expand Up @@ -75,6 +76,9 @@ GuiApplication* GuiApplication::instance()

GuiApplication::GuiApplication()
{
// Add interrupt handler as early as possible
connect(this, SIGNAL(interruptOccurred(int)), this, SLOT(processInterrupt(int)), Qt::QueuedConnection);

// prompt the user to create the LMMS working directory (e.g. ~/Documents/lmms) if it doesn't exist
if ( !ConfigManager::inst()->hasWorkingDir() &&
QMessageBox::question( nullptr,
Expand Down Expand Up @@ -240,6 +244,19 @@ void GuiApplication::childDestroyed(QObject *obj)
}
}

void GuiApplication::sendInterrupt(int signal) {
emit interruptOccurred(signal);
}

// Slot for handling interrupts from main()
void GuiApplication::processInterrupt(int signal) {
switch(signal) {
case SIGINT:
// add last minute resource clean-up goes here
qApp->exit(3);
}
}

#ifdef LMMS_BUILD_WIN32
/*!
* @brief Returns the Windows System font.
Expand Down

0 comments on commit 045e506

Please sign in to comment.