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

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 "testdocumentfilewritetojob.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 TestDocumentFileWriteToJob::TestDocumentFileWriteToJob(TestDocumentFileSynchronizer* synchronizer,
0021                                                        const QUrl& url, AbstractModelSynchronizer::ConnectOption option)
0022     : AbstractFileSystemSyncWithRemoteJob(synchronizer, url, option)
0023 {}
0024 
0025 TestDocumentFileWriteToJob::~TestDocumentFileWriteToJob() = default;
0026 
0027 void TestDocumentFileWriteToJob::startSyncWithRemote()
0028 {
0029     auto* testSynchronizer = qobject_cast<TestDocumentFileSynchronizer*>(synchronizer());
0030     auto* document = qobject_cast<TestDocument*>(synchronizer()->document());
0031     auto* writeThread = new TestDocumentFileWriteThread(this, testSynchronizer->header(), document, file());
0032     writeThread->start();
0033     while (!writeThread->wait(100)) {
0034         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
0035     }
0036 
0037     const bool success = writeThread->success();
0038     delete writeThread;
0039 
0040     completeSync(success);
0041 }
0042 
0043 }
0044 
0045 #include "moc_testdocumentfilewritetojob.cpp"