mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-12 11:32:32 -04:00
Fix renaming extension key name in Database Settings
This commit is contained in:
parent
af0c1644a6
commit
132ca42ec5
4 changed files with 31 additions and 14 deletions
|
@ -616,7 +616,7 @@ QString BrowserService::storeKey(const QString& key)
|
||||||
|
|
||||||
hideWindow();
|
hideWindow();
|
||||||
db->metadata()->customData()->set(CustomData::BrowserKeyPrefix + id, key);
|
db->metadata()->customData()->set(CustomData::BrowserKeyPrefix + id, key);
|
||||||
db->metadata()->customData()->set(QString("%1_%2").arg(CustomData::Created, id),
|
db->metadata()->customData()->set(QString("%1%2").arg(CustomData::Created, id),
|
||||||
QLocale::system().toString(Clock::currentDateTime(), QLocale::ShortFormat));
|
QLocale::system().toString(Clock::currentDateTime(), QLocale::ShortFormat));
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
#include "core/Global.h"
|
#include "core/Global.h"
|
||||||
|
|
||||||
const QString CustomData::LastModified = QStringLiteral("_LAST_MODIFIED");
|
const QString CustomData::LastModified = QStringLiteral("_LAST_MODIFIED");
|
||||||
const QString CustomData::Created = QStringLiteral("_CREATED");
|
const QString CustomData::Created = QStringLiteral("_CREATED_");
|
||||||
const QString CustomData::BrowserKeyPrefix = QStringLiteral("KPXC_BROWSER_");
|
const QString CustomData::BrowserKeyPrefix = QStringLiteral("KPXC_BROWSER_");
|
||||||
const QString CustomData::BrowserLegacyKeyPrefix = QStringLiteral("Public Key: ");
|
const QString CustomData::BrowserLegacyKeyPrefix = QStringLiteral("Public Key: ");
|
||||||
const QString CustomData::ExcludeFromReportsLegacy = QStringLiteral("KnownBad");
|
const QString CustomData::ExcludeFromReportsLegacy = QStringLiteral("KnownBad");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 KeePassXC Team <team@keepassxc.org>
|
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
|
||||||
* Copyright (C) 2018 Sami Vänttinen <sami.vanttinen@protonmail.com>
|
* Copyright (C) 2018 Sami Vänttinen <sami.vanttinen@protonmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -124,7 +124,7 @@ void DatabaseSettingsWidgetBrowser::updateModel()
|
||||||
if (key.startsWith(CustomData::BrowserKeyPrefix)) {
|
if (key.startsWith(CustomData::BrowserKeyPrefix)) {
|
||||||
QString strippedKey = key;
|
QString strippedKey = key;
|
||||||
strippedKey.remove(CustomData::BrowserKeyPrefix);
|
strippedKey.remove(CustomData::BrowserKeyPrefix);
|
||||||
auto created = customData()->value(QString("%1_%2").arg(CustomData::Created, strippedKey));
|
auto created = customData()->value(getKeyWithPrefix(CustomData::Created, strippedKey));
|
||||||
auto createdItem = new QStandardItem(created);
|
auto createdItem = new QStandardItem(created);
|
||||||
createdItem->setEditable(false);
|
createdItem->setEditable(false);
|
||||||
m_customDataModel->appendRow(QList<QStandardItem*>()
|
m_customDataModel->appendRow(QList<QStandardItem*>()
|
||||||
|
@ -267,18 +267,16 @@ void DatabaseSettingsWidgetBrowser::editFinished(QStandardItem* item)
|
||||||
|
|
||||||
if (itemSelectionModel) {
|
if (itemSelectionModel) {
|
||||||
auto indexList = itemSelectionModel->selectedRows(item->column());
|
auto indexList = itemSelectionModel->selectedRows(item->column());
|
||||||
if (indexList.length() > 0) {
|
if (!indexList.isEmpty()) {
|
||||||
QString newValue = item->index().data().toString();
|
auto newValue = item->index().data().toString();
|
||||||
|
|
||||||
// The key is edited
|
// The key is edited
|
||||||
if (item->column() == 0) {
|
if (item->column() == 0) {
|
||||||
// Get the old key/value pair, remove it and replace it
|
// Update created timestamp with the new key
|
||||||
m_valueInEdit.insert(0, CustomData::BrowserKeyPrefix);
|
replaceKey(CustomData::Created, m_valueInEdit, newValue);
|
||||||
auto tempValue = customData()->value(m_valueInEdit);
|
|
||||||
newValue.insert(0, CustomData::BrowserKeyPrefix);
|
|
||||||
|
|
||||||
m_db->metadata()->customData()->remove(m_valueInEdit);
|
// Get the old key/value pair, remove it and replace it
|
||||||
m_db->metadata()->customData()->set(newValue, tempValue);
|
replaceKey(CustomData::BrowserKeyPrefix, m_valueInEdit, newValue);
|
||||||
} else {
|
} else {
|
||||||
// Replace just the value
|
// Replace just the value
|
||||||
for (const QString& key : m_db->metadata()->customData()->keys()) {
|
for (const QString& key : m_db->metadata()->customData()->keys()) {
|
||||||
|
@ -301,3 +299,20 @@ void DatabaseSettingsWidgetBrowser::updateSharedKeyList()
|
||||||
{
|
{
|
||||||
updateModel();
|
updateModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replaces a key and the created timestamp for it
|
||||||
|
void DatabaseSettingsWidgetBrowser::replaceKey(const QString& prefix,
|
||||||
|
const QString& oldName,
|
||||||
|
const QString& newName) const
|
||||||
|
{
|
||||||
|
const auto oldKey = getKeyWithPrefix(prefix, oldName);
|
||||||
|
const auto newKey = getKeyWithPrefix(prefix, newName);
|
||||||
|
const auto tempValue = customData()->value(oldKey);
|
||||||
|
m_db->metadata()->customData()->remove(oldKey);
|
||||||
|
m_db->metadata()->customData()->set(newKey, tempValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DatabaseSettingsWidgetBrowser::getKeyWithPrefix(const QString& prefix, const QString& key) const
|
||||||
|
{
|
||||||
|
return QString("%1%2").arg(prefix, key);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
|
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
|
||||||
* Copyright (C) 2018 Sami Vänttinen <sami.vanttinen@protonmail.com>
|
* Copyright (C) 2018 Sami Vänttinen <sami.vanttinen@protonmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -62,6 +62,8 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void updateModel();
|
void updateModel();
|
||||||
void settingsWarning();
|
void settingsWarning();
|
||||||
|
void replaceKey(const QString& prefix, const QString& oldName, const QString& newName) const;
|
||||||
|
QString getKeyWithPrefix(const QString& prefix, const QString& key) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent* event) override;
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue