Krita Source Code Documentation
Loading...
Searching...
No Matches
FileSystemWatcherWrapper Class Reference
+ Inheritance diagram for FileSystemWatcherWrapper:

Classes

struct  FileEntry
 

Signals

void fileChanged (const QString &path)
 
void fileExistsStateChanged (const QString &path, bool exists)
 

Public Member Functions

bool addPath (const QString &file)
 
QStringList files () const
 
 FileSystemWatcherWrapper ()
 
bool removePath (const QString &file)
 

Static Public Member Functions

static QString unifyFilePath (const QString &path)
 

Private Types

enum  FileState { Exists = 0 , Reattaching , Lost }
 

Private Slots

void slotFileChanged (const QString &path)
 
void slotFindLostFiles ()
 
void slotReattachFiles ()
 

Private Attributes

QHash< QString, FileEntrym_fileEntries
 
KisSignalCompressor m_lostCompressor
 
QHash< QString, int > m_lostFilesAbsenceCounter
 
QHash< QString, int > m_pathCount
 
KisSignalCompressor m_reattachmentCompressor
 
QFileSystemWatcher m_watcher
 

Detailed Description

Definition at line 31 of file kis_safe_document_loader.cpp.

Member Enumeration Documentation

◆ FileState

Constructor & Destructor Documentation

◆ FileSystemWatcherWrapper()

FileSystemWatcherWrapper::FileSystemWatcherWrapper ( )
inline

Member Function Documentation

◆ addPath()

bool FileSystemWatcherWrapper::addPath ( const QString & file)
inline

Definition at line 60 of file kis_safe_document_loader.cpp.

60 {
61 bool result = true;
62 const QString ufile = unifyFilePath(file);
63
64 if (m_fileEntries.contains(ufile)) {
65 m_fileEntries[ufile].numConnections++;
66 } else {
67 m_fileEntries.insert(ufile, {1, {}, Exists});
68 result = m_watcher.addPath(ufile);
69 }
70
71 return result;
72 }
static QString unifyFilePath(const QString &path)
QHash< QString, FileEntry > m_fileEntries

References Exists, m_fileEntries, m_watcher, and unifyFilePath().

◆ fileChanged

void FileSystemWatcherWrapper::fileChanged ( const QString & path)
signal

◆ fileExistsStateChanged

void FileSystemWatcherWrapper::fileExistsStateChanged ( const QString & path,
bool exists )
signal

◆ files()

QStringList FileSystemWatcherWrapper::files ( ) const
inline

Definition at line 89 of file kis_safe_document_loader.cpp.

89 {
90 return m_watcher.files();
91 }

References m_watcher.

◆ removePath()

bool FileSystemWatcherWrapper::removePath ( const QString & file)
inline

Definition at line 74 of file kis_safe_document_loader.cpp.

