KShowMail – show mails on a POP3 server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
5.3KB

  1. //
  2. // C++ Implementation: accountsetupitem
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. #include "accountsetupitem.h"
  13. AccountSetupItem::AccountSetupItem( TDEListView* parent )
  14. : TDEListViewItem( parent )
  15. {
  16. init();
  17. }
  18. AccountSetupItem::AccountSetupItem( TDEListView * parent, TQString & name )
  19. : TDEListViewItem( parent )
  20. {
  21. init();
  22. //save account name
  23. _account = name;
  24. //set column text
  25. setText( 0, getAccountName() );
  26. }
  27. AccountSetupItem::~AccountSetupItem()
  28. {
  29. }
  30. void AccountSetupItem::init( )
  31. {
  32. //set default values
  33. _account = DEFAULT_ACCOUNT_NAME;
  34. _server = DEFAULT_ACCOUNT_SERVER;
  35. _protocol = DEFAULT_ACCOUNT_PROTOCOL;
  36. _port = DEFAULT_ACCOUNT_PORT_POP3;
  37. _user = DEFAULT_ACCOUNT_USER;
  38. _password = DEFAULT_ACCOUNT_PASSWORD;
  39. _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
  40. _active = DEFAULT_ACCOUNT_ACTIVE;
  41. _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER;
  42. //get application config object (kshowmailrc)
  43. config = TDEApplication::kApplication()->config();
  44. }
  45. void AccountSetupItem::setAccountName( const TQString & name )
  46. {
  47. _account = name;
  48. }
  49. TQString AccountSetupItem::getAccountName( ) const
  50. {
  51. return _account;
  52. }
  53. void AccountSetupItem::setServer( const TQString & server )
  54. {
  55. _server = server;
  56. }
  57. TQString AccountSetupItem::getServer( ) const
  58. {
  59. return _server;
  60. }
  61. void AccountSetupItem::setProtocol( const TQString & protocol )
  62. {
  63. _protocol = protocol;
  64. }
  65. TQString AccountSetupItem::getProtocol( ) const
  66. {
  67. return _protocol;
  68. }
  69. void AccountSetupItem::setPort( int port )
  70. {
  71. if( port >= 0 && port <= 65535 )
  72. _port = port;
  73. else
  74. _port = DEFAULT_ACCOUNT_PORT_POP3;
  75. }
  76. int AccountSetupItem::getPort( ) const
  77. {
  78. return _port;
  79. }
  80. void AccountSetupItem::setUser( const TQString & user )
  81. {
  82. _user = user;
  83. }
  84. TQString AccountSetupItem::getUser( ) const
  85. {
  86. return _user;
  87. }
  88. void AccountSetupItem::setPassword( const TQString & password )
  89. {
  90. _password = password;
  91. }
  92. TQString AccountSetupItem::getPassword( ) const
  93. {
  94. return _password;
  95. }
  96. void AccountSetupItem::setPasswordStorageType( int type )
  97. {
  98. if( type == CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
  99. _passwordStorage = type;
  100. else
  101. _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
  102. }
  103. int AccountSetupItem::getPasswordStorageType( ) const
  104. {
  105. return _passwordStorage;
  106. }
  107. void AccountSetupItem::setActive( bool active )
  108. {
  109. _active = active;
  110. }
  111. bool AccountSetupItem::getActive( ) const
  112. {
  113. return _active;
  114. }
  115. void AccountSetupItem::save() const
  116. {
  117. config->setGroup( getAccountName() );
  118. config->writeEntry( CONFIG_ENTRY_ACCOUNT_NAME, getAccountName() );
  119. config->writeEntry( CONFIG_ENTRY_ACCOUNT_SERVER, getServer() );
  120. config->writeEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, getProtocol().upper() );
  121. config->writeEntry( CONFIG_ENTRY_ACCOUNT_PORT, getPort() );
  122. config->writeEntry( CONFIG_ENTRY_ACCOUNT_USER, getUser() );
  123. config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, getPasswordStorageType() );
  124. //save crypted password
  125. KURL url;
  126. url.setUser( getUser() );
  127. url.setHost( getServer() );
  128. url.setPass( getPassword() );
  129. if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE )
  130. config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, crypt( url ) );
  131. else
  132. config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, TQString::null );
  133. //save password in TDEWallet if desired
  134. if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
  135. TDEWalletAccess::savePassword( getAccountName(), getPassword() );
  136. config->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, getActive() );
  137. config->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, getTransferSecurity() );
  138. }
  139. void AccountSetupItem::load( )
  140. {
  141. config->setGroup( getAccountName() );
  142. _server = config->readEntry( CONFIG_ENTRY_ACCOUNT_SERVER, DEFAULT_ACCOUNT_SERVER );
  143. _protocol = config->readEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, DEFAULT_ACCOUNT_PROTOCOL );
  144. _port = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PORT, DEFAULT_ACCOUNT_PORT_POP3 );
  145. _user = config->readEntry( CONFIG_ENTRY_ACCOUNT_USER, DEFAULT_ACCOUNT_USER );
  146. _passwordStorage = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, DEFAULT_ACCOUNT_PASSWORD_STORAGE );
  147. if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE )
  148. _password = decrypt( config->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, DEFAULT_ACCOUNT_PASSWORD ) );
  149. else if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
  150. _password = TDEWalletAccess::getPassword( getAccountName() );
  151. else
  152. _password = TQString::null;
  153. _active = config->readBoolEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, DEFAULT_ACCOUNT_ACTIVE );
  154. _transferSecurity = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, DEFAULT_ACCOUNT_SECTRANSFER );
  155. }
  156. void AccountSetupItem::setTransferSecurity( int type )
  157. {
  158. if( type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS )
  159. _transferSecurity = type;
  160. else
  161. _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER;
  162. }
  163. int AccountSetupItem::getTransferSecurity( ) const
  164. {
  165. return _transferSecurity;
  166. }