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_H
21#define KIMAP_SESSION_H
22
23#include "kimap_export.h"
24
25#include <QtCore/QObject>
26
27#include "sessionuiproxy.h"
28
29class KSslErrorUiData;
30
31namespace KIMAP {
32
33class SessionPrivate;
34class JobPrivate;
35struct Message;
36
37class KIMAP_EXPORT Session : public QObject
38{
39 Q_OBJECT
40 Q_ENUMS( State )
41
42 friend class JobPrivate;
43
44 public:
45 enum State { Disconnected = 0, NotAuthenticated, Authenticated, Selected };
46
47 Session( const QString &hostName, quint16 port, QObject *parent=0 );
48 ~Session();
49
50 QString hostName() const;
51 quint16 port() const;
52 State state() const;
53
54 /**
55 * Returns the name that has been set with LoginJob::setUserName()
56 * The user name is useful to uniquely identify an IMAP resource, in combination with the host name
57 * @note If the Session was pre-authenticated, userName() will return an empty string
58 * @since 4.7
59 */
60 QString userName() const;
61
62 QByteArray serverGreeting() const;
63
64 /**
65 * Sets an ui proxy that displays the error messages and waits for user feedback.
66 * @param proxy the ui proxy object
67 */
68 void setUiProxy(SessionUiProxy::Ptr proxy);
69
70 /**
71 * Sets an ui proxy that displays the error messages and waits for user feedback.
72 * @param proxy the ui proxy object
73 * @deprecated Use the shared pointer version instead
74 */
75 KIMAP_DEPRECATED void setUiProxy(SessionUiProxy *proxy);
76
77 /**
78 * Set the session timeout. The default is 30 seconds.
79 * @param timeout The socket timeout in seconds, negative values disable the timeout.
80 * @since 4.6
81 */
82 void setTimeout( int timeout );
83
84 /**
85 * Returns the session timeout.
86 * @since 4.12
87 */
88 int timeout() const;
89
90 /**
91 * Returns the currently selected mailbox.
92 * @since 4.5
93 */
94 QString selectedMailBox() const;
95
96 int jobQueueSize() const;
97
98 void close();
99
100 Q_SIGNALS:
101 void jobQueueSizeChanged( int queueSize );
102
103 /**
104 @deprecated
105 Emitted when we loose a previously established connection
106
107 Likely reasons: server closed the connection, loss of internet connectivity, etc...
108
109 For historical reasons, this signal is also emitted in the event of a failed connection, but
110 you should not rely on this behavior.
111
112 New implementations should use connectionFailed() to detect a failure to connect to the host,
113 and stateChanged() to detect a loss of connectivity.
114 */
115 KIMAP_DEPRECATED void connectionLost();
116
117 /**
118 Emitted when the Session couldn't connect to the host.
119
120 Likely reasons: invalid host address, no internet connectivity, firewall blocking rules,
121 etc...
122
123 Pending jobs in the queue will be deleted, and the first job in the queue will be failed. (ie:
124 it will have its result signal emitted with a non-zero error code.)
125
126 @since 4.7
127 */
128 void connectionFailed();
129
130 /**
131 Emitted when the session's state changes.
132
133 You can use this signal to detect a connection loss (ie: stateChanged is emitted with newState
134 == KIMAP::Session::Disconnected)
135
136 If you want to receive the stateChanged arguments in your slot, you must register the State
137 enum with @c Q_DECLARE_METATYPE(KIMAP::Session::State) and @c qRegisterMetaType<KIMAP::Session::State>();
138
139 @since 4.7
140 */
141 void stateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState);
142
143 private:
144 friend class SessionPrivate;
145 SessionPrivate *const d;
146};
147
148}
149
150#endif
151