summaryrefslogtreecommitdiff
path: root/kimap/session.h
blob: e23fbc4a03d8eac26558940b664102cb60b25221 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
    Copyright (c) 2009 Kevin Ottens <ervin@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef KIMAP_SESSION_H
#define KIMAP_SESSION_H

#include "kimap_export.h"

#include <QtCore/QObject>

#include "sessionuiproxy.h"

class KSslErrorUiData;

namespace KIMAP {

class SessionPrivate;
class JobPrivate;
struct Message;

class KIMAP_EXPORT Session : public QObject
{
  Q_OBJECT
  Q_ENUMS(State)

  friend class JobPrivate;

  public:
    enum State { Disconnected = 0, NotAuthenticated, Authenticated, Selected };

    Session( const QString &hostName, quint16 port, QObject *parent=0 );
    ~Session();

    QString hostName() const;
    quint16 port() const;
    State state() const;

    /**
     * Returns the name that has been set with LoginJob::setUserName()
     * The user name is useful to uniquely identify an IMAP resource, in combination with the host name
     * @note If the Session was pre-authenticated, userName() will return an empty string
     * @since 4.7
     */
    QString userName() const;

    QByteArray serverGreeting() const;

    /**
     * Sets an ui proxy that displays the error messages and waits for user feedback.
     * @param proxy the ui proxy object
     */
    void setUiProxy(SessionUiProxy::Ptr proxy);

    /**
     * Sets an ui proxy that displays the error messages and waits for user feedback.
     * @param proxy the ui proxy object
     * @deprecated Use the shared pointer version instead
     */
    KDE_DEPRECATED void setUiProxy(SessionUiProxy *proxy);

    /**
     * Set the session timeout. The default is 30 seconds.
     * @param timeout The socket timeout in seconds, negative values disable the timeout.
     * @since 4.6
     */
    void setTimeout( int timeout );

    /**
     * Returns the currently selected mailbox.
     * @since 4.5
     */
    QString selectedMailBox() const;

    int jobQueueSize() const;

    void close();

  Q_SIGNALS:
    void jobQueueSizeChanged( int queueSize );

    /**
      @deprecated
      Emitted when we loose a previously established connection

      Likely reasons: server closed the connection, loss of internet connectivity, etc...

      For historical reasons, this signal is also emitted in the event of a failed connection, but
      you should not rely on this behavior.

      New implementations should use connectionFailed() to detect a failure to connect to the host,
      and stateChanged() to detect a loss of connectivity.
    */
    KDE_DEPRECATED void connectionLost();

    /**
      Emitted when the Session couldn't connect to the host.

      Likely reasons: invalid host address, no internet connectivity, firewall blocking rules,
      etc...

      Pending jobs in the queue will be deleted, and the first job in the queue will be failed. (ie:
      it will have its result signal emitted with a non-zero error code.)

      @since 4.7
    */
    void connectionFailed();

    /**
      Emitted when the session's state changes.

      You can use this signal to detect a connection loss (ie: stateChanged is emitted with newState
      == KIMAP::Session::Disconnected)

      If you want to receive the stateChanged arguments in your slot, you must register the State
      enum with @c Q_DECLARE_METATYPE(KIMAP::Session::State) and @c qRegisterMetaType<KIMAP::Session::State>();

      @since 4.7
    */
    void stateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState);

  private:
    Q_PRIVATE_SLOT( d, void doStartNext() )
    Q_PRIVATE_SLOT( d, void jobDone( KJob* ) )
    Q_PRIVATE_SLOT( d, void jobDestroyed( QObject* ) )
    Q_PRIVATE_SLOT( d, void responseReceived( const KIMAP::Message& ) )

    Q_PRIVATE_SLOT( d, void socketConnected() )
    Q_PRIVATE_SLOT( d, void socketDisconnected() )
    Q_PRIVATE_SLOT( d, void socketError() )
    Q_PRIVATE_SLOT( d, void socketActivity() )

    Q_PRIVATE_SLOT( d, void handleSslError( const KSslErrorUiData &errorData ) )

    friend class SessionPrivate;
    SessionPrivate *const d;
};

}

#endif