kutils: new KPasswdStore::stores() method to get all current stores

to be used by the KCM

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-20 00:14:23 +03:00
parent 581e3037cf
commit c311f7032f
2 changed files with 13 additions and 0 deletions

View file

@ -22,6 +22,7 @@
#include "kglobal.h" #include "kglobal.h"
#include "kstandarddirs.h" #include "kstandarddirs.h"
#include "klockfile.h" #include "klockfile.h"
#include "ksettings.h"
#include <QApplication> #include <QApplication>
#include <QDBusInterface> #include <QDBusInterface>
@ -146,6 +147,13 @@ bool KPasswdStore::storePasswd(const QByteArray &key, const QString &passwd, con
return result.value(); return result.value();
} }
QStringList KPasswdStore::stores()
{
KSettings passwdstore(KStandardDirs::locateLocal("data", "kpasswdstore.ini"), KSettings::SimpleConfig);
passwdstore.beginGroup("KPasswdStore");
return passwdstore.groupKeys();
}
QByteArray KPasswdStore::makeKey(const QString &string) QByteArray KPasswdStore::makeKey(const QString &string)
{ {
return QCryptographicHash::hash(string.toUtf8(), QCryptographicHash::KAT).toHex(); return QCryptographicHash::hash(string.toUtf8(), QCryptographicHash::KAT).toHex();

View file

@ -107,6 +107,11 @@ public:
*/ */
static QByteArray makeKey(const QString &string); static QByteArray makeKey(const QString &string);
/*!
@brief Returns all current password stores
*/
static QStringList stores();
private: private:
Q_DISABLE_COPY(KPasswdStore); Q_DISABLE_COPY(KPasswdStore);
KPasswdStorePrivate *d; KPasswdStorePrivate *d;