libqutim  0.3.1.0
chatsession.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 
26 #ifndef LIBQUTIM_CHATSESSION_H
27 #define LIBQUTIM_CHATSESSION_H
28 
29 #include "message.h"
30 #include "contact.h"
31 #include <QDateTime>
32 
33 class QTextDocument;
34 namespace qutim_sdk_0_3
35 {
36 
37 class Account;
38 class ChatLayer;
39 class ChatSessionPrivate;
40 class ChatLayerPrivate;
41 
42 class LIBQUTIM_EXPORT ChatSession : public QObject
43 {
44  Q_OBJECT
45  Q_DECLARE_PRIVATE(ChatSession)
46  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activated)
47  Q_PROPERTY(qutim_sdk_0_3::MessageList unread READ unread NOTIFY unreadChanged)
48  Q_PROPERTY(QDateTime dateOpened READ dateOpened WRITE setDateOpened NOTIFY dateOpenedChanged)
49 public:
50  virtual ~ChatSession();
51 
52  virtual ChatUnit *getUnit() const = 0;
53  Q_INVOKABLE inline qutim_sdk_0_3::ChatUnit *unit() const { return getUnit(); }
54  Q_INVOKABLE virtual void setChatUnit(qutim_sdk_0_3::ChatUnit* unit) = 0;
55  Q_INVOKABLE qint64 append(qutim_sdk_0_3::Message &message);
56  virtual QTextDocument *getInputField() = 0;
57  virtual void markRead(quint64 id) = 0;
58  virtual MessageList unread() const = 0;
59  bool isActive();
60  QDateTime dateOpened() const;
61  void setDateOpened(const QDateTime &date);
62 public slots:
63  virtual void addContact(qutim_sdk_0_3::Buddy *c) = 0;
64  virtual void removeContact(qutim_sdk_0_3::Buddy *c) = 0;
65  qint64 appendMessage(qutim_sdk_0_3::Message &message);
66  void setActive(bool active);
67  inline void activate() { setActive(true); }
68  inline qint64 appendMessage(const QString &text)
69  { Message msg(text); return appendMessage(msg); }
70 protected:
71  virtual void doSetActive(bool active) = 0;
72  virtual qint64 doAppendMessage(qutim_sdk_0_3::Message &message) = 0;
73 signals:
74  void dateOpenedChanged(const QDateTime &date);
75  void messageReceived(qutim_sdk_0_3::Message *message);
76  void messageSent(qutim_sdk_0_3::Message *message);
77  void contactAdded(qutim_sdk_0_3::Buddy *c);
78  void contactRemoved(qutim_sdk_0_3::Buddy *c);
79  void activated(bool active);
80  void unreadChanged(const qutim_sdk_0_3::MessageList &);
81 protected:
82  ChatSession(ChatLayer *chat);
83  virtual void virtual_hook(int id, void *data);
84  friend class MessageHandlerHook;
85 private:
86  QScopedPointer<ChatSessionPrivate> d_ptr;
87 };
88 
89 class LIBQUTIM_EXPORT ChatLayer : public QObject
90 {
91  Q_OBJECT
92  Q_DECLARE_PRIVATE(ChatLayer)
93  Q_CLASSINFO("Service", "ChatLayer")
94  Q_PROPERTY(bool alertStatus READ isAlerted WRITE alert NOTIFY alertStatusChanged)
95 public:
96  static ChatLayer *instance();
97 
98  ChatSession *getSession(Account *acc, QObject *obj, bool create = true);
99  ChatSession *getSession(QObject *obj, bool create = true);
100  ChatSession *getSession(Account *acc, const QString &id, bool create = true);
101  virtual ChatSession *getSession(ChatUnit *unit, bool create = true) = 0;
102  Q_INVOKABLE inline qutim_sdk_0_3::ChatSession *session(QObject *obj, bool create = true);
103  static ChatSession *get(ChatUnit *unit, bool create = true);
104  Q_INVOKABLE virtual QList<qutim_sdk_0_3::ChatSession*> sessions() = 0;
105  bool isAlerted() const;
106  void alert(bool on);
107  void alert(int msecs);
108  bool event(QEvent *);
109 
110 signals:
111  void sessionCreated(qutim_sdk_0_3::ChatSession *session);
112  void alertStatusChanged(bool);
113 protected:
114  ChatUnit *getUnitForSession(ChatUnit *unit) const;
115  ChatLayer();
116  virtual ~ChatLayer();
117  virtual void virtual_hook(int id, void *data);
118  QScopedPointer<ChatLayerPrivate> d_ptr;
119 };
120 
121 ChatSession *ChatLayer::session(QObject *obj, bool create)
122 {
123  return getSession(obj, create);
124 }
125 
126 }
127 
129 Q_DECLARE_METATYPE(QList<qutim_sdk_0_3::ChatSession*>)
130 
131 #endif // LIBQUTIM_CHATSESSION_H
132 

Generated by Doxygen