Commit a951caf3 authored by Michael Pyne's avatar Michael Pyne

Simplify shutdown handling.

JuK would fail to shutdown properly under Plasma 5 when the system tray
was disabled and you used the 'X' from the window manager title bar to
try to close JuK.  May have failed under other WMs or desktops as well,
I haven't tested that.

The shutdown code hasn't been reworked since KDE 3 times and for all I
know I introduced this bug with the setQuitOnLastWindowClosed setting in
main.cpp years ago and never realized.

But this way, any way you destroy the main application class (JuK), you
end up shutting down.  Continuing to use setQuitOnLastWindowClosed
appears to be necessary since Qt will remove the queued quit signal to
qApp once JuK is destructed and I don't trust running qApp->quit within
the JuK dtor itself.

Hopefully this fixes a crash-on-quit bug, but if not just reopen and
I'll figure it out somehow...

FIXED-IN:18.04
BUG:388663
parent 1eed4730
......@@ -120,8 +120,6 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent) :
setupGlobalAccels();
activateScrobblerIfEnabled();
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), SLOT(slotAboutToQuit()));
// slotCheckCache loads the cached entries first to populate the collection list
QTimer::singleShot(0, this, SLOT(slotClearOldCovers()));
......@@ -131,6 +129,19 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent) :
JuK::~JuK()
{
if(!m_shuttingDown) {
// Sometimes KMainWindow doesn't actually call QCoreApplication::quit
// after queryClose, even if not in a session shutdown, so make sure to
// do so ourselves when closing the main window.
slotQuit();
}
// Some items need to be deleted before others, though I haven't looked
// at this in some time so refinement is probably possible.
delete m_systemTray;
delete m_splitter;
delete m_player;
delete m_statusLabel;
}
JuK* JuK::JuKInstance()
......@@ -325,17 +336,20 @@ void JuK::setupActions()
void JuK::slotSetupSystemTray()
{
if(m_toggleSystemTrayAction && m_toggleSystemTrayAction->isChecked()) {
qCDebug(JUK_LOG) << "Setting up systray";
QTime stopwatch; stopwatch.start();
m_systemTray = new SystemTray(m_player, this);
m_systemTray->setObjectName( QLatin1String("systemTray" ));
m_systemTray->setObjectName(QStringLiteral("systemTray"));
m_toggleDockOnCloseAction->setEnabled(true);
m_togglePopupsAction->setEnabled(true);
qCDebug(JUK_LOG) << "Finished setting up systray, took" << stopwatch.elapsed() << "ms";
// If this flag gets set then JuK will quit if you click the cover on
// the track announcement popup when JuK is only in the system tray
// (the systray has no widget).
qGuiApp->setQuitOnLastWindowClosed(false);
}
else {
m_systemTray = 0;
m_systemTray = nullptr;
m_toggleDockOnCloseAction->setEnabled(false);
m_togglePopupsAction->setEnabled(false);
}
......@@ -490,18 +504,8 @@ bool JuK::queryClose()
hide();
return false;
}
else
{
// Some phonon backends will crash on shutdown unless we've stopped
// playback.
if(m_player->playing())
m_player->stop();
// Save configuration data.
m_startDocked = !isVisible();
saveConfig();
return true;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
......@@ -513,23 +517,20 @@ void JuK::slotShowHide()
setHidden(!isHidden());
}
void JuK::slotAboutToQuit()
{
m_shuttingDown = true;
m_player->stop();
deleteAndClear(m_systemTray);
deleteAndClear(m_splitter);
deleteAndClear(m_player);
deleteAndClear(m_statusLabel);
}
void JuK::slotQuit()
{
m_shuttingDown = true;
// Some phonon backends will crash on shutdown unless we've stopped
// playback.
if(m_player->playing()) {
m_player->stop();
}
m_startDocked = !isVisible();
saveConfig();
qApp->quit();
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -542,9 +543,11 @@ void JuK::slotToggleSystemTray(bool enabled)
slotSetupSystemTray();
else if(!enabled && m_systemTray) {
delete m_systemTray;
m_systemTray = 0;
m_systemTray = nullptr;
m_toggleDockOnCloseAction->setEnabled(false);
m_togglePopupsAction->setEnabled(false);
qGuiApp->setQuitOnLastWindowClosed(true);
}
}
......
......@@ -69,7 +69,6 @@ private:
private slots:
void slotSetupSystemTray();
void slotShowHide();
void slotAboutToQuit();
void slotQuit();
void slotToggleSystemTray(bool enabled);
void slotEditKeys();
......
......@@ -98,13 +98,7 @@ int main(int argc, char *argv[])
KCrash::initialize();
// If this flag gets set then JuK will quit if you click the cover on the track
// announcement popup when JuK is only in the system tray (the systray has no widget).
a.setQuitOnLastWindowClosed(false);
// Create the main window and such
JuK *juk = new JuK(parser.positionalArguments());
if(a.isSessionRestored() && KMainWindow::canBeRestored(1))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment