Warning, file /utilities/okteta/kasten/core/io/filesystem/bytearrayrawfilesynchronizer.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2007-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 "bytearrayrawfilesynchronizer.hpp"
0010 
0011 // lib
0012 #include "bytearrayrawfileloadjob.hpp"
0013 #include "bytearrayrawfileconnectjob.hpp"
0014 #include "bytearrayrawfilewritejob.hpp"
0015 #include "bytearrayrawfilereloadjob.hpp"
0016 #include "bytearrayrawfilewritetojob.hpp"
0017 #include "bytearraydocument.hpp"
0018 // Okteta core
0019 #include <Okteta/PieceTableByteArrayModel>
0020 // Qt
0021 #include <QUrl>
0022 
0023 namespace Kasten {
0024 
0025 ByteArrayRawFileSynchronizer::ByteArrayRawFileSynchronizer()
0026 {
0027     connect(this, &ByteArrayRawFileSynchronizer::urlChanged, this, &ByteArrayRawFileSynchronizer::onUrlChange);
0028 }
0029 
0030 AbstractDocument* ByteArrayRawFileSynchronizer::document() const { return mDocument; }
0031 
0032 LocalSyncState ByteArrayRawFileSynchronizer::localSyncState() const
0033 {
0034     return mDocument ?
0035            (mDocument->content()->isModified() ? LocalHasChanges : LocalInSync) : LocalInSync;
0036 }
0037 
0038 void ByteArrayRawFileSynchronizer::setDocument(ByteArrayDocument* document)
0039 {
0040     mDocument = document;
0041     if (mDocument) {
0042         connect(mDocument->content(), &Okteta::AbstractByteArrayModel::modifiedChanged,
0043                 this, &ByteArrayRawFileSynchronizer::onModelModified);
0044     }
0045 }
0046 
0047 AbstractLoadJob* ByteArrayRawFileSynchronizer::startLoad(const QUrl& url)
0048 {
0049     return new ByteArrayRawFileLoadJob(this, url);
0050 }
0051 
0052 AbstractSyncToRemoteJob* ByteArrayRawFileSynchronizer::startSyncToRemote()
0053 {
0054     return new ByteArrayRawFileWriteJob(this);
0055 }
0056 
0057 AbstractSyncFromRemoteJob* ByteArrayRawFileSynchronizer::startSyncFromRemote()
0058 {
0059     return new ByteArrayRawFileReloadJob(this);
0060 }
0061 
0062 AbstractSyncWithRemoteJob* ByteArrayRawFileSynchronizer::startSyncWithRemote(const QUrl& url, AbstractModelSynchronizer::ConnectOption option)
0063 {
0064     return new ByteArrayRawFileWriteToJob(this, url, option);
0065 }
0066 
0067 AbstractConnectJob* ByteArrayRawFileSynchronizer::startConnect(AbstractDocument* document,
0068                                                                const QUrl& url, AbstractModelSynchronizer::ConnectOption option)
0069 {
0070     return new ByteArrayRawFileConnectJob(this, document, url, option);
0071 }
0072 
0073 void ByteArrayRawFileSynchronizer::onUrlChange(const QUrl& url)
0074 {
0075     mDocument->setTitle(url.fileName());
0076 }
0077 
0078 void ByteArrayRawFileSynchronizer::onModelModified(bool isModified)
0079 {
0080     Q_EMIT localSyncStateChanged((isModified ? LocalHasChanges : LocalInSync));
0081 }
0082 
0083 }
0084 
0085 #include "moc_bytearrayrawfilesynchronizer.cpp"