void TransmissionChecksumValidator::uploadValidation()
{
    const QString csType = checksumType();

    if( csType.isEmpty() ) {
        // if there is no checksum defined, continue to upload
        emit validated(QByteArray());
    } else {
        // Calculate the checksum in a different thread first.

        connect( &_watcher, SIGNAL(finished()),
                 this, SLOT(slotUploadChecksumCalculated()));
        if( csType == checkSumMD5C ) {
            _checksumHeader = checkSumMD5C;
            _checksumHeader += ":";
            _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, _filePath));

        } else if( csType == checkSumSHA1C ) {
            _checksumHeader = checkSumSHA1C;
            _checksumHeader += ":";
            _watcher.setFuture(QtConcurrent::run( FileSystem::calcSha1, _filePath));
        }
#ifdef ZLIB_FOUND
        else if( csType == checkSumAdlerC) {
            _checksumHeader = checkSumAdlerC;
            _checksumHeader += ":";
            _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, _filePath));
        }
#endif
        else {
            // for an unknown checksum, continue to upload
            emit validated(QByteArray());
        }
    }
}
void TransmissionChecksumValidator::slotUploadChecksumCalculated( )
{
    QByteArray checksum = _watcher.future().result();

    if( !checksum.isEmpty() ) {
        checksum.prepend( _checksumHeader );
    }

    emit validated(checksum);
}
void TransmissionChecksumValidator::slotDownloadChecksumCalculated()
{
    const QByteArray hash = _watcher.future().result();

    if( hash != _expectedHash ) {
        emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed."));
    } else {
        // qDebug() << "Checksum checked and matching: " << _expectedHash;
        emit validated(hash);
    }
}
Ejemplo n.º 4
0
void ValidateChecksumHeader::slotChecksumCalculated(const QByteArray& checksumType,
                                                    const QByteArray& checksum)
{
    if( checksumType != _expectedChecksumType ) {
        emit validationFailed(tr("The checksum header contained an unknown checksum type '%1'").arg(
                                  QString::fromLatin1(_expectedChecksumType)));
        return;
    }
    if( checksum != _expectedChecksum ) {
        emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed."));
        return;
    }
    emit validated(checksumType, checksum);
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {
    
    partie Partie;
    string choice, answer;
    bool is_Legal = false;
    createPartie(Partie);
    displayPartie(Partie);
    for (int i=0; i<TOTALMOVE; i++){
        int numTurn=Partie.moveNum[i][0];
        
        Display:
        cout<<"Turn "<<i+1<<": "<<Partie.gamers[numTurn].name<<endl;
        cout<<"Enter your move:";
        cin>>choice;
        
        for (int i=0; i<100; i++){
            if(choice.compare(Partie.game.pos[i])==0)
                Partie.coup[8] = i;
        }
        Partie.coup[9] = numTurn;
        //check if move is legal
        is_Legal = isLegal(Partie.coup, Partie.game);
        if(!is_Legal){
            cout<<"Position illegal"<<endl;
            goto Display;
        }else{   
            validated(Partie.coup, Partie.game);
            displayPartie(Partie);
            cout<<"Do you validate your turn? (y/n)";
            cin>>answer;
            if(answer.compare("n")==0){
                isCancelled(Partie.coup, Partie.game);
                displayPartie(Partie);
                goto Display;
            }
            Partie.moveNum[i][1] = Partie.coup[8];
        }    

    }

    string winner;
    (Partie.game.pawn[BLACK]<Partie.game.pawn[WHITE]) ? winner= Partie.gamers[WHITE].name:Partie.gamers[BLACK].name;
    cout<<"Winner is: "<<winner<<" *** CONGRATULATION!!! ***" <<endl;
    return 0;
}
Ejemplo n.º 6
0
void ValidateChecksumHeader::start(const QString& filePath, const QByteArray& checksumHeader)
{
    // If the incoming header is empty no validation can happen. Just continue.
    if( checksumHeader.isEmpty() ) {
        emit validated(QByteArray(), QByteArray());
        return;
    }

    if( !parseChecksumHeader(checksumHeader, &_expectedChecksumType, &_expectedChecksum) ) {
        qDebug() << "Checksum header malformed:" << checksumHeader;
        emit validationFailed(tr("The checksum header is malformed."));
        return;
    }

    auto calculator = new ComputeChecksum(this);
    calculator->setChecksumType(_expectedChecksumType);
    connect(calculator, SIGNAL(done(QByteArray,QByteArray)),
            SLOT(slotChecksumCalculated(QByteArray,QByteArray)));
    calculator->start(filePath);
}
void TransmissionChecksumValidator::downloadValidation( const QByteArray& checksumHeader )
{
    // if the incoming header is empty, there was no checksum header, and
    // no validation can happen. Just continue.
    const QString csType = checksumType();

    // for empty checksum type, everything is valid.
    if( csType.isEmpty() ) {
        emit validated(QByteArray());
        return;
    }

    int indx = checksumHeader.indexOf(':');
    if( indx < 0 ) {
        qDebug() << "Checksum header malformed:" << checksumHeader;
        emit validationFailed(tr("The checksum header is malformed.")); // show must go on - even not validated.
        return;
    }

    const QByteArray type = checksumHeader.left(indx).toUpper();
    _expectedHash = checksumHeader.mid(indx+1);

    connect( &_watcher, SIGNAL(finished()), this, SLOT(slotDownloadChecksumCalculated()) );

    // start the calculation in different thread
    if( type == checkSumMD5C ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, _filePath));
    } else if( type == checkSumSHA1C ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcSha1, _filePath));
    }
