Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:CDrummond/cantata
Browse files Browse the repository at this point in the history
  • Loading branch information
CDrummond committed Jan 12, 2022
2 parents 53d4eaf + 680a4a8 commit e992427
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -40,6 +40,8 @@
29. Add Grouping tag support to playlists and play queue.
30. Use QCollator to compare strings.
31. If using table-style play queue, then only sort one column at a time.
32. Stop user MPD instance from GUI thread when terminating, to ensure state
can be saved.

2.4.2
-----
Expand Down
11 changes: 9 additions & 2 deletions gui/mainwindow.cpp
Expand Up @@ -37,6 +37,9 @@
#include "preferencesdialog.h"
#include "mpd-interface/mpdstats.h"
#include "mpd-interface/mpdparseutils.h"
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
#include "mpd-interface/mpduser.h"
#endif
#include "settings.h"
#include "support/utils.h"
#include "models/musiclibraryitemartist.h"
Expand Down Expand Up @@ -996,10 +999,14 @@ MainWindow::~MainWindow()
disconnect(MPDConnection::self(), nullptr, nullptr, nullptr);
if (Settings::self()->stopOnExit()) {
DynamicPlaylists::self()->stop();
}
if (Settings::self()->stopOnExit()) {
emit terminating();
Utils::sleep(); // Allow time for stop to be sent...
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
// Hide this waindow, as we /might/ delay for up to 2 seconds waiting
// for MPD to terminate...
setVisible(false);
MPDUser::self()->stop();
#endif
} else if (hadCantataStreams) {
Utils::sleep(); // Allow time for removal of cantata streams...
}
Expand Down
6 changes: 5 additions & 1 deletion mpd-interface/mpduser.cpp
Expand Up @@ -33,6 +33,7 @@
#include <QFileInfo>
#include <QSet>
#include <QCoreApplication>
#include <QMutexLocker>
#include <signal.h>

const QString MPDUser::constName=QLatin1String("-");
Expand Down Expand Up @@ -347,8 +348,11 @@ void MPDUser::killProcess()

bool MPDUser::controlMpd(bool stop)
{
// Both the UI thread (from MainWindow) and MPD thread (from MPDConnection)
// will stop MPDUser. Use a mutex to ensure thread safety...
QMutexLocker locker(&mutex);
QString confFile=Utils::dataDir(constDir, true)+constConfigFile;
if (!QFile::exists(confFile)) {
if (!QFile::exists(confFile) || (stop && (pidFileName.isEmpty() || !QFile::exists(pidFileName)))) {
if (stop) {
killProcess();
}
Expand Down
2 changes: 2 additions & 0 deletions mpd-interface/mpduser.h
Expand Up @@ -25,6 +25,7 @@
#define MPD_USER_H

#include <QString>
#include <QMutex>
#include "mpdconnection.h"

class MPDUser
Expand Down Expand Up @@ -58,6 +59,7 @@ class MPDUser
QString mpdExe;
QString pidFileName;
MPDConnectionDetails det;
QMutex mutex;
};

#endif

0 comments on commit e992427

Please sign in to comment.