From 7a2f2b67490066100f64cccf212ee81d92cae925 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Thu, 2 Jan 2014 19:07:59 +0000 Subject: [PATCH] Add CMake option to disable building of internal HTTP server. BUG: 373 --- CMakeLists.txt | 22 +++++++++++++++++----- ChangeLog | 1 + INSTALL | 4 ++++ config.h.cmake | 1 + devices/audiocddevice.h | 3 ++- devices/fsdevice.h | 3 ++- gui/mainwindow.cpp | 2 +- gui/preferencesdialog.cpp | 6 +++++- gui/preferencesdialog.h | 2 ++ gui/settings.cpp | 4 ++++ http/httpserver.cpp | 3 +++ http/httpserver.h | 25 +++++++++++++++++++++---- models/playqueuemodel.cpp | 2 +- online/podcastservice.cpp | 2 +- 14 files changed, 65 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8187025db..3b3f1c5cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ option(ENABLE_MUSICBRAINZ "Enable MusicBrianz libraries (either this or CDDB req option(ENABLE_PROXY_CONFIG "Enable proxy config in settings dialog" OFF) option(ENABLE_EXTERNAL_TAGS "Enable usage of external app for reading/writing tags (EXPERIMENTAL - NOT FULLY WORKING)" OFF) option(ENABLE_UNCACHED_MTP "Open MTP devices in un-cached mode (faster)" ON) +option(ENABLE_HTTP_SERVER "Enable internal HTTP server to play non-MPD files" ON) if (ENABLE_QT5) set(ENABLE_KDE FALSE) @@ -223,7 +224,7 @@ set(CANTATA_SRCS gui/application.cpp gui/main.cpp gui/initialsettingswizard.cpp widgets/basicitemdelegate.cpp widgets/sizegrip.cpp widgets/sizewidget.cpp widgets/servicestatuslabel.cpp widgets/spacerwidget.cpp widgets/songdialog.cpp network/networkaccessmanager.cpp network/networkproxyfactory.cpp - http/httpserversettings.cpp http/httpserver.cpp http/httpsocket.cpp + http/httpserver.cpp devices/deviceoptions.cpp context/lyricsettings.cpp context/ultimatelyricsprovider.cpp context/ultimatelyrics.cpp context/lyricsdialog.cpp context/contextwidget.cpp context/view.cpp context/artistview.cpp context/albumview.cpp context/songview.cpp context/contextengine.cpp @@ -247,7 +248,6 @@ set(CANTATA_MOC_HDRS widgets/playqueueview.h widgets/groupedview.h widgets/actionitemdelegate.h widgets/coverwidget.h widgets/volumeslider.h widgets/genrecombo.h widgets/toolbar.h widgets/searchwidget.h widgets/messageoverlay.h widgets/servicestatuslabel.h network/networkaccessmanager.h - http/httpserver.h http/httpsocket.h context/togglelist.h context/ultimatelyrics.h context/ultimatelyricsprovider.h context/lyricsdialog.h context/contextwidget.h context/artistview.h context/albumview.h context/songview.h context/view.h context/contextengine.h context/wikipediaengine.h context/wikipediasettings.h context/othersettings.h context/lastfmengine.h context/metaengine.h @@ -262,6 +262,12 @@ set(CANTATA_UIS http/httpserversettings.ui online/onlineservicespage.ui online/onlinesettings.ui) +if (ENABLE_HTTP_SERVER) + set(CANTATA_SRCS ${CANTATA_SRCS} http/httpserversettings.cpp http/httpsocket.cpp) + set(CANTATA_MOC_HDRS ${CANTATA_MOC_HDRS} http/httpserver.h http/httpsocket.h) + set(CANTATA_UIS ${CANTATA_UIS} http/httpserversettings.ui) +endif (ENABLE_HTTP_SERVER) + if (ENABLE_MODEL_TEST AND NOT ENABLE_KDE AND NOT ENABLE_QT5) set(QTLIBS ${QTLIBS} ${QT_QTTEST_LIBRARY}) set(CANTATA_SRCS ${CANTATA_SRCS} models/modeltest.cpp) @@ -619,7 +625,7 @@ if (TAGLIB_FOUND) endif (ENABLE_PROXY_CONFIG) endif (ENABLE_REMOTE_DEVICES OR ENABLE_HTTP_STREAM_PLAYBACK OR AUDIOCD_SUPPORT OR MTP_FOUND OR ENABLE_PROXY_CONFIG OR ENABLE_REPLAYGAIN_SUPPORT) - if (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE)) + if (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_HTTP_SERVER OR (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE)) message(" Disabled features:") if (NOT ENABLE_HTTP_STREAM_PLAYBACK) message(" - MPD HTTP stream playback (Phonon required for Qt4, QtMultiMedia for Qt5)") @@ -639,7 +645,10 @@ if (TAGLIB_FOUND) if (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE) message(" - Proxy configuration") endif (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE) - endif (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE)) + if (NOT ENABLE_HTTP_SERVER) + message(" - Internal HTTP server (playback of AudioCDs, and songs from media files disabled)") + endif (NOT ENABLE_HTTP_SERVER) + endif (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_HTTP_SERVER OR (NOT ENABLE_PROXY_CONFIG AND NOT ENABLE_KDE)) if (ENABLE_EXTERNAL_TAGS) message(" Tags will be read/written via an external helper app") @@ -662,8 +671,11 @@ else (TAGLIB_FOUND) message(" - Remote device sync (EXPERIMENTAL) (taglib required)") endif (NOT WIN32 AND NOT APPLE) if (NOT ENABLE_REPLAYGAIN_SUPPORT) - message(" - ReplayGain calculation(taglib, and ffmpeg and/or mpg123 required)") + message(" - ReplayGain calculation (taglib, and ffmpeg and/or mpg123 required)") endif (NOT ENABLE_REPLAYGAIN_SUPPORT) + if (NOT ENABLE_HTTP_SERVER) + message(" - Internal HTTP server (playback of AudioCDs, and songs from media files disabled)") + endif (NOT ENABLE_HTTP_SERVER) endif (TAGLIB_FOUND) diff --git a/ChangeLog b/ChangeLog index b2343a005..b2ca62b92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ 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. +16. Add CMake option to disable building of internal HTTP server. 1.2.2 ----- diff --git a/INSTALL b/INSTALL index 3a3d6c7c9..70c9fd949 100644 --- a/INSTALL +++ b/INSTALL @@ -96,6 +96,10 @@ The following options may be passed to CMake: Open MTP devices in un-cached mode (faster) Default: ON + -DENABLE_HTTP_SERVER=ON + Enable usage of internal HTTP server for non-MPD file playback. + Default: ON + Windows specific: diff --git a/config.h.cmake b/config.h.cmake index e3aef70c6..ad44ec0a4 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -39,6 +39,7 @@ #cmakedefine CDPARANOIA_HAS_CACHEMODEL_SIZE 1 #cmakedefine QT_QTDBUS_FOUND 1 #cmakedefine ENABLE_UNCACHED_MTP 1 +#cmakedefine ENABLE_HTTP_SERVER 1 /* This is done via CMake add_defintions - as it controls SLOT generation in GtkProxyStyle diff --git a/devices/audiocddevice.h b/devices/audiocddevice.h index d1a8cc0de..5fa9e75f2 100644 --- a/devices/audiocddevice.h +++ b/devices/audiocddevice.h @@ -26,6 +26,7 @@ #include "device.h" #include "covers.h" +#include "httpserver.h" #ifdef ENABLE_KDE_SUPPORT #include #else @@ -76,7 +77,7 @@ public: void saveOptions() { } QString subText() { return album; } quint32 totalTime(); - bool canPlaySongs() const { return true; } + bool canPlaySongs() const { return HttpServer::self()->isAlive(); } QString albumName() const { return album; } QString albumArtist() const { return artist; } QString albumComposer() const { return composer; } diff --git a/devices/fsdevice.h b/devices/fsdevice.h index c0891e3e6..7106878ad 100644 --- a/devices/fsdevice.h +++ b/devices/fsdevice.h @@ -29,6 +29,7 @@ #include "utils.h" #include "freespaceinfo.h" #include "musiclibraryitemroot.h" +#include "httpserver.h" #include class Thread; @@ -128,7 +129,7 @@ public: void saveCache(); void removeCache(); bool isStdFs() const { return true; } - bool canPlaySongs() const { return true; } + bool canPlaySongs() const { return HttpServer::self()->isAlive(); } Q_SIGNALS: // For talking to scanner... diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 078154249..d97adb115 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -937,7 +937,7 @@ void MainWindow::load(const QStringList &urls) } else if (u.scheme().isEmpty() || QLatin1String("file")==u.scheme()) { if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { useable.append(QLatin1String("file://")+u.path()); - } else { + } else if (HttpServer::self()->isAlive()) { useable.append(HttpServer::self()->encodeUrl(u.path())); } } diff --git a/gui/preferencesdialog.cpp b/gui/preferencesdialog.cpp index 20a4e79e8..a832a2cce 100644 --- a/gui/preferencesdialog.cpp +++ b/gui/preferencesdialog.cpp @@ -70,7 +70,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, const QStringList &hiddenP streams = hiddenPages.contains(QLatin1String("StreamsPage")) ? 0 : new StreamsSettings(0); online = hiddenPages.contains(QLatin1String("OnlineServicesPage")) ? 0 : new OnlineSettings(0); context = new ContextSettings(0); - http = new HttpServerSettings(0); cache = new CacheSettings(0); server->load(); playback->load(); @@ -90,6 +89,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, const QStringList &hiddenP online->load(); } pageWidget->addPage(context, i18n("Context"), Icons::self()->contextIcon, i18n("Context View Settings")); + #ifdef ENABLE_HTTP_SERVER + http = new HttpServerSettings(0); if (http->haveMultipleInterfaces()) { http->load(); Icon icon("network-server"); @@ -101,6 +102,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, const QStringList &hiddenP http->deleteLater(); http=0; } + #endif #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND audiocd = new AudioCdSettings(0); audiocd->load(); @@ -154,9 +156,11 @@ void PreferencesDialog::writeSettings() if (online) { online->save(); } + #ifdef ENABLE_HTTP_SERVER if (http) { http->save(); } + #endif #ifndef ENABLE_KDE_SUPPORT #ifdef ENABLE_PROXY_CONFIG proxy->save(); diff --git a/gui/preferencesdialog.h b/gui/preferencesdialog.h index 1d55aa0f8..c99a748d6 100644 --- a/gui/preferencesdialog.h +++ b/gui/preferencesdialog.h @@ -80,7 +80,9 @@ private: StreamsSettings *streams; OnlineSettings *online; ContextSettings *context; + #ifdef ENABLE_HTTP_SERVER HttpServerSettings *http; + #endif #ifdef ENABLE_PROXY_CONFIG ProxySettings *proxy; #endif diff --git a/gui/settings.cpp b/gui/settings.cpp index a1f494d82..9646bfd91 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -645,7 +645,11 @@ QString Settings::httpInterface() bool Settings::alwaysUseHttp() { + #ifdef ENABLE_HTTP_SERVER return GET_BOOL("alwaysUseHttp", false); + #else + return false; + #endif } bool Settings::playQueueGrouped() diff --git a/http/httpserver.cpp b/http/httpserver.cpp index 131b8cd96..256a58793 100644 --- a/http/httpserver.cpp +++ b/http/httpserver.cpp @@ -73,6 +73,7 @@ HttpServer * HttpServer::self() #endif } +#ifdef ENABLE_HTTP_SERVER HttpServer::HttpServer() : QObject(0) , thread(0) @@ -361,3 +362,5 @@ void HttpServer::removedIds(const QSet &ids) startCloseTimer(); } } + +#endif diff --git a/http/httpserver.h b/http/httpserver.h index 4d798b508..ed990d027 100644 --- a/http/httpserver.h +++ b/http/httpserver.h @@ -37,7 +37,9 @@ class QTimer; class HttpServer : public QObject { + #ifdef ENABLE_HTTP_SERVER Q_OBJECT + #endif public: static void enableDebug(); @@ -45,10 +47,10 @@ public: static HttpServer * self(); - HttpServer(); virtual ~HttpServer() { } - bool start(); + #ifdef ENABLE_HTTP_SERVER + HttpServer(); bool isAlive() const { return true; } // Started on-demamnd! bool forceUsage() const { return force; } void readConfig(); @@ -58,11 +60,25 @@ public: QByteArray encodeUrl(const QString &file); Song decodeUrl(const QUrl &url) const; Song decodeUrl(const QString &file) const; + #else + HttpServer() { } + bool isAlive() const { return false; } // Not used! + bool forceUsage() const { return false; } + void readConfig() { } + QString address() const { return QString(); } + bool isOurs(const QString &) const { return false; } + QByteArray encodeUrl(const Song &) { return QByteArray(); } + QByteArray encodeUrl(const QString &) { return QByteArray(); } + Song decodeUrl(const QUrl &) const { return Song(); } + Song decodeUrl(const QString &) const { return Song(); } + #endif -public Q_SLOTS: - void stop(); +private: + #ifdef ENABLE_HTTP_SERVER + bool start(); private Q_SLOTS: + void stop(); void startCloseTimer(); void mpdAddress(const QString &a); void cantataStreams(const QStringList &files); @@ -80,6 +96,7 @@ private: QString mpdAddr; QSet streamIds; // Currently playing MPD stream IDs QTimer *closeTimer; + #endif }; #endif diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index bf8571150..9a720930f 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -555,7 +555,7 @@ bool PlayQueueModel::dropMimeData(const QMimeData *data, if (checkExtension(u)) { if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { useable.append(QLatin1String("file://")+QUrl::fromPercentEncoding(u.toUtf8())); - } else { + } else if (HttpServer::self()->isAlive()) { useable.append(HttpServer::self()->encodeUrl(QUrl::fromPercentEncoding(u.toUtf8()))); } } diff --git a/online/podcastservice.cpp b/online/podcastservice.cpp index 8d732cd2e..0ca723450 100644 --- a/online/podcastservice.cpp +++ b/online/podcastservice.cpp @@ -127,7 +127,7 @@ Song PodcastService::fixPath(const Song &orig, bool) const if (!orig.podcastLocalPath().isEmpty() && QFile::exists(orig.podcastLocalPath())) { if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal()) { song.file=QLatin1String("file://")+orig.podcastLocalPath(); - } else { + } else if (HttpServer::self()->isAlive()) { song.file=orig.podcastLocalPath(); song.file=HttpServer::self()->encodeUrl(song); }