Commit 72dff67d authored by Tobias Fella's avatar Tobias Fella Committed by Nate Graham
Browse files

Port to Qt6

parent c7af011b
......@@ -3,6 +3,8 @@
include:
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android-qt6.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/windows.yml
......@@ -42,6 +42,10 @@ if (NOT WIN32 AND NOT ANDROID)
TYPE OPTIONAL)
endif()
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
set(QtDBus_FOUND 1)
endif()
find_package(Qt${QT_MAJOR_VERSION}QuickWidgets ${REQUIRED_QT_VERSION} CONFIG QUIET)
set_package_properties(Qt${QT_MAJOR_VERSION}QuickWidgets PROPERTIES
DESCRIPTION "Qt${QT_MAJOR_VERSION} Quick Widgets is needed at runtime to provide the interface."
......@@ -57,6 +61,7 @@ if (ANDROID)
set_package_properties(Qt5AndroidExtras PROPERTIES
DESCRIPTION "Qt5 AndroidExtras is needed to provide the Android integration."
TYPE REQUIRED)
set(QtAndroidExtras_FOUND 1)
endif()
find_package(KF5Kirigami2 ${REQUIRED_KF5_VERSION} CONFIG QUIET)
......
......@@ -176,7 +176,7 @@ if (KF5XmlGui_FOUND AND KF5KCMUtils_FOUND)
target_include_directories(elisaapplicationtest PRIVATE ${CMAKE_SOURCE_DIR}/src)
endif()
if (Qt5Quick_FOUND AND Qt5Widgets_FOUND AND NOT WIN32)
if (Qt${QT_MAJOR_VERSION}Quick_FOUND AND Qt${QT_MAJOR_VERSION}Widgets_FOUND AND NOT WIN32)
set(elisaqmltests_SOURCES
elisaqmltests.cpp
qmltests/tst_GridBrowserDelegate.qml
......
......@@ -10,9 +10,9 @@
#cmakedefine01 UPNPQT_FOUND
#cmakedefine01 Qt5DBus_FOUND
#cmakedefine01 QtDBus_FOUND
#cmakedefine01 Qt5AndroidExtras_FOUND
#cmakedefine01 QtAndroidExtras_FOUND
#cmakedefine01 KF5DBusAddons_FOUND
......
......@@ -146,7 +146,7 @@ if (KF5KIO_FOUND)
endif()
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
ecm_qt_declare_logging_category(elisaLib_SOURCES
HEADER "baloo/baloocommon.h"
IDENTIFIER "orgKdeElisaBaloo"
......@@ -179,7 +179,7 @@ if (KF5Baloo_FOUND)
endif()
endif()
if (Qt5DBus_FOUND)
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
set(elisaLib_SOURCES
${elisaLib_SOURCES}
mpris2/mpris2.cpp
......@@ -202,7 +202,7 @@ if (UPNPQT_FOUND)
endif()
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
qt_add_dbus_interface(elisaLib_SOURCES
${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.fileindexer.xml
baloo/fileindexer)
......@@ -263,7 +263,7 @@ if (KF5ConfigWidgets_FOUND)
endif()
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
target_link_libraries(elisaLib
LINK_PUBLIC
KF5::Baloo
......@@ -271,7 +271,7 @@ if (KF5Baloo_FOUND)
endif()
endif()
if (Qt5DBus_FOUND)
if (Qt${QT_MAJOR_VERSION}DBus_FOUND)
target_link_libraries(elisaLib
LINK_PUBLIC
Qt::DBus
......@@ -342,6 +342,12 @@ target_link_libraries(elisaqmlplugin
elisaLib
)
if(QT_MAJOR_VERSION STREQUAL "6")
target_sources(elisaqmlplugin PUBLIC res-qt6.qrc)
else()
target_sources(elisaqmlplugin PUBLIC res-qt5.qrc)
endif()
if (KF5FileMetaData_FOUND)
target_link_libraries(elisaqmlplugin
LINK_PRIVATE
......@@ -381,7 +387,7 @@ add_dependencies(elisaqmlplugin copy copy2)
ecm_generate_qmltypes(org.kde.elisa 1.0
DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/elisa)
if (Qt5Quick_FOUND AND Qt5Widgets_FOUND)
if (Qt${QT_MAJOR_VERSION}Quick_FOUND AND Qt${QT_MAJOR_VERSION}Widgets_FOUND)
set(elisa_SOURCES
main.cpp
......
......@@ -151,7 +151,7 @@ void AbstractFileListing::scanDirectory(DataTypes::ListTrackDataType &newFiles,
}
}
auto &currentDirectoryListingFiles = d->mDiscoveredFiles[path];
auto currentDirectoryListingFiles = d->mDiscoveredFiles[path];
auto currentFilesList = QSet<QUrl>();
......
......@@ -18,6 +18,12 @@
class AudioWrapperPrivate;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define PlaybackState State
#define playbackState state
#endif
class ELISALIB_EXPORT AudioWrapper : public QObject
{
Q_OBJECT
......@@ -41,7 +47,7 @@ class ELISALIB_EXPORT AudioWrapper : public QObject
READ status
NOTIFY statusChanged)
Q_PROPERTY(QMediaPlayer::State playbackState
Q_PROPERTY(QMediaPlayer::PlaybackState playbackState
READ playbackState
NOTIFY playbackStateChanged)
......@@ -76,7 +82,7 @@ public:
[[nodiscard]] QMediaPlayer::MediaStatus status() const;
[[nodiscard]] QMediaPlayer::State playbackState() const;
[[nodiscard]] QMediaPlayer::PlaybackState playbackState() const;
[[nodiscard]] QMediaPlayer::Error error() const;
......@@ -96,7 +102,7 @@ Q_SIGNALS:
void statusChanged(QMediaPlayer::MediaStatus status);
void playbackStateChanged(QMediaPlayer::State state);
void playbackStateChanged(QMediaPlayer::PlaybackState state);
void errorChanged(QMediaPlayer::Error error);
......@@ -149,7 +155,7 @@ private Q_SLOTS:
private:
void savePosition(qint64 position);
void playerStateSignalChanges(QMediaPlayer::State newState);
void playerStateSignalChanges(QMediaPlayer::PlaybackState newState);
void mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus);
......
......@@ -11,6 +11,7 @@
#include <QTimer>
#include <QAudio>
#include <QAudioOutput>
#include "config-upnp-qt.h"
......@@ -23,6 +24,13 @@ public:
QMediaPlayer mPlayer;
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
QAudioOutput mOutput;
#else
#define mOutput mPlayer
#define QAudioOutput QMediaPlayer
#endif
qint64 mSavedPosition = 0.0;
qint64 mUndoSavedPosition = 0.0;
......@@ -33,14 +41,24 @@ public:
AudioWrapper::AudioWrapper(QObject *parent) : QObject(parent), d(std::make_unique<AudioWrapperPrivate>())
{
connect(&d->mPlayer, &QMediaPlayer::mutedChanged, this, &AudioWrapper::playerMutedChanged);
connect(&d->mPlayer, &QMediaPlayer::volumeChanged, this, &AudioWrapper::playerVolumeChanged);
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
d->mPlayer.setAudioOutput(&d->mOutput);
#endif
connect(&d->mOutput, &QAudioOutput::mutedChanged, this, &AudioWrapper::playerMutedChanged);
connect(&d->mOutput, &QAudioOutput::volumeChanged, this, &AudioWrapper::playerVolumeChanged);
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
connect(&d->mPlayer, &QMediaPlayer::sourceChanged, this, &AudioWrapper::sourceChanged);
connect(&d->mPlayer, &QMediaPlayer::playbackStateChanged, this, &AudioWrapper::playbackStateChanged);
connect(&d->mPlayer, &QMediaPlayer::playbackStateChanged, this, &AudioWrapper::playerStateChanged);
connect(&d->mPlayer, QOverload<QMediaPlayer::Error, const QString &>::of(&QMediaPlayer::errorOccurred), this, &AudioWrapper::errorChanged);
#else
connect(&d->mPlayer, &QMediaPlayer::mediaChanged, this, &AudioWrapper::sourceChanged);
connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioWrapper::statusChanged);
connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioWrapper::mediaStatusChanged);
connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioWrapper::playbackStateChanged);
connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioWrapper::playerStateChanged);
connect(&d->mPlayer, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), this, &AudioWrapper::errorChanged);
#endif
connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioWrapper::statusChanged);
connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioWrapper::mediaStatusChanged);
connect(&d->mPlayer, &QMediaPlayer::durationChanged, this, &AudioWrapper::durationChanged);
connect(&d->mPlayer, &QMediaPlayer::positionChanged, this, &AudioWrapper::positionChanged);
connect(&d->mPlayer, &QMediaPlayer::seekableChanged, this, &AudioWrapper::seekableChanged);
......@@ -53,12 +71,12 @@ AudioWrapper::~AudioWrapper()
bool AudioWrapper::muted() const
{
return d->mPlayer.isMuted();
return d->mOutput.isMuted();
}
qreal AudioWrapper::volume() const
{
auto realVolume = static_cast<qreal>(d->mPlayer.volume() / 100.0);
auto realVolume = static_cast<qreal>(d->mOutput.volume() / 100.0);
auto userVolume = static_cast<qreal>(QAudio::convertVolume(realVolume, QAudio::LinearVolumeScale, QAudio::LogarithmicVolumeScale));
return userVolume * 100.0;
......@@ -67,7 +85,11 @@ qreal AudioWrapper::volume() const
QUrl AudioWrapper::source() const
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
return d->mPlayer.source();
#else
return d->mPlayer.media().request().url();
#endif
#else
return d->mPlayer.media().canonicalUrl();
#endif
......@@ -97,9 +119,9 @@ bool AudioWrapper::seekable() const
return d->mPlayer.isSeekable();
}
QMediaPlayer::State AudioWrapper::playbackState() const
QMediaPlayer::PlaybackState AudioWrapper::playbackState() const
{
return d->mPlayer.state();
return d->mPlayer.playbackState();
}
QMediaPlayer::MediaStatus AudioWrapper::status() const
......@@ -109,7 +131,7 @@ QMediaPlayer::MediaStatus AudioWrapper::status() const
void AudioWrapper::setMuted(bool muted)
{
d->mPlayer.setMuted(muted);
d->mOutput.setMuted(muted);
}
void AudioWrapper::setVolume(qreal volume)
......@@ -117,14 +139,17 @@ void AudioWrapper::setVolume(qreal volume)
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::setVolume" << volume;
auto realVolume = static_cast<qreal>(QAudio::convertVolume(volume / 100.0, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale));
d->mPlayer.setVolume(qRound(realVolume * 100));
d->mOutput.setVolume(qRound(realVolume * 100));
}
void AudioWrapper::setSource(const QUrl &source)
{
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::setSource" << source;
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
d->mPlayer.setSource({source});
#else
d->mPlayer.setMedia({source});
#endif
}
void AudioWrapper::setPosition(qint64 position)
......@@ -181,19 +206,19 @@ void AudioWrapper::mediaStatusChanged()
void AudioWrapper::playerStateChanged()
{
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::playerStateChanged" << d->mPlayer.state();
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::playerStateChanged" << d->mPlayer.playbackState();
switch(d->mPlayer.state())
switch(d->mPlayer.playbackState())
{
case QMediaPlayer::State::StoppedState:
case QMediaPlayer::PlaybackState::StoppedState:
Q_EMIT stopped();
d->mPowerInterface.setPreventSleep(false);
break;
case QMediaPlayer::State::PlayingState:
case QMediaPlayer::PlaybackState::PlayingState:
Q_EMIT playing();
d->mPowerInterface.setPreventSleep(true);
break;
case QMediaPlayer::State::PausedState:
case QMediaPlayer::PlaybackState::PausedState:
Q_EMIT paused();
d->mPowerInterface.setPreventSleep(false);
break;
......@@ -202,7 +227,7 @@ void AudioWrapper::playerStateChanged()
void AudioWrapper::playerVolumeChanged()
{
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::playerVolumeChanged" << d->mPlayer.volume();
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::playerVolumeChanged" << d->mOutput.volume();
QTimer::singleShot(0, [this]() {Q_EMIT volumeChanged();});
}
......@@ -214,7 +239,7 @@ void AudioWrapper::playerMutedChanged()
QTimer::singleShot(0, [this]() {Q_EMIT mutedChanged(muted());});
}
void AudioWrapper::playerStateSignalChanges(QMediaPlayer::State newState)
void AudioWrapper::playerStateSignalChanges(QMediaPlayer::PlaybackState newState)
{
qCDebug(orgKdeElisaPlayerQtMultimedia) << "AudioWrapper::playerStateSignalChanges" << newState;
......
......@@ -551,7 +551,11 @@ bool ElisaApplication::eventFilter(QObject *object, QEvent *event)
#if KF5XmlGui_FOUND
auto *keyEvent = static_cast<QKeyEvent*>(event);
auto playPauseAction = d->mCollection.action(QStringLiteral("Play-Pause"));
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0].key() == Qt::Key_Space) {
#else
if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0] == Qt::Key_Space) {
#endif
return true;
}
#else
......
......@@ -64,7 +64,7 @@
#include "audiowrapper.h"
#if Qt5DBus_FOUND
#if QtDBus_FOUND
#include "mpris2/mpris2.h"
#include "mpris2/mediaplayer2player.h"
#endif
......@@ -145,7 +145,7 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<QAbstractProxyModel>(uri, 1, 0, "AbstractProxyModel", QStringLiteral("Abstract Qt type"));
qmlRegisterUncreatableType<DataTypes>(uri, 1, 0, "DataTypes", QStringLiteral("Abstract type not to be used in aml directtly"));
#if Qt5DBus_FOUND
#if QtDBus_FOUND
qmlRegisterType<Mpris2>(uri, 1, 0, "Mpris2");
qRegisterMetaType<MediaPlayer2Player*>();
#endif
......
......@@ -17,7 +17,6 @@
#include <KFileMetaData/SimpleExtractionResult>
#include <KFileMetaData/UserMetaData>
#include <KFileMetaData/Properties>
#include <KFileMetaData/EmbeddedImageData>
#if KF5Baloo_FOUND
......@@ -39,7 +38,11 @@ public:
#if KF5FileMetaData_FOUND
KFileMetaData::ExtractorCollection mAllExtractors;
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
KFileMetaData::PropertyMultiMap mAllProperties;
#else
KFileMetaData::PropertyMap mAllProperties;
#endif
KFileMetaData::EmbeddedImageData mImageScanner;
#endif
......@@ -220,11 +223,13 @@ void FileScanner::scanProperties(const QString &localFileName, DataTypes::TrackD
} else {
value = (*rangeBegin).second;
}
const auto &translatedKey = d->propertyTranslation.find(key);
if (translatedKey.value() == DataTypes::DurationRole) {
trackData.insert(translatedKey.value(), QTime::fromMSecsSinceStartOfDay(int(1000 * (*rangeBegin).second.toDouble())));
} else if (translatedKey != d->propertyTranslation.end()) {
trackData.insert(translatedKey.value(), (*rangeBegin).second);
if (d->propertyTranslation.contains(key)) {
const auto &translatedKey = d->propertyTranslation.find(key);
if (translatedKey.value() == DataTypes::DurationRole) {
trackData.insert(translatedKey.value(), QTime::fromMSecsSinceStartOfDay(int(1000 * (*rangeBegin).second.toDouble())));
} else if (translatedKey != d->propertyTranslation.end()) {
trackData.insert(translatedKey.value(), (*rangeBegin).second);
}
}
rangeBegin = rangeEnd;
}
......@@ -287,11 +292,17 @@ QUrl FileScanner::searchForCoverFile(const QString &localFileName)
bool FileScanner::checkEmbeddedCoverImage(const QString &localFileName)
{
#if KF5FileMetaData_FOUND
const auto &imageData = d->mImageScanner.imageData(localFileName);
if (!imageData.isEmpty()) {
return true;
const auto &mimeType = QMimeDatabase().mimeTypeForFile(localFileName).name();
auto extractors = d->mAllExtractors.fetchExtractors(mimeType);
for (const auto &extractor : extractors) {
KFileMetaData::SimpleExtractionResult result(localFileName, mimeType, KFileMetaData::ExtractionResult::ExtractImageData);
extractor->extract(&result);
if (!result.imageData().isEmpty()) {
return true;
}
}
#else
Q_UNUSED(localFileName)
#endif
......
......@@ -37,13 +37,13 @@
#include <QQmlFileSelector>
#include <QQuickStyle>
#if Qt5AndroidExtras_FOUND
#if QtAndroidExtras_FOUND
#include <QAndroidService>
#endif
#include <memory>
#if Qt5AndroidExtras_FOUND
#if QtAndroidExtras_FOUND
#include <QAndroidJniObject>
#include <QtAndroid>
#endif
......@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
KLocalizedString::setApplicationDomain("elisa");
#if Qt5AndroidExtras_FOUND
#if QtAndroidExtras_FOUND
qInfo() << QCoreApplication::arguments();
QAndroidJniObject::callStaticMethod<void>("org/kde/elisa/ElisaService",
......
......@@ -15,6 +15,11 @@
#include <QTimer>
#include <QDateTime>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define PlaybackState State
#define playbackState state
#endif
ManageAudioPlayer::ManageAudioPlayer(QObject *parent) : QObject(parent)
{
......@@ -54,7 +59,7 @@ QMediaPlayer::MediaStatus ManageAudioPlayer::playerStatus() const
return mPlayerStatus;
}
QMediaPlayer::State ManageAudioPlayer::playerPlaybackState() const
QMediaPlayer::PlaybackState ManageAudioPlayer::playerPlaybackState() const
{
return mPlayerPlaybackState;
}
......@@ -243,12 +248,10 @@ void ManageAudioPlayer::setPlayerStatus(QMediaPlayer::MediaStatus playerStatus)
case QMediaPlayer::InvalidMedia:
triggerSkipNextTrack();
break;
case QMediaPlayer::UnknownMediaStatus:
break;
}
}
void ManageAudioPlayer::setPlayerPlaybackState(QMediaPlayer::State playerPlaybackState)
void ManageAudioPlayer::setPlayerPlaybackState(QMediaPlayer::PlaybackState playerPlaybackState)
{
if (mPlayerPlaybackState == playerPlaybackState) {
return;
......@@ -372,7 +375,6 @@ void ManageAudioPlayer::playPause()
case QMediaPlayer::NoMedia:
case QMediaPlayer::StalledMedia:
case QMediaPlayer::InvalidMedia:
case QMediaPlayer::UnknownMediaStatus:
break;
}
}
......
......@@ -15,6 +15,11 @@
#include <QUrl>
#include <QMediaPlayer>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define PlaybackState State
#define playbackState state
#endif
class QDateTime;
class ELISALIB_EXPORT ManageAudioPlayer : public QObject
......@@ -65,7 +70,7 @@ class ELISALIB_EXPORT ManageAudioPlayer : public QObject
WRITE setPlayerStatus
NOTIFY playerStatusChanged)
Q_PROPERTY(QMediaPlayer::State playerPlaybackState
Q_PROPERTY(QMediaPlayer::PlaybackState playerPlaybackState
READ playerPlaybackState
WRITE setPlayerPlaybackState
NOTIFY playerPlaybackStateChanged)
......@@ -116,7 +121,7 @@ public:
[[nodiscard]] QMediaPlayer::MediaStatus playerStatus() const;
[[nodiscard]] QMediaPlayer::State playerPlaybackState() const;
[[nodiscard]] QMediaPlayer::PlaybackState playerPlaybackState() const;
[[nodiscard]] QMediaPlayer::Error playerError() const;
......@@ -210,7 +215,7 @@ public Q_SLOTS:
void setPlayerStatus(QMediaPlayer::MediaStatus playerStatus);
void setPlayerPlaybackState(QMediaPlayer::State playerPlaybackState);
void setPlayerPlaybackState(QMediaPlayer::PlaybackState playerPlaybackState);
void setPlayerError(QMediaPlayer::Error playerError);
......@@ -280,7 +285,7 @@ private:
QMediaPlayer::MediaStatus mPlayerStatus = QMediaPlayer::NoMedia;
QMediaPlayer::State mPlayerPlaybackState = QMediaPlayer::StoppedState;
QMediaPlayer::PlaybackState mPlayerPlaybackState = QMediaPlayer::StoppedState;
QMediaPlayer::Error mPlayerError = QMediaPlayer::NoError;
......
......@@ -12,7 +12,6 @@
#include "elisa_settings.h"
#include <QItemSelection>
#include <QList>
#include <QMediaPlaylist>
#include <QRandomGenerator>
#include <QFile>
#include <QFileInfo>
......@@ -35,8 +34,6 @@ public:
QPersistentModelIndex mNextTrack;
QMediaPlaylist mLoadPlaylist;
QList<int> mRandomMapping;
QVariantMap mPersistentSettingsForUndo;
......@@ -58,8 +55,6 @@ public:
MediaPlayListProxyModel::MediaPlayListProxyModel(QObject *parent) : QAbstractProxyModel (parent),
d(std::make_unique<MediaPlayListProxyModelPrivate>())
{
connect(&d->mLoadPlaylist, &QMediaPlaylist::loaded, this, &MediaPlayListProxyModel::loadPlayListLoaded);
connect(&d->mLoadPlaylist, &QMediaPlaylist::loadFailed, this, &MediaPlayListProxyModel::loadPlayListLoadFailed);
d->mRandomGenerator.seed(static_cast<unsigned int>(QTime::currentTime().msec()));
}
......@@ -719,13 +714,18 @@ void MediaPlayListProxyModel::determineTracks()
bool MediaPlayListProxyModel::savePlayList(const QUrl &fileName)
{
QMediaPlaylist savePlaylist;
QFile outputFile(fileName.toLocalFile());
auto open = outputFile.open(QFile::WriteOnly);
if (!open) {
return false;
}
if (Elisa::ElisaConfiguration::self()->alwaysUseAbsolutePlaylistPaths()) {
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i,0), MediaPlayList::IsValidRole).toBool()) {
data(index(i,0), MediaPlayList::ResourceRole).toUrl();
savePlaylist.addMedia(QUrl(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile()));
outputFile.write(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile().toUtf8());
outputFile.write("\n");
}
}
} else {
......@@ -737,47 +737,38 @@ bool MediaPlayListProxyModel::savePlayList(const QUrl &fileName)
QFileInfo musicFile(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile());
if (musicFile.dir().path() == dir.absolutePath()) {
savePlaylist.addMedia(QUrl(musicFile.fileName()));
outputFile.write(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile().toUtf8());
} else {
savePlaylist.addMedia(QUrl(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile()));
outputFile.write(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile().toUtf8());
}
outputFile.write("\n");
}
}
}
return savePlaylist.save(fileName, "m3u8");
return true;
}
void MediaPlayListProxyModel::loadPlayList(const QUrl &fileName)
{
d->mLoadPlaylist.clear();
d->mLoadPlaylist.load(fileName, "m3u8");
}
void MediaPlayListProxyModel::loadPlayListLoaded()
{
QFile inputFile(fileName.toLocalFile());
auto open = inputFile.open(QFile::ReadOnly);
if (!open) {
Q_EMIT playListLoadFailed();
}
const auto data = inputFile.readAll();
clearPlayList();
auto newTracks = DataTypes::EntryDataList{};