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

Display tracks number next to Auto DJ and every playlist in Playlists and Crates, bug#991938 #8

Closed
wants to merge 16 commits into from
Closed
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
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Compiled Object files
*.slo
*.lo
*.o

# Compiled Dynamic libraries
*.so
*.dylib

# Compiled Static libraries
*.lai
*.la
*.a

Debug
*.cproject
*.project
*.DS_Store

*~
*.swp
*.pyc
12 changes: 11 additions & 1 deletion mixxx/src/library/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ AutoDJFeature::AutoDJFeature(QObject* parent,
m_pTrackCollection(pTrackCollection),
m_playlistDao(pTrackCollection->getPlaylistDAO()),
m_pAutoDJView(NULL) {

connect(&m_playlistDao,SIGNAL(playlistsTitleUpdate(int)),this,SLOT(slotUpdateTitle(int)));
}

AutoDJFeature::~AutoDJFeature() {
}

QVariant AutoDJFeature::title() {
return tr("Auto DJ");
int autoDJId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE);
QString title = m_playlistDao.getPlaylistName(autoDJId);
return title;
//return tr("Auto DJ");
}

QIcon AutoDJFeature::getIcon() {
Expand Down Expand Up @@ -97,3 +102,8 @@ bool AutoDJFeature::dragMoveAccept(QUrl url) {
QFileInfo file(url.toLocalFile());
return SoundSourceProxy::isFilenameSupported(file.fileName());
}

void AutoDJFeature::slotUpdateTitle(int autoDJId) {
Q_UNUSED(autoDJId);
emit(nameUpdated(this));
}
4 changes: 4 additions & 0 deletions mixxx/src/library/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class AutoDJFeature : public LibraryFeature {

TreeItemModel* getChildModel();

signals:
void nameUpdated(LibraryFeature*);

public slots:
void activate();
void slotUpdateTitle(int);

private:
ConfigObject<ConfigValue>* m_pConfig;
Expand Down
3 changes: 2 additions & 1 deletion mixxx/src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ BasePlaylistFeature::BasePlaylistFeature(QObject* parent,

connect(&m_playlistDao, SIGNAL(lockChanged(int)),
this, SLOT(slotPlaylistTableChanged(int)));
connect(&m_playlistDao, SIGNAL(playlistsTitleUpdate(int)),
this,SLOT(slotPlaylistTableChanged(int)));
}

BasePlaylistFeature::~BasePlaylistFeature() {
Expand Down Expand Up @@ -477,4 +479,3 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id)
void BasePlaylistFeature::clearChildModel() {
m_childModel.removeRows(0, m_playlistList.size());
}

3 changes: 3 additions & 0 deletions mixxx/src/library/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ CrateFeature::CrateFeature(QObject* parent,
connect(&m_crateDao, SIGNAL(lockChanged(int)),
this, SLOT(slotCrateTableChanged(int)));

connect(&m_crateDao, SIGNAL(cratesTitleUpdate(int)),
this, SLOT(slotCrateTableChanged(int)));

// construct child model
TreeItem *rootItem = new TreeItem();
m_childModel.setRootItem(rootItem);
Expand Down
125 changes: 116 additions & 9 deletions mixxx/src/library/dao/cratedao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CrateDAO::~CrateDAO() {

void CrateDAO::initialize() {
qDebug() << "CrateDAO::initialize()";
updateCratesTitleNum();
}

unsigned int CrateDAO::crateCount() {
Expand All @@ -42,6 +43,7 @@ int CrateDAO::createCrate(const QString& name) {
}

int crateId = query.lastInsertId().toInt();
updateCratesTitleNum();
emit(added(crateId));
return crateId;
}
Expand All @@ -56,6 +58,7 @@ bool CrateDAO::renameCrate(int crateId, const QString& newName) {
LOG_FAILED_QUERY(query);
return false;
}
updateCratesTitleNum();
emit(renamed(crateId));
return true;
}
Expand Down Expand Up @@ -117,21 +120,48 @@ 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 FROM " CRATE_TABLE " WHERE name = (:name)");
query.bindValue(":name", name);
query.prepare("SELECT id,name FROM " CRATE_TABLE);

if (query.exec()) {
if (query.next()) {
int id = query.value(0).toInt();
return id;
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;
}
}
}
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 @@ -209,7 +239,7 @@ bool CrateDAO::addTrackToCrate(int trackId, int crateId) {
LOG_FAILED_QUERY(query);
return false;
}

updateCratesTitleNum();
emit(trackAdded(crateId, trackId));
emit(changed(crateId));
return true;
Expand All @@ -233,7 +263,7 @@ int CrateDAO::addTracksToCrate(QList<int> trackIdList, int crateId) {
}
}
transaction.commit();

updateCratesTitleNum();
// Emitting the trackAdded signals for each trackID outside the transaction
foreach(int trackId, trackIdList) {
emit(trackAdded(crateId, trackId));
Expand All @@ -256,7 +286,7 @@ bool CrateDAO::removeTrackFromCrate(int trackId, int crateId) {
LOG_FAILED_QUERY(query);
return false;
}

updateCratesTitleNum();
emit(trackRemoved(crateId, trackId));
emit(changed(crateId));
return true;
Expand All @@ -280,6 +310,7 @@ bool CrateDAO::removeTracksFromCrate(QList<int> ids, int crateId) {
foreach (int trackId, ids) {
emit(trackRemoved(crateId, trackId));
}
updateCratesTitleNum();
emit(changed(crateId));
return true;
}
Expand All @@ -295,8 +326,84 @@ void CrateDAO::removeTracksFromCrates(QList<int> ids) {
if (!query.exec()) {
LOG_FAILED_QUERY(query);
}
updateCratesTitleNum();

// TODO(XXX) should we emit this for all crates?
// emit(trackRemoved(crateId, trackId));
// emit(changed(crateId));
}
void CrateDAO::updateCratesTitleNum() {
QString pattern("(.*)\x20(\\(([1-9]\\d*|0)\\))");
QRegExp rxnum(pattern);

m_database.transaction();
QSqlQuery selectQuery(m_database);
//selectQuery.prepare(" SELECT Crates.name,count(*),Crates.id FROM Crates, Crate_tracks "
// " WHERE Crates.id = Crate_tracks.crate_id "
// " GROUP BY Crates.id ");
selectQuery.prepare(" SELECT Crates.name,Count_table.count,Crates.id FROM Crates INNER JOIN "
" (SELECT crate_id, count(*) AS count FROM Crate_tracks GROUP BY crate_id) "
" AS Count_table ON Count_table.crate_id = Crates.id ");
if (!selectQuery.exec()) {
LOG_FAILED_QUERY(selectQuery);
} else {
while (selectQuery.next()) {
QString newNameWithNum;
QString oldName = 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 + ")");
}
}

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));
//qDebug() << "PlaylistName:" <<selectQuery.value(0).toString()
// << "Number of tracks:" << selectQuery.value(1).toInt();
}
}

selectQuery.prepare(" SELECT name,id FROM Crates "
" WHERE id NOT IN "
" (SELECT DISTINCT crate_id from Crate_tracks) ");
if (!selectQuery.exec()) {
LOG_FAILED_QUERY(selectQuery);
} else {
while (selectQuery.next()) {
QString oldName = 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));
}
}
}
m_database.commit();

}
4 changes: 3 additions & 1 deletion mixxx/src/library/dao/cratedao.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CrateDAO : public QObject, public virtual DAO {
bool removeTracksFromCrate(QList<int> ids, int crateId);
// remove tracks from all crates
void removeTracksFromCrates(QList<int> ids);
// Update the shown number of tracks in every crates
void updateCratesTitleNum();

signals:
void added(int crateId);
Expand All @@ -55,7 +57,7 @@ class CrateDAO : public QObject, public virtual DAO {
void trackRemoved(int crateId, int trackId);
void renamed(int crateId);
void lockChanged(int crateId);

void cratesTitleUpdate(int crateId);
private:
QSqlDatabase& m_database;
DISALLOW_COPY_AND_ASSIGN(CrateDAO);
Expand Down
Loading