38 #include "boost/bind.hpp" 39 #include "boost/shared_ptr.hpp" 44 #include <QTextStream> 61 qRegisterMetaType<Message>(
"Message");
63 connect(&mWatcher, &QFileSystemWatcher::directoryChanged,
this, &LogFileWatcherThread::onDirectoryChanged);
64 connect(&mWatcher, &QFileSystemWatcher::fileChanged,
this, &LogFileWatcherThread::onFileChanged);
71 void LogFileWatcherThread::onDirectoryChanged(
const QString& path)
74 QStringList nameFilters;
75 nameFilters <<
"org.custusx.*";
76 QStringList current = info.entryList(nameFilters, QDir::Files);
77 current.removeAll(
"org.custusx.log.all.txt");
80 if (current==mInitializedFiles)
83 if (!mWatcher.files().isEmpty())
84 mWatcher.removePaths(mWatcher.files());
86 mInitializedFiles = current;
87 std::multimap<QDateTime, Message> messages;
88 for (
int i=0; i<mInitializedFiles.size(); ++i)
90 QString filename = info.absoluteFilePath(mInitializedFiles[i]);
91 mWatcher.addPath(filename);
92 std::vector<Message> msg = this->readMessages(filename);
93 for (
unsigned i=0; i<msg.size(); ++i)
94 messages.insert(std::make_pair(msg[i].mTimeStamp, msg[i]));
95 this->onFileChanged(filename);
98 for (std::multimap<QDateTime, Message>::iterator i=messages.begin(); i!=messages.end(); ++i)
102 void LogFileWatcherThread::onFileChanged(
const QString& path)
108 std::vector<Message> messages = this->readMessages(path);
109 for (
unsigned i=0; i<messages.size(); ++i)
113 std::vector<Message> LogFileWatcherThread::readMessages(
const QString& path)
115 if (!mFiles.count(path))
118 std::vector<Message> messages = mFiles[path].readMessages();
122 void LogFileWatcherThread::executeSetLoggingFolder(QString absoluteLoggingFolderPath)
124 if (mLogPath == absoluteLoggingFolderPath)
127 mLogPath = absoluteLoggingFolderPath;
129 mInitializedFiles.clear();
132 mWatcher.addPath(mLogPath);
134 if (!mWatcher.directories().isEmpty())
135 mWatcher.removePaths(mWatcher.directories());
136 if (!mWatcher.files().isEmpty())
137 mWatcher.removePaths(mWatcher.files());
138 this->onDirectoryChanged(mLogPath);
LogFileWatcherThread(QObject *parent=NULL)
MessageRepositoryPtr mRepository
static LogFile fromFilename(QString filename)
void processMessage(Message msg)
virtual ~LogFileWatcherThread()
Namespace for all CustusX production code.