示例#1
0
void CodaSignalHandler::handleFileSystemRead(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply || result.values.size() != 2) {
        reportError(tr("Could not read remote file: %1").arg(result.errorString()));
        return;
    }

    QByteArray data = QByteArray::fromBase64(result.values.at(0).data());
    bool eof = result.values.at(1).toVariant().toBool();
    qint64 written = d->localFile->write(data);
    if (written < 0) {
        reportError(tr("Could not write data to host file: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
        return;
    }

    d->remoteBytesLeft -= written;
    if (!eof && d->remoteBytesLeft > 0) {
        readNextChunk();
    }
    else {
        d->localFile->flush();
        d->localFile->close();
        closeFile();
    }
}
示例#2
0
void CodaSignalHandler::handleSymbianInstall(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        reportMessage(tr("Installation has finished."));
        d->action = static_cast<CodaAction>(d->action & ~ActionInstall);
        handleActions();
    } else {
        reportError(tr("Installation failed: %1").arg(result.errorString()));
    }
}
示例#3
0
void CodaSignalHandler::handleFileSystemWrite(const Coda::CodaCommandResult &result)
{
    // Close remote file even if copy fails
    d->putWriteOk = result;
    if (!d->putWriteOk) {
        QString fileName = QFileInfo(d->copyDstFileName).fileName();
        reportError(tr("Could not write to file %1 on device: %2").arg(fileName).arg(result.errorString()));
    }

    if (!d->putWriteOk || d->putLastChunkSize < d->putChunkSize) {
        closeFile();
    } else {
        putSendNextChunk();
    }
}
示例#4
0
void CodaSignalHandler::handleFileSystemStart(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        reportError(tr("Could not open remote file: %1").arg(result.errorString()));
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).children().isEmpty()) {
        reportError(tr("Could not get file attributes"));
        return;
    }

    Coda::JsonValue val = result.values.at(0).findChild("Size");
    d->remoteFileSize = val.isValid() ? val.data().toLong() : -1L;
    if (d->remoteFileSize < 0) {
        reportError(tr("Could not get file size"));
        return;
    }

    d->remoteBytesLeft = d->remoteFileSize;
    readNextChunk();
}
示例#5
0
void CodaSignalHandler::handleFileSystemOpen(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        reportError(tr("Could not open remote file: %1").arg(result.errorString()));
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).data().isEmpty()) {
        reportError(tr("Internal error: No filehandle obtained"));
        return;
    }

    if (d->action & ActionCopy) {
        d->remoteFileHandle = result.values.at(0).data();
        d->remoteFile.reset(new QFile(d->copySrcFileName));
        if (!d->remoteFile->open(QIODevice::ReadOnly)) { // Should not fail, was checked before
            reportError(tr("Could not open local file %1").arg(d->copySrcFileName));
            return;
        }
        putSendNextChunk();
    } else if (d->action & ActionDownload) {
        d->remoteFileHandle = result.values.at(0).data();
        d->localFile.reset(new QFile(d->dlDstFileName));
        // remove any existing file with the same name
        if (d->localFile->exists() && !d->localFile->remove()) {
            reportError(tr("Could not create host file: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
            return;
        }
        // open local file in write-only mode
        if (!d->localFile->open(QFile::WriteOnly)) {
            reportError(tr("Could not open host file for writing: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
            return;
        }
        d->codaDevice->sendFileSystemFstatCommand(Coda::CodaCallback(this, &CodaSignalHandler::handleFileSystemStart),
                                                  d->remoteFileHandle);
    }
}