Example #1
0
void ITunesFeature::activate(bool forceReload) {
    //qDebug("ITunesFeature::activate()");
    if (!m_isActivated || forceReload) {
        SettingsDAO settings(m_pTrackCollection->database());
        QString dbSetting(settings.getValue(ITDB_PATH_KEY));
        // if a path exists in the database, use it
        if (!dbSetting.isEmpty() && QFile::exists(dbSetting)) {
            m_dbfile = dbSetting;
        } else {
            // No Path in settings, try the default
            m_dbfile = getiTunesMusicPath();
        }

        QFileInfo dbFile(m_dbfile);
        if (!m_dbfile.isEmpty() && dbFile.exists()) {
            // Users of Mixxx <1.12.0 didn't support sandboxing. If we are sandboxed
            // and using a custom iTunes path then we have to ask for access to this
            // file.
            Sandbox::askForAccess(m_dbfile);
        } else {
            // if the path we got between the default and the database doesn't
            // exist, ask for a new one and use/save it if it exists
            m_dbfile = QFileDialog::getOpenFileName(
                NULL, tr("Select your iTunes library"), QDir::homePath(), "*.xml");
            QFileInfo dbFile(m_dbfile);
            if (m_dbfile.isEmpty() || !dbFile.exists()) {
                emit(showTrackModel(m_pITunesTrackModel));
                return;
            }

            // The user has picked a new directory via a file dialog. This means the
            // system sandboxer (if we are sandboxed) has granted us permission to
            // this folder. Create a security bookmark while we have permission so
            // that we can access the folder on future runs. We need to canonicalize
            // the path so we first wrap the directory string with a QDir.
            Sandbox::createSecurityToken(dbFile);
            settings.setValue(ITDB_PATH_KEY, m_dbfile);
        }
        m_isActivated =  true;
        // Usually the maximum number of threads
        // is > 2 depending on the CPU cores
        // Unfortunately, within VirtualBox
        // the maximum number of allowed threads
        // is 1 at all times We'll need to increase
        // the number to > 1, otherwise importing the music collection
        // takes place when the GUI threads terminates, i.e., on
        // Mixxx shutdown.
        QThreadPool::globalInstance()->setMaxThreadCount(4); //Tobias decided to use 4
        // Let a worker thread do the XML parsing
        m_future = QtConcurrent::run(this, &ITunesFeature::importLibrary);
        m_future_watcher.setFuture(m_future);
        m_title = tr("(loading) iTunes");
        // calls a slot in the sidebar model such that 'iTunes (isLoading)' is displayed.
        emit(featureIsLoading(this, true));
    }

    emit(showTrackModel(m_pITunesTrackModel));
    emit(enableCoverArtDisplay(false));
}
Example #2
0
void ITunesFeature::activate(bool forceReload) {
    //qDebug("ITunesFeature::activate()");
    if (!m_isActivated || forceReload) {
        SettingsDAO settings(m_pTrackCollection->getDatabase());
        QString dbSetting(settings.getValue(ITDB_PATH_KEY));
        // if a path exists in the database, use it
        if (!dbSetting.isEmpty() && QFile::exists(dbSetting)) {
            m_dbfile = dbSetting;
        } else {
            // No Path in settings, try the default
            m_dbfile = getiTunesMusicPath();
        }
        // if the path we got between the default and the database doesn't
        // exist, ask for a new one and use/save it if it exists
        if (!QFile::exists(m_dbfile)) {
            m_dbfile = QFileDialog::getOpenFileName(
                NULL, tr("Select your iTunes library"), QDir::homePath(), "*.xml");
            if (m_dbfile.isEmpty() || !QFile::exists(m_dbfile)) {
                emit(showTrackModel(m_pITunesTrackModel));
                return;
            }
            settings.setValue(ITDB_PATH_KEY, m_dbfile);
        }
        m_isActivated =  true;
        // Ususally the maximum number of threads
        // is > 2 depending on the CPU cores
        // Unfortunately, within VirtualBox
        // the maximum number of allowed threads
        // is 1 at all times We'll need to increase
        // the number to > 1, otherwise importing the music collection
        // takes place when the GUI threads terminates, i.e., on
        // Mixxx shutdown.
        QThreadPool::globalInstance()->setMaxThreadCount(4); //Tobias decided to use 4
        // Let a worker thread do the XML parsing
        m_future = QtConcurrent::run(this, &ITunesFeature::importLibrary);
        m_future_watcher.setFuture(m_future);
        m_title = tr("(loading) iTunes");
        // calls a slot in the sidebar model such that 'iTunes (isLoading)' is displayed.
        emit (featureIsLoading(this));
    }

    emit(showTrackModel(m_pITunesTrackModel));
}