Commit 62c585df authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

some ProWriter API cleanup

detach the special handling of files from generic values
parent 846e4d3d
......@@ -266,7 +266,7 @@ void S60PublisherOvi::updateProFile(const QString &var, const QString &values)
//todo: after ossi has added scope profile writing, make sure the following works
//QString scope("symbian");
ProWriter::addVarValues(profile, &lines, m_qt4project->rootProjectNode()->path(), QStringList() << values, var);
ProWriter::addVarValues(profile, &lines, QStringList() << values, var);
if (qfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
qfile.write(lines.join("\n").toLocal8Bit());
......
......@@ -175,17 +175,8 @@ static const ushort *skipToken(ushort tok, const ushort *&tokPtr, int &lineNo)
}
void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QString &var,
bool valuesAreFiles)
const QStringList &values, const QString &var)
{
QStringList valuesToWrite;
if (valuesAreFiles) {
foreach (const QString &v, values)
valuesToWrite << proFileDir.relativeFilePath(v);
} else {
valuesToWrite = values;
}
// Check if variable item exists as child of root item
const ushort *tokPtr = profile->tokPtr();
int lineNo = 0;
......@@ -213,7 +204,7 @@ void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
}
}
QString added;
foreach (const QString &v, valuesToWrite)
foreach (const QString &v, values)
added += QLatin1String(" ") + v + QLatin1String(" \\\n");
added.chop(3);
lines->insert(lineNo, added);
......@@ -227,11 +218,21 @@ void ProWriter::addVarValues(ProFile *profile, QStringList *lines,
// Create & append new variable item
QString added = QLatin1Char('\n') + var + QLatin1String(" +=");
foreach (const QString &v, valuesToWrite)
foreach (const QString &v, values)
added += QLatin1String(" \\\n ") + v;
*lines << added;
}
void ProWriter::addFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QString &var)
{
QStringList valuesToWrite;
foreach (const QString &v, values)
valuesToWrite << proFileDir.relativeFilePath(v);
addVarValues(profile, lines, valuesToWrite, var);
}
static void findProVariables(const ushort *tokPtr, const QStringList &vars,
QList<int> *proVars, const uint firstLine = 0)
{
......@@ -256,25 +257,17 @@ static void findProVariables(const ushort *tokPtr, const QStringList &vars,
}
}
QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QStringList &vars,
bool valuesAreFiles)
QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
const QStringList &values, const QStringList &vars)
{
QStringList notChanged = values;
QList<int> notChanged;
// yeah, this is a bit silly
for (int i = 0; i < values.size(); i++)
notChanged << i;
QList<int> varLines;
findProVariables(profile->tokPtr(), vars, &varLines);
QStringList valuesToFind;
if (valuesAreFiles) {
// This is a tad stupid - basically, it can remove only entries which
// the above code added.
foreach (const QString &absoluteFilePath, values)
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
} else {
valuesToFind = values;
}
// This code expects proVars to be sorted by the variables' appearance in the file.
int delta = 1;
foreach (int ln, varLines) {
......@@ -326,9 +319,9 @@ QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
colNo++;
}
const QString fn = line.mid(varCol, colNo - varCol);
const int pos = valuesToFind.indexOf(fn);
const int pos = values.indexOf(fn);
if (pos != -1) {
notChanged.removeOne(values.at(pos));
notChanged.removeOne(pos);
if (colNo < lineLen)
colNo++;
else if (varCol)
......@@ -380,3 +373,18 @@ QStringList ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
}
return notChanged;
}
QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QStringList &vars)
{
// This is a tad stupid - basically, it can remove only entries which
// the above code added.
QStringList valuesToFind;
foreach (const QString &absoluteFilePath, values)
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
QStringList notChanged;
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
notChanged.append(values.at(i));
return notChanged;
}
......@@ -49,41 +49,15 @@ namespace Internal {
class ProWriter
{
public:
static void addFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths, const QString &var)
{
addVarValues(profile, lines, proFileDir, filePaths, var, true);
}
static QStringList removeFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths,
const QStringList &vars)
{
return removeVarValues(profile, lines, proFileDir, filePaths, vars, true);
}
static void addVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QString &var)
{
addVarValues(profile, lines, proFileDir, values, var, false);
}
static QStringList removeVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values,
const QStringList &vars)
{
return removeVarValues(profile, lines, proFileDir, values, vars, false);
}
private:
static void addVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QString &var,
bool valuesAreFiles);
const QStringList &values, const QString &var);
static QList<int> removeVarValues(ProFile *profile, QStringList *lines,
const QStringList &values, const QStringList &vars);
static QStringList removeVarValues(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values,
const QStringList &vars, bool valuesAreFiles);
static void addFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths, const QString &var);
static QStringList removeFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths, const QStringList &vars);
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment