try resend message when channel is closed (max ten attempts)
[makneto-zunavac1.git] / src / backend / session.h
blob74840af841dd18f036412980e998cf3a9616566d
1 /*
2 <one line to give the library's name and an idea of what it does.>
3 Copyright (C) 2011 Vojta Kulicka <vojtechkulicka@gmail.com>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef MAKNETOLIB_SESSION_H
22 #define MAKNETOLIB_SESSION_H
24 #include <QtCore/QObject>
25 #include <QList>
26 #include <QFile>
28 #include <TelepathyQt4/Contact>
29 #include <TelepathyQt4/Constants>
30 #include <TelepathyQt4/Types>
31 #include <TelepathyQt4/FileTransferChannel>
32 #include <TelepathyQt4/PendingChannelRequest>
34 #include "voip/callparticipant.h"
35 #include "makneto-backend.h"
37 class QString;
38 class QStringList;
40 namespace Tp {
42 class PendingOperation;
43 class Message;
44 class ReceivedMessage;
45 class Contact;
48 namespace MaknetoBackend {
50 class CallChannelHandler;
52 class MAKNETO_EXPORT Session : public QObject {
54 Q_OBJECT
55 Q_ENUMS(SessionType FileTransferState ChatState)
56 Q_PROPERTY(SesstionTypes sessionType READ getSessionType NOTIFY sessionTypeChanged)
58 public:
59 enum SessionType {
60 SessionTypeNone = 0x0, // 00000
61 SessionTypeText = 0x1, // 00001
62 SessionTypeMuc = 0x2, // 00010
63 SessionTypeAudio = 0x4, // 00100
64 SessionTypeVideo = 0x8, // 01000
65 SessionTypeCallPending = 0x10 // 10000
68 Q_DECLARE_FLAGS(SesstionTypes, SessionType)
70 enum FileTransferState {
71 fileTransferAccepted,
72 fileTransferCancelled,
73 fileTransferCompleted,
74 fileTransferOpen
77 enum ChatState {
78 ChatStateComposing = Tp::ChannelChatStateComposing,
79 ChatStateActive = Tp::ChannelChatStateActive,
80 ChatStateInactive = Tp::ChannelChatStateInactive,
81 ChatStateGone = Tp::ChannelChatStateGone,
82 ChatStatePaused = Tp::ChannelChatStatePaused
86 Session(const Tp::ChannelPtr &, SesstionTypes, QObject *parent = 0);
87 Session(const Tp::AccountPtr &, const Tp::ContactPtr &, SesstionTypes, QObject *parent = 0);
88 virtual ~Session();
90 QString getName();
91 QString getUniqueName();
92 QString getMyId();
93 QString getMyNick();
94 QString getIcon();
95 SesstionTypes getSessionType();
96 bool isMUC();
98 void startTextChat();
99 void startMediaCall(bool);
100 void startTextChatroom(const QString &);
101 void startFileTransfer(const QString &);
103 static QString sessionNameForChannel(const Tp::AccountPtr &, const Tp::ChannelPtr &);
104 static QString sessionNameForMuc(const Tp::AccountPtr &, const QString &);
105 static QString sessionName(const Tp::AccountPtr &, const Tp::ContactPtr &);
107 public
108 Q_SLOTS:
109 void onAddCapability(SessionType chatType);
110 //Text messaging
111 void onTextChannelReady(Tp::TextChannelPtr &textChannel, bool);
112 void onMessageReceived(const Tp::ReceivedMessage &);
113 void sendMessage(const QString &text);
114 void onMessageSent(Tp::PendingOperation *);
115 void onChatStateChanged(Tp::ContactPtr, Tp::ChannelChatState);
116 void changeChatState(MaknetoBackend::Session::ChatState);
118 //VoIP
119 void onIncomingCallChannel(Tp::StreamedMediaChannelPtr &mediaChannel, SessionType mediaType);
120 void acceptCall();
121 void rejectCall();
122 void onCallEnded(const QString &);
123 void onHangup();
124 void onCallError(const QString &);
125 void callChannelRequestFinished(Tp::PendingOperation*);
126 void onCallParticipantLeft(CallParticipant *participant);
127 void onCallParticipantJoined(CallParticipant *participant);
128 void onVideoStreamAdded(CallParticipant *participant);
129 void onVideoStreamRemoved(CallParticipant *participant);
130 void onAudioStreamAdded(CallParticipant *participant);
132 //File transfer
133 void onFileTransfer(Tp::FileTransferChannelPtr &fileTransferChannel);
134 void onAcceptFileTransfer(bool accept, QString filename = QString());
135 void onFileTransferStateChanged(Tp::FileTransferState, Tp::FileTransferStateChangeReason);
136 void onFileTransferTransferredBytesChanged(qulonglong);
139 Q_SIGNALS:
140 //text messaging
141 void messageReceived(const QString &, const QString &);
142 void messageSent(const QString &message); // outgoing message was successfully send
143 void sendingError(const QString &message, const QString &errorMessage); // outgoing message sending failed
144 void chatStateChanged(MaknetoBackend::Session::ChatState, const QString &);
145 void sessionTypeChanged();
147 //VoIP
148 void incomingCall();
149 void callReady();
150 void callEnded(const QString &);
151 void callError(const QString &);
152 void videoPreviewAvailable(QGst::ElementPtr videoOutElemPtr);
153 void videoAvailable(QGst::ElementPtr videoOutElemPtr);
154 void videoPreviewRemoved(QGst::ElementPtr videoOutElemPtr);
155 void videoRemoved(QGst::ElementPtr videoOutElemPtr);
156 void remoteAudioStreamAdded(); // signaling that application should stop beeping
158 //file transfer
159 void incomingFileTransfer(const QString &filename);
160 void fileTransferCreated();
161 void fileTransferStateChanged(FileTransferState);
162 void fileTransferAlreadyInProgress();
163 void fileTransferTransferredBytesChanged(qulonglong);
165 private:
166 Tp::TextChannelPtr m_textChannel;
167 Tp::StreamedMediaChannelPtr m_mediaChannel;
168 Tp::FileTransferChannelPtr m_fileTransferChannel;
170 Tp::AccountPtr m_account;
171 Tp::ContactPtr m_myContact;
172 Tp::ContactPtr m_contact;
173 QSet<Tp::ContactPtr> *m_contacts;
175 QFile m_fileTransferFile;
176 QString m_sessionName;
177 QString m_uniqueSessionName;
178 CallChannelHandler *m_callChannelHandler;
179 Tp::PendingChannelRequest *m_pendingCallRequest;
180 SesstionTypes m_chatType;
181 QList<QString> _outgoingQueue;
182 bool chatStateReported;
183 int sendErrors;
186 Q_DECLARE_OPERATORS_FOR_FLAGS(Session::SesstionTypes)
190 #endif // MAKNETOLIB_SESSION_H