void DownloadUpdateDialog::startDownload(QString version)
{
#ifdef Q_OS_WIN
    tmpFile = new QFile(QDir::tempPath() + "/" + "ScreenCloud-" + version + "-" + QString(ARCH) + ".msi", this);
    if(tmpFile->exists())
    {
        INFO(tr("Removing existing installer ") + tmpFile->fileName());
        tmpFile->remove();
    }
    INFO(tr("Saving installer to ") + tmpFile->fileName());
    QNetworkRequest downloadRequest("https://screencloud.net/files/windows/ScreenCloud-" + version + "-" + QString(ARCH) + ".msi");
    QNetworkReply* r = netManager->get(downloadRequest);
    connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64)));
    INFO(tr("Downloading ") + downloadRequest.url().toString());
#endif
#ifdef Q_OS_MACX
    tmpFile = new QFile(QDir::tempPath() + "/" + "ScreenCloud-" + version + ".dmg", this);
    if(tmpFile->exists())
    {
        INFO(tr("Removing existing dmg ") + tmpFile->fileName());
        tmpFile->remove();
    }
    INFO(tr("Saving dmg to ") + tmpFile->fileName());
    QNetworkRequest downloadRequest("https://screencloud.net/files/mac/ScreenCloud-" + version + ".dmg");
    QNetworkReply* r = netManager->get(downloadRequest);
    connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64)));
    INFO(tr("Downloading ") + downloadRequest.url().toString());
