libqutim  0.3.2.0
chatunit.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 CHATUNIT_H
00027 #define CHATUNIT_H
00028 
00029 #include "menucontroller.h"
00030 #include <QMetaType>
00031 #include <QEvent>
00032 #include <QDateTime>
00033 
00034 namespace qutim_sdk_0_3
00035 {
00036 
00037 class MetaContact;
00038 class Account;
00039 class Message;
00040 class ChatUnit;
00041 class ChatUnitPrivate;
00042 class Contact;
00043 typedef QList<ChatUnit *> ChatUnitList;
00044 
00045 enum ChatState
00046 {
00047     ChatStateActive = 0,    // User is actively participating in the chat session.
00048     ChatStateInActive,      // User has not been actively participating in the chat session.
00049     ChatStateGone,          // User has effectively ended their participation in the chat session.
00050     ChatStateComposing,     // User is composing a message.
00051     ChatStatePaused         // User had been composing but now has stopped.
00052 };
00053 
00057 class LIBQUTIM_EXPORT ChatUnit : public MenuController
00058 {
00059     Q_DECLARE_PRIVATE(ChatUnit)
00060     Q_OBJECT
00061     Q_PROPERTY(QString id READ id CONSTANT)
00062     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
00063     Q_PROPERTY(ChatState chatState READ chatState WRITE setChatState NOTIFY chatStateChanged)
00064     Q_PROPERTY(QDateTime lastActivity READ lastActivity NOTIFY lastActivityChanged)
00065     Q_PROPERTY(qutim_sdk_0_3::Account* account READ account CONSTANT)
00066     Q_PROPERTY(bool conference READ isConference CONSTANT)
00067 public:
00073     ChatUnit(Account *account);
00083     ChatUnit(ChatUnitPrivate &d, Account *account);
00087     virtual ~ChatUnit();
00093     virtual QString id() const = 0;
00099     virtual QString title() const;
00105     Account *account();
00111     const Account *account() const;
00112     bool isConference() const;
00118     virtual bool sendMessage(const qutim_sdk_0_3::Message &message) = 0;
00119 
00120     Q_INVOKABLE bool send(const qutim_sdk_0_3::Message &message);
00126     Q_INVOKABLE virtual QList<qutim_sdk_0_3::ChatUnit*> lowerUnits();
00132     Q_INVOKABLE virtual qutim_sdk_0_3::ChatUnit *upperUnit();
00138     ChatUnit *buddy();
00139     const ChatUnit *buddy() const;
00145     ChatUnit *metaContact();
00146     const ChatUnit *metaContact() const;
00147     virtual const ChatUnit *getHistoryUnit() const;
00148     QDateTime lastActivity() const;
00149     void setLastActivity(const QDateTime &time = QDateTime::currentDateTime());
00155     void setChatState(qutim_sdk_0_3::ChatState state);
00156     qutim_sdk_0_3::ChatState chatState() const;
00157 public slots:
00158     quint64 sendMessage(const QString &text);
00159 signals:
00164     void titleChanged(const QString &current, const QString &previous);
00168     void lowerUnitAdded(ChatUnit *unit);
00169     void chatStateChanged(qutim_sdk_0_3::ChatState current,qutim_sdk_0_3::ChatState previous);
00170     void lastActivityChanged(const QDateTime &current, const QDateTime &previous);
00171 };
00172 
00176 class LIBQUTIM_EXPORT ChatStateEvent : public QEvent
00177 {
00178 public:
00184     ChatStateEvent(ChatState state);
00190     inline ChatState chatState() const { return m_state; }
00196     static QEvent::Type eventType();
00197 protected:
00198     ChatState m_state;
00199 };
00200 }
00201 
00202 Q_DECLARE_METATYPE(qutim_sdk_0_3::ChatUnit*)
00203 Q_DECLARE_METATYPE(QList<qutim_sdk_0_3::ChatUnit*>)
00204 Q_ENUMS(qutim_sdk_0_3::ChatState)
00205 
00206 #endif // CHATUNIT_H
00207