Add config option to enable/disable simple MPD mode.

This commit is contained in:
Craig Drummond
2015-04-27 20:33:51 +01:00
committed by Craig Drummond
parent b350b5698f
commit 7251275924
7 changed files with 71 additions and 20 deletions

View File

@@ -58,6 +58,10 @@ option(ENABLE_HTTP_SERVER "Enable internal HTTP server to play non-MPD files" ON
option(ENABLE_DYNAMIC "Enable support for dynamic playlists" ON)
option(ENABLE_STREAMS "Enable support for streams tab (to save favourite streams, and search for others)" ON)
option(ENABLE_ONLINE_SERVICES "Enable support for online services (Jamendo, Magnatune, SoundCloud, and Podcasts)" ON)
if (NOT WIN32 AND NOT APPLE AND NOT ENABLE_UBUNTU)
option(ENABLE_SIMPLE_MPD_SUPPORT "Enable support for simple (Cantata controlled) MPD" ON)
endif (NOT WIN32 AND NOT APPLE AND NOT ENABLE_UBUNTU)
if (WIN32 OR APPLE)
option(ENABLE_DEVICES_SUPPORT "Enable suport for external devices" OFF)
else (WIN32 OR APPLE)
@@ -425,7 +429,6 @@ set(CANTATA_SRCS ${CANTATA_CORE_SRCS} ${CANTATA_SRCS}
gui/settings.cpp gui/application.cpp gui/initialsettingswizard.cpp gui/mainwindow.cpp gui/preferencesdialog.cpp
gui/filesettings.cpp gui/interfacesettings.cpp gui/playbacksettings.cpp gui/serversettings.cpp gui/librarypage.cpp gui/albumspage.cpp
gui/folderpage.cpp gui/playlistspage.cpp gui/trayitem.cpp gui/cachesettings.cpp gui/coverdialog.cpp gui/searchpage.cpp gui/stdactions.cpp
mpd-interface/mpduser.cpp
devices/deviceoptions.cpp
widgets/treeview.cpp widgets/listview.cpp widgets/itemview.cpp widgets/autohidingsplitter.cpp widgets/nowplayingwidget.cpp
widgets/actionlabel.cpp widgets/playqueueview.cpp widgets/groupedview.cpp widgets/actionitemdelegate.cpp widgets/textbrowser.cpp
@@ -459,6 +462,10 @@ set(CANTATA_UIS ${CANTATA_UIS}
context/togglelist.ui context/othersettings.ui
widgets/itemview.ui scrobbling/scrobblingsettings.ui)
if (ENABLE_SIMPLE_MPD_SUPPORT)
set(CANTATA_SRCS ${CANTATA_CORE_SRCS} ${CANTATA_SRCS} mpd-interface/mpduser.cpp)
endif (ENABLE_SIMPLE_MPD_SUPPORT)
if (ENABLE_UBUNTU)
set(UBUNTU_SRCS ${CANTATA_CORE_SRCS} ubuntu/main.cpp ubuntu/backend/mpdbackend.cpp gui/plurals_qt.cpp)
set(UBUNTU_MOC_HDRS ${CANTATA_CORE_MOC_HDRS} ubuntu/backend/mpdbackend.h)

View File

@@ -158,6 +158,9 @@ The following options may be passed to CMake:
install into /usr/lib64/cantata instead of /usr/lib/cantata
Default: <empty (which means /usr/lib will be used) >
-DENABLE_SIMPLE_MPD_SUPPORT=ON
Enable support for basic, Cantata controlled, MPD instance.
Default: ON
Windows specific:

View File

@@ -45,6 +45,7 @@
#cmakedefine QT_MAC_EXTRAS_FOUND 1
#cmakedefine UNITY_MENU_HACK 1
#cmakedefine ENABLE_TOUCH_SUPPORT 1
#cmakedefine ENABLE_SIMPLE_MPD_SUPPORT 1
#ifdef ENABLE_UBUNTU
#define CANTATA_REV_URL "com.ubuntu.developer.nikwen.cantata-touch-reboot" //Sadly, it requires the com.ubuntu.developer.nikwen prefix to be published to the click store

View File

@@ -27,7 +27,9 @@
#include "support/utils.h"
#include "support/icon.h"
#include "widgets/icons.h"
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
#include "mpd-interface/mpduser.h"
#endif
#include <QDir>
#if QT_VERSION > 0x050000
#include <QStandardPaths>
@@ -44,7 +46,6 @@ enum Pages {
InitialSettingsWizard::InitialSettingsWizard(QWidget *p)
: QWizard(p)
, singleUserSupported(MPDUser::self()->isSupported())
{
setupUi(this);
connect(this, SIGNAL(currentIdChanged(int)), SLOT(pageChanged(int)));
@@ -82,9 +83,15 @@ InitialSettingsWizard::InitialSettingsWizard(QWidget *p)
filesPage->setBackground(Icons::self()->filesIcon);
finishedPage->setBackground(Icon("dialog-ok"));
introStack->setCurrentIndex(singleUserSupported ? 1 : 0);
basic->setChecked(false); //singleUserSupported);
advanced->setChecked(true); // !singleUserSupported);
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
introStack->setCurrentIndex(MPDUser::self()->isSupported() ? 1 : 0);
basic->setChecked(false);
advanced->setChecked(true);
#else
introStack->setCurrentIndex(0);
basic->setChecked(true);
advanced->setChecked(false);
#endif
#ifndef Q_OS_WIN
QSize sz=size();
@@ -119,10 +126,12 @@ InitialSettingsWizard::~InitialSettingsWizard()
MPDConnectionDetails InitialSettingsWizard::getDetails()
{
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (basic->isChecked()) {
MPDUser::self()->setMusicFolder(basicDir->text().trimmed());
return MPDUser::self()->details(true);
}
#endif
MPDConnectionDetails det;
det.hostname=host->text().trimmed();
det.port=port->value();
@@ -215,11 +224,14 @@ void InitialSettingsWizard::accept()
Settings::self()->saveStoreCoversInMpdDir(storeCoversInMpdDir->isChecked());
Settings::self()->saveStoreLyricsInMpdDir(storeLyricsInMpdDir->isChecked());
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (basic->isChecked()) {
Settings::self()->saveCurrentConnection(MPDUser::constName);
Settings::self()->saveStopOnExit(true);
emit setDetails(MPDUser::self()->details());
} else {
} else
#endif
{
MPDUser::self()->cleanup();
}
Settings::self()->save();

View File

@@ -26,6 +26,7 @@
#include "ui_initialsettingswizard.h"
#include "mpd-interface/mpdconnection.h"
#include "config.h"
#include <QWizard>
class InitialSettingsWizard : public QWizard, public Ui::InitialSettingsWizard
@@ -49,9 +50,6 @@ private Q_SLOTS:
void accept();
void reject();
void controlNextButton();
private:
bool singleUserSupported;
};
#endif

View File

@@ -28,7 +28,9 @@
#include "support/messagebox.h"
#include "widgets/icons.h"
#include "models/musiclibrarymodel.h"
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
#include "mpd-interface/mpduser.h"
#endif
#include "support/utils.h"
#include <QDir>
#include <QComboBox>
@@ -64,6 +66,7 @@ class CoverNameValidator : public QValidator
}
};
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
class CollectionNameValidator : public QValidator
{
public:
@@ -75,6 +78,7 @@ class CollectionNameValidator : public QValidator
return input.startsWith(MPDUser::constName) ? Invalid : Acceptable;
}
};
#endif
ServerSettings::ServerSettings(QWidget *p)
: QWidget(p)
@@ -139,11 +143,13 @@ void ServerSettings::load()
prevIndex=idx;
}
idx++;
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (d.name==MPDUser::constName) {
d.dir=MPDUser::self()->details().dir;
haveBasicCollection=true;
prevBasic=d;
}
#endif
DeviceOptions opts;
opts.load(MPDConnectionDetails::configGroupName(d.name), true);
collections.append(Collection(d, opts));
@@ -186,9 +192,11 @@ void ServerSettings::save()
if (!found) {
toAdd.append(c);
}
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (c.details.name==MPDUser::constName) {
prevBasic=c;
}
#endif
}
foreach (const MPDConnectionDetails &c, existingInConfig) {
@@ -200,6 +208,7 @@ void ServerSettings::save()
c.namingOpts.save(MPDConnectionDetails::configGroupName(c.details.name), true);
}
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (!haveBasicCollection && MPDUser::self()->isSupported()) {
MPDUser::self()->cleanup();
}
@@ -207,16 +216,19 @@ void ServerSettings::save()
if (current.details.name==MPDUser::constName) {
MPDUser::self()->setDetails(current.details);
}
#endif
Settings::self()->saveCurrentConnection(current.details.name);
MusicLibraryModel::cleanCache();
}
void ServerSettings::cancel()
{
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
// If we are canceling any changes, then we need to restore user settings...
if (prevBasic.details.name==MPDUser::constName) {
MPDUser::self()->setDetails(prevBasic.details);
}
#endif
}
void ServerSettings::showDetails(int index)
@@ -237,6 +249,7 @@ void ServerSettings::showDetails(int index)
void ServerSettings::add()
{
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
bool addStandard=true;
if (!haveBasicCollection && MPDUser::self()->isSupported()) {
@@ -260,14 +273,17 @@ void ServerSettings::add()
default: return;
}
}
#endif
MPDConnectionDetails details;
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (addStandard) {
#endif
details.name=generateName();
details.port=6600;
details.hostname=QLatin1String("localhost");
details.dir=QLatin1String("/var/lib/mpd/music/");
combo->addItem(details.name);
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
} else {
details=MPDUser::self()->details(true);
#if QT_VERSION > 0x050000
@@ -284,6 +300,7 @@ void ServerSettings::add()
MPDUser::self()->setMusicFolder(dir);
combo->addItem(MPDUser::translatedName());
}
#endif
removeButton->setEnabled(combo->count()>1);
collections.append(Collection(details));
combo->setCurrentIndex(combo->count()-1);
@@ -294,7 +311,11 @@ void ServerSettings::add()
void ServerSettings::remove()
{
int index=combo->currentIndex();
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
QString cName=1==stackedWidget->currentIndex() ? MPDUser::translatedName() : name->text();
#else
QString cName=name->text();
#endif
if (combo->count()>1 && MessageBox::Yes==MessageBox::questionYesNo(this, i18n("Delete '%1'?", cName),
i18n("Delete"), StdGuiItem::del(), StdGuiItem::cancel())) {
bool isLast=index==(combo->count()-1);
@@ -371,11 +392,13 @@ QString ServerSettings::generateName(int ignore) const
void ServerSettings::setDetails(const MPDConnectionDetails &details)
{
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (details.name==MPDUser::constName) {
basicDir->setText(Utils::convertPathForDisplay(details.dir));
basicCoverName->setText(details.coverName);
stackedWidget->setCurrentIndex(1);
} else {
#endif
name->setText(details.name.isEmpty() ? i18n("Default") : details.name);
host->setText(details.hostname);
port->setValue(details.port);
@@ -387,7 +410,9 @@ void ServerSettings::setDetails(const MPDConnectionDetails &details)
#endif
topLevel->setText(details.topLevel);
stackedWidget->setCurrentIndex(0);
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
}
#endif
}
MPDConnectionDetails ServerSettings::getDetails() const
@@ -395,9 +420,11 @@ MPDConnectionDetails ServerSettings::getDetails() const
MPDConnectionDetails details;
if (0==stackedWidget->currentIndex()) {
details.name=name->text().trimmed();
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (details.name==MPDUser::constName) {
details.name=QString();
}
#endif
details.hostname=host->text().trimmed();
details.port=port->value();
details.password=password->text();
@@ -407,12 +434,15 @@ MPDConnectionDetails ServerSettings::getDetails() const
details.streamUrl=streamUrl->text().trimmed();
#endif
details.topLevel=topLevel->text().trimmed();
} else {
}
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
else {
details=MPDUser::self()->details(true);
details.dir=Utils::convertPathFromDisplay(basicDir->text());
details.coverName=basicCoverName->text().trimmed();
MPDUser::self()->setMusicFolder(details.dir);
}
#endif
details.setDirReadable();
return details;
}

View File

@@ -28,7 +28,7 @@
#include "mpdparseutils.h"
#include "models/musiclibraryitemroot.h"
#include "models/streamsmodel.h"
#ifndef ENABLE_UBUNTU
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
#include "mpduser.h"
#endif
#include "support/localize.h"
@@ -200,10 +200,10 @@ MPDConnectionDetails::MPDConnectionDetails()
QString MPDConnectionDetails::getName() const
{
#ifdef ENABLE_UBUNTU
return name.isEmpty() ? i18n("Default") : name;
#else
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
return name.isEmpty() ? i18n("Default") : (name==MPDUser::constName ? MPDUser::translatedName() : name);
#else
return name.isEmpty() ? i18n("Default") : name;
#endif
}
@@ -296,7 +296,7 @@ void MPDConnection::start()
void MPDConnection::stop()
{
#ifndef ENABLE_UBUNTU
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (details.name==MPDUser::constName && Settings::self()->stopOnExit()) {
MPDUser::self()->stop();
}
@@ -517,11 +517,11 @@ void MPDConnection::reconnect()
void MPDConnection::setDetails(const MPDConnectionDetails &d)
{
#ifdef ENABLE_UBUNTU
const MPDConnectionDetails &det=d;
#else
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
bool isUser=d.name==MPDUser::constName;
const MPDConnectionDetails &det=isUser ? MPDUser::self()->details() : d;
#else
const MPDConnectionDetails &det=d;
#endif
bool changedDir=det.dir!=details.dir;
bool diffName=det.name!=details.name;
@@ -542,7 +542,7 @@ void MPDConnection::setDetails(const MPDConnectionDetails &d)
unmuteVol=-1;
toggleStopAfterCurrent(false);
mopidy=false;
#ifndef ENABLE_UBUNTU
#ifdef ENABLE_SIMPLE_MPD_SUPPORT
if (isUser) {
MPDUser::self()->start();
}