1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 04:19:55 +01:00

Tabs to spaces in the keychain source

This commit is contained in:
David Sansome 2011-02-18 20:14:01 +00:00
parent 43f55a7bcd
commit 6b9f41d6ae
7 changed files with 98 additions and 97 deletions

View File

@ -3,12 +3,12 @@
const QString DefaultKeychain::kImplementationName = "Default";
const QString DefaultKeychain::getPassword(const QString& account) {
Q_UNUSED(account);
return password_;
Q_UNUSED(account);
return password_;
}
bool DefaultKeychain::setPassword(const QString& account, const QString& password) {
Q_UNUSED(account);
password_ = password;
return true;
Q_UNUSED(account);
password_ = password;
return true;
}

View File

@ -5,15 +5,15 @@
class DefaultKeychain : public Keychain {
public:
virtual ~DefaultKeychain() {}
virtual bool isAvailable() { return true; }
virtual ~DefaultKeychain() {}
virtual bool isAvailable() { return true; }
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString& implementationName() const { return kImplementationName; }
virtual const QString& implementationName() const { return kImplementationName; }
static const QString kImplementationName;
static const QString kImplementationName;
private:
QString password_;
};

View File

@ -8,51 +8,51 @@
const QString GnomeKeychain::kImplementationName = "Gnome Keyring";
const GnomeKeyringPasswordSchema GnomeKeychain::kOurSchema = {
GNOME_KEYRING_ITEM_GENERIC_SECRET,
{
{ "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL },
},
GNOME_KEYRING_ITEM_GENERIC_SECRET,
{
{ "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL },
},
};
bool GnomeKeychain::isAvailable() {
return gnome_keyring_is_available();
return gnome_keyring_is_available();
}
const QString GnomeKeychain::getPassword(const QString& account) {
Q_ASSERT(isAvailable());
char* password;
GnomeKeyringResult result = gnome_keyring_find_password_sync(
&kOurSchema,
&password,
Q_ASSERT(isAvailable());
char* password;
GnomeKeyringResult result = gnome_keyring_find_password_sync(
&kOurSchema,
&password,
"username", account.toUtf8().constData(),
"service", kServiceName.toUtf8().constData(),
NULL);
if (result == GNOME_KEYRING_RESULT_OK) {
QString pass(password);
gnome_keyring_free_password(password);
return pass;
}
NULL);
if (result == GNOME_KEYRING_RESULT_OK) {
QString pass(password);
gnome_keyring_free_password(password);
return pass;
}
qWarning() << "Failed to get password from keychain for account" << account;
return QString::null;
return QString::null;
}
bool GnomeKeychain::setPassword(const QString& account, const QString& password) {
Q_ASSERT(isAvailable());
Q_ASSERT(isAvailable());
QString displayName = QString("%1 account for %2").arg(
QCoreApplication::applicationName(), account);
GnomeKeyringResult result = gnome_keyring_store_password_sync(
&kOurSchema,
NULL,
GnomeKeyringResult result = gnome_keyring_store_password_sync(
&kOurSchema,
NULL,
displayName.toUtf8().constData(),
password.toUtf8().constData(),
"username", account.toUtf8().constData(),
"service", kServiceName.toUtf8().constData(),
NULL);
return result == GNOME_KEYRING_RESULT_OK;
NULL);
return result == GNOME_KEYRING_RESULT_OK;
}

View File

@ -9,16 +9,16 @@ extern "C" {
class GnomeKeychain : public Keychain {
public:
virtual ~GnomeKeychain() {}
virtual bool isAvailable();
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual ~GnomeKeychain() {}
virtual bool isAvailable();
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString& implementationName() const { return kImplementationName; }
virtual const QString& implementationName() const { return kImplementationName; }
static const QString kImplementationName;
static const QString kImplementationName;
private:
static const GnomeKeyringPasswordSchema kOurSchema;
static const GnomeKeyringPasswordSchema kOurSchema;
};
#endif

View File

@ -9,51 +9,52 @@ const QString KWalletKeychain::kKWalletPath = "/modules/kwalletd";
const QString KWalletKeychain::kKWalletFolder = "Passwords";
KWalletKeychain::KWalletKeychain()
: kwallet_(kKWalletServiceName, kKWalletPath, QDBusConnection::sessionBus()) {
if (isAvailable()) {
QDBusPendingReply<QString> wallet_name = kwallet_.networkWallet();
wallet_name.waitForFinished();
if (wallet_name.isValid()) {
wallet_name_ = wallet_name.value();
QDBusPendingReply<int> open_request = kwallet_.open(wallet_name_, 0, kServiceName);
open_request.waitForFinished();
if (open_request.isValid()) {
handle_ = open_request.value();
}
}
}
: kwallet_(kKWalletServiceName, kKWalletPath, QDBusConnection::sessionBus())
{
if (isAvailable()) {
QDBusPendingReply<QString> wallet_name = kwallet_.networkWallet();
wallet_name.waitForFinished();
if (wallet_name.isValid()) {
wallet_name_ = wallet_name.value();
QDBusPendingReply<int> open_request = kwallet_.open(wallet_name_, 0, kServiceName);
open_request.waitForFinished();
if (open_request.isValid()) {
handle_ = open_request.value();
}
}
}
}
KWalletKeychain::~KWalletKeychain() {
}
bool KWalletKeychain::isAvailable() {
if(!kwallet_.isValid())
return false;
QDBusPendingReply<bool> check = kwallet_.isEnabled();
check.waitForFinished();
return check.isValid() && check.value();
if(!kwallet_.isValid())
return false;
QDBusPendingReply<bool> check = kwallet_.isEnabled();
check.waitForFinished();
return check.isValid() && check.value();
}
const QString KWalletKeychain::getPassword(const QString& account) {
QDBusPendingReply<QString> password =
kwallet_.readPassword(handle_, kKWalletFolder, account, kServiceName);
password.waitForFinished();
if (password.isValid()) {
return password.value();
}
QDBusPendingReply<QString> password =
kwallet_.readPassword(handle_, kKWalletFolder, account, kServiceName);
password.waitForFinished();
if (password.isValid()) {
return password.value();
}
return QString::null;
return QString::null;
}
bool KWalletKeychain::setPassword(const QString& account, const QString& password) {
QDBusPendingReply<int> ret =
kwallet_.writePassword(handle_, kKWalletFolder, account, password, kServiceName);
ret.waitForFinished();
if (ret.isValid() && ret.value() == 0) {
return true;
}
QDBusPendingReply<int> ret =
kwallet_.writePassword(handle_, kKWalletFolder, account, password, kServiceName);
ret.waitForFinished();
if (ret.isValid() && ret.value() == 0) {
return true;
}
return false;
return false;
}

View File

@ -7,25 +7,25 @@
class KWalletKeychain : public Keychain {
public:
KWalletKeychain();
virtual ~KWalletKeychain();
KWalletKeychain();
virtual ~KWalletKeychain();
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual bool isAvailable();
virtual bool isAvailable();
virtual const QString& implementationName() const { return kImplementationName; }
virtual const QString& implementationName() const { return kImplementationName; }
static const QString kImplementationName;
static const QString kImplementationName;
private:
org::kde::KWallet kwallet_;
QString wallet_name_;
int handle_;
org::kde::KWallet kwallet_;
QString wallet_name_;
int handle_;
static const QString kKWalletServiceName;
static const QString kKWalletPath;
static const QString kKWalletFolder;
static const QString kKWalletServiceName;
static const QString kKWalletPath;
static const QString kKWalletFolder;
};
#endif

View File

@ -5,15 +5,15 @@
class MacKeychain : public Keychain {
public:
virtual ~MacKeychain() {}
virtual bool isAvailable();
virtual ~MacKeychain() {}
virtual bool isAvailable();
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString getPassword(const QString& account);
virtual bool setPassword(const QString& account, const QString& password);
virtual const QString& implementationName() const { return kImplementationName; }
virtual const QString& implementationName() const { return kImplementationName; }
static const QString kImplementationName;
static const QString kImplementationName;
};
#endif