kmail Library API Documentation

networkaccount.cpp

00001 00026 #ifdef HAVE_CONFIG_H 00027 #include <config.h> 00028 #endif 00029 00030 #include "networkaccount.h" 00031 00032 #include <kconfig.h> 00033 #include <kio/global.h> 00034 using KIO::MetaData; 00035 00036 #include <climits> 00037 00038 namespace KMail { 00039 00040 NetworkAccount::NetworkAccount( KMAcctMgr * parent, const QString & name, uint id ) 00041 : KMAccount( parent, name, id ), 00042 mSlave( 0 ), 00043 mAuth( "*" ), 00044 mPort( 0 ), 00045 mStorePasswd( false ), 00046 mUseSSL( false ), 00047 mUseTLS( false ), 00048 mAskAgain( false ) 00049 { 00050 00051 } 00052 00053 NetworkAccount::~NetworkAccount() { 00054 00055 } 00056 00057 void NetworkAccount::init() { 00058 KMAccount::init(); 00059 00060 mSieveConfig = SieveConfig(); 00061 mLogin = QString::null; 00062 mPasswd = QString::null; 00063 mAuth = "*"; 00064 mHost = QString::null; 00065 mPort = defaultPort(); 00066 mStorePasswd = false; 00067 mUseSSL = false; 00068 mUseTLS = false; 00069 mAskAgain = false; 00070 } 00071 00072 // 00073 // 00074 // Getters and Setters 00075 // 00076 // 00077 00078 void NetworkAccount::setLogin( const QString & login ) { 00079 mLogin = login; 00080 } 00081 00082 QString NetworkAccount::passwd() const { 00083 return decryptStr( mPasswd ); 00084 } 00085 00086 void NetworkAccount::setPasswd( const QString & passwd, bool storeInConfig ) { 00087 mPasswd = encryptStr( passwd ); 00088 setStorePasswd( storeInConfig ); 00089 } 00090 00091 void NetworkAccount::clearPasswd() { 00092 setPasswd( "", false ); 00093 } 00094 00095 void NetworkAccount::setAuth( const QString & auth ) { 00096 mAuth = auth; 00097 } 00098 00099 void NetworkAccount::setStorePasswd( bool store ) { 00100 mStorePasswd = store; 00101 } 00102 00103 void NetworkAccount::setHost( const QString & host ) { 00104 mHost = host; 00105 } 00106 00107 void NetworkAccount::setPort( unsigned short int port ) { 00108 mPort = port; 00109 } 00110 00111 void NetworkAccount::setUseSSL( bool use ) { 00112 mUseSSL = use; 00113 } 00114 00115 void NetworkAccount::setUseTLS( bool use ) { 00116 mUseTLS = use; 00117 } 00118 00119 void NetworkAccount::setSieveConfig( const SieveConfig & config ) { 00120 mSieveConfig = config; 00121 } 00122 00123 // 00124 // 00125 // read/write config 00126 // 00127 // 00128 00129 void NetworkAccount::readConfig( /*const*/ KConfig/*Base*/ & config ) { 00130 KMAccount::readConfig( config ); 00131 00132 setLogin( config.readEntry( "login" ) ); 00133 00134 if ( config.readNumEntry( "store-passwd", false ) ) { // ### s/Num/Bool/ 00135 QString encpasswd = config.readEntry( "pass" ); 00136 if ( encpasswd.isEmpty() ) { 00137 encpasswd = config.readEntry( "passwd" ); 00138 if ( !encpasswd.isEmpty() ) encpasswd = importPassword( encpasswd ); 00139 } 00140 setPasswd( decryptStr( encpasswd ), true ); 00141 } else 00142 setPasswd( "", false ); 00143 00144 setHost( config.readEntry( "host" ) ); 00145 00146 unsigned int port = config.readUnsignedNumEntry( "port", defaultPort() ); 00147 if ( port > USHRT_MAX ) port = defaultPort(); 00148 setPort( port ); 00149 00150 setAuth( config.readEntry( "auth", "*" ) ); 00151 setUseSSL( config.readBoolEntry( "use-ssl", false ) ); 00152 setUseTLS( config.readBoolEntry( "use-tls", false ) ); 00153 00154 mSieveConfig.readConfig( config ); 00155 } 00156 00157 void NetworkAccount::writeConfig( KConfig/*Base*/ & config ) /*const*/ { 00158 KMAccount::writeConfig( config ); 00159 00160 config.writeEntry( "login", login() ); 00161 config.writeEntry( "store-passwd", storePasswd() ); 00162 if ( storePasswd() ) config.writeEntry( "pass", mPasswd ); // NOT passwd() 00163 else config.writeEntry( "passwd", "" ); // ### ???? why two different keys? 00164 00165 config.writeEntry( "host", host() ); 00166 config.writeEntry( "port", static_cast<unsigned int>( port() ) ); 00167 config.writeEntry( "auth", auth() ); 00168 config.writeEntry( "use-ssl", useSSL() ); 00169 config.writeEntry( "use-tls", useTLS() ); 00170 00171 mSieveConfig.writeConfig( config ); 00172 } 00173 00174 // 00175 // 00176 // Network processing 00177 // 00178 // 00179 00180 KURL NetworkAccount::getUrl() const { 00181 KURL url; 00182 url.setProtocol( protocol() ); 00183 url.setUser( login() ); 00184 url.setPass( passwd() ); 00185 url.setHost( host() ); 00186 url.setPort( port() ); 00187 return url; 00188 } 00189 00190 MetaData NetworkAccount::slaveConfig() const { 00191 MetaData m; 00192 m.insert( "tls", useTLS() ? "on" : "off" ); 00193 return m; 00194 } 00195 00196 void NetworkAccount::pseudoAssign( const KMAccount * a ) { 00197 KMAccount::pseudoAssign( a ); 00198 00199 const NetworkAccount * n = dynamic_cast<const NetworkAccount*>( a ); 00200 if ( !n ) return; 00201 00202 setLogin( n->login() ); 00203 setPasswd( n->passwd(), n->storePasswd() ); 00204 setHost( n->host() ); 00205 setPort( n->port() ); 00206 setAuth( n->auth() ); 00207 setUseSSL( n->useSSL() ); 00208 setUseTLS( n->useTLS() ); 00209 setSieveConfig( n->sieveConfig() ); 00210 } 00211 00212 } // namespace KMail 00213 00214 #include "networkaccount.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:52:51 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003