Skip to content

Commit

Permalink
ITunesDAO: Pass TreeItem by not-null pointer
Browse files Browse the repository at this point in the history
Co-authored-by: Swiftb0y <[email protected]>
  • Loading branch information
fwcd and Swiftb0y committed Apr 24, 2023
1 parent 2c1b3b5 commit 037008b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/library/itunes/itunesdao.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "library/itunes/itunesdao.h"

#include <QSqlQuery>
#include <gsl/pointers>

#include "library/itunes/ituneslocalhosttoken.h"
#include "library/itunes/itunespathmapping.h"
Expand Down Expand Up @@ -111,15 +112,15 @@ bool ITunesDAO::applyPathMapping(const ITunesPathMapping& pathMapping) {
return true;
}

void ITunesDAO::appendPlaylistTree(TreeItem& item, int playlistId) {
void ITunesDAO::appendPlaylistTree(gsl::not_null<TreeItem*> item, int playlistId) {
auto childsRange = m_playlistIdsByParentId.equal_range(playlistId);
std::for_each(childsRange.first,
childsRange.second,
[this, &item](auto childEntry) {
int childId = childEntry.second;
QString childName = m_playlistNameById[childId];
TreeItem* child = item.appendChild(childName);
appendPlaylistTree(*child, childId);
TreeItem* child = item->appendChild(childName);
appendPlaylistTree(child, childId);
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/library/itunes/itunesdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <gsl/pointers>
#include <map>

#include "library/dao/dao.h"
Expand Down Expand Up @@ -50,7 +51,8 @@ class ITunesDAO : public DAO {
virtual bool importPlaylistTrack(int playlistId, int trackId, int position);
virtual bool applyPathMapping(const ITunesPathMapping& pathMapping);

virtual void appendPlaylistTree(TreeItem& item, int playlistId = kRootITunesPlaylistId);
virtual void appendPlaylistTree(gsl::not_null<TreeItem*> item,
int playlistId = kRootITunesPlaylistId);

private:
QHash<QString, int> m_playlistDuplicatesByName;
Expand Down
5 changes: 3 additions & 2 deletions src/library/itunes/itunesmacosimporter.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "library/itunes/itunesmacosimporter.h"

#import <iTunesLibrary/iTunesLibrary.h>
#include <gsl/pointers>
#include "library/itunes/itunesdao.h"

#include <QHash>
Expand Down Expand Up @@ -62,7 +63,7 @@ void importMediaItems(NSArray<ITLibMediaItem*>* items) {
}
}

void appendPlaylistTree(TreeItem& item) {
void appendPlaylistTree(gsl::not_null<TreeItem*> item) {
m_dao.appendPlaylistTree(item);
}

Expand Down Expand Up @@ -216,7 +217,7 @@ void importMediaItem(ITLibMediaItem* item) {

impl.importPlaylists(library.allPlaylists);
impl.importMediaItems(library.allMediaItems);
impl.appendPlaylistTree(*rootItem);
impl.appendPlaylistTree(rootItem.get());

iTunesImport.playlistRoot = std::move(rootItem);
} else if (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/itunes/itunesxmlimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ITunesImport ITunesXMLImporter::importLibrary() {
parsePlaylists();

std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(m_parentFeature);
m_dao.appendPlaylistTree(*pRootItem);
m_dao.appendPlaylistTree(pRootItem.get());

iTunesImport.playlistRoot = std::move(pRootItem);
isTracksParsed = true;
Expand Down

0 comments on commit 037008b

Please sign in to comment.