Commit 01891c33 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

only use std::unique_ptr for private implementatio d pointers

fix memory leak when modifying removing local file indexers

may need a fix under review for KFileMetaData
parent 5f073589
......@@ -40,12 +40,15 @@ public:
};
AbstractFileListener::AbstractFileListener(QObject *parent)
: QObject(parent), d(new AbstractFileListenerPrivate)
: QObject(parent), d(std::make_unique<AbstractFileListenerPrivate>())
{
}
AbstractFileListener::~AbstractFileListener()
= default;
{
d->mFileQueryThread.quit();
d->mFileQueryThread.wait();
}
DatabaseInterface *AbstractFileListener::databaseInterface() const
{
......
......@@ -70,7 +70,7 @@ public:
};
AbstractFileListing::AbstractFileListing(const QString &sourceName, QObject *parent) : QObject(parent), d(new AbstractFileListingPrivate(sourceName))
AbstractFileListing::AbstractFileListing(const QString &sourceName, QObject *parent) : QObject(parent), d(std::make_unique<AbstractFileListingPrivate>(sourceName))
{
connect(&d->mFileSystemWatcher, &QFileSystemWatcher::directoryChanged,
this, &AbstractFileListing::directoryChanged);
......
......@@ -42,7 +42,7 @@ public:
};
AlbumModel::AlbumModel(QObject *parent) : QAbstractItemModel(parent), d(new AlbumModelPrivate)
AlbumModel::AlbumModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique<AlbumModelPrivate>())
{
}
......
......@@ -42,7 +42,7 @@ public:
};
AllAlbumsModel::AllAlbumsModel(QObject *parent) : QAbstractItemModel(parent), d(new AllAlbumsModelPrivate)
AllAlbumsModel::AllAlbumsModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique<AllAlbumsModelPrivate>())
{
}
......
......@@ -42,7 +42,7 @@ public:
};
AllArtistsModel::AllArtistsModel(QObject *parent) : QAbstractItemModel(parent), d(new AllArtistsModelPrivate)
AllArtistsModel::AllArtistsModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique<AllArtistsModelPrivate>())
{
}
......
......@@ -33,7 +33,7 @@ public:
};
AllTracksModel::AllTracksModel(QObject *parent) : QAbstractItemModel(parent), d(new AllTracksModelPrivate)
AllTracksModel::AllTracksModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique<AllTracksModelPrivate>())
{
}
......
......@@ -34,7 +34,7 @@ public:
};
AudioWrapper::AudioWrapper(QObject *parent) : QObject(parent), d(new AudioWrapperPrivate)
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);
......
......@@ -82,7 +82,7 @@ public:
};
LocalBalooFileListing::LocalBalooFileListing(QObject *parent)
: AbstractFileListing(QStringLiteral("baloo"), parent), d(new LocalBalooFileListingPrivate)
: AbstractFileListing(QStringLiteral("baloo"), parent), d(std::make_unique<LocalBalooFileListingPrivate>())
{
d->mQuery.addType(QStringLiteral("Audio"));
setHandleNewFiles(false);
......
......@@ -32,7 +32,7 @@ public:
};
FileListener::FileListener(QObject *parent) : AbstractFileListener(parent), d(new FileListenerPrivate)
FileListener::FileListener(QObject *parent) : AbstractFileListener(parent), d(std::make_unique<FileListenerPrivate>())
{
setFileListing(&d->mLocalFileIndexer);
connect(&d->mLocalFileIndexer, &LocalFileListing::rootPathChanged,
......
......@@ -47,7 +47,7 @@ public:
};
LocalFileListing::LocalFileListing(QObject *parent) : AbstractFileListing(QStringLiteral("local"), parent), d(new LocalFileListingPrivate)
LocalFileListing::LocalFileListing(QObject *parent) : AbstractFileListing(QStringLiteral("local"), parent), d(std::make_unique<LocalFileListingPrivate>())
{
}
......
......@@ -56,7 +56,7 @@ public:
};
MusicAlbum::MusicAlbum() : d(new MusicAlbumPrivate)
MusicAlbum::MusicAlbum() : d(std::make_unique<MusicAlbumPrivate>())
{
}
......@@ -65,7 +65,7 @@ MusicAlbum::MusicAlbum(MusicAlbum &&other)
d.swap(other.d);
}
MusicAlbum::MusicAlbum(const MusicAlbum &other) : d(new MusicAlbumPrivate(*other.d))
MusicAlbum::MusicAlbum(const MusicAlbum &other) : d(std::make_unique<MusicAlbumPrivate>(*other.d))
{
}
......
......@@ -37,7 +37,7 @@ public:
};
MusicArtist::MusicArtist() : d(new MusicArtistPrivate)
MusicArtist::MusicArtist() : d(std::make_unique<MusicArtistPrivate>())
{
}
......@@ -46,7 +46,7 @@ MusicArtist::MusicArtist(MusicArtist &&other)
d.swap(other.d);
}
MusicArtist::MusicArtist(const MusicArtist &other) : d(new MusicArtistPrivate(*other.d))
MusicArtist::MusicArtist(const MusicArtist &other) : d(std::make_unique<MusicArtistPrivate>(*other.d))
{
}
......
......@@ -82,14 +82,14 @@ public:
};
MusicAudioTrack::MusicAudioTrack() : d(new MusicAudioTrackPrivate)
MusicAudioTrack::MusicAudioTrack() : d(std::make_unique<MusicAudioTrackPrivate>())
{
}
MusicAudioTrack::MusicAudioTrack(bool aValid, const QString &aId, const QString &aParentId,
const QString &aTitle, const QString &aArtist, const QString &aAlbumName, const QString &aAlbumArtist,
int aTrackNumber, QTime aDuration, const QUrl &aResourceURI, const QUrl &aAlbumCover, int rating)
: d(new MusicAudioTrackPrivate(aValid, aId, aParentId, aTitle, aArtist, aAlbumName, aAlbumArtist, aTrackNumber, aDuration, aResourceURI, aAlbumCover, rating))
: d(std::make_unique<MusicAudioTrackPrivate>(aValid, aId, aParentId, aTitle, aArtist, aAlbumName, aAlbumArtist, aTrackNumber, aDuration, aResourceURI, aAlbumCover, rating))
{
}
......@@ -97,7 +97,7 @@ MusicAudioTrack::MusicAudioTrack(bool aValid, const QString &aId, const QString
const QString &aTitle, const QString &aArtist, const QString &aAlbumName,
const QString &aAlbumArtist, int aTrackNumber, int aDiscNumber,
QTime aDuration, const QUrl &aResourceURI, const QUrl &aAlbumCover, int rating)
: d(new MusicAudioTrackPrivate(aValid, aId, aParentId, aTitle, aArtist, aAlbumName, aAlbumArtist, aTrackNumber, aDiscNumber, aDuration, aResourceURI, aAlbumCover, rating))
: d(std::make_unique<MusicAudioTrackPrivate>(aValid, aId, aParentId, aTitle, aArtist, aAlbumName, aAlbumArtist, aTrackNumber, aDiscNumber, aDuration, aResourceURI, aAlbumCover, rating))
{
}
......@@ -106,7 +106,7 @@ MusicAudioTrack::MusicAudioTrack(MusicAudioTrack &&other)
d.swap(other.d);
}
MusicAudioTrack::MusicAudioTrack(const MusicAudioTrack &other) : d(new MusicAudioTrackPrivate(*other.d))
MusicAudioTrack::MusicAudioTrack(const MusicAudioTrack &other) : d(std::make_unique<MusicAudioTrackPrivate>(*other.d))
{
}
......
......@@ -47,6 +47,8 @@
#include <QPointer>
#include <QFileSystemWatcher>
#include <list>
class MusicListenersManagerPrivate
{
public:
......@@ -64,7 +66,7 @@ public:
#endif
#if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND
QList<QPointer<FileListener>> mFileListener;
std::list<std::unique_ptr<FileListener>> mFileListener;
#endif
DatabaseInterface mDatabaseInterface;
......@@ -80,7 +82,7 @@ public:
};
MusicListenersManager::MusicListenersManager(QObject *parent)
: QObject(parent), d(new MusicListenersManagerPrivate)
: QObject(parent), d(std::make_unique<MusicListenersManagerPrivate>())
{
d->mListenerThread.start();
d->mDatabaseThread.start();
......@@ -210,7 +212,7 @@ void MusicListenersManager::resetImportedTracksCounter()
#endif
#if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND
for (auto itFileListener : d->mFileListener) {
for (const auto &itFileListener : d->mFileListener) {
itFileListener->resetImportedTracksCounter();
}
#endif
......@@ -272,28 +274,28 @@ void MusicListenersManager::configChanged()
for (const auto &oneRootPath : allRootPaths) {
auto itPath = std::find_if(d->mFileListener.begin(), d->mFileListener.end(),
[&oneRootPath](auto value)->bool {return value->localFileIndexer().rootPath() == oneRootPath;});
[&oneRootPath](const auto &value)->bool {return value->localFileIndexer().rootPath() == oneRootPath;});
if (itPath == d->mFileListener.end()) {
auto newFileIndexer = new FileListener;
auto newFileIndexer = std::make_unique<FileListener>();
newFileIndexer->setDatabaseInterface(&d->mDatabaseInterface);
newFileIndexer->moveToThread(&d->mListenerThread);
connect(this, &MusicListenersManager::applicationIsTerminating,
newFileIndexer, &FileListener::applicationAboutToQuit, Qt::DirectConnection);
connect(newFileIndexer, &FileListener::indexingStarted,
newFileIndexer.get(), &FileListener::applicationAboutToQuit, Qt::DirectConnection);
connect(newFileIndexer.get(), &FileListener::indexingStarted,
this, &MusicListenersManager::monitorStartingListeners);
connect(newFileIndexer, &FileListener::indexingFinished,
connect(newFileIndexer.get(), &FileListener::indexingFinished,
this, &MusicListenersManager::monitorEndingListeners);
connect(newFileIndexer, &FileListener::notification,
connect(newFileIndexer.get(), &FileListener::notification,
this, &MusicListenersManager::listenerNotification);
connect(newFileIndexer, &FileListener::importedTracksCountChanged,
connect(newFileIndexer.get(), &FileListener::importedTracksCountChanged,
this, &MusicListenersManager::computeImportedTracksCount);
newFileIndexer->setRootPath(oneRootPath);
d->mFileListener.push_back({newFileIndexer});
QMetaObject::invokeMethod(newFileIndexer.get(), "performInitialScan", Qt::QueuedConnection);
QMetaObject::invokeMethod(newFileIndexer, "performInitialScan", Qt::QueuedConnection);
d->mFileListener.emplace_back(std::move(newFileIndexer));
}
}
}
......@@ -311,7 +313,7 @@ void MusicListenersManager::computeImportedTracksCount()
#endif
#if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND
for (auto itFileListener : d->mFileListener) {
for (const auto &itFileListener : d->mFileListener) {
d->mImportedTracksCount += itFileListener->importedTracksCount();
}
#endif
......
......@@ -39,7 +39,7 @@ public:
};
TracksListener::TracksListener(DatabaseInterface *database, QObject *parent) : QObject(parent), d(new TracksListenerPrivate)
TracksListener::TracksListener(DatabaseInterface *database, QObject *parent) : QObject(parent), d(std::make_unique<TracksListenerPrivate>())
{
d->mDatabase = database;
}
......
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