bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> urls, QObject* pSource) { int crateId = crateIdFromIndex(index); if (crateId == -1) { return false; } QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); QList<int> trackIds; if (pSource) { trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); m_pTrackCollection->getTrackDAO().unhideTracks(trackIds); } else { // Adds track, does not insert duplicates, handles unremoving logic. trackIds = m_pTrackCollection->getTrackDAO().addTracks(files, true); } qDebug() << "CrateFeature::dropAcceptChild adding tracks" << trackIds.size() << " to crate "<< crateId; // remove tracks that could not be added for (int trackId = 0; trackId < trackIds.size(); ++trackId) { if (trackIds.at(trackId) < 0) { trackIds.removeAt(trackId--); } } m_crateDao.addTracksToCrate(crateId, &trackIds); return true; }
void CrateFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index) { //Save the model index so we can get it in the action slots... m_lastRightClickedIndex = index; int crateId = crateIdFromIndex(index); if (crateId == -1) { return; } bool locked = m_crateDao.isCrateLocked(crateId); m_pDeleteCrateAction->setEnabled(!locked); m_pRenameCrateAction->setEnabled(!locked); bool bAutoDj = m_crateDao.isCrateInAutoDj(crateId); m_pAutoDjTrackSource->setChecked(bAutoDj); m_pLockCrateAction->setText(locked ? tr("Unlock") : tr("Lock")); QMenu menu(NULL); menu.addAction(m_pCreateCrateAction); menu.addSeparator(); menu.addAction(m_pRenameCrateAction); menu.addAction(m_pDuplicateCrateAction); menu.addAction(m_pDeleteCrateAction); menu.addAction(m_pLockCrateAction); menu.addSeparator(); menu.addAction(m_pAutoDjTrackSource); menu.addSeparator(); menu.addAction(m_pAnalyzeCrateAction); menu.addSeparator(); menu.addAction(m_pImportPlaylistAction); menu.addAction(m_pExportPlaylistAction); menu.addAction(m_pExportTrackFilesAction); menu.exec(globalPos); }
void CrateFeature::slotAutoDjTrackSourceChanged() { #ifdef __AUTODJCRATES__ int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId != -1) { m_crateDao.setCrateInAutoDj(crateId, m_pAutoDjTrackSource->isChecked()); } #endif // __AUTODJCRATES__ }
void CrateFeature::slotAnalyzeCrate() { if (m_lastRightClickedIndex.isValid()) { int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId >= 0) { QList<int> ids = m_crateDao.getTrackIds(crateId); emit(analyzeTracks(ids)); } } }
bool CrateFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { int crateId = crateIdFromIndex(index); if (crateId == -1) { return false; } bool locked = m_crateDao.isCrateLocked(crateId); bool formatSupported = SoundSourceProxy::isUrlSupported(url) || Parser::isPlaylistFilenameSupported(url.toLocalFile()); return !locked && formatSupported; }
void CrateFeature::activateChild(const QModelIndex& index) { if (!index.isValid()) return; int crateId = crateIdFromIndex(index); if (crateId == -1) { return; } m_crateTableModel.setTableModel(crateId); emit(showTrackModel(&m_crateTableModel)); emit(enableCoverArtDisplay(true)); }
void CrateFeature::slotToggleCrateLock() { int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId == -1) { return; } QString crateName = m_crateDao.crateName(crateId); bool locked = !m_crateDao.isCrateLocked(crateId); if (!m_crateDao.setCrateLocked(crateId, locked)) { qDebug() << "Failed to toggle lock of crateId " << crateId; } }
void CrateFeature::slotDuplicateCrate() { int oldCrateId = crateIdFromIndex(m_lastRightClickedIndex); if (oldCrateId == -1) { return; } QString oldName = m_crateDao.crateName(oldCrateId); QString name; bool validNameGiven = false; while (!validNameGiven) { bool ok = false; name = QInputDialog::getText(NULL, tr("Duplicate Crate"), tr("Enter name for new crate:"), QLineEdit::Normal, //: Appendix to default name when duplicating a crate oldName + tr("_copy" , "[noun]"), &ok).trimmed(); if (!ok || name == oldName) { return; } int existingId = m_crateDao.getCrateIdByName(name); if (existingId != -1) { QMessageBox::warning(NULL, tr("Renaming Crate Failed"), tr("A crate by that name already exists.")); } else if (name.isEmpty()) { QMessageBox::warning(NULL, tr("Renaming Crate Failed"), tr("A crate cannot have a blank name.")); } else { validNameGiven = true; } } int newCrateId = m_crateDao.createCrate(name); m_crateDao.copyCrateTracks(oldCrateId, newCrateId); if (newCrateId != -1) { emit(showTrackModel(&m_crateTableModel)); } else { qDebug() << "Error creating crate with name " << name; QMessageBox::warning(NULL, tr("Creating Crate Failed"), tr("An unknown error occurred while creating crate: ") + name); } }
void CrateFeature::slotRenameCrate() { int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId == -1) { return; } QString oldName = m_crateDao.crateName(crateId); bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { qDebug() << "Skipping crate rename because crate" << crateId << "is locked."; return; } QString newName; bool validNameGiven = false; while (!validNameGiven) { bool ok = false; newName = QInputDialog::getText(NULL, tr("Rename Crate"), tr("Enter new name for crate:"), QLineEdit::Normal, oldName, &ok).trimmed(); if (!ok || newName == oldName) { return; } int existingId = m_crateDao.getCrateIdByName(newName); if (existingId != -1) { QMessageBox::warning(NULL, tr("Renaming Crate Failed"), tr("A crate by that name already exists.")); } else if (newName.isEmpty()) { QMessageBox::warning(NULL, tr("Renaming Crate Failed"), tr("A crate cannot have a blank name.")); } else { validNameGiven = true; } } if (!m_crateDao.renameCrate(crateId, newName)) { qDebug() << "Failed to rename crateId" << crateId; } }
void CrateFeature::slotDeleteCrate() { int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId == -1) { return; } bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { qDebug() << "Skipping crate deletion because crate" << crateId << "is locked."; return; } bool deleted = m_crateDao.deleteCrate(crateId); if (deleted) { activate(); } else { qDebug() << "Failed to delete crateId" << crateId; } }
void CrateFeature::slotAutoDjTrackSourceChanged() { int crateId = crateIdFromIndex(m_lastRightClickedIndex); if (crateId != -1) { m_crateDao.setCrateInAutoDj(crateId, m_pAutoDjTrackSource->isChecked()); } }