mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
KWallet: Store passwords entries in map fortmat
BUG: 391298 FIXED-IN: 23.04.0 Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
b0606740e3
commit
52ae23a36b
@ -34,11 +34,14 @@ static PasswordEntry decodeEntry(const QByteArray &data)
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray encodeEntry(const PasswordEntry &entry)
|
static QMap<QString, QString> encodeEntry(const PasswordEntry &entry)
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QMap<QString, QString> data = {
|
||||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
{"host", entry.host},
|
||||||
stream << entry;
|
{"username", entry.username},
|
||||||
|
{"password", entry.password},
|
||||||
|
{"data", QString::fromUtf8(entry.data)}
|
||||||
|
};
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +96,7 @@ void KWalletPasswordBackend::addEntry(const PasswordEntry &entry)
|
|||||||
stored.id = QString("%1/%2").arg(entry.host, entry.username);
|
stored.id = QString("%1/%2").arg(entry.host, entry.username);
|
||||||
stored.updated = QDateTime::currentDateTime().toTime_t();
|
stored.updated = QDateTime::currentDateTime().toTime_t();
|
||||||
|
|
||||||
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
|
m_wallet->writeMap(stored.id.toString(), encodeEntry(stored));
|
||||||
m_allEntries.append(stored);
|
m_allEntries.append(stored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +110,7 @@ bool KWalletPasswordBackend::updateEntry(const PasswordEntry &entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_wallet->removeEntry(entry.id.toString());
|
m_wallet->removeEntry(entry.id.toString());
|
||||||
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
m_wallet->writeMap(entry.id.toString(), encodeEntry(entry));
|
||||||
|
|
||||||
int index = m_allEntries.indexOf(entry);
|
int index = m_allEntries.indexOf(entry);
|
||||||
|
|
||||||
@ -131,7 +134,7 @@ void KWalletPasswordBackend::updateLastUsed(PasswordEntry &entry)
|
|||||||
|
|
||||||
entry.updated = QDateTime::currentDateTime().toTime_t();
|
entry.updated = QDateTime::currentDateTime().toTime_t();
|
||||||
|
|
||||||
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
m_wallet->writeMap(entry.id.toString(), encodeEntry(entry));
|
||||||
|
|
||||||
int index = m_allEntries.indexOf(entry);
|
int index = m_allEntries.indexOf(entry);
|
||||||
|
|
||||||
@ -169,8 +172,8 @@ void KWalletPasswordBackend::removeAll()
|
|||||||
|
|
||||||
m_allEntries.clear();
|
m_allEntries.clear();
|
||||||
|
|
||||||
m_wallet->removeFolder("Falkon");
|
m_wallet->removeFolder("FalkonPasswords");
|
||||||
m_wallet->createFolder("Falkon");
|
m_wallet->createFolder("FalkonPasswords");
|
||||||
}
|
}
|
||||||
|
|
||||||
void KWalletPasswordBackend::showErrorNotification()
|
void KWalletPasswordBackend::showErrorNotification()
|
||||||
@ -201,32 +204,40 @@ void KWalletPasswordBackend::initialize()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool migrate = !m_wallet->hasFolder("Falkon") && m_wallet->hasFolder("QupZilla");
|
bool migrationFalkon = !m_wallet->hasFolder("FalkonPasswords") && m_wallet->hasFolder("Falkon");
|
||||||
|
bool migrateQupzilla = !m_wallet->hasFolder("FalkonPasswords") && !m_wallet->hasFolder("Falkon") && m_wallet->hasFolder("QupZilla");
|
||||||
|
bool migration = false;
|
||||||
|
|
||||||
if (!m_wallet->hasFolder("Falkon") && !m_wallet->createFolder("Falkon")) {
|
if (!m_wallet->hasFolder("FalkonPasswords") && !m_wallet->createFolder("FalkonPasswords")) {
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot create folder \"Falkon\"!";
|
qWarning() << "KWalletPasswordBackend::initialize Cannot create folder \"FalkonPasswords\"!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migrate) {
|
if (migrationFalkon) {
|
||||||
if (!m_wallet->setFolder("QupZilla")) {
|
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!m_wallet->setFolder("Falkon")) {
|
if (!m_wallet->setFolder("Falkon")) {
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
migration = true;
|
||||||
|
}
|
||||||
|
else if (migrateQupzilla) {
|
||||||
|
if (!m_wallet->setFolder("QupZilla")) {
|
||||||
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
migration = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!m_wallet->setFolder("FalkonPasswords")) {
|
||||||
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"FalkonPasswords\"!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (migration) {
|
||||||
QMap<QString, QByteArray> entries;
|
QMap<QString, QByteArray> entries;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
#if KWALLET_VERSION < QT_VERSION_CHECK(5, 72, 0)
|
|
||||||
ok = m_wallet->readEntryList("*", entries) == 0;
|
|
||||||
#else
|
|
||||||
entries = m_wallet->entriesList(&ok);
|
entries = m_wallet->entriesList(&ok);
|
||||||
#endif
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot read entries!";
|
qWarning() << "KWalletPasswordBackend::initialize Cannot read entries!";
|
||||||
return;
|
return;
|
||||||
@ -241,16 +252,35 @@ void KWalletPasswordBackend::initialize()
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migrate) {
|
if (!m_wallet->setFolder("FalkonPasswords")) {
|
||||||
if (!m_wallet->setFolder("Falkon")) {
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"FalkonPasswords\"!";
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const PasswordEntry &entry : qAsConst(m_allEntries)) {
|
for (const PasswordEntry &entry : qAsConst(m_allEntries)) {
|
||||||
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
|
m_wallet->writeMap(entry.id.toString(), encodeEntry(entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
QMap<QString, QMap<QString, QString>> entriesMap;
|
||||||
|
bool ok = false;
|
||||||
|
entriesMap = m_wallet->mapList(&ok);
|
||||||
|
QMap<QString, QMap<QString, QString>>::const_iterator j = entriesMap.constBegin();
|
||||||
|
while (j != entriesMap.constEnd()) {
|
||||||
|
PasswordEntry entry;
|
||||||
|
entry.id = j.key();
|
||||||
|
entry.host = j.value()["host"];
|
||||||
|
entry.username = j.value()["username"];
|
||||||
|
entry.password = j.value()["password"];
|
||||||
|
entry.data = j.value()["data"].toUtf8();
|
||||||
|
if (entry.isValid()) {
|
||||||
|
m_allEntries.append(entry);
|
||||||
|
}
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KWalletPasswordBackend::~KWalletPasswordBackend()
|
KWalletPasswordBackend::~KWalletPasswordBackend()
|
||||||
|
Loading…
Reference in New Issue
Block a user