File indexing completed on 2024-05-12 05:17:23

0001 /*
0002     Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #ifndef KIMAP2_JOB_H
0021 #define KIMAP2_JOB_H
0022 
0023 #include "kimap2_export.h"
0024 
0025 #include <KJob>
0026 #include <QtNetwork/QAbstractSocket>
0027 
0028 namespace KIMAP2
0029 {
0030 
0031 class Session;
0032 class SessionPrivate;
0033 class JobPrivate;
0034 struct Message;
0035 
0036 enum ErrorCodes {
0037     ConnectionLost = KJob::UserDefinedError + 1,
0038     CommandFailed,
0039     CouldNotConnect,
0040     SslHandshakeFailed,
0041     HostNotFound,
0042     LoginFailed,
0043     LastError
0044 };
0045 
0046 class KIMAP2_EXPORT Job : public KJob
0047 {
0048     Q_OBJECT
0049     Q_DECLARE_PRIVATE(Job)
0050 
0051     friend class SessionPrivate;
0052 
0053 public:
0054     virtual ~Job();
0055 
0056     Session *session() const;
0057 
0058     void start() Q_DECL_OVERRIDE;
0059 
0060 private:
0061     virtual void doStart() = 0;
0062     virtual void handleResponse(const Message &response);
0063     virtual void connectionLost();
0064     void setSocketError(QAbstractSocket::SocketError);
0065     void setErrorMessage(const QString &message);
0066 
0067 protected:
0068     enum HandlerResponse {
0069         Handled = 0,
0070         NotHandled
0071     };
0072 
0073     HandlerResponse handleErrorReplies(const Message &response);
0074 
0075     explicit Job(Session *session);
0076     explicit Job(JobPrivate &dd);
0077 
0078     JobPrivate *const d_ptr;
0079 };
0080 
0081 }
0082 
0083 #endif