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, 2011 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 "bytearrayrawfilereloadthread.hpp" 0010 0011 // Okteta core 0012 #include <Okteta/PieceTableByteArrayModel> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QDataStream> 0017 #include <QFile> 0018 // C++ 0019 #include <limits> 0020 0021 namespace Kasten { 0022 0023 ByteArrayRawFileReloadThread::ByteArrayRawFileReloadThread(QObject* parent, QFile* file) 0024 : QThread(parent) 0025 , mFile(file) 0026 { 0027 } 0028 0029 ByteArrayRawFileReloadThread::~ByteArrayRawFileReloadThread() = default; 0030 0031 void ByteArrayRawFileReloadThread::run() 0032 { 0033 const qint64 fileSize = mFile->size(); 0034 0035 // check if the file content can be addressed with int 0036 // check if the file content can be addressed with Okteta::Address 0037 const Okteta::Address maxAddress = std::numeric_limits<Okteta::Address>::max(); 0038 0039 mSuccess = (fileSize <= maxAddress); 0040 0041 if (mSuccess) { 0042 mData.resize(fileSize); 0043 mSuccess = (mData.size() == fileSize); 0044 0045 if (mSuccess) { 0046 QDataStream inStream(mFile); 0047 inStream.readRawData(mData.data(), fileSize); 0048 0049 mSuccess = (inStream.status() == QDataStream::Ok); 0050 0051 if (!mSuccess) { 0052 mErrorString = mFile->errorString(); 0053 } 0054 } else { 0055 mErrorString = i18n("There is not enough free working memory to load this file."); 0056 } 0057 } else { 0058 mErrorString = i18n("Support to load files larger than 2 GiB has not yet been implemented."); 0059 } 0060 0061 Q_EMIT documentReloaded(mSuccess); 0062 } 0063 0064 } 0065 0066 #include "moc_bytearrayrawfilereloadthread.cpp"