2 * Copyright (c) 2000 Alex Zepeda <zipzippy@sonic.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "kemailsettings.h"
30 #include <kconfiggroup.h>
34 class KEMailSettingsPrivate
{
36 KEMailSettingsPrivate() : m_pConfig( 0 ) {}
37 ~KEMailSettingsPrivate() { delete m_pConfig
; }
40 QString m_sDefaultProfile
, m_sCurrentProfile
;
43 QString
KEMailSettings::defaultProfileName() const
45 return p
->m_sDefaultProfile
;
48 QString
KEMailSettings::getSetting(KEMailSettings::Setting s
) const
50 KConfigGroup
cg( p
->m_pConfig
, QString("PROFILE_")+p
->m_sCurrentProfile
);
53 return cg
.readEntry("EmailClient");
56 case ClientTerminal
: {
57 return cg
.readEntry("TerminalClient", QVariant(false)).toString();
61 return cg
.readEntry("FullName");
65 return cg
.readEntry("EmailAddress");
68 case ReplyToAddress
: {
69 return cg
.readEntry("ReplyAddr");
73 return cg
.readEntry("Organization");
77 return cg
.readEntry("OutgoingServer");
80 case OutServerLogin
: {
81 return cg
.readEntry("OutgoingUserName");
85 return cg
.readEntry("OutgoingPassword");
89 return cg
.readEntry("OutgoingServerType");
92 case OutServerCommand
: {
93 return cg
.readEntry("OutgoingCommand");
97 return cg
.readEntry("OutgoingServerTLS", QVariant(false)).toString();
101 return cg
.readEntry("IncomingServer");
104 case InServerLogin
: {
105 return cg
.readEntry("IncomingUserName");
109 return cg
.readEntry("IncomingPassword");
113 return cg
.readEntry("IncomingServerType");
116 case InServerMBXType
: {
117 return cg
.readEntry("IncomingServerMBXType");
121 return cg
.readEntry("IncomingServerTLS", QVariant(false)).toString();
127 void KEMailSettings::setSetting(KEMailSettings::Setting s
, const QString
&v
)
129 KConfigGroup
cg( p
->m_pConfig
, QString("PROFILE_")+p
->m_sCurrentProfile
);
131 case ClientProgram
: {
132 cg
.writePathEntry("EmailClient", v
);
135 case ClientTerminal
: {
136 cg
.writeEntry("TerminalClient", (v
== "true") );
140 cg
.writeEntry("FullName", v
);
144 cg
.writeEntry("EmailAddress", v
);
147 case ReplyToAddress
: {
148 cg
.writeEntry("ReplyAddr", v
);
152 cg
.writeEntry("Organization", v
);
156 cg
.writeEntry("OutgoingServer", v
);
159 case OutServerLogin
: {
160 cg
.writeEntry("OutgoingUserName", v
);
163 case OutServerPass
: {
164 cg
.writeEntry("OutgoingPassword", v
);
167 case OutServerType
: {
168 cg
.writeEntry("OutgoingServerType", v
);
171 case OutServerCommand
: {
172 cg
.writeEntry("OutgoingCommand", v
);
176 cg
.writeEntry("OutgoingServerTLS", (v
== "true") );
180 cg
.writeEntry("IncomingServer", v
);
183 case InServerLogin
: {
184 cg
.writeEntry("IncomingUserName", v
);
188 cg
.writeEntry("IncomingPassword", v
);
192 cg
.writeEntry("IncomingServerType", v
);
195 case InServerMBXType
: {
196 cg
.writeEntry("IncomingServerMBXType", v
);
200 cg
.writeEntry("IncomingServerTLS", (v
== "true") );
207 void KEMailSettings::setDefault(const QString
&s
)
209 p
->m_pConfig
->group("Defaults").writeEntry("Profile", s
);
210 p
->m_pConfig
->sync();
211 p
->m_sDefaultProfile
=s
;
215 void KEMailSettings::setProfile (const QString
&s
)
217 QString groupname
="PROFILE_";
219 p
->m_sCurrentProfile
=s
;
220 if (!p
->m_pConfig
->hasGroup(groupname
)) { // Create a group if it doesn't exist
221 KConfigGroup
cg(p
->m_pConfig
, groupname
);
222 cg
.writeEntry("ServerType", QString());
227 QString
KEMailSettings::currentProfileName() const
229 return p
->m_sCurrentProfile
;
232 QStringList
KEMailSettings::profiles() const
237 KEMailSettings::KEMailSettings()
238 :p(new KEMailSettingsPrivate())
240 p
->m_sCurrentProfile
.clear();
242 p
->m_pConfig
= new KConfig("emaildefaults");
244 const QStringList groups
= p
->m_pConfig
->groupList();
245 for (QStringList::ConstIterator it
= groups
.begin(); it
!= groups
.end(); ++it
) {
246 if ( (*it
).startsWith( QLatin1String( "PROFILE_" ) ) )
247 p
->profiles
+= (*it
).mid(8, (*it
).length());
250 KConfigGroup
cg( p
->m_pConfig
, "Defaults");
251 p
->m_sDefaultProfile
= cg
.readEntry("Profile", i18n("Default"));
252 if (!p
->m_sDefaultProfile
.isNull()) {
253 if (!p
->m_pConfig
->hasGroup(QString("PROFILE_")+p
->m_sDefaultProfile
))
254 setDefault(i18n("Default"));
256 setDefault(p
->m_sDefaultProfile
);
258 if (p
->profiles
.count()) {
259 setDefault(p
->profiles
[0]);
261 setDefault(i18n("Default"));
263 setProfile(defaultProfileName());
266 KEMailSettings::~KEMailSettings()