From 6d6a50dc53f39606f8b374cd0eed41e0fef623c3 Mon Sep 17 00:00:00 2001 From: weixindut Date: Sat, 15 Jun 2013 22:21:58 +0000 Subject: [PATCH] display tracks number for Auto DJ, each playlist and crate, through adding a name_displayed coloumn into table Playlists and Crates, bug#991938 --- mixxx/res/schema.xml | 9 ++ mixxx/src/library/autodjfeature.cpp | 3 +- .../library/baseexternallibraryfeature.cpp | 6 +- mixxx/src/library/baseplaylistfeature.cpp | 24 +++- mixxx/src/library/cratefeature.cpp | 26 ++-- mixxx/src/library/dao/cratedao.cpp | 115 +++++++--------- mixxx/src/library/dao/cratedao.h | 2 + mixxx/src/library/dao/playlistdao.cpp | 125 ++++++++---------- mixxx/src/library/dao/playlistdao.h | 6 + mixxx/src/library/playlistfeature.cpp | 11 +- mixxx/src/library/setlogfeature.cpp | 6 +- mixxx/src/library/trackcollection.cpp | 2 +- mixxx/src/widget/wpreparecratestableview.cpp | 3 +- 13 files changed, 177 insertions(+), 161 deletions(-) diff --git a/mixxx/res/schema.xml b/mixxx/res/schema.xml index 9dd9fdc617b..16f3965eff9 100644 --- a/mixxx/res/schema.xml +++ b/mixxx/res/schema.xml @@ -338,4 +338,13 @@ METADATA ALTER TABLE Library ADD COLUMN keys_sub_version TEXT; + + + Add name_displayed column to playlists table. + + + ALTER TABLE Playlists ADD COLUMN name_displayed varchar(48); + ALTER TABLE Crates ADD COLUMN name_displayed varchar(48); + + diff --git a/mixxx/src/library/autodjfeature.cpp b/mixxx/src/library/autodjfeature.cpp index 59c6324e875..70ee08f5d0d 100644 --- a/mixxx/src/library/autodjfeature.cpp +++ b/mixxx/src/library/autodjfeature.cpp @@ -32,9 +32,8 @@ AutoDJFeature::~AutoDJFeature() { QVariant AutoDJFeature::title() { int autoDJId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE); - QString title = m_playlistDao.getPlaylistName(autoDJId); + QString title = m_playlistDao.getPlaylistNameDisplayed(autoDJId); return title; - //return tr("Auto DJ"); } QIcon AutoDJFeature::getIcon() { diff --git a/mixxx/src/library/baseexternallibraryfeature.cpp b/mixxx/src/library/baseexternallibraryfeature.cpp index ceb8aeccf85..9068594d728 100644 --- a/mixxx/src/library/baseexternallibraryfeature.cpp +++ b/mixxx/src/library/baseexternallibraryfeature.cpp @@ -121,7 +121,8 @@ void BaseExternalLibraryFeature::slotImportAsMixxxPlaylist() { pPlaylistModelToAdd->select(); PlaylistDAO& playlistDao = m_pTrackCollection->getPlaylistDAO(); - int playlistId = playlistDao.getPlaylistIdFromName(playlist); + //int playlistId = playlistDao.getPlaylistIdFromName(playlist); + int playlistId = playlistDao.getPlaylistIdFromNameDisplayed(playlist); int i = 1; if (playlistId != -1) { @@ -129,7 +130,8 @@ void BaseExternalLibraryFeature::slotImportAsMixxxPlaylist() { playlist += "(%1)"; while (playlistId != -1) { i++; - playlistId = playlistDao.getPlaylistIdFromName(playlist.arg(i)); + //playlistId = playlistDao.getPlaylistIdFromName(playlist.arg(i)); + playlistId = playlistDao.getPlaylistIdFromNameDisplayed(playlist.arg(i)); } playlist = playlist.arg(i); } diff --git a/mixxx/src/library/baseplaylistfeature.cpp b/mixxx/src/library/baseplaylistfeature.cpp index 9436369b034..65f5b8d1aa0 100644 --- a/mixxx/src/library/baseplaylistfeature.cpp +++ b/mixxx/src/library/baseplaylistfeature.cpp @@ -96,7 +96,9 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) { // Switch the playlist table model's playlist. QString playlistName = index.data().toString(); - int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName); + + //int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName); + int playlistId = m_playlistDao.getPlaylistIdFromNameDisplayed(playlistName); if (m_pPlaylistTableModel) { m_pPlaylistTableModel->setTableModel(playlistId); emit(showTrackModel(m_pPlaylistTableModel)); @@ -105,7 +107,10 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) { void BasePlaylistFeature::slotRenamePlaylist() { QString oldName = m_lastRightClickedIndex.data().toString(); - int playlistId = m_playlistDao.getPlaylistIdFromName(oldName); + + //int playlistId = m_playlistDao.getPlaylistIdFromName(oldName); + int playlistId = m_playlistDao.getPlaylistIdFromNameDisplayed(oldName); + bool locked = m_playlistDao.isPlaylistLocked(playlistId); if (locked) { @@ -152,8 +157,8 @@ void BasePlaylistFeature::slotRenamePlaylist() { void BasePlaylistFeature::slotDuplicatePlaylist() { QString oldName = m_lastRightClickedIndex.data().toString(); - int oldPlaylistId = m_playlistDao.getPlaylistIdFromName(oldName); - + //int oldPlaylistId = m_playlistDao.getPlaylistIdFromName(oldName); + int oldPlaylistId = m_playlistDao.getPlaylistIdFromNameDisplayed(oldName); QString name; bool validNameGiven = false; @@ -199,7 +204,9 @@ void BasePlaylistFeature::slotDuplicatePlaylist() { void BasePlaylistFeature::slotTogglePlaylistLock() { QString playlistName = m_lastRightClickedIndex.data().toString(); - int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName); + //int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName); + int playlistId = m_playlistDao.getPlaylistIdFromNameDisplayed(playlistName); + bool locked = !m_playlistDao.isPlaylistLocked(playlistId); if (!m_playlistDao.setPlaylistLocked(playlistId, locked)) { @@ -259,7 +266,9 @@ void BasePlaylistFeature::slotCreatePlaylist() { void BasePlaylistFeature::slotDeletePlaylist() { //qDebug() << "slotDeletePlaylist() row:" << m_lastRightClickedIndex.data(); - int playlistId = m_playlistDao.getPlaylistIdFromName(m_lastRightClickedIndex.data().toString()); + + //int playlistId = m_playlistDao.getPlaylistIdFromName(m_lastRightClickedIndex.data().toString()); + int playlistId = m_playlistDao.getPlaylistIdFromNameDisplayed(m_lastRightClickedIndex.data().toString()); bool locked = m_playlistDao.isPlaylistLocked(playlistId); if (locked) { @@ -400,7 +409,8 @@ void BasePlaylistFeature::addToAutoDJ(bool bTop) { //qDebug() << "slotAddToAutoDJ() row:" << m_lastRightClickedIndex.data(); if (m_lastRightClickedIndex.isValid()) { - int playlistId = m_playlistDao.getPlaylistIdFromName( + //int playlistId = m_playlistDao.getPlaylistIdFromName( + int playlistId = m_playlistDao.getPlaylistIdFromNameDisplayed( m_lastRightClickedIndex.data().toString()); if (playlistId >= 0) { // Insert this playlist diff --git a/mixxx/src/library/cratefeature.cpp b/mixxx/src/library/cratefeature.cpp index efcb80d6c5f..1e79d771989 100644 --- a/mixxx/src/library/cratefeature.cpp +++ b/mixxx/src/library/cratefeature.cpp @@ -96,7 +96,8 @@ QIcon CrateFeature::getIcon() { bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, QWidget *pSource) { QString crateName = index.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); QList files; foreach (QUrl url, urls) { //XXX: See the comment in PlaylistFeature::dropAcceptChild() about @@ -126,7 +127,8 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, bool CrateFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { //TODO: Filter by supported formats regex and reject anything that doesn't match. QString crateName = index.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); bool locked = m_crateDao.isCrateLocked(crateId); QFileInfo file(url.toLocalFile()); @@ -159,7 +161,8 @@ void CrateFeature::activateChild(const QModelIndex& index) { if (!index.isValid()) return; QString crateName = index.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); m_crateTableModel.setTableModel(crateId); emit(showTrackModel(&m_crateTableModel)); } @@ -176,7 +179,8 @@ void CrateFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index) m_lastRightClickedIndex = index; QString crateName = index.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); bool locked = m_crateDao.isCrateLocked(crateId); @@ -248,7 +252,8 @@ void CrateFeature::slotCreateCrate() { void CrateFeature::slotDeleteCrate() { QString crateName = m_lastRightClickedIndex.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { @@ -267,7 +272,8 @@ void CrateFeature::slotDeleteCrate() { void CrateFeature::slotRenameCrate() { QString oldName = m_lastRightClickedIndex.data().toString(); - int crateId = m_crateDao.getCrateIdByName(oldName); + //int crateId = m_crateDao.getCrateIdByName(oldName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(oldName); bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { @@ -316,7 +322,8 @@ void CrateFeature::slotRenameCrate() { void CrateFeature::slotDuplicateCrate() { QString oldName = m_lastRightClickedIndex.data().toString(); - int oldCrateId = m_crateDao.getCrateIdByName(oldName); + //int oldCrateId = m_crateDao.getCrateIdByName(oldName); + int oldCrateId = m_crateDao.getCrateIdByNameDisplayed(oldName); QString name; bool validNameGiven = false; @@ -370,7 +377,8 @@ void CrateFeature::slotDuplicateCrate() { void CrateFeature::slotToggleCrateLock() { QString crateName = m_lastRightClickedIndex.data().toString(); - int crateId = m_crateDao.getCrateIdByName(crateName); + //int crateId = m_crateDao.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByNameDisplayed(crateName); bool locked = !m_crateDao.isCrateLocked(crateId); if (!m_crateDao.setCrateLocked(crateId, locked)) { @@ -389,7 +397,7 @@ void CrateFeature::buildCrateList() { while (crateListTableModel.canFetchMore()) { crateListTableModel.fetchMore(); } - int nameColumn = crateListTableModel.record().indexOf("name"); + int nameColumn = crateListTableModel.record().indexOf("name_displayed"); int idColumn = crateListTableModel.record().indexOf("id"); for (int row = 0; row < crateListTableModel.rowCount(); ++row) { diff --git a/mixxx/src/library/dao/cratedao.cpp b/mixxx/src/library/dao/cratedao.cpp index 990462e6285..9e2099424fd 100644 --- a/mixxx/src/library/dao/cratedao.cpp +++ b/mixxx/src/library/dao/cratedao.cpp @@ -34,8 +34,9 @@ unsigned int CrateDAO::crateCount() { int CrateDAO::createCrate(const QString& name) { QSqlQuery query(m_database); - query.prepare("INSERT INTO " CRATE_TABLE " (name) VALUES (:name)"); + query.prepare("INSERT INTO " CRATE_TABLE " (name, name_displayed) VALUES (:name, :name_displayed)"); query.bindValue(":name", name); + query.bindValue(":name_displayed", name); if (!query.exec()) { LOG_FAILED_QUERY(query); @@ -120,48 +121,36 @@ bool CrateDAO::deleteCrate(int crateId) { return true; } -//int CrateDAO::getCrateIdByName(const QString& name) { -// QSqlQuery query(m_database); -// query.prepare("SELECT id FROM " CRATE_TABLE " WHERE name = (:name)"); -// query.bindValue(":name", name); -// if (query.exec()) { -// if (query.next()) { -// int id = query.value(0).toInt(); -// return id; -// } -// } else { -// LOG_FAILED_QUERY(query); -// } -// return -1; -//} - int CrateDAO::getCrateIdByName(const QString& name) { - QString pattern("(.*)\x20(\\(([1-9]\\d*|0)\\))"); - QRegExp rxnum(pattern); - QSqlQuery query(m_database); - query.prepare("SELECT id,name FROM " CRATE_TABLE); + query.prepare("SELECT id FROM " CRATE_TABLE " WHERE name = (:name)"); + query.bindValue(":name", name); + if (query.exec()) { + if (query.next()) { + int id = query.value(0).toInt(); + return id; + } + } else { + LOG_FAILED_QUERY(query); + } + return -1; +} +int CrateDAO::getCrateIdByNameDisplayed(const QString& name) { + QSqlQuery query(m_database); + query.prepare("SELECT id FROM " CRATE_TABLE " WHERE name_displayed = (:name)"); + query.bindValue(":name", name); if (query.exec()) { - while (query.next()) { - int queryID = query.value(0).toInt(); - QString queryName = query.value(1).toString(); - - if (queryName == name) { - return queryID; - } else if (rxnum.exactMatch(queryName)) { - QString originalName = rxnum.cap(1); - if (originalName == name) { - return queryID; - } - } + if (query.next()) { + int id = query.value(0).toInt(); + return id; } - return -1; } else { LOG_FAILED_QUERY(query); } return -1; } + int CrateDAO::getCrateId(int position) { QSqlQuery query(m_database); query.prepare("SELECT id FROM " CRATE_TABLE); @@ -193,6 +182,19 @@ QString CrateDAO::crateName(int crateId) { return QString(); } +QString CrateDAO::crateNameDisplayed(int crateId) { + QSqlQuery query(m_database); + query.prepare("SELECT name_displayed FROM " CRATE_TABLE " WHERE id = (:id)"); + query.bindValue(":id", crateId); + if (query.exec()) { + if (query.next()) { + return query.value(0).toString(); + } + } else { + LOG_FAILED_QUERY(query); + } + return QString(); +} unsigned int CrateDAO::crateSize(int crateId) { QSqlQuery query(m_database); query.prepare("SELECT COUNT(*) FROM " CRATE_TRACKS_TABLE " WHERE crate_id = (:id)"); @@ -333,13 +335,10 @@ void CrateDAO::removeTracksFromCrates(QList ids) { // emit(changed(crateId)); } void CrateDAO::updateCratesTitleNum() { - QString pattern("(.*)\x20(\\(([1-9]\\d*|0)\\))"); - QRegExp rxnum(pattern); m_database.transaction(); QSqlQuery selectQuery(m_database); - //select crates.name, crates.id,count(*) from crates, crate_tracks - //where crates.id = crate_tracks.crate_id group by crates.id + selectQuery.prepare(" SELECT Crates.name,count(*),Crates.id FROM Crates, Crate_tracks " " WHERE Crates.id = Crate_tracks.crate_id " " GROUP BY Crates.id "); @@ -348,25 +347,15 @@ void CrateDAO::updateCratesTitleNum() { LOG_FAILED_QUERY(selectQuery); } else { while (selectQuery.next()) { - QString newNameWithNum; - QString oldName = selectQuery.value(0).toString(); + + QString Name = selectQuery.value(0).toString(); QString tracksNum = selectQuery.value(1).toString(); int cratesID = selectQuery.value(2).toInt(); - if (!rxnum.exactMatch(oldName)) { - //qDebug() << "no:"<(hidden)); + query.bindValue(":name_displayed", name);// same with name column in default. if (!query.exec()) { LOG_FAILED_QUERY(query); @@ -87,56 +88,58 @@ QString PlaylistDAO::getPlaylistName(int playlistId) } return name; } +QString PlaylistDAO::getPlaylistNameDisplayed(int playlistId) +{ + // qDebug() << "PlaylistDAO::getPlaylistName" << QThread::currentThread() << m_database.connectionName(); + + QSqlQuery query(m_database); + query.prepare("SELECT name_displayed FROM Playlists " + "WHERE id= :id"); + query.bindValue(":id", playlistId); -//int PlaylistDAO::getPlaylistIdFromName(QString name) { -// // qDebug() << "PlaylistDAO::getPlaylistIdFromName" << QThread::currentThread() << m_database.connectionName(); -// -// QSqlQuery query(m_database); -// query.prepare("SELECT id FROM Playlists WHERE name = :name"); -// query.bindValue(":name", name); -// if (query.exec()) { -// if (query.next()) { -// return query.value(query.record().indexOf("id")).toInt(); -// } -// } else { -// LOG_FAILED_QUERY(query); -// } -// return -1; -//} + if (!query.exec()) { + LOG_FAILED_QUERY(query); + return ""; + } + // Get the name_displayed field + QString name = ""; + while (query.next()) { + name = query.value(query.record().indexOf("name_displayed")).toString(); + } + return name; +} int PlaylistDAO::getPlaylistIdFromName(QString name) { - //qDebug() << "PlaylistDAO::getPlaylistIdFromName" << QThread::currentThread() << m_database.connectionName(); - // since now showing the number of the tracks in every playlist is through change the "name" column - // in "playlists" table, so here we need a regular expression to match. - QString pattern("(.*)\x20(\\(([1-9]\\d*|0)\\))"); - QRegExp rxnum(pattern); + // qDebug() << "PlaylistDAO::getPlaylistIdFromName" << QThread::currentThread() << m_database.connectionName(); QSqlQuery query(m_database); - query.prepare("SELECT id,name FROM Playlists"); + query.prepare("SELECT id FROM Playlists WHERE name = :name"); + query.bindValue(":name", name); + if (query.exec()) { + if (query.next()) { + return query.value(query.record().indexOf("id")).toInt(); + } + } else { + LOG_FAILED_QUERY(query); + } + return -1; +} +int PlaylistDAO::getPlaylistIdFromNameDisplayed(QString name) { + // qDebug() << "PlaylistDAO::getPlaylistIdFromName" << QThread::currentThread() << m_database.connectionName(); + QSqlQuery query(m_database); + query.prepare("SELECT id FROM Playlists WHERE name_displayed = :name"); + query.bindValue(":name", name); if (query.exec()) { - while (query.next()) { - int queryID = query.value(0).toInt(); - QString queryName = query.value(1).toString(); - - //qDebug() << "queryID:" << queryID - // << "queryName:" << queryName; - - if (queryName == name) { - return queryID; - } else if (rxnum.exactMatch(queryName)) { - QString originalName = rxnum.cap(1); - if (originalName == name) { - return queryID; - } - } + if (query.next()) { + return query.value(query.record().indexOf("id")).toInt(); } - return -1; } else { LOG_FAILED_QUERY(query); } return -1; } + void PlaylistDAO::deletePlaylist(int playlistId) { // qDebug() << "PlaylistDAO::deletePlaylist" << QThread::currentThread() << m_database.connectionName(); @@ -714,8 +717,6 @@ int PlaylistDAO::tracksInPlaylist(int playlistId) { } void PlaylistDAO::updatePlaylistsTitleNum() { - QString pattern("(.*)\x20(\\(([1-9]\\d*|0)\\))"); - QRegExp rxnum(pattern); m_database.transaction(); QSqlQuery selectQuery(m_database); @@ -728,25 +729,14 @@ void PlaylistDAO::updatePlaylistsTitleNum() { LOG_FAILED_QUERY(selectQuery); } else { while (selectQuery.next()) { - QString newNameWithNum; - QString oldName = selectQuery.value(0).toString(); + + QString Name = selectQuery.value(0).toString(); QString tracksNum = selectQuery.value(1).toString(); int playlistsID = selectQuery.value(2).toInt(); - - if (!rxnum.exactMatch(oldName)) { - //qDebug() << "no:"<