Skip to content

Commit

Permalink
check available wallets at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Dec 8, 2024
1 parent b6748c3 commit 8f4c9fe
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 53 deletions.
58 changes: 31 additions & 27 deletions src/favorites2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ favorites2::favorites2( QWidget * parent,
m_ui->rbLibSecret->setEnabled( false ) ;
m_ui->rbMacOSKeyChain->setEnabled( false ) ;
m_ui->rbWindowsDPAPI->setEnabled( false ) ;
m_ui->rbInternalWallet->setEnabled( LXQt::Wallet::backEndIsSupported( bk::libsecret ) ) ;
m_ui->rbInternalWallet->setEnabled( false ) ;

auto walletBk = m_settings.autoMountBackEnd() ;

Expand Down Expand Up @@ -1716,7 +1716,7 @@ void favorites2::setDefaultUI( const engines::engine& engine )

if( engine.usesOnlyMountPoint() ){

m_ui->pbFolderPath->setIcon( QIcon( ":/icons/folder.png" ) ) ;
m_ui->pbFolderPath->setIcon( QIcon( ":/icons/folder.png" ) ) ;

m_ui->pbFolderPath->setObjectName( "FolderHandle" ) ;
m_ui->labelName->setText( tr( "Mount Point Path" ) ) ;
Expand All @@ -1729,7 +1729,7 @@ void favorites2::setDefaultUI( const engines::engine& engine )

m_ui->pbFolderPath->setObjectName( "FileHandle" ) ;

m_ui->pbFolderPath->setIcon( QIcon( ":/icons/file.png" ) ) ;
m_ui->pbFolderPath->setIcon( QIcon( ":/icons/file.png" ) ) ;

m_ui->labelName ->setText( tr( "File Path" ) ) ;

Expand Down Expand Up @@ -1805,10 +1805,10 @@ void favorites2::walletOpts::setActive( favorites2 * m )
{
m_parent = m ;

if( m_set ){
this->setStatus() ;

if( !m_set ){

this->setStatus( m_status ) ;
}else{
this->getStatus() ;
}
}
Expand All @@ -1823,39 +1823,43 @@ void favorites2::walletOpts::checkAvaibale()
this->setActive( nullptr ) ;
}

void favorites2::walletOpts::setStatus( const favorites2::walletOpts::status& s )
{
m_status = s ;

if( m_parent ){

m_parent->m_ui->rbKWallet->setEnabled( m_status.m_kdeWallet ) ;
m_parent->m_ui->rbLibSecret->setEnabled( m_status.m_gnomeWallet ) ;
m_parent->m_ui->rbMacOSKeyChain->setEnabled( m_status.m_osxkeychain ) ;
m_parent->m_ui->rbWindowsDPAPI->setEnabled( m_status.m_windows_dpapi ) ;
}
}

void favorites2::walletOpts::getStatus()
{
Task::run( [ & ](){

return favorites2::walletOpts::status( 0 ) ;
using wbe = LXQt::Wallet::BackEnd ;

} ).then( [ & ]( const favorites2::walletOpts::status& s ){
return LXQt::Wallet::backEndIsSupported( wbe::kwallet ) ;

} ).then( [ & ]( bool s ){

m_set = true ;

this->setStatus( s ) ;
m_status.kdeWallet = s ;

this->setStatus() ;
} ) ;
}

favorites2::walletOpts::status::status( int )
void favorites2::walletOpts::setStatus()
{
if( m_parent ){

m_parent->m_ui->rbKWallet->setEnabled( m_status.kdeWallet ) ;
m_parent->m_ui->rbLibSecret->setEnabled( m_status.gnomeWallet ) ;
m_parent->m_ui->rbMacOSKeyChain->setEnabled( m_status.osxkeychain ) ;
m_parent->m_ui->rbWindowsDPAPI->setEnabled( m_status.windows_dpapi ) ;
m_parent->m_ui->rbInternalWallet->setEnabled( m_status.internal ) ;
}
}

favorites2::walletOpts::status::status()
{
using wbe = LXQt::Wallet::BackEnd ;

m_gnomeWallet = LXQt::Wallet::backEndIsSupported( wbe::libsecret ) ;
m_kdeWallet = LXQt::Wallet::backEndIsSupported( wbe::kwallet ) ;
m_osxkeychain = LXQt::Wallet::backEndIsSupported( wbe::osxkeychain ) ;
m_windows_dpapi = LXQt::Wallet::backEndIsSupported( wbe::windows_dpapi ) ;
gnomeWallet = LXQt::Wallet::backEndIsSupported( wbe::libsecret ) ;
osxkeychain = LXQt::Wallet::backEndIsSupported( wbe::osxkeychain ) ;
windows_dpapi = LXQt::Wallet::backEndIsSupported( wbe::windows_dpapi ) ;
internal = LXQt::Wallet::backEndIsSupported( wbe::internal ) ;
kdeWallet = false ;
}
34 changes: 23 additions & 11 deletions src/favorites2.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,42 @@ class favorites2 : public QDialog
class walletOpts
{
public:
struct status
{
status() ;
bool gnomeWallet;
bool kdeWallet ;
bool osxkeychain ;
bool windows_dpapi ;
bool internal ;
} ;
walletOpts() ;
void setActive( favorites2 * ) ;
void setInactive() ;
void checkAvaibale() ;
private:
struct status
template< typename Function >
void getAvailableWallets( const Function& function )
{
status() = default ;
status( int ) ;
bool m_gnomeWallet ;
bool m_kdeWallet ;
bool m_osxkeychain ;
bool m_windows_dpapi ;
} ;
void setStatus( const status& ) ;
function( utility::asConst( m_walletOpts.m_status ) ) ;
}
private:
void getStatus() ;
void setStatus() ;
bool m_set = false ;
status m_status ;
favorites2::walletOpts::status m_status ;
favorites2 * m_parent ;
} ;

template< typename Function >
static void getAvailableWallets( const Function& function )
{
m_walletOpts.getAvailableWallets( function ) ;
}

static void checkAvailableWallets() ;

static QString encodeKeyKeyFile( const QString&,const QString& ) ;

class credentials
{
public:
Expand Down
33 changes: 18 additions & 15 deletions src/keydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,30 +2080,33 @@ void keyDialog::keyType::keyOptions( QComboBox * s,keyDialog * object,void( keyD
this->addItem( keyType::name::yubikey,tr( "YubiKey Challenge/Response" ) ) ;
this->addItem( keyType::name::externalExecutable,tr( "ExternalExecutable" ) ) ;

if( LXQt::Wallet::backEndIsSupported( LXQt::Wallet::BackEnd::internal ) ){
favorites2::getAvailableWallets( [ this ]( const favorites2::walletOpts::status& s ){

this->addItem( keyType::name::internalWallet,tr( "Internal Wallet" ) ) ;
}
if( s.internal ){

if( LXQt::Wallet::backEndIsSupported( LXQt::Wallet::BackEnd::libsecret ) ){
this->addItem( keyType::name::internalWallet,tr( "Internal Wallet" ) ) ;
}

this->addItem( keyType::name::libsecret,tr( "Gnome Wallet" ) ) ;
}
if( s.gnomeWallet ){

if( LXQt::Wallet::backEndIsSupported( LXQt::Wallet::BackEnd::kwallet ) ){
this->addItem( keyType::name::libsecret,tr( "Gnome Wallet" ) ) ;
}

this->addItem( keyType::name::kdewallet,tr( "Kde Wallet" ) ) ;
}
if( s.kdeWallet ){

this->addItem( keyType::name::kdewallet,tr( "Kde Wallet" ) ) ;
}

if( LXQt::Wallet::backEndIsSupported( LXQt::Wallet::BackEnd::osxkeychain ) ){
if( s.osxkeychain ){

this->addItem( keyType::name::kdewallet,tr( "OSX KeyChain" ) ) ;
}
this->addItem( keyType::name::kdewallet,tr( "OSX KeyChain" ) ) ;
}

if( LXQt::Wallet::backEndIsSupported( LXQt::Wallet::BackEnd::windows_dpapi ) ){
if( s.windows_dpapi ){

this->addItem( keyType::name::windowsdpapi,tr( "Windows DPAPI" ) ) ;
}
this->addItem( keyType::name::windowsdpapi,tr( "Windows DPAPI" ) ) ;
}
} ) ;

this->setAsKey() ;

Expand Down

0 comments on commit 8f4c9fe

Please sign in to comment.