kio
kemailsettings.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "kemailsettings.h"
00030
00031 #include <kconfig.h>
00032 #include <klocale.h>
00033 #include <kdebug.h>
00034
00035 class KEMailSettingsPrivate {
00036 public:
00037 KEMailSettingsPrivate() : m_pConfig( 0 ) {}
00038 ~KEMailSettingsPrivate() { delete m_pConfig; }
00039 KConfig *m_pConfig;
00040 QStringList profiles;
00041 QString m_sDefaultProfile, m_sCurrentProfile;
00042 };
00043
00044 QString KEMailSettings::defaultProfileName() const
00045 {
00046 return p->m_sDefaultProfile;
00047 }
00048
00049 QString KEMailSettings::getSetting(KEMailSettings::Setting s)
00050 {
00051 p->m_pConfig->setGroup(QString("PROFILE_")+p->m_sCurrentProfile);
00052 switch (s) {
00053 case ClientProgram: {
00054 return p->m_pConfig->readEntry("EmailClient");
00055 break;
00056 }
00057 case ClientTerminal: {
00058 return ((p->m_pConfig->readBoolEntry("TerminalClient")) ? QString("true") : QString("false") );
00059 break;
00060 }
00061 case RealName: {
00062 return p->m_pConfig->readEntry("FullName");
00063 break;
00064 }
00065 case EmailAddress: {
00066 return p->m_pConfig->readEntry("EmailAddress");
00067 break;
00068 }
00069 case ReplyToAddress: {
00070 return p->m_pConfig->readEntry("ReplyAddr");
00071 break;
00072 }
00073 case Organization: {
00074 return p->m_pConfig->readEntry("Organization");
00075 break;
00076 }
00077 case OutServer: {
00078 return p->m_pConfig->readEntry("OutgoingServer");
00079 break;
00080 }
00081 case OutServerLogin: {
00082 return p->m_pConfig->readEntry("OutgoingUserName");
00083 break;
00084 }
00085 case OutServerPass: {
00086 return p->m_pConfig->readEntry("OutgoingPassword");
00087 break;
00088 }
00089 case OutServerType: {
00090 return p->m_pConfig->readEntry("OutgoingServerType");
00091 break;
00092 }
00093 case OutServerCommand: {
00094 return p->m_pConfig->readEntry("OutgoingCommand");
00095 break;
00096 }
00097 case OutServerTLS: {
00098 return ((p->m_pConfig->readBoolEntry("OutgoingServerTLS")) ? QString("true") : QString("false") );
00099 break;
00100 }
00101 case InServer: {
00102 return p->m_pConfig->readEntry("IncomingServer");
00103 break;
00104 }
00105 case InServerLogin: {
00106 return p->m_pConfig->readEntry("IncomingUserName");
00107 break;
00108 }
00109 case InServerPass: {
00110 return p->m_pConfig->readEntry("IncomingPassword");
00111 break;
00112 }
00113 case InServerType: {
00114 return p->m_pConfig->readEntry("IncomingServerType");
00115 break;
00116 }
00117 case InServerMBXType: {
00118 return p->m_pConfig->readEntry("IncomingServerMBXType");
00119 break;
00120 }
00121 case InServerTLS: {
00122 return ((p->m_pConfig->readBoolEntry("IncomingServerTLS")) ? QString("true") : QString("false") );
00123 break;
00124 }
00125 };
00126 return QString::null;
00127 }
00128 void KEMailSettings::setSetting(KEMailSettings::Setting s, const QString &v)
00129 {
00130 p->m_pConfig->setGroup(QString("PROFILE_")+p->m_sCurrentProfile);
00131 switch (s) {
00132 case ClientProgram: {
00133 p->m_pConfig->writePathEntry("EmailClient", v);
00134 break;
00135 }
00136 case ClientTerminal: {
00137 p->m_pConfig->writeEntry("TerminalClient", (v == "true") ? true : false );
00138 break;
00139 }
00140 case RealName: {
00141 p->m_pConfig->writeEntry("FullName", v);
00142 break;
00143 }
00144 case EmailAddress: {
00145 p->m_pConfig->writeEntry("EmailAddress", v);
00146 break;
00147 }
00148 case ReplyToAddress: {
00149 p->m_pConfig->writeEntry("ReplyAddr", v);
00150 break;
00151 }
00152 case Organization: {
00153 p->m_pConfig->writeEntry("Organization", v);
00154 break;
00155 }
00156 case OutServer: {
00157 p->m_pConfig->writeEntry("OutgoingServer", v);
00158 break;
00159 }
00160 case OutServerLogin: {
00161 p->m_pConfig->writeEntry("OutgoingUserName", v);
00162 break;
00163 }
00164 case OutServerPass: {
00165 p->m_pConfig->writeEntry("OutgoingPassword", v);
00166 break;
00167 }
00168 case OutServerType: {
00169 p->m_pConfig->writeEntry("OutgoingServerType", v);
00170 break;
00171 }
00172 case OutServerCommand: {
00173 p->m_pConfig->writeEntry("OutgoingCommand", v);
00174 break;
00175 }
00176 case OutServerTLS: {
00177 p->m_pConfig->writeEntry("OutgoingServerTLS", (v == "true") ? true : false );
00178 break;
00179 }
00180 case InServer: {
00181 p->m_pConfig->writeEntry("IncomingServer", v);
00182 break;
00183 }
00184 case InServerLogin: {
00185 p->m_pConfig->writeEntry("IncomingUserName", v);
00186 break;
00187 }
00188 case InServerPass: {
00189 p->m_pConfig->writeEntry("IncomingPassword", v);
00190 break;
00191 }
00192 case InServerType: {
00193 p->m_pConfig->writeEntry("IncomingServerType", v);
00194 break;
00195 }
00196 case InServerMBXType: {
00197 p->m_pConfig->writeEntry("IncomingServerMBXType", v);
00198 break;
00199 }
00200 case InServerTLS: {
00201 p->m_pConfig->writeEntry("IncomingServerTLS", (v == "true") ? true : false );
00202 break;
00203 }
00204 };
00205 p->m_pConfig->sync();
00206 }
00207
00208 void KEMailSettings::setDefault(const QString &s)
00209 {
00210 p->m_pConfig->setGroup("Defaults");
00211 p->m_pConfig->writeEntry("Profile", s);
00212 p->m_pConfig->sync();
00213 p->m_sDefaultProfile=s;
00214
00215 }
00216
00217 void KEMailSettings::setProfile (const QString &s)
00218 {
00219 QString groupname="PROFILE_";
00220 groupname.append(s);
00221 p->m_sCurrentProfile=s;
00222 if (!p->m_pConfig->hasGroup(groupname)) {
00223 p->m_pConfig->setGroup(groupname);
00224 p->m_pConfig->writeEntry("ServerType", QString::null);
00225 p->m_pConfig->sync();
00226 p->profiles+=s;
00227 }
00228 }
00229
00230 QString KEMailSettings::currentProfileName() const
00231 {
00232 return p->m_sCurrentProfile;
00233 }
00234
00235 QStringList KEMailSettings::profiles() const
00236 {
00237 return p->profiles;
00238 }
00239
00240 KEMailSettings::KEMailSettings()
00241 {
00242 p = new KEMailSettingsPrivate();
00243 p->m_sCurrentProfile=QString::null;
00244
00245 p->m_pConfig = new KConfig("emaildefaults");
00246
00247 QStringList groups = p->m_pConfig->groupList();
00248 for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it) {
00249 if ( (*it).left(8) == "PROFILE_" )
00250 p->profiles+= (*it).mid(8, (*it).length());
00251 }
00252
00253 p->m_pConfig->setGroup("Defaults");
00254 p->m_sDefaultProfile=p->m_pConfig->readEntry("Profile", i18n("Default"));
00255 if (!p->m_sDefaultProfile.isNull()) {
00256 if (!p->m_pConfig->hasGroup(QString("PROFILE_")+p->m_sDefaultProfile))
00257 setDefault(i18n("Default"));
00258 else
00259 setDefault(p->m_sDefaultProfile);
00260 } else {
00261 if (p->profiles.count()) {
00262 setDefault(p->profiles[0]);
00263 } else
00264 setDefault(i18n("Default"));
00265 }
00266 setProfile(defaultProfileName());
00267 }
00268
00269 KEMailSettings::~KEMailSettings()
00270 {
00271 delete p;
00272 }