void ReadabilityArticle::tryLoad()
{
    if (!m_api) {
        m_error = "Cannot access article content (Invalid API Configuration)";
    }
    else if (!m_url.isValid()) {
        m_error = "Cannot access article content (Invalid URL)";
    }
    else {
        m_error.clear();
        if (m_request) {
            disconnect(m_request);
            m_request->disconnect(this);
            m_request->cancel();
            m_request->deleteLater();
        }

        m_request = m_api->getParseRequest(m_url);
        connect(m_request, SIGNAL(responseReady(QJsonObject)),
                this, SLOT(onResponseReceived(QJsonObject)));
        connect(m_request, SIGNAL(requestError(QNetworkReply::NetworkError,QString)),
                this, SLOT(onRequestError(QNetworkReply::NetworkError,QString)));
        m_request->send();
        emit startedLoading();
    }
    emit loadingChanged();
    emit errorChanged(m_error);
}
Exemplo n.º 2
0
/** Do a non-recursive import of all the songs in a directory. Does NOT decend into subdirectories.
    @param trackDao The track data access object which provides a connection to the database. We use this parameter in order to make this function callable from separate threads. You need to use a different DB connection for each thread.
    @return true if the scan completed without being cancelled. False if the scan was cancelled part-way through.
*/
bool TrackCollection::importDirectory(const QString& directory, TrackDAO& trackDao,
                                      const QStringList& nameFilters,
                                      volatile bool* cancel) {
    //qDebug() << "TrackCollection::importDirectory(" << directory<< ")";

    emit(startedLoading());
    // QFileInfoList files;

    //get a list of the contents of the directory and go through it.
    QDirIterator it(directory, nameFilters, QDir::Files | QDir::NoDotAndDotDot);
    while (it.hasNext()) {

        //If a flag was raised telling us to cancel the library scan then stop.
        if (*cancel) {
            return false;
        }

        QString absoluteFilePath = it.next();

        // If the track is in the database, mark it as existing. This code gets exectuted
        // when other files in the same directory have changed (the directory hash has changed).
        trackDao.markTrackLocationAsVerified(absoluteFilePath);

        // If the file already exists in the database, continue and go on to
        // the next file.

        // If the file doesn't already exist in the database, then add
        // it. If it does exist in the database, then it is either in the
        // user's library OR the user has "removed" the track via
        // "Right-Click -> Remove". These tracks stay in the library, but
        // their mixxx_deleted column is 1.
        if (!trackDao.trackExistsInDatabase(absoluteFilePath)) {
            //qDebug() << "Loading" << it.fileName();
            emit(progressLoading(it.fileName()));

            TrackPointer pTrack = TrackPointer(new TrackInfoObject(
                                                   absoluteFilePath), &QObject::deleteLater);

            if (trackDao.addTracksAdd(pTrack.data(), false)) {
                // Successful added
                // signal the main instance of TrackDao, that there is a
                // new Track in the database
                m_trackDao->databaseTrackAdded(pTrack);
            } else {
                qDebug() << "Track ("+absoluteFilePath+") could not be added";
            }
        }
    }
    emit(finishedLoading());
    return true;
}
void StelQGLTextureBackend::startAsynchronousLoading()
{
	invariant();
	startedLoading();

	bool http = path.startsWith("http://");
	bool pvr  = path.endsWith(".pvr");

	Q_ASSERT_X(!(http && pvr), Q_FUNC_INFO,
	           "Can't load .pvr textures from network");

	if(pvr)
	{
		// We're using a single QGLContext::bindTexture() call to load .pvr,
		// and that must be done in the main (GL) thread.
		//
		// (TODO): It might be possible to load it manually through GL calls
		// and separate file loading (separate thread) from uploading to the GPU
		// (GL thread).
		qWarning() << "Trying to load a .pvr texture asynchronously."
		              "Asynchronous loading of .pvr is not implemented at the moment."
		              "Will load the texture normally (this might cause lag)";

		loadFromPVR();
		return;
	}

	if(http)
	{
		loader = new StelHTTPTextureLoader(path, 100, renderer->getLoaderThread());
		connect(loader, SIGNAL(finished(QImage)), this, SLOT(onImageLoaded(QImage)));
		connect(loader, SIGNAL(error(QString)), this, SLOT(onLoadingError(QString)));
		return;
	}

	loader = new StelFileTextureLoader(path, 100, renderer->getLoaderThread());
	connect(loader, SIGNAL(finished(QImage)), this, SLOT(onImageLoaded(QImage)));
	connect(loader, SIGNAL(error(QString)), this, SLOT(onLoadingError(QString)));
	invariant();
}