File indexing completed on 2024-06-16 05:25:08
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008-2009 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 "bytearrayrawfilereloadjob.hpp" 0010 0011 // lib 0012 // #include "externalbookmarkstorage.hpp" 0013 #include "bytearrayrawfilesynchronizer.hpp" 0014 #include "bytearrayrawfilereloadthread.hpp" 0015 #include "bytearraydocument.hpp" 0016 // Okteta core 0017 #include <Okteta/PieceTableByteArrayModel> 0018 // Qt 0019 #include <QCoreApplication> 0020 0021 namespace Kasten { 0022 0023 ByteArrayRawFileReloadJob::ByteArrayRawFileReloadJob(ByteArrayRawFileSynchronizer* synchronizer) 0024 : AbstractFileSystemSyncFromRemoteJob(synchronizer) 0025 {} 0026 0027 ByteArrayRawFileReloadJob::~ByteArrayRawFileReloadJob() = default; 0028 0029 void ByteArrayRawFileReloadJob::startReadFromFile() 0030 { 0031 auto* document = qobject_cast<ByteArrayDocument*>(synchronizer()->document()); 0032 auto* reloadThread = new ByteArrayRawFileReloadThread(this, /*document, */ file()); 0033 reloadThread->start(); 0034 while (!reloadThread->wait(100)) { 0035 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); 0036 } 0037 0038 bool success = reloadThread->success(); 0039 // TODO: moved this here to avoid marshalling the change signals out of the thread. Good idea? 0040 if (success) { 0041 auto* byteArray = qobject_cast<Okteta::PieceTableByteArrayModel*>(document->content()); 0042 byteArray->setData(reloadThread->data()); 0043 0044 // ExternalBookmarkStorage().readBookmarks( document, synchronizer()->url() ); 0045 } else { 0046 setError(KJob::KilledJobError); 0047 setErrorText(reloadThread->errorString()); 0048 } 0049 0050 delete reloadThread; 0051 0052 completeRead(success); 0053 } 0054 0055 } 0056 0057 #include "moc_bytearrayrawfilereloadjob.cpp"