17 #include "boost/bind.hpp" 18 #include "boost/shared_ptr.hpp" 23 #include <QTextStream> 40 qRegisterMetaType<Message>(
"Message");
42 connect(&mWatcher, &QFileSystemWatcher::directoryChanged,
this, &LogFileWatcherThread::onDirectoryChanged);
43 connect(&mWatcher, &QFileSystemWatcher::fileChanged,
this, &LogFileWatcherThread::onFileChanged);
50 void LogFileWatcherThread::onDirectoryChanged(
const QString& path)
53 QStringList nameFilters;
54 nameFilters <<
"org.custusx.*";
55 QStringList current = info.entryList(nameFilters, QDir::Files);
56 current.removeAll(
"org.custusx.log.all.txt");
59 if (current==mInitializedFiles)
62 if (!mWatcher.files().isEmpty())
63 mWatcher.removePaths(mWatcher.files());
65 mInitializedFiles = current;
66 std::multimap<QDateTime, Message> messages;
67 for (
int i=0; i<mInitializedFiles.size(); ++i)
69 QString filename = info.absoluteFilePath(mInitializedFiles[i]);
70 mWatcher.addPath(filename);
71 std::vector<Message> msg = this->readMessages(filename);
72 for (
unsigned i=0; i<msg.size(); ++i)
73 messages.insert(std::make_pair(msg[i].mTimeStamp, msg[i]));
74 this->onFileChanged(filename);
77 for (std::multimap<QDateTime, Message>::iterator i=messages.begin(); i!=messages.end(); ++i)
81 void LogFileWatcherThread::onFileChanged(
const QString& path)
87 std::vector<Message> messages = this->readMessages(path);
88 for (
unsigned i=0; i<messages.size(); ++i)
92 std::vector<Message> LogFileWatcherThread::readMessages(
const QString& path)
94 if (!mFiles.count(path))
97 std::vector<Message> messages = mFiles[path].readMessages();
101 void LogFileWatcherThread::executeSetLoggingFolder(QString absoluteLoggingFolderPath)
103 if (mLogPath == absoluteLoggingFolderPath)
106 mLogPath = absoluteLoggingFolderPath;
108 mInitializedFiles.clear();
111 mWatcher.addPath(mLogPath);
113 if (!mWatcher.directories().isEmpty())
114 mWatcher.removePaths(mWatcher.directories());
115 if (!mWatcher.files().isEmpty())
116 mWatcher.removePaths(mWatcher.files());
117 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.