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

WTrackMenu: show 'Update ReplayGain' only in decks' menus #4719

Merged
merged 5 commits into from
Apr 14, 2022
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
24 changes: 15 additions & 9 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,13 @@ void WTrackMenu::createActions() {
&WTrackMenu::slotClearBeats);
}

if (featureIsEnabled(Feature::UpdateReplayGain)) {
m_pUpdateReplayGain =
// This action is only usable when m_deckGroup is set. That is true only
// for WTrackmenu instantiated by WTrackProperty and other deck widgets, thus
// don't create it if a track model is set.
if (!m_pTrackModel && featureIsEnabled(Feature::UpdateReplayGainFromPregain)) {
m_pUpdateReplayGainAct =
new QAction(tr("Update ReplayGain from Deck Gain"), m_pClearMetadataMenu);
connect(m_pUpdateReplayGain,
connect(m_pUpdateReplayGainAct,
&QAction::triggered,
this,
&WTrackMenu::slotUpdateReplayGainFromPregain);
Expand Down Expand Up @@ -526,8 +529,10 @@ void WTrackMenu::setupActions() {
addMenu(m_pClearMetadataMenu);
}

if (featureIsEnabled(Feature::UpdateReplayGain)) {
addAction(m_pUpdateReplayGain);
// This action is created only for menus instantiated by deck widgets (e.g.
// WTrackProperty) and if UpdateReplayGainFromPregain is supported.
if (m_pUpdateReplayGainAct) {
addAction(m_pUpdateReplayGainAct);
}

addSeparator();
Expand Down Expand Up @@ -763,8 +768,11 @@ void WTrackMenu::updateMenus() {
}
}

if (featureIsEnabled(Feature::UpdateReplayGain)) {
m_pUpdateReplayGain->setEnabled(!m_deckGroup.isEmpty());
// This action is created only for menus instantiated by deck widgets (e.g.
// WTrackProperty) and if UpdateReplayGainFromPregain is supported.
// Disable it if no deck group was set.
if (m_pUpdateReplayGainAct) {
m_pUpdateReplayGainAct->setEnabled(!m_deckGroup.isEmpty());
}

if (featureIsEnabled(Feature::Color)) {
Expand Down Expand Up @@ -2098,8 +2106,6 @@ bool WTrackMenu::featureIsEnabled(Feature flag) const {
return m_pTrackModel->hasCapabilities(TrackModel::Capability::EditMetadata);
case Feature::SearchRelated:
return m_pLibrary != nullptr;
case Feature::UpdateReplayGain:
return m_pTrackModel->hasCapabilities(TrackModel::Capability::EditMetadata);
default:
DEBUG_ASSERT(!"unreachable");
return false;
Expand Down
21 changes: 11 additions & 10 deletions src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class WTrackMenu : public QMenu {
FileBrowser = 1 << 11,
Properties = 1 << 12,
SearchRelated = 1 << 13,
UpdateReplayGain = 1 << 14,
UpdateReplayGainFromPregain = 1 << 14,
TrackModelFeatures = Remove | HideUnhidePurge,
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset |
BPM | Color | HideUnhidePurge | RemoveFromDisk | FileBrowser |
Properties | SearchRelated | UpdateReplayGain
Properties | SearchRelated | UpdateReplayGainFromPregain
};
Q_DECLARE_FLAGS(Features, Feature)

Expand Down Expand Up @@ -220,7 +220,7 @@ class WTrackMenu : public QMenu {
QMenu* m_pRemoveFromDiskMenu{};

// Update ReplayGain from Track
QAction* m_pUpdateReplayGain{};
QAction* m_pUpdateReplayGainAct{};

// Reload Track Metadata Action:
QAction* m_pImportMetadataFromFileAct{};
Expand Down Expand Up @@ -289,14 +289,15 @@ class WTrackMenu : public QMenu {
struct UpdateExternalTrackCollection {
QPointer<ExternalTrackCollection> externalTrackCollection;
QAction* action{};
};
QList<UpdateExternalTrackCollection> m_updateInExternalTrackCollections;
};

bool m_bPlaylistMenuLoaded;
bool m_bCrateMenuLoaded;
QList<UpdateExternalTrackCollection> m_updateInExternalTrackCollections;

Features m_eActiveFeatures;
const Features m_eTrackModelFeatures;
};
bool m_bPlaylistMenuLoaded;
bool m_bCrateMenuLoaded;

Features m_eActiveFeatures;
const Features m_eTrackModelFeatures;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(WTrackMenu::Features)
2 changes: 1 addition & 1 deletion src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::RemoveFromDisk |
WTrackMenu::Feature::FileBrowser |
WTrackMenu::Feature::Properties |
WTrackMenu::Feature::UpdateReplayGain;
WTrackMenu::Feature::UpdateReplayGainFromPregain;
} // namespace

WTrackProperty::WTrackProperty(
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtracktext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Color |
WTrackMenu::Feature::FileBrowser |
WTrackMenu::Feature::Properties |
WTrackMenu::Feature::UpdateReplayGain;
WTrackMenu::Feature::UpdateReplayGainFromPregain;
} // namespace

WTrackText::WTrackText(QWidget* pParent,
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtrackwidgetgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Color |
WTrackMenu::Feature::FileBrowser |
WTrackMenu::Feature::Properties |
WTrackMenu::Feature::UpdateReplayGain;
WTrackMenu::Feature::UpdateReplayGainFromPregain;

} // anonymous namespace

Expand Down