00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "accountsetupitem.h"
00019
00020 AccountSetupItem::AccountSetupItem( QTreeWidget* parent )
00021 : QTreeWidgetItem( parent )
00022 {
00023 init();
00024
00025 }
00026
00027 AccountSetupItem::AccountSetupItem( QTreeWidget* parent, const QString & name )
00028 : QTreeWidgetItem( parent )
00029 {
00030 init();
00031
00032
00033 _account = name;
00034
00035
00036 setText( 0, name );
00037
00038 }
00039
00040 AccountSetupItem::~AccountSetupItem()
00041 {
00042 }
00043
00044 void AccountSetupItem::init( )
00045 {
00046
00047 _account = DEFAULT_ACCOUNT_NAME;
00048 _server = DEFAULT_ACCOUNT_SERVER;
00049 _protocol = DEFAULT_ACCOUNT_PROTOCOL;
00050 _port = DEFAULT_ACCOUNT_PORT_POP3;
00051 _user = DEFAULT_ACCOUNT_USER;
00052 _password = DEFAULT_ACCOUNT_PASSWORD;
00053 _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
00054 _active = DEFAULT_ACCOUNT_ACTIVE;
00055 _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER;
00056
00057
00058 config = KGlobal::config();
00059
00060
00061 KIcon picIcon = KIcon( KStandardDirs::locate( "data", "kshowmail/pics/account.svgz" ) );
00062 setIcon( 0, picIcon );
00063 }
00064
00065 void AccountSetupItem::setAccountName( const QString & name )
00066 {
00067 _account = name;
00068 }
00069
00070 QString AccountSetupItem::getAccountName( ) const
00071 {
00072 return _account;
00073 }
00074
00075 void AccountSetupItem::setServer( const QString & server )
00076 {
00077 _server = server;
00078 }
00079
00080 QString AccountSetupItem::getServer( ) const
00081 {
00082 return _server;
00083 }
00084
00085 void AccountSetupItem::setProtocol( const QString & protocol )
00086 {
00087 _protocol = protocol;
00088 }
00089
00090 QString AccountSetupItem::getProtocol( ) const
00091 {
00092 return _protocol;
00093 }
00094
00095 void AccountSetupItem::setPort( int port )
00096 {
00097 if( port >= 0 && port <= 65535 )
00098 _port = port;
00099 else
00100 _port = DEFAULT_ACCOUNT_PORT_POP3;
00101 }
00102
00103 int AccountSetupItem::getPort( ) const
00104 {
00105 return _port;
00106 }
00107
00108 void AccountSetupItem::setUser( const QString & user )
00109 {
00110 _user = user;
00111 }
00112
00113 QString AccountSetupItem::getUser( ) const
00114 {
00115 return _user;
00116 }
00117
00118 void AccountSetupItem::setPassword( const QString & password )
00119 {
00120 _password = password;
00121 }
00122
00123 QString AccountSetupItem::getPassword( ) const
00124 {
00125 return _password;
00126 }
00127
00128 void AccountSetupItem::setPasswordStorageType( int type )
00129 {
00130 if( type == CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
00131 _passwordStorage = type;
00132 else
00133 _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
00134 }
00135
00136 int AccountSetupItem::getPasswordStorageType( ) const
00137 {
00138 return _passwordStorage;
00139 }
00140
00141 void AccountSetupItem::setActive( bool active )
00142 {
00143 _active = active;
00144 }
00145
00146 bool AccountSetupItem::getActive( ) const
00147 {
00148 return _active;
00149 }
00150
00151 void AccountSetupItem::save() const
00152 {
00153 KConfigGroup* accountConfig = new KConfigGroup( config, getAccountName() );
00154
00155 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_NAME, getAccountName() );
00156 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_SERVER, getServer() );
00157 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, getProtocol().toUpper() );
00158 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_PORT, getPort() );
00159 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_USER, getUser() );
00160 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, getPasswordStorageType() );
00161
00162
00163 KUrl url;
00164 url.setUser( getUser() );
00165 url.setHost( getServer() );
00166 url.setPass( getPassword() );
00167
00168 if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE )
00169 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, crypt( url ) );
00170 else
00171 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, QVariant() );
00172
00173
00174 if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
00175 KWalletAccess::savePassword( getAccountName(), getPassword() );
00176
00177 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, getActive() );
00178 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, getTransferSecurity() );
00179 accountConfig->writeEntry( CONFIG_ENTRY_ACCOUNT_ALLOW_UNSECURE_LOGIN, getUnsecureLoginAllowed() );
00180
00181 }
00182
00183 void AccountSetupItem::load( )
00184 {
00185 KConfigGroup* accountConfig = new KConfigGroup( config, getAccountName() );
00186
00187 _server = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_SERVER, DEFAULT_ACCOUNT_SERVER );
00188 _protocol = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, DEFAULT_ACCOUNT_PROTOCOL );
00189 _port = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_PORT, DEFAULT_ACCOUNT_PORT_POP3 );
00190 _user = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_USER, DEFAULT_ACCOUNT_USER );
00191 _passwordStorage = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00192
00193 if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE )
00194 _password = decrypt( accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, DEFAULT_ACCOUNT_PASSWORD ) );
00195 else if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
00196 _password = KWalletAccess::getPassword( getAccountName() );
00197 else
00198 _password.clear();
00199
00200 _active = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, DEFAULT_ACCOUNT_ACTIVE );
00201 _transferSecurity = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, DEFAULT_ACCOUNT_SECTRANSFER );
00202 _allowUnsecureLogin = accountConfig->readEntry( CONFIG_ENTRY_ACCOUNT_ALLOW_UNSECURE_LOGIN, DEFAULT_ACCOUNT_ALLOW_UNSECURE_LOGIN );
00203 }
00204
00205 void AccountSetupItem::setTransferSecurity( int type )
00206 {
00207 if( type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS )
00208 _transferSecurity = type;
00209 else
00210 _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER;
00211 }
00212
00213 int AccountSetupItem::getTransferSecurity( ) const
00214 {
00215 return _transferSecurity;
00216 }
00217
00218 void AccountSetupItem::print()
00219 {
00220 kDebug() << "Account Name: " << getAccountName() << endl;
00221 kDebug() << "Server: " << getServer() << endl;
00222 kDebug() << "Port: " << getPort() << endl;
00223 kDebug() << "Protocol: " << getProtocol() << endl;
00224 kDebug() << "User: " << getUser() << endl;
00225 kDebug() << "Password: " << getPassword() << endl;
00226
00227 switch( getPasswordStorageType() )
00228 {
00229 case CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE :
00230 kDebug() << "Password Storage: Don't Save" << endl; break;
00231
00232 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE :
00233 kDebug() << "Password Storage: File" << endl; break;
00234
00235 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET :
00236 kDebug() << "Password Storage: KWallet" << endl; break;
00237
00238 default :
00239 kDebug() << "unknown" << endl; break;
00240 }
00241
00242 kDebug() << "Active: " << getActive() << endl;
00243
00244 switch( getTransferSecurity() )
00245 {
00246 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE :
00247 kDebug() << "Transfer Security: None" << endl; break;
00248
00249 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL :
00250 kDebug() << "Transfer Security: SSL" << endl; break;
00251
00252 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS :
00253 kDebug() << "Transfer Security: TLS" << endl; break;
00254
00255 default :
00256 kDebug() << "Transfer Security: unknwon" << endl; break;
00257
00258 }
00259 }
00260
00261 void AccountSetupItem::setUnsecureLoginAllowed(bool allowed)
00262 {
00263 _allowUnsecureLogin = allowed;
00264 }
00265
00266 bool AccountSetupItem::getUnsecureLoginAllowed() const
00267 {
00268 return _allowUnsecureLogin;
00269 }
00270
00271
00272