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.

138 lines
3.4KB

  1. //
  2. // C++ Implementation: tdewalletaccess
  3. //
  4. // Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
  5. //
  6. // Copyright: See COPYING file that comes with this distribution
  7. //
  8. //
  9. #include "tdewalletaccess.h"
  10. bool TDEWalletAccess::savePassword( const TQString & account, const TQString & password )
  11. {
  12. //check for enabled TDEWallet
  13. if( !TDEWallet::Wallet::isEnabled() )
  14. {
  15. KMessageBox::error( NULL, i18n( "TDEWallet is not available." ) );
  16. return false;
  17. }
  18. //get wallet name for network data
  19. TQString name = TDEWallet::Wallet::NetworkWallet();
  20. if( name == "" || name == TQString::null )
  21. {
  22. KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from TDEWallet." ) );
  23. return false;
  24. }
  25. //open wallet
  26. //we want to create a connection object just at first call of this function
  27. static TDEWallet::Wallet* wallet;
  28. if( wallet == NULL )
  29. {
  30. wallet = TDEWallet::Wallet::openWallet( name );
  31. }
  32. else if( !wallet->isOpen() )
  33. {
  34. delete wallet;
  35. wallet = TDEWallet::Wallet::openWallet( name );
  36. }
  37. if( wallet == NULL )
  38. {
  39. KMessageBox::error( NULL, i18n( "Could not open TDEWallet." ) );
  40. return false;
  41. }
  42. //create kshowmail folder if it does not exist
  43. if( !wallet->hasFolder( "KShowmail" ) )
  44. {
  45. bool createFolderSuccess = wallet->createFolder( "KShowmail" );
  46. if( !createFolderSuccess )
  47. {
  48. KMessageBox::error( NULL, i18n( "Could not create folder for KShowmail in TDEWallet." ) );
  49. return false;
  50. }
  51. }
  52. //set folder
  53. bool setFolderSuccess = wallet->setFolder( "KShowmail" );
  54. if( !setFolderSuccess )
  55. {
  56. KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in TDEWallet." ) );
  57. return false;
  58. }
  59. //write password
  60. int writePasswordSuccess = wallet->writePassword( account, password );
  61. if( writePasswordSuccess != 0 )
  62. {
  63. KMessageBox::error( NULL, i18n( "Could not save password in TDEWallet." ) );
  64. return false;
  65. }
  66. return true;
  67. }
  68. TQString TDEWalletAccess::getPassword( const TQString & account )
  69. {
  70. //check for enabled TDEWallet
  71. if( !TDEWallet::Wallet::isEnabled() )
  72. {
  73. KMessageBox::error( NULL, i18n( "TDEWallet is not available." ) );
  74. return TQString::null;
  75. }
  76. //get wallet name for network data
  77. TQString name = TDEWallet::Wallet::NetworkWallet();
  78. if( name == "" || name == TQString::null )
  79. {
  80. KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from TDEWallet." ) );
  81. return TQString::null;
  82. }
  83. //open wallet
  84. //we want to create a connection object just at first call of this function
  85. static TDEWallet::Wallet* wallet;
  86. if( wallet == NULL )
  87. {
  88. wallet = TDEWallet::Wallet::openWallet( name );
  89. }
  90. else if( !wallet->isOpen() )
  91. {
  92. delete wallet;
  93. wallet = TDEWallet::Wallet::openWallet( name );
  94. }
  95. if( wallet == NULL )
  96. {
  97. KMessageBox::error( NULL, i18n( "Could not open TDEWallet." ) );
  98. return TQString::null;
  99. }
  100. //set folder
  101. bool setFolderSuccess = wallet->setFolder( "KShowmail" );
  102. if( !setFolderSuccess )
  103. {
  104. KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in TDEWallet." ) );
  105. return TQString::null;
  106. }
  107. //read password
  108. TQString password;
  109. int readPasswordSuccess = wallet->readPassword( account, password );
  110. if( readPasswordSuccess != 0 )
  111. {
  112. KMessageBox::error( NULL, i18n( "Could not get password of account %1 from TDEWallet." ).arg( account) );
  113. return TQString::null;
  114. }
  115. return password;
  116. }