74 {
75 bool result = true;
76 const QString ufile = unifyFilePath(file);
77
79
80 if (m_fileEntries[ufile].numConnections == 1) {
81 m_fileEntries.remove(ufile);
82 result = m_watcher.removePath(ufile);
83 } else {
84 m_fileEntries[ufile].numConnections--;
85 }
86 return result;
87 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_fileEntries, m_watcher, and unifyFilePath().

◆ slotFileChanged

void FileSystemWatcherWrapper::slotFileChanged ( const QString & path)
inlineprivateslot

Definition at line 94 of file kis_safe_document_loader.cpp.

94 {
95
97
98 FileEntry &entry = m_fileEntries[path];
99
100 // re-add the file after QSaveFile optimization
101 if (!m_watcher.files().contains(path)) {
102
103 if (QFileInfo(path).exists()) {
104 const FileState oldState = entry.state;
105
106 m_watcher.addPath(path);
107 entry.state = Exists;
108
109 if (oldState == Lost) {
110 Q_EMIT fileExistsStateChanged(path, true);
111 } else {
112 Q_EMIT fileChanged(path);
113 }
114
115 } else {
116
117 if (entry.state == Exists) {
118 entry.state = Reattaching;
119 entry.lostTimer.start();
121
122 } else if (entry.state == Reattaching) {
123 if (entry.lostTimer.elapsed() > 10000) {
124 entry.state = Lost;
126 Q_EMIT fileExistsStateChanged(path, false);
127 } else {
129 }
130
131 } else if (entry.state == Lost) {
133 }
134
135
136#if 0
137 const bool shouldSpitWarning =
138 absenceTimeMSec <= 600000 &&
139 ((absenceTimeMSec >= 60000 && (absenceTimeMSec % 60000 == 0)) ||
140 (absenceTimeMSec >= 10000 && (absenceTimeMSec % 10000 == 0)));
141
142 if (shouldSpitWarning) {
143 QString message;
144 QTextStream log(&message);
146
147 log << "WARNING: couldn't reconnect to a removed file layer's file (" << path << "). File is not available for " << absenceTimeMSec / 1000 << " seconds";
148
149 qWarning() << message;
150 KisUsageLogger::log(message);
151
152 if (absenceTimeMSec == 600000) {
153 message.clear();
154 log.reset();
155
156 log << "Giving up... :( No more reports about " << path;
157
158 qWarning() << message;
159 KisUsageLogger::log(message);
160 }
161 }
162#endif
163 }
164 } else {
165 Q_EMIT fileChanged(path);
166 }
167 }
void fileExistsStateChanged(const QString &path, bool exists)
static void log(const QString &message)
Logs with date/time.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
void setUtf8OnStream(QTextStream &stream)

References Exists, fileChanged(), fileExistsStateChanged(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisUsageLogger::log(), Lost, FileSystemWatcherWrapper::FileEntry::lostTimer, m_fileEntries, m_lostCompressor, m_reattachmentCompressor, m_watcher, Reattaching, KisPortingUtils::setUtf8OnStream(), KisSignalCompressor::start(), and FileSystemWatcherWrapper::FileEntry::state.

◆ slotFindLostFiles

void FileSystemWatcherWrapper::slotFindLostFiles ( )
inlineprivateslot

Definition at line 169 of file kis_safe_document_loader.cpp.

169 {
170 for (auto it = m_fileEntries.constBegin(); it != m_fileEntries.constEnd(); ++it) {
171 if (it.value().state == Lost)
172 slotFileChanged(it.key());
173 }
174 }

References Lost, m_fileEntries, and slotFileChanged().

◆ slotReattachFiles

void FileSystemWatcherWrapper::slotReattachFiles ( )
inlineprivateslot

Definition at line 176 of file kis_safe_document_loader.cpp.

176 {
177 for (auto it = m_fileEntries.constBegin(); it != m_fileEntries.constEnd(); ++it) {
178 if (it.value().state == Reattaching)
179 slotFileChanged(it.key());
180 }
181 }

References m_fileEntries, Reattaching, and slotFileChanged().

◆ unifyFilePath()

static QString FileSystemWatcherWrapper::unifyFilePath ( const QString & path)
inlinestatic

Definition at line 189 of file kis_safe_document_loader.cpp.

189 {
190 return QFileInfo(path).absoluteFilePath();
191 }

Member Data Documentation

◆ m_fileEntries

QHash<QString, FileEntry> FileSystemWatcherWrapper::m_fileEntries
private

Definition at line 199 of file kis_safe_document_loader.cpp.

◆ m_lostCompressor

KisSignalCompressor FileSystemWatcherWrapper::m_lostCompressor
private

Definition at line 197 of file kis_safe_document_loader.cpp.

◆ m_lostFilesAbsenceCounter

QHash<QString, int> FileSystemWatcherWrapper::m_lostFilesAbsenceCounter
private

Definition at line 198 of file kis_safe_document_loader.cpp.

◆ m_pathCount

QHash<QString, int> FileSystemWatcherWrapper::m_pathCount
private

Definition at line 195 of file kis_safe_document_loader.cpp.

◆ m_reattachmentCompressor

KisSignalCompressor FileSystemWatcherWrapper::m_reattachmentCompressor
private

Definition at line 196 of file kis_safe_document_loader.cpp.

◆ m_watcher

QFileSystemWatcher FileSystemWatcherWrapper::m_watcher
private

Definition at line 194 of file kis_safe_document_loader.cpp.


The documentation for this class was generated from the following file: