File indexing completed on 2025-02-09 07:11:25
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2007-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 "abstractmodelfilesystemsynchronizer_p.hpp" 0010 0011 // lib 0012 #include <logging.hpp> 0013 // KF 0014 #include <KDirWatch> 0015 // Qt 0016 #include <QNetworkConfigurationManager> 0017 0018 namespace Kasten { 0019 0020 AbstractModelFileSystemSynchronizerPrivate::~AbstractModelFileSystemSynchronizerPrivate() 0021 { 0022 delete mNetworkConfigurationManager; 0023 } 0024 0025 void AbstractModelFileSystemSynchronizerPrivate::startFileWatching() 0026 { 0027 Q_Q(AbstractModelFileSystemSynchronizer); 0028 0029 if (!mDirWatch) { 0030 mDirWatch = new KDirWatch(q); 0031 QObject::connect(mDirWatch, &KDirWatch::dirty, 0032 q, [&](const QString& path) { onFileDirty(path); }); 0033 0034 QObject::connect(mDirWatch, &KDirWatch::created, 0035 q, [&](const QString& path) { onFileCreated(path); }); 0036 0037 QObject::connect(mDirWatch, &KDirWatch::deleted, 0038 q, [&](const QString& path) { onFileDeleted(path); }); 0039 } 0040 0041 mDirWatch->addFile(mUrl.toLocalFile()); 0042 } 0043 0044 void AbstractModelFileSystemSynchronizerPrivate::stopFileWatching() 0045 { 0046 if (!mDirWatch) { 0047 return; 0048 } 0049 0050 mDirWatch->removeFile(mUrl.toLocalFile()); 0051 } 0052 0053 void AbstractModelFileSystemSynchronizerPrivate::pauseFileWatching() 0054 { 0055 if (!mDirWatch) { 0056 return; 0057 } 0058 0059 mDirWatch->stopScan(); 0060 } 0061 0062 void AbstractModelFileSystemSynchronizerPrivate::unpauseFileWatching() 0063 { 0064 if (!mDirWatch) { 0065 return; 0066 } 0067 0068 mDirWatch->startScan(); 0069 } 0070 0071 void AbstractModelFileSystemSynchronizerPrivate::startNetworkWatching() 0072 { 0073 Q_Q(AbstractModelFileSystemSynchronizer); 0074 0075 // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager 0076 QT_WARNING_PUSH 0077 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") 0078 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") 0079 mNetworkConfigurationManager = new QNetworkConfigurationManager(); 0080 QObject::connect(mNetworkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, 0081 q, [&](bool online) { onOnlineStateChanged(online); }); 0082 QT_WARNING_POP 0083 } 0084 void AbstractModelFileSystemSynchronizerPrivate::stopNetworkWatching() 0085 { 0086 delete mNetworkConfigurationManager; 0087 mNetworkConfigurationManager = nullptr; 0088 } 0089 0090 void AbstractModelFileSystemSynchronizerPrivate::onFileDirty(const QString& fileName) 0091 { 0092 Q_UNUSED(fileName) 0093 qCDebug(LOG_KASTEN_CORE) << fileName; 0094 setRemoteState(RemoteHasChanges); 0095 } 0096 0097 void AbstractModelFileSystemSynchronizerPrivate::onFileCreated(const QString& fileName) 0098 { 0099 Q_UNUSED(fileName) 0100 qCDebug(LOG_KASTEN_CORE) << fileName; 0101 // TODO: could happen after a delete, what to do? 0102 setRemoteState(RemoteHasChanges); 0103 } 0104 0105 void AbstractModelFileSystemSynchronizerPrivate::onFileDeleted(const QString& fileName) 0106 { 0107 Q_UNUSED(fileName) 0108 qCDebug(LOG_KASTEN_CORE) << fileName; 0109 setRemoteState(RemoteDeleted); 0110 } 0111 0112 void AbstractModelFileSystemSynchronizerPrivate::onOnlineStateChanged(bool isOnline) 0113 { 0114 qCDebug(LOG_KASTEN_CORE); 0115 setRemoteState(isOnline ? RemoteUnknown : RemoteUnreachable); 0116 } 0117 0118 }