~mkas/mixxx/mysql

« back to all changes in this revision

Viewing changes to mixxx/src/library/autodjfeature.cpp

  • Committer: MKas
  • Date: 2012-11-03 12:55:54 UTC
  • Revision ID: mkas@tux.lt-20121103125554-ez5ajqyk7bwehrp2
merge with trunk + sql fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
                                      QModelIndex /*index*/) {
73
73
}
74
74
 
75
 
bool AutoDJFeature::dropAccept(QUrl url) {
 
75
bool AutoDJFeature::dropAccept(QList<QUrl> urls) {
76
76
    //TODO: Filter by supported formats regex and reject anything that doesn't match.
77
77
    TrackDAO &trackDao = m_pTrackCollection->getTrackDAO();
78
78
 
79
79
    //If a track is dropped onto a playlist's name, but the track isn't in the library,
80
80
    //then add the track to the library before adding it to the playlist.
81
 
 
82
 
    //XXX: See the note in PlaylistFeature::dropAccept() about using QUrl::toLocalFile()
83
 
    //     instead of toString()
84
 
    QFileInfo file(url.toLocalFile());
85
 
 
86
 
    if (!SoundSourceProxy::isFilenameSupported(file.fileName())) {
87
 
        return false;
88
 
    }
89
 
 
90
 
    // Adds track, does not insert duplicates, handles unremoving logic.
91
 
    int trackId = trackDao.addTrack(file, true);
92
 
 
93
 
    if (trackId < 0) {
94
 
        return false;
95
 
    }
96
 
 
97
 
    // TODO(XXX) No feedback on whether this worked.
98
 
    if (m_pAutoDJView) {
99
 
        m_pAutoDJView->appendTrack(trackId);
100
 
    } else {
101
 
        int playlistId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE);
102
 
        m_playlistDao.appendTrackToPlaylist(trackId, playlistId);
103
 
    }
104
 
 
 
81
    QList<QFileInfo> files;
 
82
    foreach (QUrl url, urls) {
 
83
        //XXX: See the note in PlaylistFeature::dropAccept() about using QUrl::toLocalFile()
 
84
        //     instead of toString()
 
85
        QFileInfo file = url.toLocalFile();
 
86
        if (SoundSourceProxy::isFilenameSupported(file.fileName())) {
 
87
            files.append(file);
 
88
        }
 
89
    }
 
90
    QList<int> trackIds = trackDao.addTracks(files, true);
 
91
 
 
92
    int playlistId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE);
 
93
    // remove tracks that could not be added
 
94
    for (int trackId =0; trackId<trackIds.size() ; trackId++) {
 
95
        if (trackIds.at(trackId) < 0) {
 
96
            trackIds.removeAt(trackId--);
 
97
        }
 
98
    }
 
99
    m_playlistDao.appendTracksToPlaylist(trackIds, playlistId);
105
100
    return true;
106
101
}
107
102
 
108
 
bool AutoDJFeature::dropAcceptChild(const QModelIndex& /*index*/, QUrl /*url*/) {
 
103
bool AutoDJFeature::dropAcceptChild(const QModelIndex& /*index*/, QList<QUrl> /*url*/) {
109
104
    return false;
110
105
}
111
106