diff options
author | Harshit Maurya <hmaurya999@gmail.com> | 2020-04-02 16:01:59 +0530 |
---|---|---|
committer | Harshit Maurya <hmaurya999@gmail.com> | 2020-04-02 16:01:59 +0530 |
commit | 746a565239cdb84a9c104b34a87ac6d6b3682a5c (patch) | |
tree | f984b595b046022ed97ef5e23ebb96257f50720f /src/widget/wtracktableview.cpp | |
parent | 9abb8a6798aac08e89bb9f3f98b173ecbd275ae0 (diff) |
widget/wtrackmenu: move remaining actions from wtracktableview
Diffstat (limited to 'src/widget/wtracktableview.cpp')
-rw-r--r-- | src/widget/wtracktableview.cpp | 1234 |
1 files changed, 18 insertions, 1216 deletions
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index e3efe93bdc..7b957304bc 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -1,7 +1,6 @@ #include "widget/wtracktableview.h" #include <QCheckBox> -#include <QDesktopServices> #include <QDrag> #include <QInputDialog> #include <QLinkedList> @@ -9,11 +8,9 @@ #include <QScrollBar> #include <QShortcut> #include <QUrl> -#include <QWidgetAction> #include "control/controlobject.h" #include "control/controlproxy.h" -#include "library/coverartutils.h" #include "library/crate/cratefeaturehelper.h" #include "library/dao/trackschema.h" #include "library/dlgtagfetcher.h" @@ -41,6 +38,8 @@ #include "widget/wtracktableviewheader.h" #include "widget/wwidget.h" +#include <iostream> + WTrackTableView::WTrackTableView(QWidget * parent, UserSettingsPointer pConfig, TrackCollectionManager* pTrackCollectionManager, @@ -51,24 +50,10 @@ WTrackTableView::WTrackTableView(QWidget * parent, m_pConfig(pConfig), m_pTrackCollectionManager(pTrackCollectionManager), m_sorting(sorting), - m_iCoverSourceColumn(-1), - m_iCoverTypeColumn(-1), - m_iCoverLocationColumn(-1), - m_iCoverHashColumn(-1), - m_iCoverColumn(-1), m_selectionChangedSinceLastGuiTick(true), - m_loadCachedOnly(false), - m_bPlaylistMenuLoaded(false), - m_bCrateMenuLoaded(false) { + m_loadCachedOnly(false) { - m_pNumSamplers = new ControlProxy( - "[Master]", "num_samplers", this); - m_pNumDecks = new ControlProxy( - "[Master]", "num_decks", this); - m_pNumPreviewDecks = new ControlProxy( - "[Master]", "num_preview_decks", this); - m_pMenu = new WTrackMenu(this, m_pTrackCollectionManager); // Connect slots and signals to make the world go 'round. connect(this, SIGNAL(doubleClicked(const QModelIndex &)), @@ -92,6 +77,8 @@ WTrackTableView::WTrackTableView(QWidget * parent, QKeySequence(tr("ESC", "Focus")), this); connect(setFocusShortcut, SIGNAL(activated()), this, SLOT(setFocus())); + + m_pMenu = new WTrackMenu(this, pConfig, m_pTrackCollectionManager); } WTrackTableView::~WTrackTableView() { @@ -101,50 +88,7 @@ WTrackTableView::~WTrackTableView() { pHeader->saveHeaderState(); } -// delete m_pImportMetadataFromFileAct; -// delete m_pImportMetadataFromMusicBrainzAct; -// delete m_pExportMetadataAct; -// delete m_pAddToPreviewDeck; -// delete m_pAutoDJBottomAct; -// delete m_pAutoDJTopAct; -// delete m_pAutoDJReplaceAct; -// delete m_pRemoveAct; -// delete m_pRemovePlaylistAct; -// delete m_pRemoveCrateAct; -// delete m_pHideAct; -// delete m_pUnhideAct; -// delete m_pPropertiesAct; delete m_pMenu; -// delete m_pLoadToMenu; -// delete m_pDeckMenu; -// delete m_pSamplerMenu; -// delete m_pPlaylistMenu; -// delete m_pCrateMenu; -// delete m_pMetadataMenu; -// delete m_pClearMetadataMenu; -// delete m_pCoverMenu; -// delete m_pBpmLockAction; -// delete m_pBpmUnlockAction; -// delete m_pBpmDoubleAction; -// delete m_pBpmHalveAction; -// delete m_pBpmTwoThirdsAction; -// delete m_pBpmThreeFourthsAction; -// delete m_pBpmFourThirdsAction; -// delete m_pBpmThreeHalvesAction; -// delete m_pBPMMenu; -// delete m_pColorMenu; -// delete m_pClearBeatsAction; -// delete m_pClearPlayCountAction; -// delete m_pClearMainCueAction; -// delete m_pClearHotCuesAction; -// delete m_pClearIntroCueAction; -// delete m_pClearOutroCueAction; -// delete m_pClearLoopAction; -// delete m_pClearReplayGainAction; -// delete m_pClearWaveformAction; -// delete m_pClearAllMetadataAction; -// delete m_pPurgeAct; -// delete m_pFileBrowserAct; } void WTrackTableView::enableCachedOnly() { @@ -238,12 +182,7 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { // by slotLoadCoverArt(). As this value will not change when the model // still the same, we must avoid doing hundreds of "fieldIndex" calls // when it is completely unnecessary... - m_iCoverSourceColumn = trackModel->fieldIndex(LIBRARYTABLE_COVERART_SOURCE); - m_iCoverTypeColumn = trackModel->fieldIndex(LIBRARYTABLE_COVERART_TYPE); - m_iCoverLocationColumn = trackModel->fieldIndex(LIBRARYTABLE_COVERART_LOCATION); - m_iCoverHashColumn = trackModel->fieldIndex(LIBRARYTABLE_COVERART_HASH); - m_iCoverColumn = trackModel->fieldIndex(LIBRARYTABLE_COVERART); - m_iTrackLocationColumn = trackModel->fieldIndex(TRACKLOCATIONSTABLE_LOCATION); + setVisible(false); @@ -382,114 +321,6 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) { // scrollbar positions with respect to different models are backed by map } -void WTrackTableView::createActions() { - /* - - - - for (const auto& externalTrackCollection : m_pTrackCollectionManager->externalCollections()) { - UpdateExternalTrackCollection updateInExternalTrackCollection; - updateInExternalTrackCollection.externalTrackCollection = externalTrackCollection; - updateInExternalTrackCollection.action = new QAction(externalTrackCollection->name(), this); - updateInExternalTrackCollection.action->setToolTip(externalTrackCollection->description()); - m_updateInExternalTrackCollections += updateInExternalTrackCollection; - auto externalTrackCollectionPtr = updateInExternalTrackCollection.externalTrackCollection; - connect(updateInExternalTrackCollection.action, &QAction::triggered, - this, [this, externalTrackCollectionPtr] { - slotUpdateExternalTrackCollection(externalTrackCollectionPtr); - }); - } - - m_pAddToPreviewDeck = new QAction(tr("Preview Deck"), this); - // currently there is only one preview deck so just map it here. - QString previewDeckGroup = PlayerManager::groupForPreviewDeck(0); - connect(m_pAddToPreviewDeck, &QAction::triggered, - this, [this, previewDeckGroup] { loadSelectionToGroup(previewDeckGroup); }); - - - // Clear metadata actions - m_pClearBeatsAction = new QAction(tr("BPM and Beatgrid"), this); - connect(m_pClearBeatsAction, SIGNAL(triggered()), - this, SLOT(slotClearBeats())); - - m_pClearPlayCountAction = new QAction(tr("Play Count"), this); - connect(m_pClearPlayCountAction, SIGNAL(triggered()), - this, SLOT(slotClearPlayCount())); - - m_pClearMainCueAction = new QAction(tr("Cue Point"), this); - connect(m_pClearMainCueAction, SIGNAL(triggered()), - this, SLOT(slotClearMainCue())); - - m_pClearHotCuesAction = new QAction(tr("Hotcues"), this); - connect(m_pClearHotCuesAction, SIGNAL(triggered()), - this, SLOT(slotClearHotCues())); - - m_pClearIntroCueAction = new QAction(tr("Intro"), this); - connect(m_pClearIntroCueAction, SIGNAL(triggered()), - this, SLOT(slotClearIntroCue())); - - m_pClearOutroCueAction = new QAction(tr("Outro"), this); - connect(m_pClearOutroCueAction, SIGNAL(triggered()), - this, SLOT(slotClearOutroCue())); - - m_pClearLoopAction = new QAction(tr("Loop"), this); - connect(m_pClearLoopAction, SIGNAL(triggered()), - this, SLOT(slotClearLoop())); - - m_pClearKeyAction = new QAction(tr("Key"), this); - connect(m_pClearKeyAction, SIGNAL(triggered()), - this, SLOT(slotClearKey())); - - m_pClearReplayGainAction = new QAction(tr("ReplayGain"), this); - connect(m_pClearReplayGainAction, SIGNAL(triggered()), - this, SLOT(slotClearReplayGain())); - - m_pClearWaveformAction = new QAction(tr("Waveform"), this); - connect(m_pClearWaveformAction, SIGNAL(triggered()), - this, SLOT(slotClearWaveform())); - - m_pClearAllMetadataAction = new QAction(tr("All"), this); - connect(m_pClearAllMetadataAction, SIGNAL(triggered()), - this, SLOT(slotClearAllMetadata())); - - - m_pBpmLockAction = new QAction(tr("Lock BPM"), this); - m_pBpmUnlockAction = new QAction(tr("Unlock BPM"), this); - connect(m_pBpmLockAction, SIGNAL(triggered()), - this, SLOT(slotLockBpm())); - connect(m_pBpmUnlockAction, SIGNAL(triggered()), - this, SLOT(slotUnlockBpm())); - - //BPM edit actions - m_pBpmDoubleAction = new QAction(tr("Double BPM"), this); - m_pBpmHalveAction = new QAction(tr("Halve BPM"), this); - m_pBpmTwoThirdsAction = new QAction(tr("2/3 BPM"), this); - m_pBpmThreeFourthsAction = new QAction(tr("3/4 BPM"), this); - m_pBpmFourThirdsAction = new QAction(tr("4/3 BPM"), this); - m_pBpmThreeHalvesAction = new QAction(tr("3/2 BPM"), this); - - connect(m_pBpmDoubleAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::DOUBLE); }); - connect(m_pBpmHalveAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::HALVE); }); - connect(m_pBpmTwoThirdsAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::TWOTHIRDS); }); - connect(m_pBpmThreeFourthsAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::THREEFOURTHS); }); - connect(m_pBpmFourThirdsAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::FOURTHIRDS); }); - connect(m_pBpmThreeHalvesAction, &QAction::triggered, - this, [this] { slotScaleBpm(Beats::THREEHALVES); }); - - ColorPaletteSettings colorPaletteSettings(m_pConfig); - m_pColorPickerAction = new WColorPickerAction(WColorPicker::Option::AllowNoColor, colorPaletteSettings.getTrackColorPalette(), this); - m_pColorPickerAction->setObjectName("TrackColorPickerAction"); - connect(m_pColorPickerAction, - &WColorPickerAction::colorPicked, - this, - &WTrackTableView::slotColorPicked);*/ -} - // slot void WTrackTableView::slotMouseDoubleClicked(const QModelIndex &index) { // Read the current TrackLoadAction settings @@ -519,16 +350,17 @@ void WTrackTableView::slotMouseDoubleClicked(const QModelIndex &index) { } } + void WTrackTableView::loadSelectionToGroup(QString group, bool play) { QModelIndexList indices = selectionModel()->selectedRows(); if (indices.size() > 0) { // If the track load override is disabled, check to see if a track is // playing before trying to load it if (!(m_pConfig->getValueString( - ConfigKey("[Controls]","AllowTrackLoadToPlayingDeck")).toInt())) { + ConfigKey("[Controls]","AllowTrackLoadToPlayingDeck")).toInt())) { // TODO(XXX): Check for other than just the first preview deck. if (group != "[PreviewDeck1]" && - ControlObject::get(ConfigKey(group, "play")) > 0.0) { + ControlObject::get(ConfigKey(group, "play")) > 0.0) { return; } } @@ -536,21 +368,13 @@ void WTrackTableView::loadSelectionToGroup(QString group, bool play) { TrackModel* trackModel = getTrackModel(); TrackPointer pTrack; if (trackModel && - (pTrack = trackModel->getTrack(index))) { + (pTrack = trackModel->getTrack(index))) { emit loadTrackToPlayer(pTrack, group, play); } } } -void WTrackTableView::slotRemove() { - QModelIndexList indices = selectionModel()->selectedRows(); - if (indices.size() > 0) { - TrackModel* trackModel = getTrackModel(); - if (trackModel) { - trackModel->removeTracks(indices); - } - } -} + void WTrackTableView::slotPurge() { QModelIndexList indices = selectionModel()->selectedRows(); @@ -562,16 +386,6 @@ void WTrackTableView::slotPurge() { } } -void WTrackTableView::slotHide() { - QModelIndexList indices = selectionModel()->selectedRows(); - if (indices.size() > 0) { - TrackModel* trackModel = getTrackModel(); - if (trackModel) { - trackModel->hideTracks(indices); - } - } -} - void WTrackTableView::slotUnhide() { QModelIndexList indices = selectionModel()->selectedRows(); @@ -583,458 +397,15 @@ void WTrackTableView::slotUnhide() { } } -void WTrackTableView::slotTrackInfoClosed() { - DlgTrackInfo* pTrackInfo = m_pTrackInfo.take(); - // We are in a slot directly invoked from DlgTrackInfo. Delete it - // later. - if (pTrackInfo != nullptr) { - pTrackInfo->deleteLater(); - } -} - -void WTrackTableView::slotTagFetcherClosed() { - DlgTagFetcher* pTagFetcher = m_pTagFetcher.take(); - // We are in a slot directly invoked from DlgTagFetcher. Delete it - // later. - if (pTagFetcher != nullptr) { - pTagFetcher->deleteLater(); - } -} - -void WTrackTableView::slotShowTrackInfo() { - QModelIndexList indices = selectionModel()->selectedRows(); - - if (indices.size() > 0) { - showTrackInfo(indices[0]); - } -} - -void WTrackTableView::slotNextTrackInfo() { - QModelIndex nextRow = currentTrackInfoIndex.sibling( - currentTrackInfoIndex.row()+1, currentTrackInfoIndex.column()); - if (nextRow.isValid()) { - showTrackInfo(nextRow); - if (!m_pTagFetcher.isNull()) { - showDlgTagFetcher(nextRow); - } - } -} - -void WTrackTableView::slotPrevTrackInfo() { - QModelIndex prevRow = currentTrackInfoIndex.sibling( - currentTrackInfoIndex.row()-1, currentTrackInfoIndex.column()); - if (prevRow.isValid()) { - showTrackInfo(prevRow); - if (!m_pTagFetcher.isNull()) { - showDlgTagFetcher(prevRow); - } - } -} - -void WTrackTableView::showTrackInfo(QModelIndex index) { - TrackModel* trackModel = getTrackModel(); - - if (!trackModel) { - return; - } - - if (m_pTrackInfo.isNull()) { - // Give a NULL parent because otherwise it inherits our style which can - // make it unreadable. Bug #673411 - m_pTrackInfo.reset(new DlgTrackInfo(m_pConfig, nullptr)); - - connect(m_pTrackInfo.data(), SIGNAL(next()), - this, SLOT(slotNextTrackInfo())); - connect(m_pTrackInfo.data(), SIGNAL(previous()), - this, SLOT(slotPrevTrackInfo())); - connect(m_pTrackInfo.data(), SIGNAL(showTagFetcher(TrackPointer)), - this, SLOT(slotShowTrackInTagFetcher(TrackPointer))); - connect(m_pTrackInfo.data(), SIGNAL(finished(int)), - this, SLOT(slotTrackInfoClosed())); - } - TrackPointer pTrack = trackModel->getTrack(index); - m_pTrackInfo->loadTrack(pTrack); // NULL is fine. - currentTrackInfoIndex = index; - m_pTrackInfo->show(); -} - -void WTrackTableView::slotNextDlgTagFetcher() { - QModelIndex nextRow = currentTrackInfoIndex.sibling( - currentTrackInfoIndex.row()+1, currentTrackInfoIndex.column()); - if (nextRow.isValid()) { - showDlgTagFetcher(nextRow); - if (!m_pTrackInfo.isNull()) { - showTrackInfo(nextRow); - } - } -} - -void WTrackTableView::slotPrevDlgTagFetcher() { - QModelIndex prevRow = currentTrackInfoIndex.sibling( - currentTrackInfoIndex.row()-1, currentTrackInfoIndex.column()); - if (prevRow.isValid()) { - showDlgTagFetcher(prevRow); - if (!m_pTrackInfo.isNull()) { - showTrackInfo(prevRow); - } - } -} - -void WTrackTableView::showDlgTagFetcher(QModelIndex index) { - TrackModel* trackModel = getTrackModel(); - - if (!trackModel) { - return; - } - - TrackPointer pTrack = trackModel->getTrack(index); - currentTrackInfoIndex = index; - slotShowTrackInTagFetcher(pTrack); -} - -void WTrackTableView::slotShowTrackInTagFetcher(TrackPointer pTrack) { - if (m_pTagFetcher.isNull()) { - m_pTagFetcher.reset(new DlgTagFetcher(nullptr)); - connect(m_pTagFetcher.data(), SIGNAL(next()), - this, SLOT(slotNextDlgTagFetcher())); - connect(m_pTagFetcher.data(), SIGNAL(previous()), - this, SLOT(slotPrevDlgTagFetcher())); - connect(m_pTagFetcher.data(), SIGNAL(finished(int)), - this, SLOT(slotTagFetcherClosed())); - } - - // NULL is fine - m_pTagFetcher->loadTrack(pTrack); - m_pTagFetcher->show(); -} - -void WTrackTableView::slotShowDlgTagFetcher() { - QModelIndexList indices = selectionModel()->selectedRows(); - - if (indices.size() > 0) { - showDlgTagFetcher(indices[0]); - } -} - void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) { - /* - QModelIndexList indices = selectionModel()->selectedRows(); - - // Gray out some stuff if multiple songs were selected. - bool oneSongSelected = indices.size() == 1; - TrackModel* trackModel = getTrackModel(); - - m_pMenu->clear(); - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_ADDTOAUTODJ)) { - m_pMenu->clear(); - m_pMenu->addAction(m_pAutoDJBottomAct); - m_pMenu->addAction(m_pAutoDJTopAct); - m_pMenu->addAction(m_pAutoDJReplaceAct); - m_pMenu->addSeparator(); - } - - m_pLoadToMenu->clear(); - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_LOADTODECK)) { - int iNumDecks = m_pNumDecks->get(); - m_pDeckMenu->clear(); - if (iNumDecks > 0) { - for (int i = 1; i <= iNumDecks; ++i) { - // PlayerManager::groupForDeck is 0-indexed. - QString deckGroup = PlayerManager::groupForDeck(i - 1); - bool deckPlaying = ControlObject::get( - ConfigKey(deckGroup, "play")) > 0.0; - bool loadTrackIntoPlayingDeck = m_pConfig->getValue<bool>( - ConfigKey("[Controls]", "AllowTrackLoadToPlayingDeck")); - bool deckEnabled = (!deckPlaying || loadTrackIntoPlayingDeck) && oneSongSelected; - QAction* pAction = new QAction(tr("Deck %1").arg(i), m_pMenu); - pAction->setEnabled(deckEnabled); - m_pDeckMenu->addAction(pAction); - connect(pAction, &QAction::triggered, - this, [this, deckGroup] { loadSelectionToGroup(deckGroup); }); - } - } - m_pLoadToMenu->addMenu(m_pDeckMenu); - } - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_LOADTOSAMPLER)) { - int iNumSamplers = m_pNumSamplers->get(); - if (iNumSamplers > 0) { - m_pSamplerMenu->clear(); - for (int i = 1; i <= iNumSamplers; ++i) { - // PlayerManager::groupForSampler is 0-indexed. - QString samplerGroup = PlayerManager::groupForSampler(i - 1); - bool samplerPlaying = ControlObject::get( - ConfigKey(samplerGroup, "play")) > 0.0; - bool samplerEnabled = !samplerPlaying && oneSongSelected; - QAction* pAction = new QAction(tr("Sampler %1").arg(i), m_pSamplerMenu); - pAction->setEnabled(samplerEnabled); - m_pSamplerMenu->addAction(pAction); - connect(pAction, &QAction::triggered, - this, [this, samplerGroup] {loadSelectionToGroup(samplerGroup); } ); - - } - m_pLoadToMenu->addMenu(m_pSamplerMenu); - } - } - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_LOADTOPREVIEWDECK) && - m_pNumPreviewDecks->get() > 0.0) { - m_pLoadToMenu->addAction(m_pAddToPreviewDeck); - } - - m_pMenu->addMenu(m_pLoadToMenu); - m_pMenu->addSeparator(); - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_ADDTOPLAYLIST)) { - // Playlist menu is lazy loaded on hover by slotPopulatePlaylistMenu - // to avoid unnecessary database queries - m_bPlaylistMenuLoaded = false; - m_pMenu->addMenu(m_pPlaylistMenu); - } - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_ADDTOCRATE)) { - // Crate menu is lazy loaded on hover by slotPopulateCrateMenu - // to avoid unnecessary database queries - m_bCrateMenuLoaded = false; - m_pMenu->addMenu(m_pCrateMenu); - } - - // REMOVE and HIDE should not be at the first menu position to avoid accidental clicks - bool locked = modelHasCapabilities(TrackModel::TRACKMODELCAPS_LOCKED); - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_REMOVE)) { - m_pRemoveAct->setEnabled(!locked); - m_pMenu->addAction(m_pRemoveAct); - } - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_REMOVE_PLAYLIST)) { - m_pRemovePlaylistAct->setEnabled(!locked); - m_pMenu->addAction(m_pRemovePlaylistAct); - } - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_REMOVE_CRATE)) { - m_pRemoveCrateAct->setEnabled(!locked); - m_pMenu->addAction(m_pRemoveCrateAct); - } - - m_pMenu->addSeparator(); - m_pMetadataMenu->clear(); - m_pMetadataUpdateExternalCollectionsMenu->clear(); - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - m_pMetadataMenu->addAction(m_pImportMetadataFromFileAct); - m_pImportMetadataFromMusicBrainzAct->setEnabled(oneSongSelected); - m_pMetadataMenu->addAction(m_pImportMetadataFromMusicBrainzAct); - m_pMetadataMenu->addAction(m_pExportMetadataAct); - - for (const auto& updateInExternalTrackCollection : m_updateInExternalTrackCollections) { - ExternalTrackCollection* externalTrackCollection = - updateInExternalTrackCollection.externalTrackCollection; - if (externalTrackCollection) { - updateInExternalTrackCollection.action->setEnabled( - externalTrackCollection->isConnected()); - m_pMetadataUpdateExternalCollectionsMenu->addAction( - updateInExternalTrackCollection.action); - } - } - if (!m_pMetadataUpdateExternalCollectionsMenu->isEmpty()) { - m_pMetadataMenu->addMenu(m_pMetadataUpdateExternalCollectionsMenu); - } - - for (const auto& updateInExternalTrackCollection : m_updateInExternalTrackCollections) { - ExternalTrackCollection* externalTrackCollection = - updateInExternalTrackCollection.externalTrackCollection; - if (externalTrackCollection) { - updateInExternalTrackCollection.action->setEnabled( - externalTrackCollection->isConnected()); - m_pMetadataUpdateExternalCollectionsMenu->addAction( - updateInExternalTrackCollection.action); - } - } - if (!m_pMetadataUpdateExternalCollectionsMenu->isEmpty()) { - m_pMetadataMenu->addMenu(m_pMetadataUpdateExternalCollectionsMenu); - } - - m_pClearMetadataMenu->clear(); + // Set the track model + m_pMenu->setTrackModel(getTrackModel()); - if (trackModel == nullptr) { - return; - } - bool allowClear = true; - int column = trackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK); - for (int i = 0; i < indices.size() && allowClear; ++i) { - int row = indices.at(i).row(); - QModelIndex index = indices.at(i).sibling(row,column); - if (index.data().toBool()) { - allowClear = false; - } - } - m_pClearBeatsAction->setEnabled(allowClear); - m_pClearMetadataMenu->addAction(m_pClearBeatsAction); - } - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_RESETPLAYED)) { - m_pClearMetadataMenu->addAction(m_pClearPlayCountAction); - } - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - // FIXME: Why is clearing the loop not working? - m_pClearMetadataMenu->addAction(m_pClearMainCueAction); - m_pClearMetadataMenu->addAction(m_pClearHotCuesAction); - m_pClearMetadataMenu->addAction(m_pClearIntroCueAction); - m_pClearMetadataMenu->addAction(m_pClearOutroCueAction); - //m_pClearMetadataMenu->addAction(m_pClearLoopAction); - m_pClearMetadataMenu->addAction(m_pClearKeyAction); - m_pClearMetadataMenu->addAction(m_pClearReplayGainAction); - m_pClearMetadataMenu->addAction(m_pClearWaveformAction); - m_pClearMetadataMenu->addSeparator(); - m_pClearMetadataMenu->addAction(m_pClearAllMetadataAction); - - // Cover art menu only applies if at least one track is selected. - if (indices.size()) { - // We load a single track to get the necessary context for the cover (we use - // last to be consistent with selectionChanged above). - QModelIndex last = indices.last(); - CoverInfo info; - info.source = static_cast<CoverInfo::Source>( - last.sibling(last.row(), m_iCoverSourceColumn).data().toInt()); - info.type = static_cast<CoverInfo::Type>( - last.sibling(last.row(), m_iCoverTypeColumn).data().toInt()); - info.hash = last.sibling(last.row(), m_iCoverHashColumn).data().toUInt(); - info.trackLocation = last.sibling( - last.row(), m_iTrackLocationColumn).data().toString(); - info.coverLocation = last.sibling( - last.row(), m_iCoverLocationColumn).data().toString(); - m_pCoverMenu->setCoverArt(info); - m_pMetadataMenu->addMenu(m_pCoverMenu); - } - - m_pMenu->addMenu(m_pMetadataMenu); - m_pMenu->addMenu(m_pClearMetadataMenu); - - m_pBPMMenu->addAction(m_pBpmDoubleAction); - m_pBPMMenu->addAction(m_pBpmHalveAction); - m_pBPMMenu->addAction(m_pBpmTwoThirdsAction); - m_pBPMMenu->addAction(m_pBpmThreeFourthsAction); - m_pBPMMenu->addAction(m_pBpmFourThirdsAction); - m_pBPMMenu->addAction(m_pBpmThreeHalvesAction); - m_pBPMMenu->addSeparator(); - m_pBPMMenu->addAction(m_pBpmLockAction); - m_pBPMMenu->addAction(m_pBpmUnlockAction); - m_pBPMMenu->addSeparator(); - if (oneSongSelected) { - if (trackModel == nullptr) { - return; - } - int column = trackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK); - QModelIndex index = indices.at(0).sibling(indices.at(0).row(),column); - if (index.data().toBool()) { //BPM is locked - m_pBpmUnlockAction->setEnabled(true); - m_pBpmLockAction->setEnabled(false); - m_pBpmDoubleAction->setEnabled(false); - m_pBpmHalveAction->setEnabled(false); - m_pBpmTwoThirdsAction->setEnabled(false); - m_pBpmThreeFourthsAction->setEnabled(false); - m_pBpmFourThirdsAction->setEnabled(false); - m_pBpmThreeHalvesAction->setEnabled(false); - } else { //BPM is not locked - m_pBpmUnlockAction->setEnabled(false); - m_pBpmLockAction->setEnabled(true); - m_pBpmDoubleAction->setEnabled(true); - m_pBpmHalveAction->setEnabled(true); - m_pBpmTwoThirdsAction->setEnabled(true); - m_pBpmThreeFourthsAction->setEnabled(true); - m_pBpmFourThirdsAction->setEnabled(true); - m_pBpmThreeHalvesAction->setEnabled(true); - } - } else { - bool anyLocked = false; //true if any of the selected items are locked - int column = trackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK); - for (int i = 0; i < indices.size() && !anyLocked; ++i) { - int row = indices.at(i).row(); - QModelIndex index = indices.at(i).sibling(row,column); - if (index.data().toBool()) { - anyLocked = true; - } - } - if (anyLocked) { - m_pBpmLockAction->setEnabled(false); - m_pBpmUnlockAction->setEnabled(true); - m_pBpmDoubleAction->setEnabled(false); - m_pBpmHalveAction->setEnabled(false); - m_pBpmTwoThirdsAction->setEnabled(false); - m_pBpmThreeFourthsAction->setEnabled(false); - m_pBpmFourThirdsAction->setEnabled(false); - m_pBpmThreeHalvesAction->setEnabled(false); - } else { - m_pBpmLockAction->setEnabled(true); - m_pBpmUnlockAction->setEnabled(false); - m_pBpmDoubleAction->setEnabled(true); - m_pBpmHalveAction->setEnabled(true); - m_pBpmTwoThirdsAction->setEnabled(true); - m_pBpmThreeFourthsAction->setEnabled(true); - m_pBpmFourThirdsAction->setEnabled(true); - m_pBpmThreeHalvesAction->setEnabled(true); - } - } - m_pMenu->addMenu(m_pBPMMenu); - - // Track color menu only appears if at least one track is selected - if (indices.size()) { - m_pColorPickerAction->setColorPalette( - ColorPaletteSettings(m_pConfig).getTrackColorPalette()); - - // Get color of first selected track - int column = trackModel->fieldIndex(LIBRARYTABLE_COLOR); - QModelIndex index = indices.at(0).sibling(indices.at(0).row(), column); - auto trackColor = mixxx::RgbColor::fromQVariant(index.data()); - - // Check if all other selected tracks have the same color - bool multipleTrackColors = false; - for (int i = 1; i < indices.size(); ++i) { - int row = indices.at(i).row(); - QModelIndex index = indices.at(i).sibling(row, column); - - if (trackColor != mixxx::RgbColor::fromQVariant(index.data())) { - trackColor = mixxx::RgbColor::nullopt(); - multipleTrackColors = true; - break; - } - } - - if (multipleTrackColors) { - m_pColorPickerAction->resetSelectedColor(); - } else { - m_pColorPickerAction->setSelectedColor(trackColor); - } - m_pColorMenu->addAction(m_pColorPickerAction); - m_pMenu->addMenu(m_pColorMenu); - } - } - - m_pMenu->addSeparator(); - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_HIDE)) { - m_pHideAct->setEnabled(!locked); - m_pMenu->addAction(m_pHideAct); - } - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_UNHIDE)) { - m_pUnhideAct->setEnabled(!locked); - m_pMenu->addAction(m_pUnhideAct); - } - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_PURGE)) { - m_pPurgeAct->setEnabled(!locked); - m_pMenu->addAction(m_pPurgeAct); - } - m_pMenu->addAction(m_pFileBrowserAct); - - if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - m_pMenu->addSeparator(); - m_pPropertiesAct->setEnabled(oneSongSelected); - m_pMenu->addAction(m_pPropertiesAct); - } -*/ - - // Update track ids in context menu - TrackIdList trackIds = getSelectedTrackIds(); - m_pMenu->setTracks(trackIds); + // Update track indices in context menu + QModelIndexList indices = selectionModel()->selectedRows(); + std::cout << "passing this many indices: " << indices.size() << std::endl; + DEBUG_ASSERT(!indices.empty()); + m_pMenu->setTrackIndexList(selectionModel()->selectedRows()); //Create the right-click menu m_pMenu->popup(event->globalPos()); @@ -1317,7 +688,6 @@ void WTrackTableView::dropEvent(QDropEvent * event) { updateGeometries(); verticalScrollBar()->setValue(vScrollBarPos); } - TrackModel* WTrackTableView::getTrackModel() const { TrackModel* trackModel = dynamic_cast<TrackModel*>(model()); return trackModel; @@ -1351,18 +721,7 @@ void WTrackTableView::loadSelectedTrackToGroup(QString group, bool play) { loadSelectionToGroup(group, play); } -void WTrackTableView::slotAddToAutoDJBottom() { - // append to auto DJ - addToAutoDJ(PlaylistDAO::AutoDJSendLoc::BOTTOM); -} -void WTrackTableView::slotAddToAutoDJTop() { - addToAutoDJ(PlaylistDAO::AutoDJSendLoc::TOP); -} - -void WTrackTableView::slotAddToAutoDJReplace() { - addToAutoDJ(PlaylistDAO::AutoDJSendLoc::REPLACE); -} QList<TrackId> WTrackTableView::getSelectedTrackIds() const { QList<TrackId> trackIds; @@ -1438,313 +797,6 @@ void WTrackTableView::addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc) { playlistDao.addTracksToAutoDJQueue(trackIds, loc); } -void WTrackTableView::slotImportTrackMetadataFromFileTags() { - if (!modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - return; - } - - const QModelIndexList indices = selectionModel()->selectedRows(); - - TrackModel* trackModel = getTrackModel(); - - if (trackModel == nullptr) { - return; - } - - for (const QModelIndex& index : indices) { - TrackPointer pTrack = trackModel->getTrack(index); - if (pTrack) { - // The user has explicitly requested to reload metadata from the file - // to override the information within Mixxx! Custom cover art must be - // reloaded separately. - SoundSourceProxy(pTrack).updateTrackFromSource( - SoundSourceProxy::ImportTrackMetadataMode::Again); - } - } -} - -void WTrackTableView::slotExportTrackMetadataIntoFileTags() { - if (!modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - return; - } - - TrackModel* pTrackModel = getTrackModel(); - if (!pTrackModel) { - return; - } - - const QModelIndexList indices = selectionModel()->selectedRows(); - if (indices.isEmpty()) { - return; - } - - mixxx::DlgTrackMetadataExport::showMessageBoxOncePerSession(); - - for (const QModelIndex& index : indices) { - TrackPointer pTrack = pTrackModel->getTrack(index); - if (pTrack) { - // Export of metadata is deferred until all references to the - // corresponding track object have been dropped. Otherwise - // writing to files that are still used for playback might - // cause crashes or at least audible glitches! - mixxx::DlgTrackMetadataExport::showMessageBoxOncePerSession(); - pTrack->markForMetadataExport(); - } - } -} - -void WTrackTableView::slotUpdateExternalTrackCollection( - ExternalTrackCollection* externalTrackCollection) { - VERIFY_OR_DEBUG_ASSERT(externalTrackCollection) { - return; - } - - if (!modelHasCapabilities(TrackModel::TRACKMODELCAPS_EDITMETADATA)) { - return; - } - - TrackModel* pTrackModel = getTrackModel(); - if (!pTrackModel) { - return; - } - - const QModelIndexList indices = selectionModel()->selectedRows(); - if (indices.isEmpty()) { - return; - } - - QList<TrackRef> trackRefs; - trackRefs.reserve(indices.size()); - for (const QModelIndex& index : indices) { - trackRefs.append( - TrackRef::fromFileInfo( - pTrackModel->getTrackLocation(index), - pTrackModel->getTrackId(index))); - } - - externalTrackCollection->updateTracks(std::move(trackRefs)); -} - -//slot for reset played count, sets count to 0 of one or more tracks -void WTrackTableView::slotClearPlayCount() { - const QModelIndexList indices = selectionModel()->selectedRows(); - TrackModel* trackModel = getTrackModel(); - - if (trackModel == nullptr) { - return; - } - - for (const QModelIndex& index : indices) { - TrackPointer pTrack = trackModel->getTrack(index); - if (pTrack) { - pTrack->resetPlayCounter(); - } - } -} -/* -void WTrackTableView::slotPopulatePlaylistMenu() { - // The user may open the Playlist submenu, move their cursor away, then - // return to the Playlist submenu before exiting the track context menu. - // Avoid querying the database multiple times in that case. - if (m_bPlaylistMenuLoaded) { - return; - } - m_pPlaylistMenu->clear(); - PlaylistDAO& playlistDao = m_pTrackCollectionManager->internalCollection()->getPlaylistDAO(); - QMap<QString,int> playlists; - int numPlaylists = playlistDao.playlistCount(); - for (int i = 0; i < numPlaylists; ++i) { - int iPlaylistId = playlistDao.getPlaylistId(i); - playlists.insert(playlistDao.getPlaylistName(iPlayli |