Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseExternalLibraryFeature: Add ability to import external playlists as crates #11852

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/library/baseexternallibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "library/library.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "library/trackset/crate/crate.h"
#include "moc_baseexternallibraryfeature.cpp"
#include "util/logger.h"
#include "widget/wlibrarysidebar.h"
Expand Down Expand Up @@ -40,11 +41,17 @@ BaseExternalLibraryFeature::BaseExternalLibraryFeature(
this,
&BaseExternalLibraryFeature::slotAddToAutoDJReplace);

m_pImportAsMixxxPlaylistAction = make_parented<QAction>(tr("Import Playlist"), this);
m_pImportAsMixxxPlaylistAction = make_parented<QAction>(tr("Import as Playlist"), this);
connect(m_pImportAsMixxxPlaylistAction,
&QAction::triggered,
this,
&BaseExternalLibraryFeature::slotImportAsMixxxPlaylist);

m_pImportAsMixxxCrateAction = make_parented<QAction>(tr("Import as Crate"), this);
connect(m_pImportAsMixxxCrateAction,
&QAction::triggered,
this,
&BaseExternalLibraryFeature::slotImportAsMixxxCrate);
}

void BaseExternalLibraryFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
Expand All @@ -68,6 +75,7 @@ void BaseExternalLibraryFeature::onRightClickChild(
menu.addAction(m_pAddToAutoDJReplaceAction);
menu.addSeparator();
menu.addAction(m_pImportAsMixxxPlaylistAction);
menu.addAction(m_pImportAsMixxxCrateAction);
menu.exec(globalPos);
}

Expand Down Expand Up @@ -101,7 +109,7 @@ void BaseExternalLibraryFeature::addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc) {
}

void BaseExternalLibraryFeature::slotImportAsMixxxPlaylist() {
// qDebug() << "slotAddToAutoDJ() row:" << m_lastRightClickedIndex.data();
// qDebug() << "slotImportAsMixxxPlaylist() row:" << m_lastRightClickedIndex.data();

QList<TrackId> trackIds;
QString playlist;
Expand All @@ -125,6 +133,30 @@ void BaseExternalLibraryFeature::slotImportAsMixxxPlaylist() {
}
}

void BaseExternalLibraryFeature::slotImportAsMixxxCrate() {
// qDebug() << "slotImportAsMixxxCrate() row:" << m_lastRightClickedIndex.data();

QList<TrackId> trackIds;
QString playlist;
appendTrackIdsFromRightClickIndex(&trackIds, &playlist);
if (trackIds.isEmpty()) {
return;
}

Crate crate;
crate.setName(playlist);

CrateId crateId;

if (m_pTrackCollection->insertCrate(crate, &crateId)) {
m_pTrackCollection->addCrateTracks(crateId, trackIds);
} else {
QMessageBox::warning(nullptr,
tr("Crate Creation Failed"),
tr("Could not create crate, it most likely already exists: ") + playlist);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have a better error message here but I guess thats not currently possible with the insertCrate API, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, anything more specific would likely require refactoring those APIs (aside from manually checking the crates, though I haven't dug too far into the crate APIs yet).

}
}

// This is a common function for all external Librarys copied to Mixxx DB
void BaseExternalLibraryFeature::appendTrackIdsFromRightClickIndex(
QList<TrackId>* trackIds, QString* pPlaylist) {
Expand Down
2 changes: 2 additions & 0 deletions src/library/baseexternallibraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BaseExternalLibraryFeature : public LibraryFeature {
void slotAddToAutoDJTop();
void slotAddToAutoDJReplace();
void slotImportAsMixxxPlaylist();
void slotImportAsMixxxCrate();

protected:
QModelIndex lastRightClickedIndex() const {
Expand All @@ -60,6 +61,7 @@ class BaseExternalLibraryFeature : public LibraryFeature {
parented_ptr<QAction> m_pAddToAutoDJTopAction;
parented_ptr<QAction> m_pAddToAutoDJReplaceAction;
parented_ptr<QAction> m_pImportAsMixxxPlaylistAction;
parented_ptr<QAction> m_pImportAsMixxxCrateAction;

QPointer<WLibrarySidebar> m_pSidebarWidget;
};
Loading