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 30 of file kis_safe_document_loader.cpp.

Member Enumeration Documentation

◆ FileState

Constructor & Destructor Documentation

◆ FileSystemWatcherWrapper()

FileSystemWatcherWrapper::FileSystemWatcherWrapper ( )
inline

Definition at line 49 of file kis_safe_document_loader.cpp.

52
53 {
54 connect(&m_watcher, SIGNAL(fileChanged(QString)), SLOT(slotFileChanged(QString)));
55 connect(&m_reattachmentCompressor, SIGNAL(timeout()), SLOT(slotReattachFiles()));
56 connect(&m_lostCompressor, SIGNAL(timeout()), SLOT(slotFindLostFiles()));
57 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisSignalCompressor m_reattachmentCompressor
void slotFileChanged(const QString &path)
void fileChanged(const QString &path)

References connect(), fileChanged(), m_lostCompressor, m_reattachmentCompressor, m_watcher, slotFileChanged(), slotFindLostFiles(), and slotReattachFiles().

Member Function Documentation

◆ addPath()

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

Definition at line 59 of file kis_safe_document_loader.cpp.

59 {
60 bool result = true;
61 const QString ufile = unifyFilePath(file);
62
63 if (m_fileEntries.contains(ufile)) {
64 m_fileEntries[ufile].numConnections++;
65 } else {
66 m_fileEntries.insert(ufile, {1, {}, Exists});
67 result = m_watcher.addPath(ufile);
68 }
69
70 return result;
71 }
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 88 of file kis_safe_document_loader.cpp.

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

References m_watcher.

◆ removePath()

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

Definition at line 73 of file kis_safe_document_loader.cpp.

73 {
74 bool result = true;
75 const QString ufile = unifyFilePath(file);
76
78
79 if (m_fileEntries[ufile].numConnections == 1) {
80 m_fileEntries.remove(ufile);
81 result = m_watcher.removePath(ufile);
82 } else {
83 m_fileEntries[ufile].numConnections--;
84 }
85 return result;
86 }
#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 93 of file kis_safe_document_loader.cpp.

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

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

References Lost, m_fileEntries, and slotFileChanged().

◆ slotReattachFiles

void FileSystemWatcherWrapper::slotReattachFiles ( )
inlineprivateslot

Definition at line 175 of file kis_safe_document_loader.cpp.

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

References m_fileEntries, Reattaching, and slotFileChanged().

◆ unifyFilePath()

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

Definition at line 188 of file kis_safe_document_loader.cpp.

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

Member Data Documentation

◆ m_fileEntries

QHash<QString, FileEntry> FileSystemWatcherWrapper::m_fileEntries
private

Definition at line 198 of file kis_safe_document_loader.cpp.

◆ m_lostCompressor

KisSignalCompressor FileSystemWatcherWrapper::m_lostCompressor
private

Definition at line 196 of file kis_safe_document_loader.cpp.

◆ m_lostFilesAbsenceCounter

QHash<QString, int> FileSystemWatcherWrapper::m_lostFilesAbsenceCounter
private

Definition at line 197 of file kis_safe_document_loader.cpp.

◆ m_pathCount

QHash<QString, int> FileSystemWatcherWrapper::m_pathCount
private

Definition at line 194 of file kis_safe_document_loader.cpp.

◆ m_reattachmentCompressor

KisSignalCompressor FileSystemWatcherWrapper::m_reattachmentCompressor
private

Definition at line 195 of file kis_safe_document_loader.cpp.

◆ m_watcher

QFileSystemWatcher FileSystemWatcherWrapper::m_watcher
private

Definition at line 193 of file kis_safe_document_loader.cpp.


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