#ifdef ZLIB_FOUND
    else if( type == checkSumAdlerUpperC ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, _filePath));
    }
#endif
    else {
        qDebug() << "Unknown checksum type" << type;
        emit validationFailed(tr("The checksum header is malformed."));
        return;
    }
}
Ejemplo n.º 8
0
void PropagateUploadFileQNAM::start()
{
    if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
        return;
    }

    const QString filePath = _propagator->getFilePath(_item->_file);

    // remember the modtime before checksumming to be able to detect a file
    // change during the checksum calculation
    _item->_modtime = FileSystem::getModTime(filePath);

    _stopWatch.start();

    // do whatever is needed to add a checksum to the http upload request.
    // in any case, the validator will emit signal startUpload to let the flow
    // continue in slotStartUpload here.
    TransmissionChecksumValidator *validator = new TransmissionChecksumValidator(filePath, this);
    connect(validator, SIGNAL(validated(QByteArray)), this, SLOT(slotStartUpload(QByteArray)));
    validator->uploadValidation();
}
Ejemplo n.º 9
0
void WebServiceWindow::save()
{
	int id = -1, order = 0;
	if (m_webService != nullptr)
	{
		id = m_webService->id();
		order = m_webService->order();
	}

	// Save favicon contents
	QByteArray faviconData;
	if (m_faviconReply->error() == QNetworkReply::NoError)
	{
		faviconData = m_faviconReply->readAll();
		m_faviconReply->deleteLater();
	}

	// Emit the success signal
	QString name = ui->lineName->text();
	QString url = ui->lineUrl->text();
	emit validated(ReverseSearchEngine(id, "", name, url, order), faviconData);

	deleteLater();
}
Ejemplo n.º 10
0
void CustomWindow::accept()
{
	emit validated(ui->lineName->text(), ui->textTags->toPlainText());
	close();
}
Ejemplo n.º 11
0
void conditionWindow::accept()
{
	emit validated(ui->lineCondition->text(), ui->lineFilename->text(), ui->lineFolder->text());
	close();
}
Ejemplo n.º 12
0
void startWindow::on_buttonFilenamePlus_clicked()
{
	FilenameWindow *fw = new FilenameWindow(ui->lineFilename->text(), this);
	connect(fw, SIGNAL(validated(QString)), ui->lineFilename, SLOT(setText(QString)));
	fw->show();
}