mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +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
97a613c89a
commit
6a258adc31
|
@ -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,14 +172,14 @@ 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()
|
||||||
{
|
{
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
mApp->desktopNotifications()->showNotification(KDEFrameworksIntegrationPlugin::tr("KWallet disabled"), KDEFrameworksIntegrationPlugin::tr("Please enable KWallet to save password."));
|
mApp->desktopNotifications()->showNotification(KDEFrameworksIntegrationPlugin::tr("KWallet disabled"), KDEFrameworksIntegrationPlugin::tr("Please enable KWallet to save password."));
|
||||||
|
@ -201,56 +204,83 @@ 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("Falkon")) {
|
||||||
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
migration = true;
|
||||||
|
}
|
||||||
|
else if (migrateQupzilla) {
|
||||||
if (!m_wallet->setFolder("QupZilla")) {
|
if (!m_wallet->setFolder("QupZilla")) {
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
migration = true;
|
||||||
if (!m_wallet->setFolder("Falkon")) {
|
}
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
else {
|
||||||
|
if (!m_wallet->setFolder("FalkonPasswords")) {
|
||||||
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"FalkonPasswords\"!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QByteArray> entries;
|
if (migration) {
|
||||||
bool ok = false;
|
QMap<QString, QByteArray> entries;
|
||||||
#if KWALLET_VERSION < QT_VERSION_CHECK(5, 72, 0)
|
bool ok = false;
|
||||||
ok = m_wallet->readEntryList("*", entries) == 0;
|
entries = m_wallet->entriesList(&ok);
|
||||||
#else
|
if (!ok) {
|
||||||
entries = m_wallet->entriesList(&ok);
|
qWarning() << "KWalletPasswordBackend::initialize Cannot read entries!";
|
||||||
#endif
|
return;
|
||||||
if (!ok) {
|
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot read entries!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QByteArray>::const_iterator i = entries.constBegin();
|
|
||||||
while (i != entries.constEnd()) {
|
|
||||||
PasswordEntry entry = decodeEntry(i.value());
|
|
||||||
if (entry.isValid()) {
|
|
||||||
m_allEntries.append(entry);
|
|
||||||
}
|
}
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (migrate) {
|
QMap<QString, QByteArray>::const_iterator i = entries.constBegin();
|
||||||
if (!m_wallet->setFolder("Falkon")) {
|
while (i != entries.constEnd()) {
|
||||||
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"Falkon\"!";
|
PasswordEntry entry = decodeEntry(i.value());
|
||||||
|
if (entry.isValid()) {
|
||||||
|
m_allEntries.append(entry);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_wallet->setFolder("FalkonPasswords")) {
|
||||||
|
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"FalkonPasswords\"!";
|
||||||
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