KIMAP2

session.h
1 /*
2  Copyright (c) 2009 Kevin Ottens <[email protected]>
3  Copyright (c) 2017 Christian Mollekopf <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #ifndef KIMAP2_SESSION_H
22 #define KIMAP2_SESSION_H
23 
24 #include "kimap2_export.h"
25 
26 #include <QtCore/QObject>
27 #include <QtNetwork/QSsl>
28 #include <QtNetwork/QSslSocket>
29 
30 namespace KIMAP2
31 {
32 
33 class SessionPrivate;
34 class JobPrivate;
35 struct Message;
36 
37 class KIMAP2_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 = Q_NULLPTR);
48  ~Session();
49 
50  QString hostName() const;
51  quint16 port() const;
52  State state() const;
53  /**
54  * Returns true if the session is in either Authenticated or Selected state
55  */
56  bool isConnected() const;
57 
58  /**
59  * Returns the name that has been set with LoginJob::setUserName()
60  * The user name is useful to uniquely identify an IMAP resource, in combination with the host name
61  * @note If the Session was pre-authenticated, userName() will return an empty string
62  */
63  QString userName() const;
64 
65  QByteArray serverGreeting() const;
66 
67  void setErrorHandler();
68 
69  /**
70  * Set the session timeout. The default is 30 seconds.
71  * @param timeout The socket timeout in seconds, negative values disable the timeout.
72  */
73  void setTimeout(int timeout);
74 
75  /**
76  * Returns the session timeout.
77  */
78  int timeout() const;
79 
80  /**
81  * Returns the currently selected mailbox.
82  */
83  QString selectedMailBox() const;
84 
85  int jobQueueSize() const;
86 
87  void close();
88 
89  /**
90  * Use to ignore specific ssl errrs.
91  *
92  * Use in conjunction with @see sslErrors
93  */
94  void ignoreErrors(const QList<QSslError> &errors);
95 
96 Q_SIGNALS:
97  void jobQueueSizeChanged(int queueSize);
98 
99  /**
100  * Emitted when ssl errors occur.
101  *
102  * Use in conjunction with @see ignoreErrors to ignore an error as it appears.
103  * Note that ignore errors must be called synchronously directly in the callback.
104  */
105  void sslErrors(const QList<QSslError> &errors);
106 
107  /**
108  Emitted when the Session couldn't connect to the host.
109 
110  Likely reasons: invalid host address, no internet connectivity, firewall blocking rules,
111  etc...
112 
113  Pending jobs in the queue will be deleted, and the first job in the queue will be failed. (ie:
114  it will have its result signal emitted with a non-zero error code.)
115  */
116  void connectionFailed();
117 
118  /**
119  Emitted when the session's state changes.
120 
121  You can use this signal to detect a connection loss (ie: stateChanged is emitted with newState
122  == KIMAP2::Session::Disconnected)
123 
124  If you want to receive the stateChanged arguments in your slot, you must register the State
125  enum with @c Q_DECLARE_METATYPE(KIMAP2::Session::State) and @c qRegisterMetaType<KIMAP2::Session::State>();
126  */
127  void stateChanged(KIMAP2::Session::State newState, KIMAP2::Session::State oldState);
128 
129 private:
130  friend class SessionPrivate;
131  SessionPrivate *const d;
132 };
133 
134 }
135 
136 #endif
const QList< QKeySequence > & close()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:10:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.