Commit 2c47c529 authored by Matthieu Gallien's avatar Matthieu Gallien

Merge branch 'release/19.12'

parents c6b401e9 d2837716
......@@ -20,7 +20,6 @@
#include "androidmusiclistener.h"
#include "databaseinterface.h"
#include "musicaudiotrack.h"
#include <QDateTime>
#include <QMetaObject>
......@@ -40,7 +39,7 @@ public:
QHash<QUrl, QDateTime> mAllFiles;
QList<MusicAudioTrack> mNewTracks;
DataTypes::ListTrackDataType mNewTracks;
QHash<QString, QUrl> mCovers;
};
......@@ -124,28 +123,28 @@ void AndroidMusicListener::androidMusicTracksScanStarted()
void AndroidMusicListener::newMusicTrack(const QString &trackDescription)
{
auto trackData = trackDescription.split(QStringLiteral("||"));
auto newTrack = MusicAudioTrack{};
newTrack.setTitle(trackData[1]);
auto newTrack = DataTypes::TrackDataType{};
newTrack[DataTypes::TitleRole] = trackData[1];
bool conversionOK = false;
if (trackData[2] != QLatin1String("null")) {
newTrack.setTrackNumber(trackData[2].toInt(&conversionOK));
newTrack[DataTypes::TrackNumberRole] = trackData[2].toInt(&conversionOK);
if (!conversionOK) {
qInfo() << "newMusicTrack" << trackData[1] << trackData[2];
}
}
if (trackData[3] != QLatin1String("null")) {
newTrack.setYear(trackData[3].toInt(&conversionOK));
newTrack[DataTypes::YearRole] = trackData[3].toInt(&conversionOK);
if (!conversionOK) {
qInfo() << "newMusicTrack" << trackData[1] << trackData[3];
}
}
if (trackData[4] != QLatin1String("null")) {
newTrack.setDuration(QTime::fromMSecsSinceStartOfDay(trackData[4].toInt()));
newTrack[DataTypes::DurationRole] = QTime::fromMSecsSinceStartOfDay(trackData[4].toInt());
}
newTrack.setResourceURI(QUrl::fromLocalFile(trackData[5]));
newTrack.setArtist(trackData[6]);
newTrack.setAlbumName(trackData[8]);
newTrack.setComposer(trackData[10]);
newTrack[DataTypes::ResourceRole] = QUrl::fromLocalFile(trackData[5]);
newTrack[DataTypes::ArtistRole] = trackData[6];
newTrack[DataTypes::AlbumRole] = trackData[8];
newTrack[DataTypes::ComposerRole] = trackData[10];
d->mNewTracks.push_back(newTrack);
}
......@@ -169,7 +168,7 @@ void AndroidMusicListener::newMusicAlbum(const QString &albumDescription)
void AndroidMusicListener::androidMusicAlbumsScanFinished()
{
Q_EMIT tracksList(d->mNewTracks, d->mCovers, d->mSourceName);
Q_EMIT tracksList(d->mNewTracks, d->mCovers);
}
void AndroidMusicListener::setDatabaseInterface(DatabaseInterface *model)
......@@ -177,7 +176,6 @@ void AndroidMusicListener::setDatabaseInterface(DatabaseInterface *model)
if (model) {
connect(this, &AndroidMusicListener::tracksList, model, &DatabaseInterface::insertTracksList);
connect(this, &AndroidMusicListener::removedTracksList, model, &DatabaseInterface::removeTracksList);
connect(this, &AndroidMusicListener::modifyTracksList, model, &DatabaseInterface::modifyTracksList);
connect(this, &AndroidMusicListener::askRestoredTracks, model, &DatabaseInterface::askRestoredTracks);
connect(model, &DatabaseInterface::restoredTracks, this, &AndroidMusicListener::restoredTracks);
}
......@@ -200,16 +198,14 @@ void AndroidMusicListener::quitListener()
Q_EMIT clearDatabase(d->mSourceName);
}
void AndroidMusicListener::restoredTracks(const QString &musicSource, QHash<QUrl, QDateTime> allFiles)
void AndroidMusicListener::restoredTracks(QHash<QUrl, QDateTime> allFiles)
{
if (d->mSourceName == musicSource) {
d->mAllFiles = allFiles;
d->mAllFiles = allFiles;
QAndroidJniObject::callStaticMethod<void>("org/kde/elisa/ElisaAndroidMusicScanner",
"listAudioFiles",
"(Landroid/content/Context;)V",
QtAndroid::androidContext().object());
}
QAndroidJniObject::callStaticMethod<void>("org/kde/elisa/ElisaAndroidMusicScanner",
"listAudioFiles",
"(Landroid/content/Context;)V",
QtAndroid::androidContext().object());
}
void AndroidMusicListener::init()
......
......@@ -20,6 +20,8 @@
#ifndef ANDROIDMUSICLISTENER_H
#define ANDROIDMUSICLISTENER_H
#include "datatypes.h"
#include <QObject>
#include <QList>
#include <QHash>
......@@ -76,12 +78,10 @@ Q_SIGNALS:
void clearDatabase(const QString &listenerName);
void tracksList(const QList<MusicAudioTrack> &tracks, const QHash<QString, QUrl> &covers, const QString &musicSource);
void tracksList(const DataTypes::ListTrackDataType &tracks, const QHash<QString, QUrl> &covers);
void removedTracksList(const QList<QUrl> &removedTracks);
void modifyTracksList(const QList<MusicAudioTrack> &modifiedTracks, const QHash<QString, QUrl> &covers, const QString &musicSource);
void askRestoredTracks(const QString &musicSource);
public Q_SLOTS:
......@@ -92,7 +92,7 @@ public Q_SLOTS:
void quitListener();
void restoredTracks(const QString &musicSource, QHash<QUrl, QDateTime> allFiles);
void restoredTracks(QHash<QUrl, QDateTime> allFiles);
void init();
......
......@@ -170,7 +170,13 @@ QVariant ManageHeaderBar::artist() const
return QString();
}
return mCurrentTrack.data(mArtistRole);
auto artistValue = mCurrentTrack.data(mArtistRole);
if (!artistValue.isValid()) {
return mCurrentTrack.data(mAlbumArtistRole);
}
return artistValue;
}
QUrl ManageHeaderBar::image() const
......
......@@ -213,6 +213,40 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
}
break;
}
case DataTypes::ColumnsRoles::ArtistRole:
{
switch (d->mModelType)
{
case ElisaUtils::Track:
{
auto itArtist = d->mAllTrackData[index.row()].find(TrackDataType::key_type::ArtistRole);
if (itArtist != d->mAllTrackData[index.row()].end()) {
result = d->mAllTrackData[index.row()][TrackDataType::key_type::ArtistRole];
} else {
result = d->mAllTrackData[index.row()][TrackDataType::key_type::AlbumArtistRole];
}
break;
}
case ElisaUtils::Album:
result = d->mAllAlbumData[index.row()][static_cast<AlbumDataType::key_type>(role)];
break;
case ElisaUtils::Artist:
result = d->mAllArtistData[index.row()][static_cast<ArtistDataType::key_type>(role)];
break;
case ElisaUtils::Genre:
result = d->mAllGenreData[index.row()][static_cast<GenreDataType::key_type>(role)];
break;
case ElisaUtils::Radio:
result = d->mAllRadiosData[index.row()][static_cast<TrackDataType::key_type>(role)];
break;
case ElisaUtils::Lyricist:
case ElisaUtils::Composer:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
break;
}
break;
}
default:
switch(d->mModelType)
{
......
......@@ -406,8 +406,6 @@ void MusicListenersManager::configChanged()
this, &MusicListenersManager::monitorStartingListeners);
connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::indexingFinished,
this, &MusicListenersManager::monitorEndingListeners);
connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::clearDatabase,
&d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource);
}
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment