Skip to content

Commit

Permalink
Merge pull request #13593 from cr7pt0gr4ph7/ready-for-merge/toggle-au…
Browse files Browse the repository at this point in the history
…todj-via-contextmenu

Auto DJ: Add context menu action for enabling/disabling the Auto DJ
  • Loading branch information
daschuer authored Aug 24, 2024
2 parents 3fc0ad3 + 151017b commit ef153be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QMenu>
#include <QtDebug>

#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/autodj/autodjprocessor.h"
#include "library/autodj/dlgautodj.h"
#include "library/library.h"
Expand Down Expand Up @@ -95,6 +96,20 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
this,
&AutoDJFeature::slotCrateChanged);

// Create context-menu items for enabling/disabling the auto-DJ
m_pEnableAutoDJAction = make_parented<QAction>(tr("Enable Auto DJ"), this);
connect(m_pEnableAutoDJAction.get(),
&QAction::triggered,
this,
&AutoDJFeature::slotEnableAutoDJ);

m_pDisableAutoDJAction = make_parented<QAction>(tr("Disable Auto DJ"), this);
connect(m_pDisableAutoDJAction.get(),
&QAction::triggered,
this,
&AutoDJFeature::slotDisableAutoDJ);

// Create context-menu item for clearing the auto-DJ queue
m_pClearQueueAction = make_parented<QAction>(tr("Clear Auto DJ Queue"), this);
const auto removeKeySequence =
// TODO(XXX): Qt6 replace enum | with QKeyCombination
Expand All @@ -105,6 +120,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
&QAction::triggered,
this,
&AutoDJFeature::slotClearQueue);

// Create context-menu items to allow crates to be added to, and removed
// from, the auto-DJ queue.
m_pRemoveCrateFromAutoDjAction =
Expand Down Expand Up @@ -157,6 +173,13 @@ void AutoDJFeature::bindLibraryWidget(
&DlgAutoDJ::addRandomTrackButton,
this,
&AutoDJFeature::slotAddRandomTrack);

// Update shortcuts displayed in the context menu
QKeySequence toggleAutoDJShortcut = QKeySequence(
keyboard->getKeyboardConfig()->getValueString(ConfigKey("[AutoDJ]", "enabled")),
QKeySequence::PortableText);
m_pEnableAutoDJAction->setShortcut(toggleAutoDJShortcut);
m_pDisableAutoDJAction->setShortcut(toggleAutoDJShortcut);
}

void AutoDJFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
Expand Down Expand Up @@ -229,6 +252,14 @@ bool AutoDJFeature::dragMoveAccept(const QUrl& url) {
Parser::isPlaylistFilenameSupported(url.toLocalFile());
}

void AutoDJFeature::slotEnableAutoDJ() {
m_pAutoDJProcessor->toggleAutoDJ(true);
}

void AutoDJFeature::slotDisableAutoDJ() {
m_pAutoDJProcessor->toggleAutoDJ(false);
}

void AutoDJFeature::slotClearQueue() {
clear();
}
Expand Down Expand Up @@ -336,6 +367,11 @@ void AutoDJFeature::constructCrateChildModel() {

void AutoDJFeature::onRightClick(const QPoint& globalPos) {
QMenu menu(m_pSidebarWidget);
if (m_pAutoDJProcessor->getState() == AutoDJProcessor::ADJ_DISABLED) {
menu.addAction(m_pEnableAutoDJAction.get());
} else {
menu.addAction(m_pDisableAutoDJAction.get());
}
menu.addAction(m_pClearQueueAction.get());
menu.exec(globalPos);
}
Expand Down
6 changes: 6 additions & 0 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ class AutoDJFeature : public LibraryFeature {
// How we access the auto-DJ-crates database.
AutoDJCratesDAO m_autoDjCratesDao;

parented_ptr<QAction> m_pEnableAutoDJAction;
parented_ptr<QAction> m_pDisableAutoDJAction;
parented_ptr<QAction> m_pClearQueueAction;

// A context-menu item that allows crates to be removed from the
// auto-DJ list.
parented_ptr<QAction> m_pRemoveCrateFromAutoDjAction;

QPointer<WLibrarySidebar> m_pSidebarWidget;

private slots:
void slotEnableAutoDJ();
void slotDisableAutoDJ();
void slotClearQueue();

// Add a crate to the auto-DJ queue.
void slotAddCrateToAutoDj(CrateId crateId);
// Implements the context-menu item.
Expand Down

0 comments on commit ef153be

Please sign in to comment.