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.
kshowmail/kshowmail/tdewalletaccess.cpp

138 lines
3.4 KiB

//
// C++ Implementation: tdewalletaccess
//
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "tdewalletaccess.h"
bool KWalletAccess::savePassword( const TQString & account, const TQString & password )
{
//check for enabled KWallet
if( !KWallet::Wallet::isEnabled() )
{
KMessageBox::error( NULL, i18n( "KWallet is not available." ) );
return false;
}
//get wallet name for network data
TQString name = KWallet::Wallet::NetworkWallet();
if( name == "" || name == TQString::null )
{
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;
}
TQString KWalletAccess::getPassword( const TQString & account )
{
//check for enabled KWallet
if( !KWallet::Wallet::isEnabled() )
{
KMessageBox::error( NULL, i18n( "KWallet is not available." ) );
return TQString::null;
}
//get wallet name for network data
TQString name = KWallet::Wallet::NetworkWallet();
if( name == "" || name == TQString::null )
{
KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from KWallet." ) );
return TQString::null;
}
//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 TQString::null;
}
//set folder
bool setFolderSuccess = wallet->setFolder( "KShowmail" );
if( !setFolderSuccess )
{
KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in KWallet." ) );
return TQString::null;
}
//read password
TQString password;
int readPasswordSuccess = wallet->readPassword( account, password );
if( readPasswordSuccess != 0 )
{
KMessageBox::error( NULL, i18n( "Could not get password of account %1 from KWallet." ).arg( account) );
return TQString::null;
}
return password;
}