libqutim 0.2.80.1

event.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 EVENT_H
00027 #define EVENT_H
00028 
00029 #include "libqutim_global.h"
00030 #include <QtCore/QVariant>
00031 #include <QtCore/QVarLengthArray>
00032 #include <QtCore/QObject>
00033 #include <QtCore/QEvent>
00034 
00035 namespace qutim_sdk_0_3
00036 {
00037     class LIBQUTIM_EXPORT Event : public QEvent
00038     {
00039     public:
00040         inline Event(const char *id = 0, const QVariant &arg0 = QVariant(),
00041                      const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(),
00042                      const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant());
00043 
00044         inline Event(quint16 id, const QVariant &arg0 = QVariant(),
00045                      const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(),
00046                      const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant());
00047 
00048         static QEvent::Type eventType();
00049         static quint16 registerType(const char *id);
00050         static const char *getId(quint16 id);
00051         static QObject *eventManager();
00052 
00053         template<typename T>
00054         T at(int index) const { return args[index].value<T>(); }
00055         void send();
00056 
00057         quint16 id;
00058         QVarLengthArray<QVariant, 5> args;
00059     };
00060 
00061     Event::Event(const char *id, const QVariant &arg0, const QVariant &arg1, const QVariant &arg2,
00062           const QVariant &arg3, const QVariant &arg4) : QEvent(eventType()), args(5)
00063     {
00064         this->id = registerType(id);
00065         args[0] = arg0; args[1] = arg1; args[2] = arg2; args[3] = arg3; args[4] = arg4;
00066     }
00067 
00068     Event::Event(quint16 id, const QVariant &arg0, const QVariant &arg1, const QVariant &arg2,
00069           const QVariant &arg3, const QVariant &arg4) : QEvent(eventType()), args(5)
00070     {
00071         this->id = id;
00072         args[0] = arg0; args[1] = arg1; args[2] = arg2; args[3] = arg3; args[4] = arg4;
00073     }
00074 
00075     LIBQUTIM_EXPORT QDebug operator<<(QDebug, const Event &);
00076 }
00077 
00078 #endif // EVENT_H
00079