File indexing completed on 2025-01-05 05:23:50

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "bytearrayrawfilewritethread.hpp"
0010 
0011 // lib
0012 #include "bytearraydocument.hpp"
0013 // Okteta core
0014 #include <Okteta/PieceTableByteArrayModel>
0015 // Qt
0016 #include <QDataStream>
0017 #include <QFile>
0018 
0019 namespace Kasten {
0020 
0021 ByteArrayRawFileWriteThread::~ByteArrayRawFileWriteThread() = default;
0022 
0023 void ByteArrayRawFileWriteThread::run()
0024 {
0025     auto* byteArray = qobject_cast<Okteta::PieceTableByteArrayModel*>(mDocument->content());
0026 
0027     QDataStream outStream(mFile);
0028 
0029     // TODO: this was
0030 //     outStream.writeRawData( byteArray->data(), byteArray->size() );
0031     // make it quicker again by writing spans -> spaniterator
0032 
0033     for (int i = 0; i < byteArray->size(); ++i) {
0034         const Okteta::Byte byte = byteArray->byte(i);
0035         outStream.writeRawData(reinterpret_cast<const char*>(&byte), 1);
0036     }
0037 
0038     byteArray->setModified(false);
0039 
0040     mSuccess = (outStream.status() == QDataStream::Ok);
0041 
0042     Q_EMIT documentWritten(mSuccess);
0043 }
0044 
0045 }
0046 
0047 #include "moc_bytearrayrawfilewritethread.cpp"