summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppfilesettingspage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools/cppfilesettingspage.cpp')
-rw-r--r--src/plugins/cpptools/cppfilesettingspage.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp
index f0af6904cc..f6766dbd76 100644
--- a/src/plugins/cpptools/cppfilesettingspage.cpp
+++ b/src/plugins/cpptools/cppfilesettingspage.cpp
@@ -145,28 +145,26 @@ bool CppFileSettings::equals(const CppFileSettings &rhs) const
// Replacements of special license template keywords.
static bool keyWordReplacement(const QString &keyWord,
- const QString &file,
- const QString &className,
QString *value)
{
if (keyWord == QLatin1String("%YEAR%")) {
- *value = QString::number(QDate::currentDate().year());
+ *value = QLatin1String("%{CurrentDate:yyyy}");
return true;
}
if (keyWord == QLatin1String("%MONTH%")) {
- *value = QString::number(QDate::currentDate().month());
+ *value = QLatin1String("%{CurrentDate:M}");
return true;
}
if (keyWord == QLatin1String("%DAY%")) {
- *value = QString::number(QDate::currentDate().day());
+ *value = QLatin1String("%{CurrentDate:d}");
return true;
}
if (keyWord == QLatin1String("%CLASS%")) {
- *value = className;
+ *value = QLatin1String("%{Cpp:License:ClassName}");
return true;
}
if (keyWord == QLatin1String("%FILENAME%")) {
- *value = Utils::FileName::fromString(file).fileName();
+ *value = QLatin1String("%{Cpp:License:FileName}");
return true;
}
if (keyWord == QLatin1String("%DATE%")) {
@@ -179,17 +177,17 @@ static bool keyWordReplacement(const QString &keyWord,
if (format.count(ypsilon) == 2)
format.insert(format.indexOf(ypsilon), QString(2, ypsilon));
}
- *value = QDate::currentDate().toString(format);
+ *value = QString::fromLatin1("%{CurrentDate:") + format + QLatin1Char('}');
return true;
}
if (keyWord == QLatin1String("%USER%")) {
- *value = Utils::Environment::systemEnvironment().userName();
+ *value = QLatin1String("%{Env:USER}");
return true;
}
// Environment variables (for example '%$EMAIL%').
if (keyWord.startsWith(QLatin1String("%$"))) {
const QString varName = keyWord.mid(2, keyWord.size() - 3);
- *value = QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit()));
+ *value = QString::fromLatin1("%{Env:") + varName + QLatin1Char('}');
return true;
}
return false;
@@ -197,10 +195,11 @@ static bool keyWordReplacement(const QString &keyWord,
// Parse a license template, scan for %KEYWORD% and replace if known.
// Replace '%%' by '%'.
-static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, const QString &className)
+static void parseLicenseTemplatePlaceholders(QString *t)
{
int pos = 0;
const QChar placeHolder = QLatin1Char('%');
+ bool isCompatibilityStyle = false;
do {
const int placeHolderPos = t->indexOf(placeHolder, pos);
if (placeHolderPos == -1)
@@ -214,7 +213,8 @@ static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, co
} else {
const QString keyWord = t->mid(placeHolderPos, endPlaceHolderPos + 1 - placeHolderPos);
QString replacement;
- if (keyWordReplacement(keyWord, file, className, &replacement)) {
+ if (keyWordReplacement(keyWord, &replacement)) {
+ isCompatibilityStyle = true;
t->replace(placeHolderPos, keyWord.size(), replacement);
pos = placeHolderPos + replacement.size();
} else {
@@ -223,12 +223,14 @@ static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, co
}
}
} while (pos < t->size());
+
+ if (isCompatibilityStyle)
+ t->replace(QLatin1Char('\\'), QLatin1String("\\\\"));
}
// Convenience that returns the formatted license template.
-QString CppFileSettings::licenseTemplate(const QString &fileName, const QString &className)
+QString CppFileSettings::licenseTemplate()
{
-
const QSettings *s = Core::ICore::settings();
QString key = QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP);
key += QLatin1Char('/');
@@ -247,7 +249,7 @@ QString CppFileSettings::licenseTemplate(const QString &fileName, const QString
licenseStream.setAutoDetectUnicode(true);
QString license = licenseStream.readAll();
- parseLicenseTemplatePlaceholders(&license, fileName, className);
+ parseLicenseTemplatePlaceholders(&license);
// Ensure at least one newline at the end of the license template to separate it from the code
const QChar newLine = QLatin1Char('\n');