예제 #1
0
void BrowseTableModel::removeTracks(QStringList trackLocations) {
    if (trackLocations.size() == 0)
        return;

    // Ask user if s/he is sure
    if (QMessageBox::question(
        NULL, tr("Mixxx Library"),
        tr("Warning: This will permanently delete the following files:")
        + "\n" + trackLocations.join("\n") + "\n" +
        tr("Are you sure you want to delete these files from your computer?"),
        QMessageBox::Yes, QMessageBox::Abort) == QMessageBox::Abort) {
        return;
    }

    QList<int> deleted_ids;
    bool any_deleted = false;
    TrackDAO& track_dao = m_pTrackCollection->getTrackDAO();

    foreach (QString track_location, trackLocations) {
        // If track is in use or deletion fails, show an error message.
        if (isTrackInUse(track_location) || !QFile::remove(track_location)) {
            QMessageBox::critical(
                0, tr("Mixxx Library"),
                tr("Could not delete the following file because"
                   " it is in use by Mixxx or another application:") + "\n" +track_location);
            continue;
        }

        qDebug() << "BrowseFeature: User deleted track " << track_location;
        any_deleted = true;

        deleted_ids.append(track_dao.getTrackId(track_location));
    }

    // If the tracks are contained in the Mixxx library, delete them
    if (!deleted_ids.isEmpty()) {
        qDebug() << "BrowseFeature: Purge affected track from database";
        track_dao.purgeTracks(deleted_ids);
    }

    // Repopulate model if any tracks were actually deleted
    if (any_deleted) {
        m_pBrowseThread->executePopulation(m_current_directory,
                                                       this);
    }
}
예제 #2
0
Qt::ItemFlags BrowseTableModel::flags(const QModelIndex &index) const {
    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);

    // Enable dragging songs from this data model to elsewhere (like the
    // waveform widget to load a track into a Player).
    defaultFlags |= Qt::ItemIsDragEnabled;

    QString track_location = getTrackLocation(index);
    int column = index.column();

    if (isTrackInUse(track_location) ||
       column == COLUMN_FILENAME ||
       column == COLUMN_BITRATE ||
       column == COLUMN_DURATION ||
       column == COLUMN_TYPE) {
        return defaultFlags;
    } else {
        return defaultFlags | Qt::ItemIsEditable;
    }
}