File indexing completed on 2024-05-12 05:39:45
0001 /************************************************************************* 0002 * Copyright (C) 2014 by Renaud Guezennec * 0003 * * 0004 * https://rolisteam.org/ * 0005 * * 0006 * Rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published * 0008 * by the Free Software Foundation; either version 2 of the License, * 0009 * or (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 *************************************************************************/ 0021 #ifndef LOGCONTROLLER_H 0022 #define LOGCONTROLLER_H 0023 0024 #include <QFile> 0025 #include <QMutex> 0026 #include <QObject> 0027 #include <QTextStream> 0028 #include <memory> 0029 0030 #include <common/common_global.h> 0031 0032 namespace helper 0033 { 0034 namespace log 0035 { 0036 COMMON_EXPORT QString humanReadableDiceResult(const QString& json); 0037 } 0038 } // namespace helper 0039 /** 0040 * @brief The LogController class receives log messeges and displays them in the right sink. 0041 */ 0042 class COMMON_EXPORT LogController : public QObject 0043 { 0044 Q_OBJECT 0045 Q_PROPERTY(LogController::LogLevel logLevel READ logLevel WRITE setLogLevel NOTIFY logLevelChanged) 0046 Q_PROPERTY(QString currentPath READ currentPath WRITE setCurrentPath NOTIFY currentPathChanged) 0047 public: 0048 enum LogLevel 0049 { 0050 Features= -1, 0051 Error= 0, 0052 Warning, 0053 Info, 0054 Debug, 0055 Hidden, 0056 Search, 0057 }; 0058 Q_ENUM(LogLevel) 0059 0060 enum StorageMode 0061 { 0062 Console= 1, 0063 File= 2, 0064 Gui= 4, 0065 Network= 8 0066 }; 0067 Q_ENUM(StorageMode) 0068 Q_DECLARE_FLAGS(StorageModes, StorageMode) 0069 Q_FLAGS(StorageModes) 0070 0071 explicit LogController(bool attachMessage, QObject* parent= nullptr); 0072 ~LogController(); 0073 0074 LogController::StorageModes currentModes() const; 0075 LogController::LogLevel logLevel() const; 0076 0077 bool signalInspection() const; 0078 QString currentPath() const; 0079 void setSignalInspection(bool signalInspection); 0080 void setListenOutSide(bool); 0081 0082 void setMessageHandler(bool attachMessage); 0083 static QString typeToText(LogController::LogLevel type); 0084 0085 void setCurrentPath(const QString& path); 0086 0087 signals: 0088 void showMessage(QString, LogController::LogLevel); 0089 void sendOffMessage(QString, QString, QString category, QString timestamps); 0090 void logLevelChanged(); 0091 void currentPathChanged(); 0092 0093 public slots: 0094 void manageMessage(QString message, const QString &category, LogController::LogLevel type); 0095 void listenObjects(const QObject* widget); 0096 void signalActivated(); 0097 void actionActivated(); 0098 void setLogLevel(const LogController::LogLevel& logLevel); 0099 void setCurrentModes(const LogController::StorageModes& currentModes); 0100 void logToFile(const QString& msg, const LogController::LogLevel& type, const QString& log); 0101 0102 private: 0103 LogLevel m_logLevel= Error; 0104 StorageModes m_currentModes= Console; 0105 bool m_signalInspection= false; 0106 bool m_listenOutSide= false; 0107 QString m_currentFile; 0108 bool m_streamUp= false; 0109 }; 0110 Q_DECLARE_OPERATORS_FOR_FLAGS(LogController::StorageModes) 0111 #endif // LOGCONTROLLER_H