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_SESSION_P_H
21#define KIMAP_SESSION_P_H
22
23#include "session.h"
24#include "sessionuiproxy.h"
25
26#include <ktcpsocket.h>
27
28#include <QtCore/QObject>
29#include <QtCore/QQueue>
30#include <QtCore/QString>
31#include <QtCore/QTimer>
32
33class KJob;
34
35namespace KIMAP {
36
37class Job;
38struct Message;
39class SessionLogger;
40class SessionThread;
41
42class KIMAP_EXPORT SessionPrivate : public QObject
43{
44 Q_OBJECT
45
46 friend class Session;
47
48 public:
49 explicit SessionPrivate( Session *session );
50 virtual ~SessionPrivate();
51
52 void addJob(Job *job);
53 QByteArray sendCommand( const QByteArray &command, const QByteArray &args = QByteArray() );
54 void startSsl(const KTcpSocket::SslVersion &version);
55 void sendData( const QByteArray &data );
56
57 KTcpSocket::SslVersion negotiatedEncryption() const;
58
59 void setSocketTimeout( int ms );
60 int socketTimeout() const;
61
62 Q_SIGNALS:
63 void encryptionNegotiationResult(bool);
64
65 private Q_SLOTS:
66 void onEncryptionNegotiationResult(bool isEncrypted, KTcpSocket::SslVersion sslVersion);
67 void onSocketTimeout();
68
69 void doStartNext();
70 void jobDone( KJob* );
71 void jobDestroyed( QObject* );
72 void responseReceived( const KIMAP::Message& );
73
74 void socketConnected();
75 void socketDisconnected();
76 void socketError(KTcpSocket::Error);
77 void socketActivity();
78
79 void handleSslError( const KSslErrorUiData &errorData );
80
81 private:
82 void startNext();
83 void clearJobQueue();
84 void setState(Session::State state);
85
86 void startSocketTimer();
87 void stopSocketTimer();
88 void restartSocketTimer();
89
90 Session *const q;
91
92 bool isSocketConnected;
93 Session::State state;
94
95 SessionLogger *logger;
96 SessionThread *thread;
97 SessionUiProxy::Ptr uiProxy;
98
99 bool jobRunning;
100 Job *currentJob;
101 QQueue<Job*> queue;
102
103 QByteArray authTag;
104 QByteArray selectTag;
105 QByteArray closeTag;
106
107 QString userName;
108 QByteArray greeting;
109 QByteArray currentMailBox;
110 QByteArray upcomingMailBox;
111 quint16 tagCount;
112
113 KTcpSocket::SslVersion sslVersion;
114
115 int socketTimerInterval;
116 QTimer socketTimer;
117};
118
119}
120
121#endif
122