libqutim  0.3.2.0
message.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** qutIM - instant messenger
00004 **
00005 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
00006 **
00007 *****************************************************************************
00008 **
00009 ** $QUTIM_BEGIN_LICENSE$
00010 ** This program is free software: you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation, either version 3 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 ** See the GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program.  If not, see http://www.gnu.org/licenses/.
00022 ** $QUTIM_END_LICENSE$
00023 **
00024 ****************************************************************************/
00025 
00026 #ifndef LIBQUTIM_MESSAGE_H
00027 #define LIBQUTIM_MESSAGE_H
00028 
00029 #include "libqutim_global.h"
00030 #include <QSharedData>
00031 #include <QVariant>
00032 #include <QEvent>
00033 
00034 class QScriptEngine;
00035 
00036 namespace qutim_sdk_0_3
00037 {
00038 class ChatUnit;
00039 class MessagePrivate;
00040 
00041 class LIBQUTIM_EXPORT Message
00042 {
00043 public:
00044     Message();
00045     Message(const QString &text);
00046     Message(const Message &other);
00047     virtual ~Message();
00048     Message &operator =(const Message &other);
00049     static void scriptRegister(QScriptEngine *engine);
00050     const QString &text() const;
00051     void setText(const QString &text);
00052     QString html() const;
00053     void setHtml(const QString &html);
00054     const QDateTime &time() const;
00055     void setTime(const QDateTime &time);
00056     void setIncoming(bool input);
00057     bool isIncoming() const;
00058     void setChatUnit (ChatUnit *chatUnit);
00059     ChatUnit *chatUnit() const;
00060     QString unitName() const;
00061     QString unitId() const;
00062     QString unitAvatar() const;
00063     quint64 id() const;
00064     QVariant property(const char *name, const QVariant &def = QVariant()) const;
00065     template<typename T>
00066     T property(const char *name, const T &def) const;
00067     void setProperty(const char *name, const QVariant &value);
00068     QList<QByteArray> dynamicPropertyNames() const;
00069 private:
00070     QSharedDataPointer<MessagePrivate> p;
00071 };
00072 
00073 template<typename T>
00074 T Message::property(const char *name, const T &def) const
00075 {
00076     QVariant var = property(name, QVariant::fromValue<T>(def));
00077     return var.value<T>();
00078 }
00079 
00080 
00081 class LIBQUTIM_EXPORT MessageReceiptEvent : public QEvent
00082 {
00083 public:
00084     MessageReceiptEvent(quint64 id, bool success);
00085     inline quint64 id() const { return i; }
00086     inline bool success() const { return s; }
00087     static QEvent::Type eventType();
00088 protected:
00089     quint64 i;
00090     bool s;
00091 };
00092 
00093 LIBQUTIM_EXPORT QString unescape(const QString &html);
00094 
00095 typedef QList<Message> MessageList;
00096 }
00097 
00098 LIBQUTIM_EXPORT QDebug operator<<(QDebug dbg, const qutim_sdk_0_3::Message &msg);
00099 
00100 
00101 Q_DECLARE_METATYPE(qutim_sdk_0_3::Message)
00102 Q_DECLARE_METATYPE(qutim_sdk_0_3::Message*)
00103 Q_DECLARE_METATYPE(qutim_sdk_0_3::MessageList)
00104 
00105 #endif // LIBQUTIM_MESSAGE_H
00106