Implemented remote credential storage via qtkeychain

Imported qtkeychain

FossilOrigin-Name: 7c068aa8acdae1b86dee004d2d4cd7fb42904186
This commit is contained in:
kostas
2015-05-25 14:03:38 +00:00
parent 86af187c23
commit e6fa4062d0
29 changed files with 2844 additions and 18 deletions

View File

@@ -2,6 +2,9 @@
#include <QMessageBox>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QEventLoop>
#include "ext/qtkeychain/keychain.h"
#define KEYCHAIN_ROOT "Fuel-SCM"
///////////////////////////////////////////////////////////////////////////////
QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, const QString &query, QMessageBox::StandardButtons buttons)
@@ -388,4 +391,56 @@ void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel
Q_ASSERT(item);
BuildNameToModelIndex(map, *item);
}
}
}
//------------------------------------------------------------------------------
bool KeychainSet(QObject *parent, const QUrl &url)
{
QEventLoop loop(parent);
QKeychain::WritePasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
job.setAutoDelete( false );
job.setInsecureFallback(false);
job.setKey(url.userName());
job.setTextData(url.password());
job.start();
loop.exec();
return job.error() == QKeychain::NoError;
}
//------------------------------------------------------------------------------
bool KeychainGet(QObject *parent, QUrl &url)
{
QEventLoop loop(parent);
QKeychain::ReadPasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()));
job.setAutoDelete( false );
job.setInsecureFallback(false);
job.setAutoDelete( false );
job.setKey(url.userName());
job.start();
loop.exec();
if(job.error() != QKeychain::NoError)
return false;
url.setUserName(job.key());
url.setPassword(job.textData());
return true;
}
//------------------------------------------------------------------------------
bool KeychainDelete(QObject* parent, const QUrl& url)
{
QEventLoop loop(parent);
QKeychain::DeletePasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()));
job.setAutoDelete( false );
job.setInsecureFallback(false);
job.setAutoDelete( false );
job.setKey(url.userName());
job.start();
loop.exec();
return job.error() == QKeychain::NoError;
}