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.4 KiB
138 lines
3.4 KiB
11 years ago
|
//
|
||
11 years ago
|
// C++ Implementation: tdewalletaccess
|
||
11 years ago
|
//
|
||
|
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
|
||
|
//
|
||
|
// Copyright: See COPYING file that comes with this distribution
|
||
|
//
|
||
|
//
|
||
11 years ago
|
#include "tdewalletaccess.h"
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
bool KWalletAccess::savePassword( const TQString & account, const TQString & password )
|
||
11 years ago
|
{
|
||
|
//check for enabled KWallet
|
||
|
if( !KWallet::Wallet::isEnabled() )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "KWallet is not available." ) );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//get wallet name for network data
|
||
11 years ago
|
TQString name = KWallet::Wallet::NetworkWallet();
|
||
|
if( name == "" || name == TQString::null )
|
||
11 years ago
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from KWallet." ) );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//open wallet
|
||
|
//we want to create a connection object just at first call of this function
|
||
|
static KWallet::Wallet* wallet;
|
||
|
|
||
|
if( wallet == NULL )
|
||
|
{
|
||
|
wallet = KWallet::Wallet::openWallet( name );
|
||
|
}
|
||
|
else if( !wallet->isOpen() )
|
||
|
{
|
||
|
delete wallet;
|
||
|
wallet = KWallet::Wallet::openWallet( name );
|
||
|
}
|
||
|
|
||
|
if( wallet == NULL )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not open KWallet." ) );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//create kshowmail folder if it does not exist
|
||
|
if( !wallet->hasFolder( "KShowmail" ) )
|
||
|
{
|
||
|
bool createFolderSuccess = wallet->createFolder( "KShowmail" );
|
||
|
|
||
|
if( !createFolderSuccess )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not create folder for KShowmail in KWallet." ) );
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//set folder
|
||
|
bool setFolderSuccess = wallet->setFolder( "KShowmail" );
|
||
|
if( !setFolderSuccess )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in KWallet." ) );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//write password
|
||
|
int writePasswordSuccess = wallet->writePassword( account, password );
|
||
|
if( writePasswordSuccess != 0 )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not save password in KWallet." ) );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
11 years ago
|
TQString KWalletAccess::getPassword( const TQString & account )
|
||
11 years ago
|
{
|
||
|
//check for enabled KWallet
|
||
|
if( !KWallet::Wallet::isEnabled() )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "KWallet is not available." ) );
|
||
11 years ago
|
return TQString::null;
|
||
11 years ago
|
}
|
||
|
|
||
|
//get wallet name for network data
|
||
11 years ago
|
TQString name = KWallet::Wallet::NetworkWallet();
|
||
|
if( name == "" || name == TQString::null )
|
||
11 years ago
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from KWallet." ) );
|
||
11 years ago
|
return TQString::null;
|
||
11 years ago
|
}
|
||
|
|
||
|
//open wallet
|
||
|
//we want to create a connection object just at first call of this function
|
||
|
static KWallet::Wallet* wallet;
|
||
|
|
||
|
if( wallet == NULL )
|
||
|
{
|
||
|
wallet = KWallet::Wallet::openWallet( name );
|
||
|
}
|
||
|
else if( !wallet->isOpen() )
|
||
|
{
|
||
|
delete wallet;
|
||
|
wallet = KWallet::Wallet::openWallet( name );
|
||
|
}
|
||
|
|
||
|
if( wallet == NULL )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not open KWallet." ) );
|
||
11 years ago
|
return TQString::null;
|
||
11 years ago
|
}
|
||
|
|
||
|
//set folder
|
||
|
bool setFolderSuccess = wallet->setFolder( "KShowmail" );
|
||
|
if( !setFolderSuccess )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in KWallet." ) );
|
||
11 years ago
|
return TQString::null;
|
||
11 years ago
|
}
|
||
|
|
||
|
//read password
|
||
11 years ago
|
TQString password;
|
||
11 years ago
|
|
||
|
int readPasswordSuccess = wallet->readPassword( account, password );
|
||
|
if( readPasswordSuccess != 0 )
|
||
|
{
|
||
|
KMessageBox::error( NULL, i18n( "Could not get password of account %1 from KWallet." ).arg( account) );
|
||
11 years ago
|
return TQString::null;
|
||
11 years ago
|
}
|
||
|
|
||
|
return password;
|
||
|
}
|