mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-06 21:44:32 -04:00
Add DateTime placeholders to AutoType feature (#4409)
This commit is contained in:
parent
e6c2c7ed93
commit
5927b6298d
3 changed files with 105 additions and 3 deletions
|
@ -684,7 +684,7 @@ bool AutoType::checkSyntax(const QString& string)
|
||||||
QString allowRepetition = "(?:\\s\\d+)?";
|
QString allowRepetition = "(?:\\s\\d+)?";
|
||||||
// the ":" allows custom commands with syntax S:Field
|
// the ":" allows custom commands with syntax S:Field
|
||||||
// exclude BEEP otherwise will be checked as valid
|
// exclude BEEP otherwise will be checked as valid
|
||||||
QString normalCommands = "(?!BEEP\\s)[A-Z:]*" + allowRepetition;
|
QString normalCommands = "(?!BEEP\\s)[A-Z:_]*" + allowRepetition;
|
||||||
QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+]" + allowRepetition;
|
QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+]" + allowRepetition;
|
||||||
QString functionKeys = "(?:F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition;
|
QString functionKeys = "(?:F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition;
|
||||||
QString numpad = "NUMPAD\\d" + allowRepetition;
|
QString numpad = "NUMPAD\\d" + allowRepetition;
|
||||||
|
|
|
@ -916,11 +916,84 @@ QString Entry::resolvePlaceholderRecursive(const QString& placeholder, int maxDe
|
||||||
}
|
}
|
||||||
case PlaceholderType::Reference:
|
case PlaceholderType::Reference:
|
||||||
return resolveReferencePlaceholderRecursive(placeholder, maxDepth);
|
return resolveReferencePlaceholderRecursive(placeholder, maxDepth);
|
||||||
|
case PlaceholderType::DateTimeSimple:
|
||||||
|
case PlaceholderType::DateTimeYear:
|
||||||
|
case PlaceholderType::DateTimeMonth:
|
||||||
|
case PlaceholderType::DateTimeDay:
|
||||||
|
case PlaceholderType::DateTimeHour:
|
||||||
|
case PlaceholderType::DateTimeMinute:
|
||||||
|
case PlaceholderType::DateTimeSecond:
|
||||||
|
case PlaceholderType::DateTimeUtcSimple:
|
||||||
|
case PlaceholderType::DateTimeUtcYear:
|
||||||
|
case PlaceholderType::DateTimeUtcMonth:
|
||||||
|
case PlaceholderType::DateTimeUtcDay:
|
||||||
|
case PlaceholderType::DateTimeUtcHour:
|
||||||
|
case PlaceholderType::DateTimeUtcMinute:
|
||||||
|
case PlaceholderType::DateTimeUtcSecond:
|
||||||
|
return resolveMultiplePlaceholdersRecursive(resolveDateTimePlaceholder(typeOfPlaceholder), maxDepth - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return placeholder;
|
return placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Entry::resolveDateTimePlaceholder(Entry::PlaceholderType placeholderType) const
|
||||||
|
{
|
||||||
|
QDateTime time = Clock::currentDateTime();
|
||||||
|
QDateTime time_utc = Clock::currentDateTimeUtc();
|
||||||
|
QString date_formatted{};
|
||||||
|
|
||||||
|
switch (placeholderType) {
|
||||||
|
case PlaceholderType::DateTimeSimple:
|
||||||
|
date_formatted = time.toString("yyyyMMddhhmmss");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeYear:
|
||||||
|
date_formatted = time.toString("yyyy");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeMonth:
|
||||||
|
date_formatted = time.toString("MM");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeDay:
|
||||||
|
date_formatted = time.toString("dd");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeHour:
|
||||||
|
date_formatted = time.toString("hh");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeMinute:
|
||||||
|
date_formatted = time.toString("mm");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeSecond:
|
||||||
|
date_formatted = time.toString("ss");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcSimple:
|
||||||
|
date_formatted = time_utc.toString("yyyyMMddhhmmss");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcYear:
|
||||||
|
date_formatted = time_utc.toString("yyyy");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcMonth:
|
||||||
|
date_formatted = time_utc.toString("MM");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcDay:
|
||||||
|
date_formatted = time_utc.toString("dd");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcHour:
|
||||||
|
date_formatted = time_utc.toString("hh");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcMinute:
|
||||||
|
date_formatted = time_utc.toString("mm");
|
||||||
|
break;
|
||||||
|
case PlaceholderType::DateTimeUtcSecond:
|
||||||
|
date_formatted = time_utc.toString("ss");
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
Q_ASSERT_X(false, "Entry::resolveDateTimePlaceholder", "Bad DateTime placeholder type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return date_formatted;
|
||||||
|
}
|
||||||
|
|
||||||
QString Entry::resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const
|
QString Entry::resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const
|
||||||
{
|
{
|
||||||
if (maxDepth <= 0) {
|
if (maxDepth <= 0) {
|
||||||
|
@ -1141,7 +1214,21 @@ Entry::PlaceholderType Entry::placeholderType(const QString& placeholder) const
|
||||||
{QStringLiteral("{URL:FRAGMENT}"), PlaceholderType::UrlFragment},
|
{QStringLiteral("{URL:FRAGMENT}"), PlaceholderType::UrlFragment},
|
||||||
{QStringLiteral("{URL:USERINFO}"), PlaceholderType::UrlUserInfo},
|
{QStringLiteral("{URL:USERINFO}"), PlaceholderType::UrlUserInfo},
|
||||||
{QStringLiteral("{URL:USERNAME}"), PlaceholderType::UrlUserName},
|
{QStringLiteral("{URL:USERNAME}"), PlaceholderType::UrlUserName},
|
||||||
{QStringLiteral("{URL:PASSWORD}"), PlaceholderType::UrlPassword}};
|
{QStringLiteral("{URL:PASSWORD}"), PlaceholderType::UrlPassword},
|
||||||
|
{QStringLiteral("{DT_SIMPLE}"), PlaceholderType::DateTimeSimple},
|
||||||
|
{QStringLiteral("{DT_YEAR}"), PlaceholderType::DateTimeYear},
|
||||||
|
{QStringLiteral("{DT_MONTH}"), PlaceholderType::DateTimeMonth},
|
||||||
|
{QStringLiteral("{DT_DAY}"), PlaceholderType::DateTimeDay},
|
||||||
|
{QStringLiteral("{DT_HOUR}"), PlaceholderType::DateTimeHour},
|
||||||
|
{QStringLiteral("{DT_MINUTE}"), PlaceholderType::DateTimeMinute},
|
||||||
|
{QStringLiteral("{DT_SECOND}"), PlaceholderType::DateTimeSecond},
|
||||||
|
{QStringLiteral("{DT_UTC_SIMPLE}"), PlaceholderType::DateTimeUtcSimple},
|
||||||
|
{QStringLiteral("{DT_UTC_YEAR}"), PlaceholderType::DateTimeUtcYear},
|
||||||
|
{QStringLiteral("{DT_UTC_MONTH}"), PlaceholderType::DateTimeUtcMonth},
|
||||||
|
{QStringLiteral("{DT_UTC_DAY}"), PlaceholderType::DateTimeUtcDay},
|
||||||
|
{QStringLiteral("{DT_UTC_HOUR}"), PlaceholderType::DateTimeUtcHour},
|
||||||
|
{QStringLiteral("{DT_UTC_MINUTE}"), PlaceholderType::DateTimeUtcMinute},
|
||||||
|
{QStringLiteral("{DT_UTC_SECOND}"), PlaceholderType::DateTimeUtcSecond}};
|
||||||
|
|
||||||
return placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown);
|
return placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown);
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,21 @@ public:
|
||||||
UrlUserName,
|
UrlUserName,
|
||||||
UrlPassword,
|
UrlPassword,
|
||||||
Reference,
|
Reference,
|
||||||
CustomAttribute
|
CustomAttribute,
|
||||||
|
DateTimeSimple,
|
||||||
|
DateTimeYear,
|
||||||
|
DateTimeMonth,
|
||||||
|
DateTimeDay,
|
||||||
|
DateTimeHour,
|
||||||
|
DateTimeMinute,
|
||||||
|
DateTimeSecond,
|
||||||
|
DateTimeUtcSimple,
|
||||||
|
DateTimeUtcYear,
|
||||||
|
DateTimeUtcMonth,
|
||||||
|
DateTimeUtcDay,
|
||||||
|
DateTimeUtcHour,
|
||||||
|
DateTimeUtcMinute,
|
||||||
|
DateTimeUtcSecond
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,6 +220,7 @@ public:
|
||||||
QString resolveMultiplePlaceholders(const QString& str) const;
|
QString resolveMultiplePlaceholders(const QString& str) const;
|
||||||
QString resolvePlaceholder(const QString& str) const;
|
QString resolvePlaceholder(const QString& str) const;
|
||||||
QString resolveUrlPlaceholder(const QString& str, PlaceholderType placeholderType) const;
|
QString resolveUrlPlaceholder(const QString& str, PlaceholderType placeholderType) const;
|
||||||
|
QString resolveDateTimePlaceholder(PlaceholderType placeholderType) const;
|
||||||
PlaceholderType placeholderType(const QString& placeholder) const;
|
PlaceholderType placeholderType(const QString& placeholder) const;
|
||||||
QString resolveUrl(const QString& url) const;
|
QString resolveUrl(const QString& url) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue