diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index fcca77552..896544d05 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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 &)), this, SLOT(outputsUpdated(const QList &))); 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) { diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d77312db5..981b00abc 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -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"); } diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index ee2a32457..0d59b45c1 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -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 #include @@ -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; diff --git a/models/playqueuemodel.h b/models/playqueuemodel.h index b7e627162..5520a3cb4 100644 --- a/models/playqueuemodel.h +++ b/models/playqueuemodel.h @@ -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);