QXmpp Version:0.3.0
|
00001 /* 00002 * Copyright (C) 2008-2011 The QXmpp developers 00003 * 00004 * Author: 00005 * Manjeet Dahiya 00006 * 00007 * Source: 00008 * http://code.google.com/p/qxmpp 00009 * 00010 * This file is a part of QXmpp library. 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2.1 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 */ 00023 00024 00025 #ifndef QXMPPLOGGER_H 00026 #define QXMPPLOGGER_H 00027 00028 #include <QObject> 00029 00030 #ifdef QXMPP_LOGGABLE_TRACE 00031 #define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x) 00032 #else 00033 #define qxmpp_loggable_trace(x) (x) 00034 #endif 00035 00039 00040 class QXmppLogger : public QObject 00041 { 00042 Q_OBJECT 00043 Q_ENUMS(LoggingType) 00044 Q_FLAGS(MessageType MessageTypes) 00045 Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath) 00046 Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType) 00047 Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes) 00048 00049 public: 00051 enum LoggingType 00052 { 00053 NoLogging = 0, 00054 FileLogging = 1, 00055 StdoutLogging = 2, 00056 SignalLogging = 4, 00057 }; 00058 00060 enum MessageType 00061 { 00062 NoMessage = 0, 00063 DebugMessage = 1, 00064 InformationMessage = 2, 00065 WarningMessage = 4, 00066 ReceivedMessage = 8, 00067 SentMessage = 16, 00068 AnyMessage = 31, 00069 }; 00070 Q_DECLARE_FLAGS(MessageTypes, MessageType) 00071 00072 QXmppLogger(QObject *parent = 0); 00073 static QXmppLogger* getLogger(); 00074 00075 QXmppLogger::LoggingType loggingType(); 00076 void setLoggingType(QXmppLogger::LoggingType type); 00077 00078 QString logFilePath(); 00079 void setLogFilePath(const QString &path); 00080 00081 QXmppLogger::MessageTypes messageTypes(); 00082 void setMessageTypes(QXmppLogger::MessageTypes types); 00083 00084 public slots: 00085 void log(QXmppLogger::MessageType type, const QString& text); 00086 00087 signals: 00089 void message(QXmppLogger::MessageType type, const QString &text); 00090 00091 private: 00092 static QXmppLogger* m_logger; 00093 QXmppLogger::LoggingType m_loggingType; 00094 QString m_logFilePath; 00095 QXmppLogger::MessageTypes m_messageTypes; 00096 }; 00097 00101 00102 class QXmppLoggable : public QObject 00103 { 00104 Q_OBJECT 00105 00106 public: 00107 QXmppLoggable(QObject *parent = 0); 00108 00109 protected: 00111 virtual void childEvent(QChildEvent *event); 00113 00117 00118 void debug(const QString &message) 00119 { 00120 emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message)); 00121 } 00122 00126 00127 void info(const QString &message) 00128 { 00129 emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message)); 00130 } 00131 00135 00136 void warning(const QString &message) 00137 { 00138 emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message)); 00139 } 00140 00144 00145 void logReceived(const QString &message) 00146 { 00147 emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message)); 00148 } 00149 00153 00154 void logSent(const QString &message) 00155 { 00156 emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message)); 00157 } 00158 00159 signals: 00161 void logMessage(QXmppLogger::MessageType type, const QString &msg); 00162 }; 00163 00164 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes) 00165 #endif // QXMPPLOGGER_H