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 "testdocumentfileconnectjob.hpp"
0010 
0011 // lib
0012 #include "testdocumentfilesynchronizer.hpp"
0013 #include "testdocumentfilewritethread.hpp"
0014 #include "testdocument.hpp"
0015 // Qt
0016 #include <QCoreApplication>
0017 
0018 namespace Kasten {
0019 
0020 TestDocumentFileConnectJob::TestDocumentFileConnectJob(TestDocumentFileSynchronizer* synchronizer,
0021                                                        AbstractDocument* document,
0022                                                        const QUrl& url,
0023                                                        AbstractModelSynchronizer::ConnectOption option)
0024     : AbstractFileSystemConnectJob(synchronizer, document, url, option)
0025 {
0026 }
0027 
0028 TestDocumentFileConnectJob::~TestDocumentFileConnectJob() = default;
0029 
0030 void TestDocumentFileConnectJob::startConnectWithFile()
0031 {
0032     auto* testSynchronizer = qobject_cast<TestDocumentFileSynchronizer*>(synchronizer());
0033     auto* testDocument = qobject_cast<TestDocument*>(document());
0034     auto* writeThread =
0035         new TestDocumentFileWriteThread(this, testSynchronizer->header(), testDocument, file());
0036 
0037     writeThread->start();
0038     while (!writeThread->wait(100)) {
0039         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
0040     }
0041 
0042     const bool success = writeThread->success();
0043 
0044     if (success) {
0045         testSynchronizer->setDocument(testDocument);
0046     }
0047     delete writeThread;
0048 
0049     complete(success);
0050 }
0051 
0052 }
0053 
0054 #include "moc_testdocumentfileconnectjob.cpp"