コード例 #1
0
// TODO: optimize and check if pattern is just one byte, so memset can be used
// TODO: see if copying larger chunks with memcpy is faster, so 
QMimeData* ByteArrayPatternGenerator::generateData()
{
    const int patternSize = mSettings.pattern.size();

    const int insertDataSize = mSettings.count * patternSize;

    QByteArray insertData( insertDataSize, '\0' );

    char* rawInsertData = insertData.data();
    const char* rawPatternData = mSettings.pattern.constData();

    for( int i=0; i < insertDataSize; i+= patternSize )
        memcpy( &rawInsertData[i], rawPatternData, patternSize );

    QMimeData* mimeData = new QMimeData;
    mimeData->setData( mimeType(), insertData );

// TODO: a method to get the description of the change, e.g. 
#if 0
    Okteta::ChangesDescribable *changesDescribable =
        qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );

    if( changesDescribable )
        changesDescribable->openGroupedChange( i18n("Pattern inserted.") );
    mByteArrayView->insert( insertData );
//     mByteArrayModel->replace( filteredSection, filterResult );
    if( changesDescribable )
        changesDescribable->closeGroupedChange();
#endif

    return mimeData;
}
コード例 #2
0
// TODO: use different RNG, with multiple characteristics and offer them in the config
QMimeData* ByteArrayRandomDataGenerator::generateData()
{
    qsrand( (unsigned int)time(0) );

    const int insertDataSize = mSettings.size;
    QByteArray insertData( insertDataSize, '\0' );

    for( int i=0; i < insertDataSize; ++i )
        insertData[i] = qrand() % 256; // TODO: modulo is expensive, even if easy to use

    QMimeData* mimeData = new QMimeData;
    mimeData->setData( mimeType(), insertData );

// TODO: a method to get the description of the change, e.g. 
#if 0
    Okteta::ChangesDescribable *changesDescribable =
        qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );

    if( changesDescribable )
        changesDescribable->openGroupedChange( i18n("RandomData inserted.") );
    mByteArrayView->insert( insertData );
//     mByteArrayModel->replace( filteredSection, filterResult );
    if( changesDescribable )
        changesDescribable->closeGroupedChange();
#endif

    return mimeData;
}
コード例 #3
0
ファイル: bytetabletool.cpp プロジェクト: KDE/okteta
void ByteTableTool::insert( unsigned char byte, int count )
{
    const QByteArray data( count, byte );

    Okteta::ChangesDescribable *changesDescribable =
        qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );

    if( changesDescribable )
    {
        // TODO: how to note the byte? charcoding might change...
        const QString changeDescription =
            i18np( "Inserted 1 Byte","Inserted %1 Bytes", count );

        changesDescribable->openGroupedChange( changeDescription );
    }

    mByteArrayView->insert( data );

    if( changesDescribable )
        changesDescribable->closeGroupedChange();
// void ByteTableController::fill( const QByteArray &Data )
// {
//     if( HexEdit && ByteArray )
//         ByteArray->insert( HexEdit->cursorPosition(), Data );
// }
    mByteArrayView->setFocus();
}
コード例 #4
0
// TODO: optimize and check if pattern is just one byte, so memset can be used
// TODO: see if copying larger chunks with memcpy is faster, so 
QMimeData* ByteArraySequenceGenerator::generateData()
{
    const Okteta::Byte firstByte = 0;
    const Okteta::Byte lastByte = 255;

    const int insertDataSize = lastByte-firstByte+1;
    QByteArray insertData( insertDataSize, '\0' );

    Okteta::Byte byte = firstByte;
    for( int i=0; i < insertDataSize; ++i, ++byte )
        insertData[i] = byte;

    QMimeData* mimeData = new QMimeData;
    mimeData->setData( mimeType(), insertData );

// TODO: a method to get the description of the change, e.g. 
#if 0
    Okteta::ChangesDescribable *changesDescribable =
        qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );

    if( changesDescribable )
        changesDescribable->openGroupedChange( i18n("Sequence inserted.") );
    mByteArrayView->insert( insertData );
//     mByteArrayModel->replace( filteredSection, filterResult );
    if( changesDescribable )
        changesDescribable->closeGroupedChange();
#endif

    return mimeData;
}
コード例 #5
0
void CharsetConversionTool::convertChars()
{
    QApplication::setOverrideCursor( Qt::WaitCursor );

    const Okteta::AddressRange convertedSection = mByteArrayView->selection();
    QByteArray conversionResult;
    conversionResult.resize( convertedSection.width() );

    Okteta::CharCodec* viewCharCodec =
        Okteta::CharCodec::createCodec( mByteArrayView->charCodingName() );
    Okteta::CharCodec* otherCharCodec =
        Okteta::CharCodec::createCodec( mOtherCharCodecName );
    const bool convertToOther = (mConversionDirection == ConvertTo);
    Okteta::CharCodec* fromCharCodec = convertToOther ? viewCharCodec : otherCharCodec;
    Okteta::CharCodec* toCharCodec = convertToOther ? otherCharCodec : viewCharCodec;
    CharsetConversionJob* charsetConversionJob =
        new CharsetConversionJob( reinterpret_cast<Okteta::Byte*>(conversionResult.data()),
                                  mByteArrayModel, convertedSection,
                                  convertToOther ? viewCharCodec : otherCharCodec,
                                  convertToOther ? otherCharCodec : viewCharCodec,
                                  mSubstitutingMissingChars, mSubstituteByte
                                ); // TODO: report also actually converted bytes
    const bool success = charsetConversionJob->exec();

    if( success ) //TODO: if nothing needed to be converted, just report and don't add change
    {
        Okteta::ChangesDescribable *changesDescribable =
            qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );

        if( changesDescribable )
        {
            const QString description =
                i18nc("Converted from charset 1 to charset 2",
                      "%1 to %2", fromCharCodec->name(), toCharCodec->name());
            changesDescribable->openGroupedChange( description );
        }
        mByteArrayModel->replace( convertedSection, conversionResult );
        if( changesDescribable )
            changesDescribable->closeGroupedChange();
    }

    delete viewCharCodec;
    delete otherCharCodec;

    QApplication::restoreOverrideCursor();

    const QMap<Okteta::Byte, int>& failedPerByteCount = charsetConversionJob->failedPerByteCount();
    const int convertedBytesCount = charsetConversionJob->convertedBytesCount();

    mByteArrayView->setFocus();

    emit conversionDone( success, convertedBytesCount, failedPerByteCount );
}