Skip to content

Commit

Permalink
display tracks number for Auto DJ, each playlist and crate, through a…
Browse files Browse the repository at this point in the history
…dding a name_displayed coloumn into table Playlists and Crates, bug#991938
  • Loading branch information
weixindut committed Jun 15, 2013
1 parent 264c051 commit 6d6a50d
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 161 deletions.
9 changes: 9 additions & 0 deletions mixxx/res/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,13 @@ METADATA
ALTER TABLE Library ADD COLUMN keys_sub_version TEXT;
</sql>
</revision>
<revision version="19" min_compatible="3">
<description>
Add name_displayed column to playlists table.
</description>
<sql>
ALTER TABLE Playlists ADD COLUMN name_displayed varchar(48);
ALTER TABLE Crates ADD COLUMN name_displayed varchar(48);
</sql>
</revision>
</schema>
3 changes: 1 addition & 2 deletions mixxx/src/library/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions mixxx/src/library/baseexternallibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ 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) {
// Calculate a unique name
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);
}
Expand Down
24 changes: 17 additions & 7 deletions mixxx/src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions mixxx/src/library/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ QIcon CrateFeature::getIcon() {
bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> 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<QFileInfo> files;
foreach (QUrl url, urls) {
//XXX: See the comment in PlaylistFeature::dropAcceptChild() about
Expand Down Expand Up @@ -126,7 +127,8 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> 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());
Expand Down Expand Up @@ -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));
}
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down
115 changes: 51 additions & 64 deletions mixxx/src/library/dao/cratedao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)");
Expand Down Expand Up @@ -333,13 +335,10 @@ void CrateDAO::removeTracksFromCrates(QList<int> 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 ");
Expand All @@ -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:"<<oldName;
newNameWithNum = oldName+" (" + tracksNum + ")";
} else {
//qDebug() << "yes:"<<oldName;
if (rxnum.cap(2) == tracksNum){
continue;
} else {
newNameWithNum = oldName.replace(rxnum.cap(2), "(" + tracksNum + ")");
}
}
QString newNameWithNum = Name + " (" + tracksNum + ")";

QSqlQuery updateQuery(m_database);
updateQuery.prepare("UPDATE Crates SET name = :name WHERE id = :id");
updateQuery.prepare("UPDATE Crates SET name_displayed = :name WHERE id = :id");
updateQuery.bindValue(":name", newNameWithNum);
updateQuery.bindValue(":id", cratesID);

Expand All @@ -387,21 +376,19 @@ void CrateDAO::updateCratesTitleNum() {
LOG_FAILED_QUERY(selectQuery);
} else {
while (selectQuery.next()) {
QString oldName = selectQuery.value(0).toString();
QString Name = selectQuery.value(0).toString();
int cratesID = selectQuery.value(1).toInt();
if (rxnum.exactMatch(oldName)) {
QString newNameWithNum = rxnum.cap(1);
QSqlQuery updateQuery(m_database);
updateQuery.prepare("UPDATE Crates SET name = :name WHERE id = :id");
updateQuery.bindValue(":name", newNameWithNum);
updateQuery.bindValue(":id", cratesID);

if (!updateQuery.exec()) {
LOG_FAILED_QUERY(updateQuery);
m_database.rollback();
}
emit(cratesTitleUpdate(cratesID));
QSqlQuery updateQuery(m_database);
updateQuery.prepare("UPDATE Crates SET name_displayed = :name WHERE id = :id");
updateQuery.bindValue(":name", Name);
updateQuery.bindValue(":id", cratesID);

if (!updateQuery.exec()) {
LOG_FAILED_QUERY(updateQuery);
m_database.rollback();
}
emit(cratesTitleUpdate(cratesID));

}
}
m_database.commit();
Expand Down
2 changes: 2 additions & 0 deletions mixxx/src/library/dao/cratedao.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class CrateDAO : public QObject, public virtual DAO {
bool setCrateLocked(int crateId, bool locked);
bool isCrateLocked(int crateId);
int getCrateIdByName(const QString& name);
int getCrateIdByNameDisplayed(const QString& name);
int getCrateId(int position);
QString crateName(int crateId);
QString crateNameDisplayed(int crateId);
unsigned int crateSize(int crateId);
bool addTrackToCrate(int trackId, int crateId);
// This method takes a list of track ids to be added to crate and returns
Expand Down
Loading

0 comments on commit 6d6a50d

Please sign in to comment.