File indexing completed on 2024-06-23 05:49:22

0001 /*
0002     This file is part of the Kasten Framework, 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 "testdocumentfileloadthread.hpp"
0010 
0011 // lib
0012 #include "testdocument.hpp"
0013 // KF
0014 #include <KLocalizedString>
0015 // Qt
0016 #include <QUrl>
0017 #include <QByteArray>
0018 #include <QDataStream>
0019 #include <QFile>
0020 #include <QCoreApplication>
0021 
0022 namespace Kasten {
0023 
0024 TestDocumentFileLoadThread::~TestDocumentFileLoadThread() = default;
0025 
0026 void TestDocumentFileLoadThread::run()
0027 {
0028     QDataStream inStream(mFile);
0029     const int fileSize = mFile->size();
0030 
0031     // test header
0032     const int headerSize = mHeader.size();
0033     QByteArray header(headerSize, ' ');
0034     const int headerResult = inStream.readRawData(header.data(), headerSize);
0035     if (headerResult == -1 || header != mHeader) {
0036         mDocument = nullptr;
0037     } else {
0038         QByteArray byteArray(fileSize, ' ');
0039 
0040         inStream.readRawData(byteArray.data(), fileSize);
0041 
0042         // registerDiskModifyTime( file ); TODO move into synchronizer
0043 
0044         const bool streamIsOk = (inStream.status() == QDataStream::Ok);
0045         //     if( success )
0046         //         *success = streamIsOk ? 0 : 1;
0047         if (streamIsOk) {
0048             mDocument = new TestDocument(byteArray);
0049             mDocument->moveToThread(QCoreApplication::instance()->thread());
0050         } else {
0051             mDocument = nullptr;
0052         }
0053     }
0054 
0055     Q_EMIT documentRead(mDocument);
0056 }
0057 
0058 }
0059 
0060 #include "moc_testdocumentfileloadthread.cpp"