From 2273b27f15484ded74113e0ea77b3f9483a7bd73 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Thu, 2 Jan 2014 19:06:13 +0000 Subject: [PATCH] If connected to MPD via a UNIX-domain socket, then send non-MPD files as file:/// URLs to MPD - i.e. dont use internal HTTP server. To foce usage of HTTP server - set alwaysUseHttp to true in Cantata's config file. BUG: 373 --- ChangeLog | 4 ++++ README | 7 +++++++ gui/mainwindow.cpp | 9 ++++++--- gui/settings.cpp | 5 +++++ gui/settings.h | 1 + http/httpserver.cpp | 1 + http/httpserver.h | 2 ++ models/playqueuemodel.cpp | 18 ++++++++---------- online/podcastservice.cpp | 8 ++++++-- 9 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba6862ded..b2343a005 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,10 @@ 13. Add 'Remove duplicates' functionality to play queue and play lists. 14. Only start internal HTTP server when required, and stop 1 second after last Cantata stream is removed. +15. If connected to MPD via a UNIX-domain socket, then send non-MPD files as + file:/// URLs to MPD - i.e. dont use internal HTTP server. To foce usage of + HTTP server - set alwaysUseHttp to true in Cantata's config file. Refer to + README for more details. 1.2.2 ----- diff --git a/README b/README index c44f03869..a0914260a 100644 --- a/README +++ b/README @@ -356,6 +356,12 @@ mpdListSize= "add" command when adding files to the playqueue. Default is 10000. (Values 100..65535 are acceptable) +alwaysUseHttp= + Set to 'true' to always serve non-MPD files via HTTP server. If set to + 'false', then Cantata will only use its internal HTTP server for songs + from media devices, or when connected to MPD via a standard socket. + Default is false. + e.g. [General] iconTheme=oxygen @@ -367,6 +373,7 @@ volumeStep=2 undoSteps=20 mpdPoll=true mpdListSize=5000 +alwaysUseHttp=true 7. CUE Files diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7e6253139..078154249 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -923,7 +923,6 @@ void MainWindow::initSizes() void MainWindow::load(const QStringList &urls) { QStringList useable; - bool haveHttp=HttpServer::self()->isAlive(); foreach (const QString &path, urls) { QUrl u(path); @@ -935,8 +934,12 @@ void MainWindow::load(const QStringList &urls) #endif if (QLatin1String("http")==u.scheme()) { useable.append(u.toString()); - } else if (haveHttp && (u.scheme().isEmpty() || QLatin1String("file")==u.scheme())) { - useable.append(HttpServer::self()->encodeUrl(u.path())); + } else if (u.scheme().isEmpty() || QLatin1String("file")==u.scheme()) { + if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { + useable.append(QLatin1String("file://")+u.path()); + } else { + useable.append(HttpServer::self()->encodeUrl(u.path())); + } } } if (useable.count()) { diff --git a/gui/settings.cpp b/gui/settings.cpp index 4099da7e2..a1f494d82 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -643,6 +643,11 @@ QString Settings::httpInterface() return GET_STRING("httpInterface", QString()); } +bool Settings::alwaysUseHttp() +{ + return GET_BOOL("alwaysUseHttp", false); +} + bool Settings::playQueueGrouped() { return GET_BOOL("playQueueGrouped", true); diff --git a/gui/settings.h b/gui/settings.h index 08d31848d..54c3a4bb0 100644 --- a/gui/settings.h +++ b/gui/settings.h @@ -159,6 +159,7 @@ public: int stopFadeDuration(); int httpAllocatedPort(); QString httpInterface(); + bool alwaysUseHttp(); bool playQueueGrouped(); bool playQueueAutoExpand(); bool playQueueStartClosed(); diff --git a/http/httpserver.cpp b/http/httpserver.cpp index 0a1d17f6a..131b8cd96 100644 --- a/http/httpserver.cpp +++ b/http/httpserver.cpp @@ -79,6 +79,7 @@ HttpServer::HttpServer() , socket(0) , closeTimer(0) { + force=Settings::self()->alwaysUseHttp(); connect(MPDConnection::self(), SIGNAL(socketAddress(QString)), this, SLOT(mpdAddress(QString))); connect(MPDConnection::self(), SIGNAL(cantataStreams(QList,bool)), this, SLOT(cantataStreams(QList,bool))); connect(MPDConnection::self(), SIGNAL(cantataStreams(QStringList)), this, SLOT(cantataStreams(QStringList))); diff --git a/http/httpserver.h b/http/httpserver.h index 5fd54061d..4d798b508 100644 --- a/http/httpserver.h +++ b/http/httpserver.h @@ -50,6 +50,7 @@ public: bool start(); bool isAlive() const { return true; } // Started on-demamnd! + bool forceUsage() const { return force; } void readConfig(); QString address() const; bool isOurs(const QString &url) const; @@ -72,6 +73,7 @@ Q_SIGNALS: void terminateSocket(); private: + bool force; Thread *thread; HttpSocket *socket; diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index b36c500ae..bf8571150 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -465,13 +465,7 @@ Qt::ItemFlags PlayQueueModel::flags(const QModelIndex &index) const */ QStringList PlayQueueModel::mimeTypes() const { - QStringList types; - types << constMoveMimeType; - types << constFileNameMimeType; - if (HttpServer::self()->isAlive()) { - types << constUriMimeType; - } - return types; + return QStringList() << constMoveMimeType << constFileNameMimeType << constUriMimeType; } /** @@ -519,6 +513,7 @@ QMimeData *PlayQueueModel::mimeData(const QModelIndexList &indexes) const * * @return bool if we accest the drop */ +#include bool PlayQueueModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex & /*parent*/) { @@ -549,17 +544,20 @@ bool PlayQueueModel::dropMimeData(const QMimeData *data, } else if(data->hasFormat(constUriMimeType)/* && MPDConnection::self()->getDetails().isLocal()*/) { QStringList orig=decode(*data, constUriMimeType); QStringList useable; - bool haveHttp=HttpServer::self()->isAlive(); foreach (QString u, orig) { if (u.startsWith(QLatin1String("http://"))) { useable.append(u); - } else if (haveHttp && (u.startsWith('/') || u.startsWith(QLatin1String("file://")))) { + } else if (u.startsWith('/') || u.startsWith(QLatin1String("file://"))) { if (u.startsWith(QLatin1String("file://"))) { u=u.mid(7); } if (checkExtension(u)) { - useable.append(HttpServer::self()->encodeUrl(QUrl::fromPercentEncoding(u.toUtf8()))); + if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { + useable.append(QLatin1String("file://")+QUrl::fromPercentEncoding(u.toUtf8())); + } else { + useable.append(HttpServer::self()->encodeUrl(QUrl::fromPercentEncoding(u.toUtf8()))); + } } } } diff --git a/online/podcastservice.cpp b/online/podcastservice.cpp index e0153da7b..8d732cd2e 100644 --- a/online/podcastservice.cpp +++ b/online/podcastservice.cpp @@ -125,8 +125,12 @@ Song PodcastService::fixPath(const Song &orig, bool) const song.setPodcastLocalPath(QString()); song.setIsFromOnlineService(constName); if (!orig.podcastLocalPath().isEmpty() && QFile::exists(orig.podcastLocalPath())) { - song.file=orig.podcastLocalPath(); - song.file=HttpServer::self()->encodeUrl(song); + if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { + song.file=QLatin1String("file://")+orig.podcastLocalPath(); + } else { + song.file=orig.podcastLocalPath(); + song.file=HttpServer::self()->encodeUrl(song); + } return song; } return encode(song);