MailTransport

socket.h
1 /*
2  SPDX-FileCopyrightText: 2006-2007 KovoKs <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "mailtransport_export.h"
10 
11 #include <QSslSocket>
12 
13 #include <memory>
14 
15 namespace MailTransport
16 {
17 class SocketPrivate;
18 
19 /**
20  * @class Socket
21  * Responsible for communicating with the server, it's designed to work
22  * with the ServerTest class.
23  * @author Tom Albers <[email protected]>
24  */
25 class Socket : public QObject
26 {
27  Q_OBJECT
28 
29 public:
30  /**
31  * Constructor, it will not auto connect. Call reconnect() to connect to
32  * the parameters given.
33  * @param parent the parent
34  */
35  explicit Socket(QObject *parent);
36 
37  /**
38  * Destructor
39  */
40  ~Socket() override;
41 
42  /**
43  * Existing connection will be closed and a new connection will be
44  * made
45  */
46  virtual void reconnect();
47 
48  /**
49  * Write @p text to the socket
50  */
51  virtual void write(const QString &text);
52 
53  /**
54  * @return true when the connection is live and kicking
55  */
56  virtual bool available();
57 
58  /**
59  * set the protocol to use
60  */
61  void setProtocol(const QString &proto);
62 
63  /**
64  * set the server to use
65  */
66  void setServer(const QString &server);
67 
68  /**
69  * set the port to use. If not specified, it will use the default
70  * belonging to the protocol.
71  */
72  void setPort(int port);
73 
74  /**
75  * returns the used port.
76  */
77  int port() const;
78 
79  /**
80  * this will be a secure connection
81  */
82  void setSecure(bool what);
83 
84  /**
85  * If you want to start TLS encryption, call this. For example after the starttls command.
86  */
87  void startTLS();
88 
89 private:
90  Q_DECLARE_PRIVATE(Socket)
91  std::unique_ptr<SocketPrivate> const d;
92 
93  Q_PRIVATE_SLOT(d, void slotConnected())
94  Q_PRIVATE_SLOT(d, void slotStateChanged(QAbstractSocket::SocketState state))
95  Q_PRIVATE_SLOT(d, void slotModeChanged(QSslSocket::SslMode state))
96  Q_PRIVATE_SLOT(d, void slotSocketRead())
97  Q_PRIVATE_SLOT(d, void slotSslErrors(const QList<QSslError> &errors))
98 
99 Q_SIGNALS:
100  /**
101  * emits the incoming data
102  */
103  void data(const QString &);
104 
105  /**
106  * emitted when there is a connection (ready to send something).
107  */
108  void connected();
109 
110  /**
111  * emitted when not connected.
112  */
113  void failed();
114 
115  /**
116  * emitted when startShake() is completed.
117  */
118  void tlsDone();
119 };
120 } // namespace MailTransport
Q_OBJECTQ_OBJECT
void connected()
emitted when there is a connection (ready to send something).
void setSecure(bool what)
this will be a secure connection
Definition: socket.cpp:207
virtual void write(const QString &text)
Write text to the socket.
Definition: socket.cpp:155
virtual void reconnect()
Existing connection will be closed and a new connection will be made.
Definition: socket.cpp:129
Socket(QObject *parent)
Constructor, it will not auto connect.
Definition: socket.cpp:117
void setProtocol(const QString &proto)
set the protocol to use
Definition: socket.cpp:187
virtual bool available()
Definition: socket.cpp:173
void failed()
emitted when not connected.
~Socket() override
Destructor.
Definition: socket.cpp:124
void tlsDone()
emitted when startShake() is completed.
void data(const QString &)
emits the incoming data
int port() const
returns the used port.
Definition: socket.cpp:202
void setPort(int port)
set the port to use.
Definition: socket.cpp:197
void setServer(const QString &server)
set the server to use
Definition: socket.cpp:192
void startTLS()
If you want to start TLS encryption, call this.
Definition: socket.cpp:180
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Feb 5 2023 03:58:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.