Move 'load' into playqueue model

This commit is contained in:
craig.p.drummond
2014-04-08 18:55:25 +00:00
committed by craig.p.drummond
parent b082f06db8
commit 28437d77ef
4 changed files with 38 additions and 62 deletions

View File

@@ -722,8 +722,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(StdActions::self()->addPrioLowAction, SIGNAL(triggered(bool)), this, SLOT(addWithPriority()));
connect(StdActions::self()->addPrioDefaultAction, SIGNAL(triggered(bool)), this, SLOT(addWithPriority()));
connect(StdActions::self()->addPrioCustomAction, SIGNAL(triggered(bool)), this, SLOT(addWithPriority()));
connect(MPDConnection::self(), SIGNAL(playlistLoaded(const QString &)), SLOT(songLoaded()));
connect(MPDConnection::self(), SIGNAL(added(const QStringList &)), SLOT(songLoaded()));
connect(MPDConnection::self(), SIGNAL(outputsUpdated(const QList<Output> &)), this, SLOT(outputsUpdated(const QList<Output> &)));
connect(this, SIGNAL(enableOutput(int, bool)), MPDConnection::self(), SLOT(enableOutput(int, bool)));
connect(this, SIGNAL(outputs()), MPDConnection::self(), SLOT(outputs()));
@@ -931,45 +929,6 @@ void MainWindow::initSizes()
MusicLibraryItemAlbum::setup();
}
void MainWindow::load(const QStringList &urls)
{
QStringList useable;
foreach (const QString &path, urls) {
QUrl u(path);
#if defined ENABLE_DEVICES_SUPPORT && (defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND)
QString cdDevice=AudioCdDevice::getDevice(u);
if (!cdDevice.isEmpty()) {
DevicesModel::self()->playCd(cdDevice);
} else
#endif
if (QLatin1String("http")==u.scheme()) {
useable.append(u.toString());
} else if (u.scheme().isEmpty() || QLatin1String("file")==u.scheme()) {
if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal() && !u.path().startsWith(QLatin1String("/media/"))) {
useable.append(QLatin1String("file://")+u.path());
} else if (HttpServer::self()->isAlive()) {
useable.append(HttpServer::self()->encodeUrl(u.path()));
}
}
}
if (useable.count()) {
playQueueModel.addItems(useable, playQueueModel.rowCount(), false, 0);
}
}
void MainWindow::songLoaded()
{
// was song was loaded from commandline when empty...
bool isInitial=-1==playQueueModel.currentSong() && MPDState_Inactive==lastState && MPDState_Inactive==MPDStatus::self()->state();
if (MPDState_Stopped==MPDStatus::self()->state() || isInitial) {
stopVolumeFade();
if (isInitial) {
emit play();
}
}
}
void MainWindow::showError(const QString &message, bool showActions)
{
if (QLatin1String("NO_SONGS")==message) {

View File

@@ -162,7 +162,7 @@ public Q_SLOTS:
void dynamicStatus(const QString &message);
void hideWindow();
void restoreWindow();
void load(const QStringList &urls);
void load(const QStringList &urls) { playQueueModel.load(urls); }
#ifdef ENABLE_KDE_SUPPORT
void configureShortcuts();
void saveShortcuts();
@@ -170,7 +170,6 @@ public Q_SLOTS:
void showAboutDialog();
#endif
void setMpdVolume(int v);
void songLoaded();
void mpdConnectionStateChanged(bool connected);
void playQueueItemsSelected(bool s);
void showSidebarPreferencesPage() { showPreferencesDialog("interface:sidebar"); }

View File

@@ -43,6 +43,9 @@
#include "actioncollection.h"
#ifdef ENABLE_DEVICES_SUPPORT
#include "devicesmodel.h"
#if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND
#include "audiocddevice.h"
#endif
#endif
#include <QPalette>
#include <QFont>
@@ -83,6 +86,30 @@ static bool checkExtension(const QString &file)
return pos>1 ? constExtensions.contains(file.mid(pos+1).toLower()) : false;
}
static QStringList parseUrls(const QStringList &urls, bool percentEncoded)
{
QStringList useable;
foreach (const QString &path, urls) {
QUrl u=percentEncoded ? QUrl::fromPercentEncoding(path.toUtf8()) : QUrl(path);
#if defined ENABLE_DEVICES_SUPPORT && (defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND)
QString cdDevice=AudioCdDevice::getDevice(u);
if (!cdDevice.isEmpty()) {
DevicesModel::self()->playCd(cdDevice);
} else
#endif
if (QLatin1String("http")==u.scheme()) {
useable.append(u.toString());
} else if ((u.scheme().isEmpty() || QLatin1String("file")==u.scheme()) && checkExtension(u.path())) {
if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal() && !u.path().startsWith(QLatin1String("/media/"))) {
useable.append(QLatin1String("file://")+u.path());
} else if (HttpServer::self()->isAlive()) {
useable.append(HttpServer::self()->encodeUrl(u.path()));
}
}
}
return useable;
}
void PlayQueueModel::encode(QMimeData &mimeData, const QString &mime, const QStringList &values)
{
QByteArray encodedData;
@@ -589,25 +616,7 @@ bool PlayQueueModel::dropMimeData(const QMimeData *data,
addItems(decode(*data, constFileNameMimeType), row, false, 0);
return true;
} else if(data->hasFormat(constUriMimeType)/* && MPDConnection::self()->getDetails().isLocal()*/) {
QStringList orig=decode(*data, constUriMimeType);
QStringList useable;
foreach (QString u, orig) {
if (u.startsWith(QLatin1String("http://"))) {
useable.append(u);
} else if (u.startsWith('/') || u.startsWith(QLatin1String("file://"))) {
if (u.startsWith(QLatin1String("file://"))) {
u=u.mid(7);
}
if (checkExtension(u)) {
if (!HttpServer::self()->forceUsage() && MPDConnection::self()->getDetails().isLocal() && !u.startsWith(QLatin1String("/media/"))) {
useable.append(QLatin1String("file://")+QUrl::fromPercentEncoding(u.toUtf8()));
} else if (HttpServer::self()->isAlive()) {
useable.append(HttpServer::self()->encodeUrl(QUrl::fromPercentEncoding(u.toUtf8())));
}
}
}
}
QStringList useable=parseUrls(decode(*data, constUriMimeType), true);
if (useable.count()) {
addItems(useable, row, false, 0);
return true;
@@ -616,6 +625,14 @@ bool PlayQueueModel::dropMimeData(const QMimeData *data,
return false;
}
void PlayQueueModel::load(const QStringList &urls)
{
QStringList useable=parseUrls(urls, false);
if (useable.count()) {
addItems(useable, songs.count(), songs.isEmpty(), 0);
}
}
void PlayQueueModel::addItems(const QStringList &items, int row, bool replace, quint8 priority)
{
bool haveRadioStream=false;

View File

@@ -123,6 +123,7 @@ private:
void addSortAction(const QString &name, const QString &key);
public Q_SLOTS:
void load(const QStringList &urls);
void addItems(const QStringList &items, int row, bool replace, quint8 priority);
void addItems(const QStringList &items, bool replace, quint8 priority) { addItems(items, -1, replace, priority); }
void addFiles(const QStringList &filenames, int row, bool replace, quint8 priority);