17 #include "boost/bind.hpp" 18 #include "boost/shared_ptr.hpp" 23 #include <QTextStream> 38 qRegisterMetaType<Message>(
"Message");
40 connect(&mWatcher, &QFileSystemWatcher::directoryChanged,
this, &LogFileWatcherThread::onDirectoryChanged);
41 connect(&mWatcher, &QFileSystemWatcher::fileChanged,
this, &LogFileWatcherThread::onFileChanged);
48 void LogFileWatcherThread::onDirectoryChanged(
const QString& path)
51 QStringList nameFilters;
52 nameFilters <<
"org.custusx.*";
53 QStringList current = info.entryList(nameFilters, QDir::Files);
54 current.removeAll(
"org.custusx.log.all.txt");
57 if (current==mInitializedFiles)
60 if (!mWatcher.files().isEmpty())
61 mWatcher.removePaths(mWatcher.files());
63 mInitializedFiles = current;
64 std::multimap<QDateTime, Message> messages;
65 for (
int i=0; i<mInitializedFiles.size(); ++i)
67 QString filename = info.absoluteFilePath(mInitializedFiles[i]);
68 mWatcher.addPath(filename);
69 std::vector<Message> msg = this->readMessages(filename);
70 for (
unsigned i=0; i<msg.size(); ++i)
71 messages.insert(std::make_pair(msg[i].mTimeStamp, msg[i]));
72 this->onFileChanged(filename);
75 for (std::multimap<QDateTime, Message>::iterator i=messages.begin(); i!=messages.end(); ++i)
79 void LogFileWatcherThread::onFileChanged(
const QString& path)
85 std::vector<Message> messages = this->readMessages(path);
86 for (
unsigned i=0; i<messages.size(); ++i)
90 std::vector<Message> LogFileWatcherThread::readMessages(
const QString& path)
92 if (!mFiles.count(path))
95 std::vector<Message> messages = mFiles[path].readMessages();
99 void LogFileWatcherThread::executeSetLoggingFolder(QString absoluteLoggingFolderPath)
101 if (mLogPath == absoluteLoggingFolderPath)
104 mLogPath = absoluteLoggingFolderPath;
106 mInitializedFiles.clear();
109 mWatcher.addPath(mLogPath);
111 if (!mWatcher.directories().isEmpty())
112 mWatcher.removePaths(mWatcher.directories());
113 if (!mWatcher.files().isEmpty())
114 mWatcher.removePaths(mWatcher.files());
115 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.