ACF $AcfVersion:0$
CTextFileLogComp.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QFile>
7#include <QtCore/QTextStream>
8#include <QtCore/QMutex>
9#include <QtCore/QTimer>
10
11// ACF includes
12#include <imod/IModel.h>
16
17
18namespace ifile
19{
20
21
28{
29 Q_OBJECT
30public:
32
33 I_BEGIN_COMPONENT(CTextFileLogComp);
34 I_ASSIGN(m_fileNameCompPtr, "LogFile", "Name of the log file", true, "LogFile");
35 I_ASSIGN_TO(m_fileNameModelCompPtr, m_fileNameCompPtr, true);
36 I_ASSIGN(m_isAppendAttrPtr, "AppendToExisting", "Don't overwrite existing log file", true, false);
37 I_END_COMPONENT;
38
40
41protected:
42 // reimplemented (CStreamLogCompBase)
43 virtual void WriteText(const QString& text, istd::IInformationProvider::InformationCategory category) override;
44
45 // reimplemented (icomp::CComponentBase)
46 virtual void OnComponentCreated() override;
47 virtual void OnComponentDestroyed() override;
48
49private:
50 bool OpenFileStream();
51 void CloseFileStream();
52
53private Q_SLOTS:
54 void OnTryTimer();
55
56private:
57 I_REF(ifile::IFileNameParam, m_fileNameCompPtr);
58 I_REF(imod::IModel, m_fileNameModelCompPtr);
59 I_ATTR(bool, m_isAppendAttrPtr);
60
61 QFile m_outputFile;
62 QTextStream m_outputFileStream;
63 QTimer m_tryTimer;
64
65 class FilePathObserver: public imod::CSingleModelObserverBase
66 {
67 public:
69
70 explicit FilePathObserver(CTextFileLogComp& parent);
71
72 protected:
73 // reimplemented (imod::CSingleModelObserverBase)
74 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
75
76 private:
77 CTextFileLogComp& m_parent;
78 };
79
80 FilePathObserver m_filePathObserver;
81
82 int m_lastDay;
83#if QT_VERSION >= 0x060000
84 mutable QRecursiveMutex m_mutex;
85#else
86 mutable QMutex m_mutex;
87#endif
88};
89
90
91} // namespace ifile
92
93
Message container displaying messages as log list.
virtual void OnComponentDestroyed() override
virtual void OnComponentCreated() override
virtual void WriteText(const QString &text, istd::IInformationProvider::InformationCategory category) override
Write a text line to the output stream.
ilog::CStreamLogCompBase BaseClass
Common interface for any file system item name (e.g directory, file or URL path)
Base class for stream-based logging components.
Basic implementation for a single model observer.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Set of change flags (its IDs).
Definition IChangeable.h:36
InformationCategory
Category of information.
Contains interfaces and implementations of file system related components.