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 "testdocumentfilereloadjob.hpp"
0010 
0011 // lib
0012 #include "testdocumentfilesynchronizer.hpp"
0013 #include "testdocumentfilereloadthread.hpp"
0014 #include "testdocument.hpp"
0015 // Qt
0016 #include <QCoreApplication>
0017 
0018 namespace Kasten {
0019 
0020 TestDocumentFileReloadJob::TestDocumentFileReloadJob(TestDocumentFileSynchronizer* synchronizer)
0021     : AbstractFileSystemSyncFromRemoteJob(synchronizer)
0022 {}
0023 
0024 TestDocumentFileReloadJob::~TestDocumentFileReloadJob() = default;
0025 
0026 void TestDocumentFileReloadJob::startReadFromFile()
0027 {
0028     auto* testSynchronizer = qobject_cast<TestDocumentFileSynchronizer*>(synchronizer());
0029     auto* document = qobject_cast<TestDocument*>(synchronizer()->document());
0030     auto* reloadThread =
0031         new TestDocumentFileReloadThread(this, testSynchronizer->header(), /*document, */ file());
0032     reloadThread->start();
0033     while (!reloadThread->wait(100)) {
0034         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
0035     }
0036 
0037     const bool success = reloadThread->success();
0038     // TODO: moved this here to avoid marshalling the change signals out of the thread. Good idea?
0039     if (success) {
0040         document->setData(reloadThread->byteArray());
0041     }
0042     delete reloadThread;
0043 
0044     completeRead(success);
0045 }
0046 
0047 }
0048 
0049 #include "moc_testdocumentfilereloadjob.cpp"