1/*
2 Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef KIMAP_SESSIONTHREAD_P_H
21#define KIMAP_SESSIONTHREAD_P_H
22
23#include <QtCore/QMutex>
24#include <QtCore/QQueue>
25
26#include <ktcpsocket.h>
27
28typedef KTcpSocket SessionSocket;
29
30namespace KIMAP {
31
32class ImapStreamParser;
33struct Message;
34
35class SessionThread : public QObject
36{
37 Q_OBJECT
38
39 public:
40 explicit SessionThread( const QString &hostName, quint16 port );
41 ~SessionThread();
42
43 inline QString hostName() { return m_hostName; }
44 inline quint16 port() { return m_port; }
45
46 void sendData( const QByteArray &payload );
47
48 public Q_SLOTS:
49 void closeSocket();
50 void startSsl(KTcpSocket::SslVersion version);
51 void sslErrorHandlerResponse(bool result);
52
53 Q_SIGNALS:
54 void socketConnected();
55 void socketDisconnected();
56 void socketActivity();
57 void socketError(KTcpSocket::Error);
58 void responseReceived(const KIMAP::Message &response);
59 void encryptionNegotiationResult(bool, KTcpSocket::SslVersion);
60 void sslError(const KSslErrorUiData&);
61
62 private Q_SLOTS:
63 void reconnect();
64 void threadInit();
65 void threadQuit();
66 void readMessage();
67 void writeDataQueue();
68 void sslConnected();
69 void doCloseSocket();
70 void slotSocketError(KTcpSocket::Error);
71 void slotSocketDisconnected();
72 void doStartSsl(KTcpSocket::SslVersion);
73 void doSslErrorHandlerResponse(bool result);
74
75 private:
76 QString m_hostName;
77 quint16 m_port;
78
79 SessionSocket *m_socket;
80 ImapStreamParser *m_stream;
81
82 QQueue<QByteArray> m_dataQueue;
83
84 // Protects m_dataQueue
85 QMutex m_mutex;
86
87 bool m_encryptedMode;
88};
89
90}
91
92#endif
93