mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-27 20:36:49 -08:00
Add auto-save delay per database (#9100)
Add a new propery autosaveDelay in Metadata of the db. The property is saved in customData to not affect database structure as this setting is unique to keepasxc. The propery sets delay to wait since last modification before saving. Co-authored-by: jNullj <[email protected]>
This commit is contained in:
1 parent
a0874a0d6d
commit
35baeaff79
10 files changed
+272
-6
No files matched your search
+29
-3
@@ -28,10 +28,17 @@
|
||||
|
||||
const int Metadata::DefaultHistoryMaxItems = 10;
|
||||
const int Metadata::DefaultHistoryMaxSize = 6 * 1024 * 1024;
|
||||
const int Metadata::DefaultAutosaveDelayMin = 0;
|
||||
|
||||
// Fallback icon for return by reference
|
||||
static const Metadata::CustomIconData NULL_ICON{};
|
||||
|
||||
namespace customDataKeys
|
||||
{
|
||||
static const QString savedSearch = QStringLiteral("KPXC_SavedSearch");
|
||||
static const QString autosaveDelay = QStringLiteral("KPXC_autosaveDelayMin");
|
||||
}; // namespace customDataKeys
|
||||
|
||||
Metadata::Metadata(QObject* parent)
|
||||
: ModifiableObject(parent)
|
||||
, m_customData(new CustomData(this))
|
||||
@@ -265,6 +272,19 @@ int Metadata::historyMaxSize() const
|
||||
return m_data.historyMaxSize;
|
||||
}
|
||||
|
||||
int Metadata::autosaveDelayMin() const
|
||||
{
|
||||
QString autosaveDelayMinStr = m_customData->value(customDataKeys::autosaveDelay);
|
||||
if (autosaveDelayMinStr.isNull()) {
|
||||
// data is not set yet, use default
|
||||
return Metadata::DefaultAutosaveDelayMin;
|
||||
}
|
||||
bool ok; // check for QString to int op failuer
|
||||
int autosaveDelayMin = autosaveDelayMinStr.toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
return autosaveDelayMin;
|
||||
}
|
||||
|
||||
CustomData* Metadata::customData()
|
||||
{
|
||||
return m_customData;
|
||||
@@ -478,6 +498,12 @@ void Metadata::setHistoryMaxSize(int value)
|
||||
set(m_data.historyMaxSize, value);
|
||||
}
|
||||
|
||||
void Metadata::setAutosaveDelayMin(int value)
|
||||
{
|
||||
Q_ASSERT(value >= 0 && value <= 420000000);
|
||||
m_customData->set(customDataKeys::autosaveDelay, QString::number(value));
|
||||
}
|
||||
|
||||
QDateTime Metadata::settingsChanged() const
|
||||
{
|
||||
return m_settingsChanged;
|
||||
@@ -494,7 +520,7 @@ void Metadata::addSavedSearch(const QString& name, const QString& searchtext)
|
||||
auto searches = savedSearches();
|
||||
searches.insert(name, searchtext);
|
||||
auto json = QJsonDocument::fromVariant(searches);
|
||||
m_customData->set("KPXC_SavedSearch", json.toJson());
|
||||
m_customData->set(customDataKeys::savedSearch, json.toJson());
|
||||
}
|
||||
|
||||
void Metadata::deleteSavedSearch(const QString& name)
|
||||
@@ -502,12 +528,12 @@ void Metadata::deleteSavedSearch(const QString& name)
|
||||
auto searches = savedSearches();
|
||||
searches.remove(name);
|
||||
auto json = QJsonDocument::fromVariant(searches);
|
||||
m_customData->set("KPXC_SavedSearch", json.toJson());
|
||||
m_customData->set(customDataKeys::savedSearch, json.toJson());
|
||||
}
|
||||
|
||||
QVariantMap Metadata::savedSearches()
|
||||
{
|
||||
auto searches = m_customData->value("KPXC_SavedSearch");
|
||||
auto searches = m_customData->value(customDataKeys::savedSearch);
|
||||
auto json = QJsonDocument::fromJson(searches.toUtf8());
|
||||
return json.toVariant().toMap();
|
||||
}
|
||||
Reference in new issue
Block a user