#endif
}
Esempio n. 2
0
void PublishToMePlugin::checkDownloadLink() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    const QString redirect = getRedirect(reply);

    if (!redirect.isEmpty()) {
        if (FILE_REGEXP.indexIn(redirect) == 0) {
            emit downloadRequest(QNetworkRequest(redirect));
        }
        else if (m_redirects < MAX_REDIRECTS) {
            followRedirect(redirect, SLOT(checkDownloadLink()));
        }
        else {
            emit error(tr("Maximum redirects reached"));
        }

        reply->deleteLater();
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    const QString response = QString::fromUtf8(reply->readAll());

    if (FILE_REGEXP.indexIn(response) != -1) {
        QString url = FILE_REGEXP.cap();
        
        if (url.startsWith("/")) {
            url.prepend(reply->url().scheme() + "://" + reply->url().authority());
        }

        emit downloadRequest(QNetworkRequest(url));
    }
    else {
        emit error(tr("Unknown error"));
    }

    reply->deleteLater();
}
Esempio n. 3
0
GS_BOOL	InGameMarketplace::RequestDownloadItems( GS_INT index, ContentInstalledCallBack callBack )
{
#if defined(_XBOX)
	if ( m_pDownloadMgr )
	{
		m_ContentInstalledCallBack = callBack;
		ULONGLONG offerID;
		if ( !m_pOfferMgr->GetOfferIDByIndex( index, offerID ) )
		{
			return FALSE;
		}
		DownloadRequest downloadRequest( 1 );
		downloadRequest.AddOffer( offerID );
		m_pDownloadMgr->DownloadItems( &downloadRequest );
		return TRUE;
	}
#elif defined(_PS3)
    if (m_pInGameBrowsing)
    {
		m_ContentInstalledCallBack = callBack;
        return m_pInGameBrowsing->BuyProduct( index, callBack );
    }
#endif

	return FALSE;
}
Esempio n. 4
0
void VimeoPlugin::submitFormat(const QVariantMap &format) {
    const QUrl url(format.value("videoFormat").toString());

    if (url.isEmpty()) {
        emit error(tr("Invalid video format chosen"));
    }
    else {
        emit downloadRequest(QNetworkRequest(url));
    }
}
Esempio n. 5
0
void VimeoPlugin::onStreamsRequestFinished() {
    if (m_streamsRequest->status() == QVimeo::StreamsRequest::Ready) {
        const QVariantList streams = m_streamsRequest->result().toList();
        
        if (streams.isEmpty()) {
            emit error(tr("No streams found"));
            return;
        }

        if (m_settings.value("useDefaultVideoFormat", true).toBool()) {
            const QString format = m_settings.value("videoFormat", "1080p").toString();

            for (int i = 0; i < VIDEO_FORMATS.indexOf(format); i++) {
                for (int j = 0; j < streams.size(); j++) {
                    const QVariantMap stream = streams.at(j).toMap();

                    if (stream.value("id") == format) {
                        emit downloadRequest(QNetworkRequest(stream.value("url").toString()));
                        return;
                    }
                }
            }

            emit error(tr("No stream found for the chosen video format"));
        }
        else {
            QVariantList settingsList;
            QVariantList options;
            QVariantMap list;
            list["type"] = "list";
            list["label"] = tr("Video format");
            list["key"] = "videoFormat";
            list["value"] = streams.first().toMap().value("url");
            
            for (int i = 0; i < streams.size(); i++) {
                const QVariantMap stream = streams.at(i).toMap();
                QVariantMap option;
                option["label"] = QString("%1P").arg(stream.value("height").toString());
                option["value"] = stream.value("url");
                options << option;
            }

            list["options"] = options;
            settingsList << list;
            emit settingsRequest(tr("Choose video format"), settingsList, "submitFormat");
        }
    }
    else if (m_streamsRequest->status() == QVimeo::StreamsRequest::Failed) {
        emit error(m_streamsRequest->errorString());
    }   
}
void Net::DownloadManager::handleReplyFinished(const QNetworkReply *reply)
{
    const ServiceID id = ServiceID::fromURL(reply->url());
    const auto waitingJobsIter = m_waitingJobs.find(id);
    if ((waitingJobsIter == m_waitingJobs.end()) || waitingJobsIter.value().isEmpty()) {
        m_busyServices.remove(id);
        return;
    }

    auto handler = static_cast<DownloadHandlerImpl *>(waitingJobsIter.value().dequeue());
    qDebug("Downloading %s...", qUtf8Printable(handler->url()));
    handler->assignNetworkReply(m_networkManager.get(createNetworkRequest(handler->downloadRequest())));
    handler->disconnect(this);
}
Esempio n. 7
0
void SqlKepper::wrapJson(QJsonObject& jsonObj)
{
    db = QSqlDatabase::database();
    if(!db.isOpen())
    {
        emit dbConnectionError("db not available");
    }
    QSqlQuery query(db);
    qDebug()<<"query state: "<<query.exec("DROP TABLE IF EXISTS BOOKS ;");
    qDebug()<<"query state: "<<query.exec("CREATE TABLE BOOKS(id INTEGER , title VARCHAR(255), author_title VARCHAR(255), free VARCHAR(24), img VARCHAR(255) );");

    QJsonArray arr = jsonObj.value("books").toArray();


    foreach (QJsonValue cortaige, arr)
    {
        QJsonObject node = cortaige.toObject();

        QString image = node.value("img").toString();
        emit downloadRequest(image);
        int start =  image.lastIndexOf("/")+1;
        int end =  image.lastIndexOf("?");
        image.resize(end);
        image = image.right(image.length() - start);

        QString paid;
        if(node.value("free").toString().toInt () == 0)
            paid="non-free";
        if(node.value("free").toString().toInt () == 1)
            paid="free";

        qDebug()<<"query state: "<<query.exec(QString(" INSERT INTO BOOKS VALUES(%1, '%2', '%3', '%4', '%5');")
                  .arg( node.value("id").toString().toInt()   )
                  .arg( node.value("title").toString() )
                  .arg( node.value("author_title").toString() )
                  .arg(  paid  )
                  .arg( image ) );
        qDebug()<<query.lastError();

    }
Esempio n. 8
0
void KWebPage::downloadUrl(const KUrl &url)
{
    downloadRequest(QNetworkRequest(url));
}
Esempio n. 9
0
void PublishToMePlugin::checkCaptcha() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    const QString redirect = getRedirect(reply);

    if (!redirect.isEmpty()) {
        if (FILE_REGEXP.indexIn(redirect) == 0) {
            emit downloadRequest(QNetworkRequest(redirect));
        }
        else if (m_redirects < MAX_REDIRECTS) {
            followRedirect(redirect, SLOT(checkCaptcha()));
        }
        else {
            emit error(tr("Maximum redirects reached"));
        }

        reply->deleteLater();
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    const QString response = QString::fromUtf8(reply->readAll());

    if (FILE_REGEXP.indexIn(response) != -1) {
        QString url = FILE_REGEXP.cap();
        
        if (url.startsWith("/")) {
            url.prepend(reply->url().scheme() + "://" + reply->url().authority());
        }
        
        emit downloadRequest(QNetworkRequest(url));
    }
    else if (response.contains("verification code is incorrect")) {
        QString recaptchaKey = response.section("/file/captcha.html?v=", 1, 1).section('"', 0, 0);

        if (recaptchaKey.isEmpty()) {
            emit error(tr("No captcha key found"));
        }
        else {
            recaptchaKey.prepend(QString("http://%1/file/captcha.html?v=").arg(reply->url().host()));
            emit captchaRequest(RECAPTCHA_PLUGIN_ID, CaptchaType::Image, recaptchaKey, "submitCaptchaResponse");
        }
    }
    else {
        const int secs = response.section("tik-tak\" >", 1, 1).section('<', 0, 0).toInt();

        if (secs > 0) {
            startWaitTimer(secs * 1000, SLOT(getDownloadLink()));
        }
        else {
            emit error(tr("Unknown error"));
        }
    }

    reply->deleteLater();
}
Esempio n. 10
0
void PublishToMePlugin::checkWaitTime() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    const QString redirect = getRedirect(reply);

    if (!redirect.isEmpty()) {
        if (FILE_REGEXP.indexIn(redirect) == 0) {
            emit downloadRequest(QNetworkRequest(redirect));
        }
        else if (m_redirects < MAX_REDIRECTS) {
            followRedirect(redirect, SLOT(checkWaitTime()));
        }
        else {
            emit error(tr("Maximum redirects reached"));
        }

        reply->deleteLater();
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    const QString response = QString::fromUtf8(reply->readAll());

    if (FILE_REGEXP.indexIn(response) != -1) {
        QString url = FILE_REGEXP.cap();
        
        if (url.startsWith("/")) {
            url.prepend(reply->url().scheme() + "://" + reply->url().authority());
        }
        
        emit downloadRequest(QNetworkRequest(url));
    }
    else if (response.contains("Downloading is not possible")) {
        const QTime time = QTime::fromString(response.section("Please wait", 1, 1).section("to download", 0, 0)
                                            .trimmed(), "hh:mm:ss");
        
        if (time.isValid()) {
            emit waitRequest(QTime(0, 0).msecsTo(time), true);
        }
        else {
            emit error(tr("Unknown error"));
        }
    }
    else {
        QString recaptchaKey = response.section("/file/captcha.html?v=", 1, 1).section('"', 0, 0);

        if (recaptchaKey.isEmpty()) {
            emit error(tr("No captcha key found"));
        }
        else {
            recaptchaKey.prepend(QString("http://%1/file/captcha.html?v=").arg(reply->url().host()));
            emit captchaRequest(RECAPTCHA_PLUGIN_ID, CaptchaType::Image, recaptchaKey, "submitCaptchaResponse");
        }
    }

    reply->deleteLater();
}