MailTransport

transport.h
1 /*
2  SPDX-FileCopyrightText: 2006-2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "mailtransport_export.h"
10 #include "transportbase.h"
11 #include "transporttype.h"
12 
13 #include <memory>
14 
15 class TransportPrivate;
16 namespace QKeychain
17 {
18 class Job;
19 }
20 namespace MailTransport
21 {
22 class TransportType;
23 
24 /**
25  Represents the settings of a specific mail transport.
26 
27  To create a new empty Transport object, use TransportManager::createTransport().
28 
29  Initialize an empty Transport object by calling the set...() methods defined in
30  kcfg-generated TransportBase, and in this class.
31 */
32 class MAILTRANSPORT_EXPORT Transport : public TransportBase
33 {
34  Q_OBJECT
35 
36  Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
37  Q_PROPERTY(TransportType transportType READ transportType NOTIFY transportTypeChanged)
38 
39  friend class TransportManager;
40  friend class TransportManagerPrivate;
41 
42 public:
43  /**
44  Destructor
45  */
46  ~Transport() override;
47 
48  using List = QList<Transport *>;
49 
50  /**
51  Returns true if this transport is valid, ie. has all necessary data set.
52  */
53  Q_REQUIRED_RESULT Q_INVOKABLE bool isValid() const;
54 
55  /**
56  Returns the password of this transport.
57  */
58  Q_REQUIRED_RESULT QString password() const;
59 
60  /**
61  Sets the password of this transport.
62  @param passwd The new password.
63  */
64  void setPassword(const QString &passwd);
65 
66  /**
67  Makes sure the transport has a unique name. Adds #1, #2, #3 etc. if
68  necessary.
69  @since 4.4
70  */
71  void forceUniqueName();
72 
73  /**
74  This function synchronizes the password of this transport with the
75  password of the transport with the same ID that is managed by the
76  transport manager. This is only useful for cloned transports, since
77  their passwords don't automatically get updated when calling
78  TransportManager::loadPasswordsAsync() or TransportManager::loadPasswords().
79 
80  @sa clone()
81  @since 4.2
82  */
83  void updatePasswordState();
84 
85  /**
86  Returns true if all settings have been loaded.
87  This is the way to find out if the password has already been loaded
88  from the wallet.
89  */
90  Q_REQUIRED_RESULT bool isComplete() const;
91 
92  /**
93  Returns a string representation of the authentication type.
94  */
95  Q_REQUIRED_RESULT QString authenticationTypeString() const;
96 
97  /**
98  Returns a string representation of the authentication type.
99  Convenience function when there isn't a Transport object
100  instantiated.
101 
102  @since 4.5
103  */
104  Q_REQUIRED_RESULT static QString authenticationTypeString(int type);
105 
106  /**
107  Returns a deep copy of this Transport object which will no longer be
108  automatically updated. Use this if you need to store a Transport object
109  over a longer time. However it is recommended to store transport identifiers
110  instead if possible.
111 
112  @sa updatePasswordState()
113  */
114  Transport *clone() const;
115 
116  /**
117  Returns the type of this transport.
118  @see TransportType.
119  @since 4.4
120  */
121  Q_REQUIRED_RESULT TransportType transportType() const;
122 
123 protected:
124  /**
125  Creates a Transport object. Should only be used by TransportManager.
126  @param cfgGroup The KConfig group to read its data from.
127  */
128  explicit Transport(const QString &cfgGroup);
129 
130  void usrRead() override;
131  bool usrSave() override;
132 
133  /**
134  Returns true if the password was not stored in the wallet.
135  */
136  Q_REQUIRED_RESULT bool needsWalletMigration() const;
137 
138  /**
139  Try to migrate the password from the config file to the wallet.
140  */
141  void migrateToWallet();
142 
143 private Q_SLOTS:
144 
145  // Used by our friend, TransportManager
146  void readPassword();
147 
148 Q_SIGNALS:
149  /**
150  Emitted when passwords have been loaded from QKeyChain.
151  */
152  void passwordLoaded();
153  /**
154  * Emitted when the password is changed
155  */
156  void passwordChanged();
157  /**
158  * Emitted when the transport type is changed
159  */
160  void transportTypeChanged();
161 
162 private:
163  void readTransportPasswordFinished(QKeychain::Job *baseJob);
164  void loadPassword();
165 
166 private:
167  std::unique_ptr<TransportPrivate> const d;
168 };
169 } // namespace MailTransport
Central transport management interface.
A representation of a transport type.
Definition: transporttype.h:30
Represents the settings of a specific mail transport.
Definition: transport.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.