Move MPD thread into MPDConnection class

This commit is contained in:
craig.p.drummond
2012-12-08 11:25:32 +00:00
committed by craig.p.drummond
parent bea83b3b93
commit db076cb6b4
4 changed files with 27 additions and 7 deletions

View File

@@ -810,9 +810,7 @@ MainWindow::MainWindow(QWidget *parent)
playQueue->setFocus();
playQueue->initHeader();
mpdThread=new QThread(this);
MPDConnection::self()->moveToThread(mpdThread);
mpdThread->start();
MPDConnection::self()->start();
connectToMpd();
QString page=Settings::self()->page();
@@ -885,7 +883,7 @@ MainWindow::~MainWindow()
emit stop();
Utils::sleep();
}
Utils::stopThread(mpdThread);
MPDConnection::self()->stop();
Covers::self()->stop();
#if defined ENABLE_DEVICES_SUPPORT
FileScheduler::self()->stop();

View File

@@ -65,7 +65,6 @@ class ServerInfoPage;
#ifdef ENABLE_DEVICES_SUPPORT
class DevicesPage;
#endif
class QThread;
class QAbstractItemView;
#ifndef Q_OS_WIN
class Mpris;
@@ -445,7 +444,6 @@ private:
DevicesPage *devicesPage;
#endif
ServerInfoPage *serverInfoPage;
QThread *mpdThread;
#ifndef Q_OS_WIN
Mpris *mpris;
GnomeMediaKeys *gnomeMediaKeys;

View File

@@ -27,6 +27,7 @@
#include "mpdconnection.h"
#include "mpdparseutils.h"
#include "localize.h"
#include "utils.h"
#ifdef ENABLE_KDE_SUPPORT
#include <KDE/KGlobal>
#endif
@@ -142,7 +143,8 @@ QString MPDConnectionDetails::description() const
}
MPDConnection::MPDConnection()
: ver(0)
: thread(0)
, ver(0)
, sock(this)
, idleSocket(this)
, state(State_Blank)
@@ -172,6 +174,24 @@ MPDConnection::~MPDConnection()
idleSocket.disconnectFromHost();
}
void MPDConnection::start()
{
if (!thread) {
thread=new QThread();
moveToThread(thread);
thread->start();
}
}
void MPDConnection::stop()
{
if (thread) {
Utils::stopThread(thread);
thread->deleteLater();
thread=0;
}
}
MPDConnection::ConnectionReturn MPDConnection::connectToMPD(MpdSocket &socket, bool enableIdle)
{
if (QAbstractSocket::ConnectedState!=socket.state()) {

View File

@@ -41,6 +41,7 @@ class MusicLibraryItemArtist;
class DirViewItemRoot;
class MusicLibraryItemRoot;
class QTimer;
class QThread;
class MpdSocket : public QObject
{
@@ -175,6 +176,8 @@ public:
MPDConnection();
~MPDConnection();
void start();
void stop();
const MPDConnectionDetails & getDetails() const { return details; }
void setDirReadable(bool r) { details.dirReadable=r; }
bool isConnected() const { return State_Connected==state; }
@@ -302,6 +305,7 @@ private:
bool doMoveInPlaylist(const QString &name, const QList<quint32> &items, quint32 pos, quint32 size);
private:
QThread *thread;
long ver;
MPDConnectionDetails details;
QDateTime dbUpdate;