Пример #1
0
void OracleImporter::httpRequestFinished(int requestId, bool error)
{
	if (error) {
		QMessageBox::information(0, tr("HTTP"), tr("Error."));
		return;
	}
	if (requestId != reqId)
		return;

	CardSet *set = new CardSet(setsToDownload[setIndex].getShortName(), setsToDownload[setIndex].getLongName());
	if (!setHash.contains(set->getShortName()))
		setHash.insert(set->getShortName(), set);
	
	buffer->seek(0);
	buffer->close();
	int cards = importTextSpoiler(set, buffer->data());
	++setIndex;
	
	if (setIndex == setsToDownload.size()) {
		emit setIndexChanged(cards, setIndex, QString());
		setIndex = -1;
	} else {
		downloadNextFile();
		emit setIndexChanged(cards, setIndex, setsToDownload[setIndex].getLongName());
	}
}
Пример #2
0
void FolderDownloadRequest::fileDownloadedCallback(Storage::BoolResponse response) {
	_workingRequest = nullptr;
	if (_ignoreCallback)
		return;
	if (!response.value) _failedFiles.push_back(_currentFile);
	_downloadedBytes += _currentFile.size();
	downloadNextFile();
}
Пример #3
0
void InstallDialog::install()
{
    //TRACE_OBJ
    QListWidgetItem *item = 0;
    for (int i=0; i<m_ui.listWidget->count(); ++i) {
        item = m_ui.listWidget->item(i);
        if (item->checkState() == Qt::Checked)
            m_itemsToInstall.append(item);
    }
    m_ui.installButton->setEnabled(false);
    downloadNextFile();
}
Пример #4
0
int OracleImporter::startDownload()
{
    setsToDownload.clear();
    for (int i = 0; i < allSets.size(); ++i)
        if (allSets[i].getImport())
            setsToDownload.append(allSets[i]);

    if (setsToDownload.isEmpty())
        return 0;
    setIndex = 0;
    emit setIndexChanged(0, 0, setsToDownload[0].getLongName());

    downloadNextFile();
    return setsToDownload.size();
}
Пример #5
0
void FolderDownloadRequest::directoryListedCallback(Storage::ListDirectoryResponse response) {
	_workingRequest = nullptr;
	if (_ignoreCallback)
		return;
	_pendingFiles = response.value;

	// remove all directories
	// non-empty directories would be created by DumpFile, and empty ones are just ignored
	for (Common::Array<StorageFile>::iterator i = _pendingFiles.begin(); i != _pendingFiles.end();)
		if (i->isDirectory())
			_pendingFiles.erase(i);
		else {
			_totalBytes += i->size();
			++i;
		}

	_totalFiles = _pendingFiles.size();
	downloadNextFile();
}
Пример #6
0
void InstallDialog::downloadNextFile()
{
    //TRACE_OBJ
    if (!m_itemsToInstall.count()) {
        m_ui.cancelButton->setEnabled(false);
        m_ui.closeButton->setEnabled(true);
        m_ui.statusLabel->setText(tr("Done."));
        m_ui.progressBar->hide();
        updateDocItemList();
        updateInstallButton();
        return;
    }

    QListWidgetItem *item = m_itemsToInstall.dequeue();
    m_currentCheckSum = item->data(QCH_CHECKSUM).toString();
    QString fileName = item->data(QCH_FILENAME).toString();
    QString saveFileName = m_ui.pathLineEdit->text() + QDir::separator()
        + fileName;

    if (QFile::exists(saveFileName)
        && QMessageBox::information(this, m_windowTitle,
        tr("The file %1 already exists. Do you want to overwrite it?")
        .arg(saveFileName), QMessageBox::Yes | QMessageBox::No,
        QMessageBox::Yes) == QMessageBox::No) {
        installFile(saveFileName);
        downloadNextFile();
        return;        
    }

    m_ui.statusLabel->setText(tr("Downloading %1...").arg(fileName));
    m_ui.progressBar->show();

    const QUrl url(QString("http://qt.nokia.com/doc/assistantdocs/") + fileName);
    
    m_httpAborted = false;
    m_networkReply = m_networkAccessManager->get(QNetworkRequest(url));
    m_networkReply->setProperty(targetFileProperty, QVariant(saveFileName));
    if (debug)
        qDebug() << "Sending " << url.toString() << saveFileName;

    m_ui.cancelButton->setEnabled(true);
    m_ui.closeButton->setEnabled(false);    
}
Пример #7
0
void SavesSyncRequest::fileDownloadedCallback(Storage::BoolResponse response) {
	_workingRequest = nullptr;
	if (_ignoreCallback)
		return;

	//stop syncing if download failed
	if (!response.value) {
		//delete the incomplete file
		g_system->getSavefileManager()->removeSavefile(_currentDownloadingFile.name());
		finishError(Networking::ErrorResponse(this, false, true, "", -1));
		return;
	}

	//update local timestamp for downloaded file
	_localFilesTimestamps = DefaultSaveFileManager::loadTimestamps();
	_localFilesTimestamps[_currentDownloadingFile.name()] = _currentDownloadingFile.timestamp();
	DefaultSaveFileManager::saveTimestamps(_localFilesTimestamps);

	//continue downloading files
	downloadNextFile();
}
Пример #8
0
void SavesSyncRequest::directoryListedCallback(Storage::ListDirectoryResponse response) {
	_workingRequest = nullptr;
	if (_ignoreCallback)
		return;

	if (response.request) _date = response.request->date();

	Common::HashMap<Common::String, bool> localFileNotAvailableInCloud;
	for (Common::HashMap<Common::String, uint32>::iterator i = _localFilesTimestamps.begin(); i != _localFilesTimestamps.end(); ++i) {
		localFileNotAvailableInCloud[i->_key] = true;
	}

	//determine which files to download and which files to upload
	Common::Array<StorageFile> &remoteFiles = response.value;
	uint64 totalSize = 0;
	for (uint32 i = 0; i < remoteFiles.size(); ++i) {
		StorageFile &file = remoteFiles[i];
		if (file.isDirectory())
			continue;
		totalSize += file.size();
		if (file.name() == DefaultSaveFileManager::TIMESTAMPS_FILENAME)
			continue;

		Common::String name = file.name();
		if (!_localFilesTimestamps.contains(name)) {
			_filesToDownload.push_back(file);
		} else {
			localFileNotAvailableInCloud[name] = false;

			if (_localFilesTimestamps[name] == file.timestamp())
				continue;

			//we actually can have some files not only with timestamp < remote
			//but also with timestamp > remote (when we have been using ANOTHER CLOUD and then switched back)
			if (_localFilesTimestamps[name] > file.timestamp() || _localFilesTimestamps[name] == DefaultSaveFileManager::INVALID_TIMESTAMP)
				_filesToUpload.push_back(file.name());
			else
				_filesToDownload.push_back(file);
		}
	}

	CloudMan.setStorageUsedSpace(CloudMan.getStorageIndex(), totalSize);

	//upload files which are unavailable in cloud
	for (Common::HashMap<Common::String, bool>::iterator i = localFileNotAvailableInCloud.begin(); i != localFileNotAvailableInCloud.end(); ++i) {
		if (i->_key == DefaultSaveFileManager::TIMESTAMPS_FILENAME)
			continue;
		if (i->_value)
			_filesToUpload.push_back(i->_key);
	}

	debug(9, "\nSavesSyncRequest: download files:");
	for (uint32 i = 0; i < _filesToDownload.size(); ++i) {
		debug(9, "%s", _filesToDownload[i].name().c_str());
	}
	debug(9, "\nSavesSyncRequest: upload files:");
	for (uint32 i = 0; i < _filesToUpload.size(); ++i) {
		debug(9, "%s", _filesToUpload[i].c_str());
	}
	_totalFilesToHandle = _filesToDownload.size() + _filesToUpload.size();

	//start downloading files
	downloadNextFile();
}
Пример #9
0
void InstallDialog::httpRequestFinished(QNetworkReply *reply)
{
    //TRACE_OBJ

    const QString targetFile = reply->property(targetFileProperty).toString();
    if (targetFile == QLatin1String(docInfoTargetFileId)) {
        m_ui.progressBar->hide();
        if (reply->error() != QNetworkReply::NoError) {
            QMessageBox::information(this, m_windowTitle,
                tr("Download failed: %1.")
                .arg(m_networkReply->errorString()));
            return;
        }
        if (!m_httpAborted) {
            while (reply->canReadLine()) {
                QByteArray ba = reply->readLine();
                const QStringList lst = QString::fromLatin1(ba.constData()).split(QLatin1Char('|'));
                if (lst.count() != 4) {
                    QMessageBox::information(this, m_windowTitle,
                        tr("Documentation info file is corrupt!"));
                } else {
                    QListWidgetItem *item = new QListWidgetItem(m_ui.listWidget);
                    item->setText(lst.at(2).trimmed());
                    item->setData(QCH_FILENAME, lst.first());
                    item->setData(QCH_NAMESPACE, lst.at(1));
                    item->setData(QCH_CHECKSUM, lst.last().trimmed());
                }
            }
            updateDocItemList();
        }
        m_ui.statusLabel->setText(tr("Done."));
        m_ui.cancelButton->setEnabled(false);        
        m_ui.closeButton->setEnabled(true);
        updateInstallButton();
        return;
    }

    // Download of file
    if (reply->error() != QNetworkReply::NoError) {
        QMessageBox::warning(this, m_windowTitle,
            tr("Download failed: %1.")
            .arg(reply->errorString()));
        downloadNextFile();
        return;
    }

    if (m_httpAborted) {
        downloadNextFile();
        return;
    }

    QFile file(targetFile);
    if (!file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
        QMessageBox::information(this, m_windowTitle,
                                 tr("Unable to save the file %1: %2.")
                                 .arg(targetFile).arg(file.errorString()));
        downloadNextFile();
        return;
    }
    const QByteArray data = reply->readAll();
    file.write(data);
    file.close();

    const QByteArray digest = QCryptographicHash::hash(data, QCryptographicHash::Md5);
    const QString checkSum = QString::fromLatin1(digest.toHex());

    if (checkSum.isEmpty() || m_currentCheckSum != checkSum) {
        file.remove();
        QMessageBox::warning(this, m_windowTitle,
                             tr("Download failed: Downloaded file is corrupted."));
        downloadNextFile();
        return;
    }

    m_ui.statusLabel->setText(tr("Installing documentation %1...")
                              .arg(QFileInfo(targetFile).fileName()));
    m_ui.progressBar->setMaximum(0);
    m_ui.statusLabel->setText(tr("Done."));
    installFile(targetFile);
    downloadNextFile();
}