File indexing completed on 2024-05-12 05:17:17
0001 /* 0002 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kimap_export.h" 0010 0011 #include <QObject> 0012 0013 #include "sessionuiproxy.h" 0014 0015 namespace KIMAP 0016 { 0017 class SessionPrivate; 0018 class JobPrivate; 0019 struct Response; 0020 0021 class KIMAP_EXPORT Session : public QObject 0022 { 0023 Q_OBJECT 0024 0025 friend class JobPrivate; 0026 0027 public: 0028 enum State { Disconnected = 0, NotAuthenticated, Authenticated, Selected }; 0029 Q_ENUM(State) 0030 Session(const QString &hostName, quint16 port, QObject *parent = nullptr); 0031 ~Session(); 0032 0033 [[nodiscard]] QString hostName() const; 0034 [[nodiscard]] quint16 port() const; 0035 [[nodiscard]] State state() const; 0036 0037 /** 0038 * Returns the name that has been set with LoginJob::setUserName() 0039 * The user name is useful to uniquely identify an IMAP resource, in combination with the host name 0040 * @note If the Session was pre-authenticated, userName() will return an empty string 0041 * @since 4.7 0042 */ 0043 [[nodiscard]] QString userName() const; 0044 0045 [[nodiscard]] QByteArray serverGreeting() const; 0046 0047 /** 0048 * Sets an ui proxy that displays the error messages and waits for user feedback. 0049 * @param proxy the ui proxy object 0050 */ 0051 void setUiProxy(const SessionUiProxy::Ptr &proxy); 0052 0053 /** 0054 * Sets an ui proxy that displays the error messages and waits for user feedback. 0055 * @param proxy the ui proxy object 0056 * @deprecated Use the shared pointer version instead 0057 */ 0058 KIMAP_DEPRECATED void setUiProxy(SessionUiProxy *proxy); 0059 0060 /** 0061 * Set the session timeout. The default is 30 seconds. 0062 * @param timeout The socket timeout in seconds, negative values disable the timeout. 0063 * @since 4.6 0064 */ 0065 void setTimeout(int timeout); 0066 0067 /** 0068 * Returns the session timeout. 0069 * @since 4.12 0070 */ 0071 [[nodiscard]] int timeout() const; 0072 0073 /** 0074 * Returns the currently selected mailbox. 0075 * @since 4.5 0076 */ 0077 [[nodiscard]] QString selectedMailBox() const; 0078 0079 /** 0080 * Sets whether the IMAP network connection should use the system proxy settings. 0081 * 0082 * @param useProxy @c true if the proxy is to be used 0083 * The default is to not use the proxy. 0084 * @since 5.11.41 0085 * 0086 * @note If the session is currently connected to the IMAP server, calling this 0087 * function will disconnect and reconnect to it with the changed proxy setting. 0088 */ 0089 void setUseNetworkProxy(bool useProxy); 0090 0091 [[nodiscard]] int jobQueueSize() const; 0092 0093 void close(); 0094 0095 Q_SIGNALS: 0096 void jobQueueSizeChanged(int queueSize); 0097 0098 /** 0099 Emitted when we lose a previously established connection 0100 0101 Likely reasons: server closed the connection, loss of internet connectivity, etc... 0102 */ 0103 void connectionLost(); 0104 0105 /** 0106 Emitted when the Session couldn't connect to the host. 0107 0108 Likely reasons: invalid host address, no internet connectivity, firewall blocking rules, 0109 etc... 0110 0111 Pending jobs in the queue will be deleted, and the first job in the queue will be failed. (ie: 0112 it will have its result signal emitted with a non-zero error code.) 0113 0114 @since 4.7 0115 */ 0116 void connectionFailed(); 0117 0118 /** 0119 Emitted when the session's state changes. 0120 0121 Not very useful after all... :-) 0122 0123 If you want to receive the stateChanged arguments in your slot, you must register the State 0124 enum with @c Q_DECLARE_METATYPE(KIMAP::Session::State) and @c qRegisterMetaType<KIMAP::Session::State>(); 0125 0126 @since 4.7 0127 */ 0128 void stateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState); 0129 0130 private: 0131 friend class SessionPrivate; 0132 SessionPrivate *const d; 0133 }; 0134 0135 }