KIO
kemailsettings.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 2000 Alex Zepeda <zipzippy@sonic.net> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00017 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00018 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00019 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00020 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00021 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00022 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00023 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00024 * SUCH DAMAGE. 00025 */ 00026 00027 #include "kemailsettings.h" 00028 00029 #include <kconfig.h> 00030 #include <kconfiggroup.h> 00031 #include <klocale.h> 00032 #include <kdebug.h> 00033 00034 class KEMailSettingsPrivate { 00035 public: 00036 KEMailSettingsPrivate() : m_pConfig( 0 ) {} 00037 ~KEMailSettingsPrivate() { delete m_pConfig; } 00038 KConfig *m_pConfig; 00039 QStringList profiles; 00040 QString m_sDefaultProfile, m_sCurrentProfile; 00041 }; 00042 00043 QString KEMailSettings::defaultProfileName() const 00044 { 00045 return p->m_sDefaultProfile; 00046 } 00047 00048 QString KEMailSettings::getSetting(KEMailSettings::Setting s) const 00049 { 00050 KConfigGroup cg( p->m_pConfig, QString("PROFILE_")+p->m_sCurrentProfile); 00051 switch (s) { 00052 case ClientProgram: { 00053 return cg.readEntry("EmailClient"); 00054 break; 00055 } 00056 case ClientTerminal: { 00057 return cg.readEntry("TerminalClient", QVariant(false)).toString(); 00058 break; 00059 } 00060 case RealName: { 00061 return cg.readEntry("FullName"); 00062 break; 00063 } 00064 case EmailAddress: { 00065 return cg.readEntry("EmailAddress"); 00066 break; 00067 } 00068 case ReplyToAddress: { 00069 return cg.readEntry("ReplyAddr"); 00070 break; 00071 } 00072 case Organization: { 00073 return cg.readEntry("Organization"); 00074 break; 00075 } 00076 case OutServer: { 00077 return cg.readEntry("OutgoingServer"); 00078 break; 00079 } 00080 case OutServerLogin: { 00081 return cg.readEntry("OutgoingUserName"); 00082 break; 00083 } 00084 case OutServerPass: { 00085 return cg.readEntry("OutgoingPassword"); 00086 break; 00087 } 00088 case OutServerType: { 00089 return cg.readEntry("OutgoingServerType"); 00090 break; 00091 } 00092 case OutServerCommand: { 00093 return cg.readEntry("OutgoingCommand"); 00094 break; 00095 } 00096 case OutServerTLS: { 00097 return cg.readEntry("OutgoingServerTLS", QVariant(false)).toString(); 00098 break; 00099 } 00100 case InServer: { 00101 return cg.readEntry("IncomingServer"); 00102 break; 00103 } 00104 case InServerLogin: { 00105 return cg.readEntry("IncomingUserName"); 00106 break; 00107 } 00108 case InServerPass: { 00109 return cg.readEntry("IncomingPassword"); 00110 break; 00111 } 00112 case InServerType: { 00113 return cg.readEntry("IncomingServerType"); 00114 break; 00115 } 00116 case InServerMBXType: { 00117 return cg.readEntry("IncomingServerMBXType"); 00118 break; 00119 } 00120 case InServerTLS: { 00121 return cg.readEntry("IncomingServerTLS", QVariant(false)).toString(); 00122 break; 00123 } 00124 }; 00125 return QString(); 00126 } 00127 void KEMailSettings::setSetting(KEMailSettings::Setting s, const QString &v) 00128 { 00129 KConfigGroup cg( p->m_pConfig, QString("PROFILE_")+p->m_sCurrentProfile); 00130 switch (s) { 00131 case ClientProgram: { 00132 cg.writePathEntry("EmailClient", v); 00133 break; 00134 } 00135 case ClientTerminal: { 00136 cg.writeEntry("TerminalClient", (v == "true") ); 00137 break; 00138 } 00139 case RealName: { 00140 cg.writeEntry("FullName", v); 00141 break; 00142 } 00143 case EmailAddress: { 00144 cg.writeEntry("EmailAddress", v); 00145 break; 00146 } 00147 case ReplyToAddress: { 00148 cg.writeEntry("ReplyAddr", v); 00149 break; 00150 } 00151 case Organization: { 00152 cg.writeEntry("Organization", v); 00153 break; 00154 } 00155 case OutServer: { 00156 cg.writeEntry("OutgoingServer", v); 00157 break; 00158 } 00159 case OutServerLogin: { 00160 cg.writeEntry("OutgoingUserName", v); 00161 break; 00162 } 00163 case OutServerPass: { 00164 cg.writeEntry("OutgoingPassword", v); 00165 break; 00166 } 00167 case OutServerType: { 00168 cg.writeEntry("OutgoingServerType", v); 00169 break; 00170 } 00171 case OutServerCommand: { 00172 cg.writeEntry("OutgoingCommand", v); 00173 break; 00174 } 00175 case OutServerTLS: { 00176 cg.writeEntry("OutgoingServerTLS", (v == "true") ); 00177 break; 00178 } 00179 case InServer: { 00180 cg.writeEntry("IncomingServer", v); 00181 break; 00182 } 00183 case InServerLogin: { 00184 cg.writeEntry("IncomingUserName", v); 00185 break; 00186 } 00187 case InServerPass: { 00188 cg.writeEntry("IncomingPassword", v); 00189 break; 00190 } 00191 case InServerType: { 00192 cg.writeEntry("IncomingServerType", v); 00193 break; 00194 } 00195 case InServerMBXType: { 00196 cg.writeEntry("IncomingServerMBXType", v); 00197 break; 00198 } 00199 case InServerTLS: { 00200 cg.writeEntry("IncomingServerTLS", (v == "true") ); 00201 break; 00202 } 00203 }; 00204 cg.sync(); 00205 } 00206 00207 void KEMailSettings::setDefault(const QString &s) 00208 { 00209 p->m_pConfig->group("Defaults").writeEntry("Profile", s); 00210 p->m_pConfig->sync(); 00211 p->m_sDefaultProfile=s; 00212 00213 } 00214 00215 void KEMailSettings::setProfile (const QString &s) 00216 { 00217 QString groupname="PROFILE_"; 00218 groupname.append(s); 00219 p->m_sCurrentProfile=s; 00220 if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist 00221 KConfigGroup cg(p->m_pConfig, groupname); 00222 cg.writeEntry("ServerType", QString()); 00223 p->profiles+=s; 00224 } 00225 } 00226 00227 QString KEMailSettings::currentProfileName() const 00228 { 00229 return p->m_sCurrentProfile; 00230 } 00231 00232 QStringList KEMailSettings::profiles() const 00233 { 00234 return p->profiles; 00235 } 00236 00237 KEMailSettings::KEMailSettings() 00238 :p(new KEMailSettingsPrivate()) 00239 { 00240 p->m_sCurrentProfile.clear(); 00241 00242 p->m_pConfig = new KConfig("emaildefaults"); 00243 00244 const QStringList groups = p->m_pConfig->groupList(); 00245 for (QStringList::ConstIterator it = groups.begin(); it != groups.end(); ++it) { 00246 if ( (*it).startsWith( QLatin1String( "PROFILE_" ) ) ) 00247 p->profiles+= (*it).mid(8, (*it).length()); 00248 } 00249 00250 KConfigGroup cg( p->m_pConfig, "Defaults"); 00251 p->m_sDefaultProfile = cg.readEntry("Profile", i18n("Default")); 00252 if (!p->m_sDefaultProfile.isNull()) { 00253 if (!p->m_pConfig->hasGroup(QString("PROFILE_")+p->m_sDefaultProfile)) 00254 setDefault(i18n("Default")); 00255 else 00256 setDefault(p->m_sDefaultProfile); 00257 } else { 00258 if (p->profiles.count()) { 00259 setDefault(p->profiles[0]); 00260 } else 00261 setDefault(i18n("Default")); 00262 } 00263 setProfile(defaultProfileName()); 00264 } 00265 00266 KEMailSettings::~KEMailSettings() 00267 { 00268 delete p; 00269 }
KDE 4.6 API Reference