kemailsettings.cpp Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kemailsettings.cpp

    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  *      $Id: kemailsettings.cpp,v 1.11 2002/06/17 17:19:59 garbanzo Exp $
    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->writeEntry("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         kdDebug() << "setDefault called with " << s << endl;
    00211         p->m_pConfig->setGroup("Defaults");
    00212         p->m_pConfig->writeEntry("Profile", s);
    00213         p->m_pConfig->sync();
    00214         p->m_sDefaultProfile=s;
    00215
    00216 }
    00217
    00218 void KEMailSettings::setProfile (const QString &s)
    00219 {
    00220         QString groupname="PROFILE_";
    00221         groupname.append(s);
    00222         p->m_sCurrentProfile=s;
    00223         if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist
    00224                 p->m_pConfig->setGroup(groupname);
    00225                 p->m_pConfig->writeEntry("ServerType", QString::null);
    00226                 p->m_pConfig->sync();
    00227                 p->profiles+=s;
    00228         }
    00229 }
    00230
    00231 QString KEMailSettings::currentProfileName() const
    00232 {
    00233         return p->m_sCurrentProfile;
    00234 }
    00235
    00236 QStringList KEMailSettings::profiles() const
    00237 {
    00238         return p->profiles;
    00239 }
    00240
    00241 KEMailSettings::KEMailSettings()
    00242 {
    00243         p = new KEMailSettingsPrivate();
    00244         p->m_sCurrentProfile=QString::null;
    00245
    00246         p->m_pConfig = new KConfig("emaildefaults");
    00247
    00248         QStringList groups = p->m_pConfig->groupList();
    00249         for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it) {
    00250                 if ( (*it).left(8) == "PROFILE_" )
    00251                         p->profiles+= (*it).mid(8, (*it).length());
    00252         }
    00253
    00254         p->m_pConfig->setGroup("Defaults");
    00255         p->m_sDefaultProfile=p->m_pConfig->readEntry("Profile", i18n("Default"));
    00256         if (p->m_sDefaultProfile != QString::null) {
    00257                 if (!p->m_pConfig->hasGroup(QString("PROFILE_")+p->m_sDefaultProfile))
    00258                         setDefault(i18n("Default"));
    00259                 else
    00260                         setDefault(p->m_sDefaultProfile);
    00261         } else {
    00262                         if (p->profiles.count()) {
    00263                                 kdDebug() << "WE ALREADY HAVE PROFILES DAMNIT" << endl;
    00264                                 setDefault(p->profiles[0]);
    00265                         } else
    00266                                 setDefault(i18n("Default"));
    00267         }
    00268         setProfile(defaultProfileName());
    00269 }
    00270
    00271 KEMailSettings::~KEMailSettings()
    00272 {
    00273     delete p;
    00274 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:25 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001