1/*
2 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef MAILTRANSPORT_TRANSPORT_H
21#define MAILTRANSPORT_TRANSPORT_H
22
23#include <mailtransport/mailtransport_export.h>
24#include <mailtransport/transportbase.h>
25#include <mailtransport/transporttype.h>
26
27class TransportPrivate;
28
29namespace MailTransport {
30
31class TransportType;
32
33/**
34 Represents the settings of a specific mail transport.
35
36 To create a new empty Transport object, use TransportManager::createTransport().
37
38 Initialize an empty Transport object by calling the set...() methods defined in
39 kcfg-generated TransportBase, and in this class. Note that some transports use
40 the "host" setting to store the following values:
41 - Sendmail transport: path to the sendmail executable
42 - Akonadi transports: resource ID.
43*/
44// TODO KDE5: Do something about the kcfg-generated TransportBase.
45// Currently it has the config stuff as private members, which means it is
46// utterly inextensible. Also the sendmail and akonadi-type transports use
47// the "host" setting for keeping the location of the sendmail executable and
48// the resource id, respectively. This is a hack; they should have separate
49// config options... (cberzan)
50class MAILTRANSPORT_EXPORT Transport : public TransportBase
51{
52 Q_OBJECT
53 friend class TransportManager;
54 friend class TransportManagerPrivate;
55
56 public:
57 /**
58 Destructor
59 */
60 virtual ~Transport();
61
62 typedef QList<Transport*> List;
63
64 /**
65 Returns true if this transport is valid, ie. has all necessary data set.
66 */
67 bool isValid() const;
68
69 /**
70 Returns the password of this transport.
71 */
72 QString password();
73
74 /**
75 Sets the password of this transport.
76 @param passwd The new password.
77 */
78 void setPassword( const QString &passwd );
79
80 /**
81 Makes sure the transport has a unique name. Adds #1, #2, #3 etc. if
82 necessary.
83 @since 4.4
84 */
85 void forceUniqueName();
86
87 /**
88 This function synchronizes the password of this transport with the
89 password of the transport with the same ID that is managed by the
90 transport manager. This is only useful for cloned transports, since
91 their passwords don't automatically get updated when calling
92 TransportManager::loadPasswordsAsync() or TransportManager::loadPasswords().
93
94 @sa clone()
95 @since 4.2
96 */
97 void updatePasswordState();
98
99 /**
100 Returns true if all settings have been loaded.
101 This is the way to find out if the password has already been loaded
102 from the wallet.
103 */
104 bool isComplete() const;
105
106 /**
107 Returns a string representation of the authentication type.
108 */
109 QString authenticationTypeString() const;
110
111 /**
112 Returns a string representation of the authentication type.
113 Convienence function when there isn't a Transport object
114 instantiated.
115
116 @since 4.5
117 */
118 static QString authenticationTypeString( int type );
119
120 /**
121 Returns a deep copy of this Transport object which will no longer be
122 automatically updated. Use this if you need to store a Transport object
123 over a longer time. However it is recommended to store transport identifiers
124 instead if possible.
125
126 @sa updatePasswordState()
127 */
128 Transport *clone() const;
129
130 /**
131 Returns the type of this transport.
132 @see TransportType.
133 @since 4.4
134 */
135 TransportType transportType() const;
136
137 /**
138 Sets the type of this transport.
139 @see TransportType.
140 @since 4.4
141 */
142 void setTransportType( const TransportType &type );
143
144 protected:
145 /**
146 Creates a Transport object. Should only be used by TransportManager.
147 @param cfgGroup The KConfig group to read its data from.
148 */
149 Transport( const QString &cfgGroup );
150
151 virtual void usrReadConfig();
152 virtual void usrWriteConfig();
153
154 /**
155 Returns true if the password was not stored in the wallet.
156 */
157 bool needsWalletMigration() const;
158
159 /**
160 Try to migrate the password from the config file to the wallet.
161 */
162 void migrateToWallet();
163
164 private Q_SLOTS:
165
166 // Used by our friend, TransportManager
167 void readPassword();
168
169 private:
170 TransportPrivate *const d;
171};
172
173} // namespace MailTransport
174
175#endif // MAILTRANSPORT_TRANSPORT_H
176